Design Tokens
Design tokens are the foundational values that define your app's visual language. PrettyUI provides a comprehensive token system for colors, spacing, border radius, shadows, and typography.
Color Tokens
Color tokens define your app's color palette. Each token has a specific semantic purpose.
Primary & Secondary
Token Purpose primaryMain brand color for CTAs, links, active states primaryForegroundText/icon color on primary backgrounds secondarySecondary actions, less prominent elements secondaryForegroundText/icon color on secondary backgrounds accentHighlights, emphasis, decorative elements accentForegroundText/icon color on accent backgrounds
Semantic Colors
Token Purpose destructiveDestructive actions (delete, remove, errors) destructiveForegroundText on destructive backgrounds successSuccess states, confirmations successForegroundText on success backgrounds warningWarning states, cautions warningForegroundText on warning backgrounds
Background & Surface
Token Purpose backgroundMain page background foregroundPrimary text color mutedSubtle backgrounds (cards, inputs) mutedForegroundSecondary/muted text cardCard and surface backgrounds cardForegroundText on card backgrounds
Border & Focus
Token Purpose borderDefault border color inputInput field borders ringFocus ring color
Usage Example
struct MyView : View {
@Environment (\.prettyTheme) private var theme
@Environment (\.colorScheme) private var colorScheme
var body: some View {
let colors = theme.colors(for: colorScheme)
VStack {
Text ("Hello" )
.foregroundColor(colors.foreground)
Button ("Action" ) { }
.background(colors.primary)
.foregroundColor(colors.primaryForeground)
}
.background(colors.background)
}
}
Spacing Tokens
Spacing tokens provide a consistent scale for padding, margins, and gaps.
Token Value Usage xxs2pt Micro spacing, icon gaps xs4pt Tight spacing, small gaps sm8pt Compact layouts, list items md16pt Default spacing, card padding lg24pt Section spacing, generous padding xl32pt Large gaps, section dividers xxl48pt Extra large spacing xxxl64pt Maximum spacing, hero sections
Usage Example
VStack (spacing: theme.spacing.md) {
Text ("Title" )
.padding(.horizontal, theme.spacing.lg)
Text ("Subtitle" )
.padding(.bottom, theme.spacing.xl)
}
.padding(theme.spacing.md)
Custom Spacing
Use .custom(_:) for one-off values:
.padding(.horizontal, theme.spacing[.custom(20 )])
Radius Tokens
Border radius tokens ensure consistent rounded corners across your app.
Token Value Usage none0pt Sharp corners sm6pt Small chips, tags, badges md10pt Inputs, small buttons lg14pt Standard cards, modals xl20pt Large cards, images xxl28pt Sheets, large modals full9999pt Pills, avatars, circular buttons
Usage Example
RoundedRectangle (cornerRadius: theme.radius.lg)
.fill(colors.card)
Text ("Tag" )
.padding(.horizontal, theme.spacing.sm)
.background(colors.muted)
.clipShape(RoundedRectangle (cornerRadius: theme.radius[.sm]))
Shadow Tokens
Shadow tokens create consistent elevation and depth.
Token Radius Y-Offset Opacity Usage none0pt 0pt 0% No shadow sm4pt 2pt 4% Cards at rest md12pt 4pt 8% Cards on hover, tooltips lg20pt 8pt 10% Floating elements xl32pt 12pt 12% Modals, sheets xxl48pt 16pt 16% Popovers, dropdowns
Usage Example
Card ()
.prettyShadow(theme.shadows.md)
Card ()
.shadow(
color: theme.shadows.lg.color,
radius: theme.shadows.lg.radius,
x: theme.shadows.lg.x,
y: theme.shadows.lg.y
)
Custom Shadows
let customShadow = ShadowStyle (
color: Color .blue.opacity(0.2 ),
radius: 16 ,
x: 0 ,
y: 8
)
Card ()
.prettyShadow(customShadow)
Typography Tokens
Typography tokens define your app's text styling system.
Font Sizes
Token Size Usage xs12pt Captions, fine print sm14pt Secondary text, labels base16pt Body text (default) lg18pt Emphasized body text xl20pt Subtitles xxl24pt Section titles xxxl30pt Page titles display36pt Hero headlines
Font Weights
Token Weight thin100 light300 regular400 medium500 semibold600 bold700 heavy800
Line Heights
Token Multiplier Usage tight1.25 Headlines, compact text normal1.5 Body text relaxed1.75 Comfortable reading loose2.0 Maximum readability
Letter Spacing
Token Value Usage tighter-0.8pt Tight headlines tight-0.4pt Headlines normal0pt Body text wide0.4pt All caps text wider0.8pt Spaced text widest1.6pt Maximum spacing
Usage Example
Text ("Headline" )
.font(.system(size: theme.typography.sizes.xxl))
.fontWeight(theme.typography.weights.bold)
.tracking(theme.typography.letterSpacing.tight)
Customizing Tokens
You can customize any token set when creating a custom theme:
extension PrettyTheme {
static let compact = PrettyTheme (
spacing: SpacingTokens (
xxs: 1 ,
xs: 2 ,
sm: 4 ,
md: 8 ,
lg: 12 ,
xl: 16 ,
xxl: 24 ,
xxxl: 32
),
radius: RadiusTokens (
none: 0 ,
sm: 4 ,
md: 6 ,
lg: 8 ,
xl: 12 ,
xxl: 16 ,
full: 9999
)
)
}
Best Practices
Use semantic tokens — Prefer colors.primary over hardcoded colors
Stick to the scale — Use existing tokens instead of arbitrary values
Be consistent — Use the same spacing token for similar elements
Use .custom() sparingly — Only for genuinely unique one-off values
Access tokens from theme — Always read from theme.spacing, theme.radius, etc.
Next Button