Skip to content

Commit 908ec62

Browse files
committed
feat(theme): add typography styles
1 parent 9d86819 commit 908ec62

5 files changed

Lines changed: 148 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { FontFace } from './interfaces.js'
2+
3+
export const scienceGothicFontFamily = 'Science Gothic'
4+
5+
const createFontSource = (fileName: string): string =>
6+
new URL(`../../../assets/fonts/science-gothic/${fileName}`, import.meta.url).toString()
7+
8+
export const scienceGothicFontFaces: Array<FontFace> = [
9+
{
10+
fontFamily: scienceGothicFontFamily,
11+
fontStyle: 'normal',
12+
fontWeight: 300,
13+
fontDisplay: 'swap',
14+
src: `url(${createFontSource('ScienceGothic-300.ttf')}) format('truetype')`,
15+
},
16+
{
17+
fontFamily: scienceGothicFontFamily,
18+
fontStyle: 'normal',
19+
fontWeight: 400,
20+
fontDisplay: 'swap',
21+
src: `url(${createFontSource('ScienceGothic-400.ttf')}) format('truetype')`,
22+
},
23+
{
24+
fontFamily: scienceGothicFontFamily,
25+
fontStyle: 'normal',
26+
fontWeight: 500,
27+
fontDisplay: 'swap',
28+
src: `url(${createFontSource('ScienceGothic-500.ttf')}) format('truetype')`,
29+
},
30+
{
31+
fontFamily: scienceGothicFontFamily,
32+
fontStyle: 'normal',
33+
fontWeight: 600,
34+
fontDisplay: 'swap',
35+
src: `url(${createFontSource('ScienceGothic-600.ttf')}) format('truetype')`,
36+
},
37+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export * from './font-faces.js'
2+
export * from './font-sizes.js'
3+
export * from './font-weights.js'
4+
export type * from './interfaces.js'
5+
export * from './letter-spacings.js'
6+
export * from './line-heights.js'
7+
export * from './styles.js'
8+
export * from './typography.js'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { fontSizes } from './font-sizes.js'
2+
import type { fontWeights } from './font-weights.js'
3+
import type { letterSpacings } from './letter-spacings.js'
4+
import type { lineHeights } from './line-heights.js'
5+
import type { textStyles } from './styles.js'
6+
7+
export interface FontFace {
8+
fontFamily: string
9+
fontStyle: 'normal'
10+
fontWeight: FontWeightValue
11+
fontDisplay: 'swap'
12+
src: string
13+
}
14+
15+
export interface TypographyStyle {
16+
fontFamily: string
17+
fontSize: FontSizeValue
18+
lineHeight: LineHeightValue
19+
fontWeight: FontWeightValue
20+
letterSpacing: LetterSpacingValue
21+
}
22+
23+
export type FontSizeValue = (typeof fontSizes)[keyof typeof fontSizes]
24+
25+
export type LineHeightValue = (typeof lineHeights)[keyof typeof lineHeights]
26+
27+
export type FontWeightValue = (typeof fontWeights)[keyof typeof fontWeights]
28+
29+
export type LetterSpacingValue = (typeof letterSpacings)[keyof typeof letterSpacings]
30+
31+
export type TextStyles = typeof textStyles
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import type { FontSizeValue } from './interfaces.js'
2+
import type { FontWeightValue } from './interfaces.js'
3+
import type { LetterSpacingValue } from './interfaces.js'
4+
import type { LineHeightValue } from './interfaces.js'
5+
import type { TypographyStyle } from './interfaces.js'
6+
7+
import { scienceGothicFontFamily } from './font-faces.js'
8+
import { fontSizes } from './font-sizes.js'
9+
import { fontWeights } from './font-weights.js'
10+
import { letterSpacings } from './letter-spacings.js'
11+
import { lineHeights } from './line-heights.js'
12+
13+
const createTextStyle = (
14+
fontSize: FontSizeValue,
15+
lineHeight: LineHeightValue,
16+
fontWeight: FontWeightValue,
17+
letterSpacing: LetterSpacingValue
18+
): TypographyStyle => ({
19+
fontFamily: scienceGothicFontFamily,
20+
fontSize,
21+
lineHeight,
22+
fontWeight,
23+
letterSpacing,
24+
})
25+
26+
export const textStyles = {
27+
display: {
28+
lg: createTextStyle(fontSizes.xl6, lineHeights.xl4, fontWeights.semiBold, letterSpacings.md),
29+
md: createTextStyle(fontSizes.xl5, lineHeights.xl3, fontWeights.semiBold, letterSpacings.md),
30+
sm: createTextStyle(fontSizes.xl4, lineHeights.xl2, fontWeights.semiBold, letterSpacings.md),
31+
},
32+
heading: {
33+
lg: createTextStyle(fontSizes.xl3, lineHeights.xl, fontWeights.medium, letterSpacings.md),
34+
md: createTextStyle(fontSizes.xl2, lineHeights.lg, fontWeights.medium, letterSpacings.md),
35+
sm: createTextStyle(fontSizes.xl, lineHeights.md, fontWeights.medium, letterSpacings.md),
36+
},
37+
title: {
38+
lg: createTextStyle(fontSizes.lg, lineHeights.sm, fontWeights.medium, letterSpacings.md),
39+
md: createTextStyle(fontSizes.md, lineHeights.sm, fontWeights.medium, letterSpacings.md),
40+
},
41+
body: {
42+
lg: createTextStyle(fontSizes.md, lineHeights.sm, fontWeights.regular, letterSpacings.md),
43+
md: createTextStyle(fontSizes.sm, lineHeights.xs, fontWeights.regular, letterSpacings.md),
44+
sm: createTextStyle(fontSizes.xs, lineHeights.xs2, fontWeights.regular, letterSpacings.md),
45+
},
46+
label: {
47+
lg: createTextStyle(fontSizes.md, lineHeights.xs, fontWeights.medium, letterSpacings.lg),
48+
md: createTextStyle(fontSizes.sm, lineHeights.xs, fontWeights.medium, letterSpacings.lg),
49+
sm: createTextStyle(fontSizes.xs, lineHeights.xs2, fontWeights.medium, letterSpacings.lg),
50+
},
51+
caption: createTextStyle(fontSizes.xs2, lineHeights.xs2, fontWeights.regular, letterSpacings.xl),
52+
overline: createTextStyle(fontSizes.xs3, lineHeights.xs3, fontWeights.medium, letterSpacings.xl),
53+
} as const
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { scienceGothicFontFaces } from './font-faces.js'
2+
import { scienceGothicFontFamily } from './font-faces.js'
3+
import { fontSizes } from './font-sizes.js'
4+
import { fontWeights } from './font-weights.js'
5+
import { letterSpacings } from './letter-spacings.js'
6+
import { lineHeights } from './line-heights.js'
7+
import { textStyles } from './styles.js'
8+
9+
export const typography = {
10+
fontFamily: scienceGothicFontFamily,
11+
fontFaces: scienceGothicFontFaces,
12+
fontSizes,
13+
lineHeights,
14+
fontWeights,
15+
letterSpacings,
16+
textStyles,
17+
} as const
18+
19+
export type TypographyTokens = typeof typography

0 commit comments

Comments
 (0)