Skip to content

Commit 4832eb3

Browse files
committed
refactor: encourage semantic tokens
1 parent 281c89e commit 4832eb3

File tree

5 files changed

+30
-34
lines changed

5 files changed

+30
-34
lines changed

layouts/component.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default function ComponentDocsLayout({ children, frontmatter }) {
5151
borderBottom='2px solid transparent'
5252
data-selected={item.match ? '' : undefined}
5353
_selected={{
54-
color: 'brand',
54+
color: 'accent',
5555
borderColor: 'currentColor',
5656
}}
5757
>

src/components/sidebar/sidebar-category.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function SidebarCategory(props: SidebarCategoryProps) {
6161
alignItems='center'
6262
justifyContent='space-between'
6363
userSelect='none'
64-
color='brand'
64+
color='accent'
6565
>
6666
{title}
6767
</chakra.p>

src/components/sidebar/sidebar-link.tsx

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PropsOf, chakra, useColorModeValue } from '@chakra-ui/react'
1+
import { PropsOf, chakra, useColorModeValue, Flex } from '@chakra-ui/react'
22
import NextLink from 'next/link'
33
import { useRouter } from 'next/router'
44
import { forwardRef, Ref, useEffect, useRef } from 'react'
@@ -23,7 +23,7 @@ const StyledLink = forwardRef(function StyledLink(
2323
transition='all 0.2s'
2424
_activeLink={{
2525
bg: useColorModeValue('teal.50', 'rgba(48, 140, 122, 0.3)'),
26-
color: useColorModeValue('teal.700', 'teal.200'),
26+
color: 'accent-emphasis',
2727
fontWeight: '600',
2828
}}
2929
{...rest}
@@ -56,19 +56,13 @@ const SidebarLink = ({ href, children, ...rest }: SidebarLinkProps) => {
5656
}, [isActive, router.query])
5757

5858
return (
59-
<chakra.div
60-
userSelect='none'
61-
display='flex'
62-
alignItems='center'
63-
lineHeight='1.5rem'
64-
{...rest}
65-
>
59+
<Flex align='center' userSelect='none' lineHeight='tall' {...rest}>
6660
<NextLink href={href} passHref>
6761
<StyledLink isActive={isActive} ref={link}>
6862
{children}
6963
</StyledLink>
7064
</NextLink>
71-
</chakra.div>
65+
</Flex>
7266
)
7367
}
7468

src/components/sidebar/sidebar.tsx

+6-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
ListItem,
88
ListProps,
99
chakra,
10-
useColorModeValue,
1110
} from '@chakra-ui/react'
1211
import sortBy from 'lodash/sortBy'
1312
import NextLink from 'next/link'
@@ -23,7 +22,6 @@ import { Routes } from 'utils/get-route-context'
2322

2423
export type SidebarContentProps = Routes & {
2524
pathname?: string
26-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2725
contentRef?: any
2826
}
2927

@@ -48,11 +46,9 @@ export function SidebarContent({
4846
<chakra.h4
4947
fontSize='sm'
5048
fontWeight='bold'
51-
my='1.25rem'
49+
my='4'
5250
textTransform='uppercase'
5351
letterSpacing='wider'
54-
color='gray.700'
55-
_dark={{ color: 'inherit' }}
5652
>
5753
{lvl1.title}
5854
</chakra.h4>
@@ -119,21 +115,18 @@ export const isMainNavLinkActive = (href: string, path: string) => {
119115
const MainNavLink = ({ href, icon, children }: MainNavLinkProps) => {
120116
const { asPath } = useRouter()
121117
const active = isMainNavLinkActive(href, asPath)
122-
const linkColor = useColorModeValue('gray.900', 'whiteAlpha.900')
123118

124119
return (
125120
<NextLink href={href} passHref>
126121
<Flex
127122
as='a'
128123
align='center'
129124
fontSize='sm'
130-
fontWeight='semibold'
131-
transitionProperty='colors'
132-
transitionDuration='200ms'
133-
color={active ? linkColor : 'gray.500'}
134-
_hover={{ color: linkColor }}
125+
fontWeight={active ? 'semibold' : 'medium'}
126+
color={active ? 'accent' : 'fg-muted'}
127+
_hover={{ color: active ? undefined : 'fg' }}
135128
>
136-
<Center w='6' h='6' bg='teal.500' rounded='base' mr='3'>
129+
<Center w='6' h='6' bg='accent-static' rounded='base' mr='3'>
137130
{icon}
138131
</Center>
139132
{children}
@@ -155,7 +148,7 @@ export const mainNavLinks = [
155148
},
156149
{
157150
icon: <DocsIcon />,
158-
href: '/docs/components/overview',
151+
href: '/docs/components',
159152
label: 'Components',
160153
},
161154
{

theme.ts

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
import { extendTheme } from '@chakra-ui/react'
2-
import { mode } from '@chakra-ui/theme-tools'
32

43
const customTheme = extendTheme({
54
config: {},
65
semanticTokens: {
76
colors: {
8-
brand: {
9-
default: 'teal.500',
10-
_dark: 'teal.200',
11-
},
7+
// accent semantic tokens
8+
accent: { default: 'teal.500', _dark: 'teal.300' },
9+
'accent-emphasis': { default: 'teal.700', _dark: 'teal.200' },
10+
'accent-static': 'teal.500',
11+
'accent-muted': { default: 'teal.300', _dark: 'teal.200' },
12+
'accent-subtle': { default: 'teal.50', _dark: 'teal.800' },
13+
// foreground semantic tokens
14+
fg: { default: 'gray.700', _dark: 'gray.100' },
15+
'fg-emphasis': { default: 'gray.900', _dark: 'gray.200' },
16+
'fg-muted': { default: 'gray.600', _dark: 'gray.400' },
17+
'fg-subtle': { default: 'gray.500', _dark: 'gray.300' },
18+
'fg-on-accent': { default: 'white', _dark: 'inherit' },
1219
},
1320
},
1421
fonts: {
1522
heading: 'Inter, sans-serif',
1623
body: 'Inter, sans-serif',
1724
},
1825
styles: {
19-
global: (props) => ({
26+
global: {
2027
body: {
21-
color: mode('gray.700', 'whiteAlpha.900')(props),
28+
WebkitFontSmoothing: 'antialiased',
29+
MozOsxFontSmoothing: 'grayscale',
30+
color: 'fg',
2231
'.deleted': {
2332
color: '#ff8383 !important',
2433
fontStyle: 'normal !important',
@@ -28,7 +37,7 @@ const customTheme = extendTheme({
2837
fontStyle: 'normal !important',
2938
},
3039
},
31-
}),
40+
},
3241
},
3342
textStyles: {
3443
heading: {
@@ -89,7 +98,7 @@ const customTheme = extendTheme({
8998
fontSize: '1.125rem',
9099
},
91100
a: {
92-
color: 'teal.500',
101+
color: 'accent',
93102
fontWeight: 'semibold',
94103
transition: 'color 0.15s',
95104
transitionTimingFunction: 'ease-out',

0 commit comments

Comments
 (0)