取材自 Primer 設計系統:中性灰階、綠色主要按鈕與藍色連結,資訊密度高且易讀。
Preview
使用 GitHub token 打造的範例元件。
Card
radius-lg · shadow-md
background
#ffffff
foreground
#1f2328
gray-100
#f6f8fa
gray-200
#eaeef2
gray-400
#afb8c1
gray-600
#656d76
gray-900
#1f2328
border
#d0d7de
primary
#1f883d
primary-foreground
#ffffff
accent
#0969da
success
#1a7f37
warning
#9a6700
error
#d1242f
// =============================================
// GitHub Style Tokens — _tokens.scss
// 實用清晰・開源社群
// =============================================
// ---------- Colors ----------
$color-background: #ffffff;
$color-foreground: #1f2328;
$color-gray-100: #f6f8fa;
$color-gray-200: #eaeef2;
$color-gray-400: #afb8c1;
$color-gray-600: #656d76;
$color-gray-900: #1f2328;
$color-border: #d0d7de;
$color-primary: #1f883d;
$color-primary-foreground: #ffffff;
$color-accent: #0969da;
$color-success: #1a7f37;
$color-warning: #9a6700;
$color-error: #d1242f;
// ---------- Typography ----------
$font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
$font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
$font-size-xs: 12px;
$font-size-sm: 14px;
$font-size-base: 16px;
$font-size-lg: 20px;
$font-size-xl: 24px;
$font-size-2xl: 32px;
$font-size-3xl: 40px;
$font-weight-regular: 400;
$font-weight-medium: 500;
$font-weight-semibold: 600;
$font-weight-bold: 700;
// ---------- Radius ----------
$radius-sm: 3px;
$radius-md: 6px;
$radius-lg: 8px;
$radius-xl: 12px;
$radius-full: 9999px;
// ---------- Spacing ----------
$space-0: 0;
$space-1: 4px;
$space-2: 8px;
$space-3: 12px;
$space-4: 16px;
$space-5: 24px;
$space-6: 32px;
$space-7: 48px;
$space-8: 64px;
// ---------- Shadows ----------
$shadow-sm: 0 1px 0 rgba(31, 35, 40, 0.04);
$shadow-md: 0 3px 6px rgba(140, 149, 159, 0.15);
$shadow-lg: 0 8px 24px rgba(140, 149, 159, 0.2);
// ---------- Motion ----------
$duration: 80ms;
$easing: cubic-bezier(0.33, 1, 0.68, 1);
// ---------- Maps ----------
$colors: (
"background": $color-background,
"foreground": $color-foreground,
"gray-100": $color-gray-100,
"gray-200": $color-gray-200,
"gray-400": $color-gray-400,
"gray-600": $color-gray-600,
"gray-900": $color-gray-900,
"border": $color-border,
"primary": $color-primary,
"primary-foreground": $color-primary-foreground,
"accent": $color-accent,
"success": $color-success,
"warning": $color-warning,
"error": $color-error,
);
$font-sizes: (
"xs": $font-size-xs,
"sm": $font-size-sm,
"base": $font-size-base,
"lg": $font-size-lg,
"xl": $font-size-xl,
"2xl": $font-size-2xl,
"3xl": $font-size-3xl,
);
$radii: (
"sm": $radius-sm,
"md": $radius-md,
"lg": $radius-lg,
"xl": $radius-xl,
"full": $radius-full,
);
$spaces: (
"0": $space-0,
"1": $space-1,
"2": $space-2,
"3": $space-3,
"4": $space-4,
"5": $space-5,
"6": $space-6,
"7": $space-7,
"8": $space-8,
);
$shadows: (
"sm": $shadow-sm,
"md": $shadow-md,
"lg": $shadow-lg,
);
// ---------- Helpers ----------
@function color($name) {
@return map-get($colors, $name);
}
@function space($step) {
@return map-get($spaces, $step);
}
// 將所有 token 輸出為 CSS 自訂屬性
:root {
@each $name, $value in $colors {
--color-#{$name}: #{$value};
}
@each $name, $value in $font-sizes {
--font-size-#{$name}: #{$value};
}
@each $name, $value in $radii {
--radius-#{$name}: #{$value};
}
@each $name, $value in $spaces {
--space-#{$name}: #{$value};
}
@each $name, $value in $shadows {
--shadow-#{$name}: #{$value};
}
--font-sans: #{$font-sans};
--font-mono: #{$font-mono};
}
// ---------- Mixins ----------
@mixin button-primary {
display: inline-flex;
align-items: center;
gap: $space-2;
padding: $space-2 $space-4;
font-family: $font-sans;
font-size: $font-size-sm;
font-weight: $font-weight-medium;
color: $color-primary-foreground;
background: $color-primary;
border: 0;
border-radius: $radius-md;
transition: opacity $duration $easing;
&:hover {
opacity: 0.85;
}
}
@mixin card {
padding: $space-5;
background: $color-background;
border: 1px solid $color-border;
border-radius: $radius-lg;
box-shadow: $shadow-sm;
}