-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rules): add typography rules (#99)
- Loading branch information
Showing
13 changed files
with
208 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { twReset } from './tw-reset.js'; | ||
import { formPreflight } from './forms/export.js'; | ||
import { transformBase } from './transform.js'; | ||
import { typographyBase } from './typography.js'; | ||
|
||
export const preflights = [twReset, transformBase, formPreflight]; | ||
export const preflights = [twReset, transformBase, formPreflight, typographyBase]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { entriesToCss } from '@unocss/core'; | ||
|
||
const fontSizeBaseValues = { | ||
'--w-font-size-xs': "1.2rem", | ||
'--w-font-size-s': "1.4rem", | ||
'--w-font-size-m': "1.6rem", | ||
'--w-font-size-ml': "2rem", | ||
'--w-font-size-l': "2.2rem", | ||
'--w-font-size-xl': "2.8rem", | ||
'--w-font-size-xxl': "3.4rem", | ||
'--w-font-size-xxxl': "4.8rem", | ||
}; | ||
|
||
const lineHeightBaseValues = { | ||
'--w-line-height-xs': "1.6rem", | ||
'--w-line-height-s': "1.8rem", | ||
'--w-line-height-m': "2.2rem", | ||
'--w-line-height-ml': "2.6rem", | ||
'--w-line-height-l': "2.8rem", | ||
'--w-line-height-xl': "3.4rem", | ||
'--w-line-height-xxl': "4.1rem", | ||
'--w-line-height-xxxl': "5.6rem", | ||
}; | ||
|
||
const headingsReset = ` | ||
h1 { | ||
font-size: var(--w-font-size-xxl); | ||
line-height:var(--w-line-height-xxl); | ||
} | ||
h2 { | ||
font-size:var(--w-font-size-xl); | ||
line-height:var(--w-line-height-xl); | ||
} | ||
h3 { | ||
font-size:var(--w-font-size-l); | ||
line-height:var(--w-line-height-l); | ||
} | ||
h4 { | ||
font-size:var(--w-font-size-m); | ||
line-height:var(--w-line-height-m); | ||
} | ||
h5 { | ||
font-size:var(--w-font-size-s); | ||
line-height:var(--w-line-height-s); | ||
} | ||
`; | ||
|
||
export const typographyBase = { | ||
layer: 'preflights', | ||
getCSS() { | ||
const css = entriesToCss(Object.entries({ ...fontSizeBaseValues, ...lineHeightBaseValues })); | ||
return `${css}${headingsReset}`; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { textMap, lineHeightMap } from '#utils'; | ||
|
||
export const typography = [ | ||
[/^text-(12|14|16|20|22|28|34|48)$/, ([, d]) => ({ 'font-size': `var(--w-font-size-${textMap[d]})`, 'line-height': `var(--w-line-height-${textMap[d]})` })], | ||
[/^text-(xs|s|m|ml|l|xl|xxl|xxxl)$/, ([, size]) => | ||
({ 'font-size': `var(--w-font-size-${size})`, 'line-height': `var(--w-line-height-${size})` }), | ||
], | ||
[/^leading-(16|18|22|26|28|34|41|56)$/, ([, d]) => ({ 'line-height': `var(--w-line-height-${lineHeightMap[d]})` })], | ||
[/^leading-(xs|s|m|ml|l|xl|xxl|xxxl)$/, ([, size]) => | ||
({ 'line-height': `var(--w-line-height-${size})` }), | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { typographyAliases } from './typography.js'; | ||
|
||
export const shortcuts = [typographyAliases]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export const typographyAliases = { | ||
t1: 'text-xxl', | ||
t2: 'text-xl', | ||
t3: 'text-l', | ||
t4: 'text-m', | ||
t5: 'text-s', | ||
t6: 'text-xs', | ||
h5: 'text-s', | ||
h4: 'text-m', | ||
h3: 'text-l', | ||
h2: 'text-xl', | ||
h1: 'text-xxl', | ||
'text-display': 'text-xxxl', | ||
'text-preamble': 'text-ml', | ||
'text-body': 'text-m', | ||
'text-caption': 'text-s', | ||
'text-detail': 'text-xs', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { useTheme } from '#theme'; | ||
export { rules } from '#rules'; | ||
export { variants } from '#variants'; | ||
export { shortcuts } from '#shortcuts'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`shortcuts 1`] = ` | ||
"/* layer: shortcuts */ | ||
.h1, | ||
.t1{font-size:var(--w-font-size-xxl);line-height:var(--w-line-height-xxl);} | ||
.h2, | ||
.t2{font-size:var(--w-font-size-xl);line-height:var(--w-line-height-xl);} | ||
.h3, | ||
.t3{font-size:var(--w-font-size-l);line-height:var(--w-line-height-l);} | ||
.h4, | ||
.t4, | ||
.text-body{font-size:var(--w-font-size-m);line-height:var(--w-line-height-m);} | ||
.h5, | ||
.t5, | ||
.text-caption{font-size:var(--w-font-size-s);line-height:var(--w-line-height-s);} | ||
.t6, | ||
.text-detail{font-size:var(--w-font-size-xs);line-height:var(--w-line-height-xs);} | ||
.text-display{font-size:var(--w-font-size-xxxl);line-height:var(--w-line-height-xxxl);} | ||
.text-preamble{font-size:var(--w-font-size-ml);line-height:var(--w-line-height-ml);}" | ||
`; | ||
|
||
exports[`typography - leading classes 1`] = ` | ||
"/* layer: default */ | ||
.leading-16, | ||
.leading-xs{line-height:var(--w-line-height-xs);} | ||
.leading-18, | ||
.leading-s{line-height:var(--w-line-height-s);} | ||
.leading-22, | ||
.leading-m{line-height:var(--w-line-height-m);} | ||
.leading-26, | ||
.leading-ml{line-height:var(--w-line-height-ml);} | ||
.leading-28, | ||
.leading-l{line-height:var(--w-line-height-l);} | ||
.leading-34, | ||
.leading-xl{line-height:var(--w-line-height-xl);} | ||
.leading-41, | ||
.leading-xxl{line-height:var(--w-line-height-xxl);} | ||
.leading-56, | ||
.leading-xxxl{line-height:var(--w-line-height-xxxl);}" | ||
`; | ||
|
||
exports[`typography - text classes 1`] = ` | ||
"/* layer: default */ | ||
.text-12, | ||
.text-xs{font-size:var(--w-font-size-xs);line-height:var(--w-line-height-xs);} | ||
.text-14, | ||
.text-s{font-size:var(--w-font-size-s);line-height:var(--w-line-height-s);} | ||
.text-16, | ||
.text-m{font-size:var(--w-font-size-m);line-height:var(--w-line-height-m);} | ||
.text-20, | ||
.text-ml{font-size:var(--w-font-size-ml);line-height:var(--w-line-height-ml);} | ||
.text-22, | ||
.text-l{font-size:var(--w-font-size-l);line-height:var(--w-line-height-l);} | ||
.text-28, | ||
.text-xl{font-size:var(--w-font-size-xl);line-height:var(--w-line-height-xl);} | ||
.text-34, | ||
.text-xxl{font-size:var(--w-font-size-xxl);line-height:var(--w-line-height-xxl);} | ||
.text-48, | ||
.text-xxxl{font-size:var(--w-font-size-xxxl);line-height:var(--w-line-height-xxxl);}" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { expect, test } from 'vitest'; | ||
import { setup } from './_helpers.js'; | ||
import { textMap, lineHeightMap } from '#utils'; | ||
import { typographyAliases } from '../src/_shortcuts/typography.js'; | ||
|
||
setup(); | ||
|
||
test('typography - text classes ', async ({ uno }) => { | ||
const classes = Object.entries(textMap).map(([number, size]) => ([`text-${number}`, `text-${size}`])).flat(1); | ||
const { css } = await uno.generate(classes); | ||
expect(css).toMatchSnapshot(); | ||
}); | ||
|
||
test('typography - leading classes ', async ({ uno }) => { | ||
const classes = Object.entries(lineHeightMap).map(([number, size]) => ([`leading-${number}`, `leading-${size}`])).flat(1); | ||
const { css } = await uno.generate(classes); | ||
expect(css).toMatchSnapshot(); | ||
}); | ||
|
||
test('shortcuts', async ({ uno }) => { | ||
const classes = Object.keys(typographyAliases); | ||
const { css } = await uno.generate(classes); | ||
expect(css).toMatchSnapshot(); | ||
}); |