Skip to content

Commit 64f1876

Browse files
authored
feat: add fontVariant to typography bag (#396)
1 parent 1a3014f commit 64f1876

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

packages/system/src/styles/typography.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ export const fontSize = style<FontSizeProps>({
8282
themeGet: getFontSize,
8383
})
8484

85+
export interface FontVariantProps<T extends ITheme = Theme> {
86+
fontVariant?: SystemProp<CSS.Property.FontVariant, T>
87+
}
88+
export const fontVariant = style<FontVariantProps>({
89+
prop: 'fontVariant',
90+
})
91+
8592
export interface LineHeightProps<T extends ITheme = Theme> {
8693
lineHeight?: SystemProp<LineHeight<T> | CSS.Property.LineHeight, T>
8794
}
@@ -197,6 +204,7 @@ interface AllProps<T extends ITheme = Theme>
197204
extends FontFamilyProps<T>,
198205
FontSizeProps<T>,
199206
FontStyleProps<T>,
207+
FontVariantProps<T>,
200208
LineHeightProps<T>,
201209
FontWeightProps<T>,
202210
TextAlignProps<T>,
@@ -215,6 +223,7 @@ const all = compose<AllProps>(
215223
fontFamily,
216224
fontSize,
217225
fontStyle,
226+
fontVariant,
218227
lineHeight,
219228
fontWeight,
220229
textAlign,
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
section: Typography
3+
title: Font Variant
4+
slug: /docs/font-variant/
5+
---
6+
7+
# Font Variant
8+
9+
Utilities for controlling optional features of a given font family. See [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant) for more information.
10+
11+
<carbon-ad />
12+
13+
| React props | CSS Properties |
14+
| ----------------------- | -------------------------- |
15+
| `fontVariant={variant}` | `font-variant: {variant};` |
16+
17+
## Usage
18+
19+
Control the font variant of an element using the `fontVariant={variant}` utility.
20+
21+
```jsx preview color=violet
22+
<>
23+
<template preview>
24+
<>
25+
{['normal', 'common-ligatures', 'small-caps'].map((variant) => (
26+
<x.dl
27+
key={size}
28+
display="flex"
29+
alignItems="baseline"
30+
color="violet-600"
31+
overflow="hidden"
32+
>
33+
<x.dt
34+
w={16}
35+
flexShrink={0}
36+
fontSize="sm"
37+
opacity={0.8}
38+
fontFamily="mono"
39+
>
40+
{size}
41+
</x.dt>
42+
<x.dd fontVariant={variant} fontWeight="medium">
43+
Computers have lots of memory but no imagination.
44+
</x.dd>
45+
</x.dl>
46+
))}
47+
</>
48+
</template>
49+
<x.p fontVariant="normal">Computers have lots ...</x.p>
50+
<x.p fontVariant="common-ligatures">Computers have lots ...</x.p>
51+
<x.p fontVariant="small-caps">Computers have lots ...</x.p>
52+
</>
53+
```
54+
55+
## Responsive
56+
57+
To control the font variant at a specific breakpoint, use responsive object notation. For example, adding the property `fontVariant={{ md: "small-caps" }}` to an element would apply the `fontVariant="small-caps"` utility at medium screen sizes and above.
58+
59+
```jsx
60+
<x.p fontVariant={{ xs: 'auto', md: 'small-caps' }}>{/* ... */}</x.p>
61+
```
62+
63+
For more information about xstyled's responsive design features, check out [Responsive Design](/docs/responsive-design/) documentation.

0 commit comments

Comments
 (0)