Skip to content

Commit

Permalink
feat: add default header sizes (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
h2xd authored Mar 20, 2024
1 parent 536bb07 commit a45788a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testing/src/views/Headings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function Headings() {
return (
<>
{headings.map(heading => (
<Heading as={heading} variant={heading}>
<Heading as={heading} key={`header_${heading}`} >
{heading.toUpperCase()} (Heading {heading[1]})
</Heading>
))}
Expand Down
4 changes: 3 additions & 1 deletion theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
"publish:dry": "pnpm publish --no-git-checks --dry-run"
},
"peerDependencies": {
"@chakra-ui/anatomy": "^2.2.2",
"@chakra-ui/react": "^2.8.2",
"@chakra-ui/theme-tools": "^2.1.2"
},
"devDependencies": {
"@chakra-ui/anatomy": "^2.2.2",
"@chakra-ui/react": "^2.8.2",
"@chakra-ui/theme-tools": "^2.1.2",
"@types/node": "^20.11.26",
"typescript": "^5.2.2",
"vite": "^5.1.4",
"vite-plugin-dts": "^3.7.3"
}
}
}
26 changes: 20 additions & 6 deletions theme/src/components/headings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const h1 = defineStyle({
lineHeight: '2.25rem'
})


const h2 = defineStyle({
fontFamily: "Raleway",
fontSize: '1.5rem',
Expand All @@ -17,7 +16,6 @@ const h2 = defineStyle({
lineHeight: '2rem'
})


const h3 = defineStyle({
fontFamily: "Raleway",
fontSize: '1.25rem',
Expand Down Expand Up @@ -48,13 +46,29 @@ const variants = {
h3,
h4,
h5
}
} as const

type HeaderVariant = typeof variants

const variantMap = new Map(Object.entries(variants))
const DEFAULT_VARIANT = h1

export const headingTheme = defineStyleConfig({
baseStyle: {
},
baseStyle: defineStyle((props) => {
let selectedVariant: HeaderVariant[keyof HeaderVariant] | undefined

if (props.variant && variantMap.has(props.variant)) {
selectedVariant = variantMap.get(props.variant)
}

if (!!props.as && variantMap.has(props.as)) {
selectedVariant = variantMap.get(props.as)
}

return selectedVariant || DEFAULT_VARIANT
}),
variants,
defaultProps: {
variant: "h1",
variant: undefined,
}
})

0 comments on commit a45788a

Please sign in to comment.