@korzun/design 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +7 -4
- package/dist/component/heading/index.d.ts +303 -0
- package/dist/component/heading/index.d.ts.map +1 -0
- package/dist/component/heading/index.js +21 -0
- package/dist/component/heading/index.js.map +1 -0
- package/dist/component/heading/style.d.ts +5 -0
- package/dist/component/heading/style.d.ts.map +1 -0
- package/dist/component/heading/style.js +5 -0
- package/dist/component/heading/style.js.map +1 -0
- package/dist/component/index.d.ts +4 -0
- package/dist/component/index.d.ts.map +1 -1
- package/dist/component/index.js +4 -0
- package/dist/component/index.js.map +1 -1
- package/dist/component/inline/index.d.ts +303 -0
- package/dist/component/inline/index.d.ts.map +1 -0
- package/dist/component/inline/index.js +13 -0
- package/dist/component/inline/index.js.map +1 -0
- package/dist/component/inline/style.d.ts +5 -0
- package/dist/component/inline/style.d.ts.map +1 -0
- package/dist/component/inline/style.js +18 -0
- package/dist/component/inline/style.js.map +1 -0
- package/dist/component/stack/gap.d.ts +4 -0
- package/dist/component/stack/gap.d.ts.map +1 -0
- package/dist/component/stack/gap.js +10 -0
- package/dist/component/stack/gap.js.map +1 -0
- package/dist/component/stack/index.d.ts +299 -0
- package/dist/component/stack/index.d.ts.map +1 -0
- package/dist/component/stack/index.js +13 -0
- package/dist/component/stack/index.js.map +1 -0
- package/dist/component/stack/style.d.ts +5 -0
- package/dist/component/stack/style.d.ts.map +1 -0
- package/dist/component/stack/style.js +12 -0
- package/dist/component/stack/style.js.map +1 -0
- package/dist/component/text/index.d.ts +307 -0
- package/dist/component/text/index.d.ts.map +1 -0
- package/dist/component/text/index.js +15 -0
- package/dist/component/text/index.js.map +1 -0
- package/dist/component/text/style.d.ts +11 -0
- package/dist/component/text/style.d.ts.map +1 -0
- package/dist/component/text/style.js +48 -0
- package/dist/component/text/style.js.map +1 -0
- package/dist/theme/theme.d.ts +1 -0
- package/dist/theme/theme.d.ts.map +1 -1
- package/dist/theme/theme.js +7 -1
- package/dist/theme/theme.js.map +1 -1
- package/docs/component/heading.md +85 -0
- package/docs/component/inline.md +64 -0
- package/docs/component/meta-line.md +13 -17
- package/docs/component/stack.md +68 -0
- package/docs/component/text.md +94 -0
- package/docs/patterns.md +28 -9
- package/docs/theme.md +6 -7
- package/docs/tokens.md +1 -1
- package/package.json +1 -1
- package/src/component/heading/index.tsx +64 -0
- package/src/component/heading/style.ts +5 -0
- package/src/component/index.ts +4 -0
- package/src/component/inline/index.tsx +57 -0
- package/src/component/inline/style.ts +18 -0
- package/src/component/stack/gap.ts +16 -0
- package/src/component/stack/index.tsx +49 -0
- package/src/component/stack/style.ts +12 -0
- package/src/component/text/index.tsx +61 -0
- package/src/component/text/style.ts +67 -0
- package/src/theme/theme.ts +14 -2
package/docs/theme.md
CHANGED
|
@@ -37,17 +37,16 @@ import { applyTransparency } from '@korzun/design';
|
|
|
37
37
|
|
|
38
38
|
export const useStyle = createUseStyles((theme: Theme) => ({
|
|
39
39
|
root: {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
gap: theme.space.md,
|
|
43
|
-
color: theme.color.text.primary,
|
|
40
|
+
padding: theme.space.md,
|
|
41
|
+
backgroundColor: theme.color.bg.card,
|
|
44
42
|
},
|
|
45
|
-
hint: { fontSize: theme.fontSize.sm, color: theme.color.text.muted },
|
|
46
43
|
highlight: { backgroundColor: applyTransparency(theme.color.brand.default, 0.12) },
|
|
47
|
-
[theme.breakpoint.mobile]: { root: {
|
|
44
|
+
[theme.breakpoint.mobile]: { root: { padding: theme.space.sm } },
|
|
48
45
|
}));
|
|
49
46
|
```
|
|
50
47
|
|
|
48
|
+
- Style files are for padding, borders, backgrounds, and one-offs (borders come from the border tokens). Lay out with
|
|
49
|
+
`Stack`/`Inline` and set text with `Text`/`Heading`.
|
|
51
50
|
- `applyTransparency(color, alpha)` turns a hex or rgb token into an `rgba()`
|
|
52
51
|
string. Use it for tints instead of writing an rgba literal.
|
|
53
52
|
- Media queries: use the `theme.breakpoint.mobile` / `.normal` strings as keys.
|
|
@@ -70,7 +69,7 @@ export const useStyle = createUseStyles((theme: Theme) => ({
|
|
|
70
69
|
| `space` | `xxxs` 0.1rem, `xxs` 0.125, `xs` 0.25, `sm` 0.375, `md` 0.5, `lg` 0.625, `xl` 0.75, `xxl` 1, `xxxl` 1.25, `xxxxl` 1.5, `xxxxxl` 2rem | `md` is the default gap between stacked fields |
|
|
71
70
|
| `radius` | `sm` 4px, `md` 8px, `lg` 16px, `circle`, `pill` | Chosen by nesting depth; see [corners](corners.md) |
|
|
72
71
|
| `fontSize` | `xxs` 0.6rem, `xs` 0.7, `sm` 0.75, `md` 0.875, `lg` 1, `xl` 1.25, `xxl` 1.75rem | Control text is `'0.80rem'`, the one sanctioned literal (already applied by `recipe.input` and Button) |
|
|
73
|
-
| `fontWeight` | `medium` 500, `semibold` 600, `bold` 700, `extrabold` 800 | |
|
|
72
|
+
| `fontWeight` | `regular` 400, `medium` 500, `semibold` 600, `bold` 700, `extrabold` 800 | |
|
|
74
73
|
| `lineHeight` | `tight` 1, `body` 1.3 | |
|
|
75
74
|
| `fontFamily` | `body`, `mono` | |
|
|
76
75
|
| `shadow` | `card`, `cardStack`, `hoverLift`, `dangerStack`, `brandStack`, `glass`, `glassActive` | Floating layers use `hoverLift` |
|
package/docs/tokens.md
CHANGED
|
@@ -46,7 +46,7 @@ Two stacks: `body` (`system-ui, sans-serif`) and `mono`.
|
|
|
46
46
|
|
|
47
47
|
## fontWeight
|
|
48
48
|
|
|
49
|
-
Numeric weights: `medium semibold bold extrabold` (500, 600, 700, 800).
|
|
49
|
+
Numeric weights: `regular medium semibold bold extrabold` (400, 500, 600, 700, 800).
|
|
50
50
|
|
|
51
51
|
## lineHeight
|
|
52
52
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import cx from 'classnames';
|
|
2
|
+
import type { HTMLAttributes, ReactNode, Ref } from 'react';
|
|
3
|
+
import { createElement } from 'react';
|
|
4
|
+
|
|
5
|
+
import { useTypography, type TextSize, type TextTone, type TextWeight } from '../text/style.js';
|
|
6
|
+
import { useStyle } from './style.js';
|
|
7
|
+
|
|
8
|
+
const LEVELS = {
|
|
9
|
+
1: { size: 'xxl', weight: 'bold' },
|
|
10
|
+
2: { size: 'xl', weight: 'bold' },
|
|
11
|
+
3: { size: 'lg', weight: 'semibold' },
|
|
12
|
+
4: { size: 'md', weight: 'semibold' },
|
|
13
|
+
} as const satisfies Record<1 | 2 | 3 | 4, { size: TextSize; weight: TextWeight }>;
|
|
14
|
+
|
|
15
|
+
export interface HeadingProps extends Omit<HTMLAttributes<HTMLHeadingElement>, 'style'> {
|
|
16
|
+
/** The heading level, rendered as `h1` to `h4`. Sets the default size and weight. */
|
|
17
|
+
level: 1 | 2 | 3 | 4;
|
|
18
|
+
/** Font size, from the theme's `fontSize` tokens. Default follows `level`: 1 `xxl`, 2 `xl`, 3 `lg`, 4 `md`. */
|
|
19
|
+
size?: TextSize;
|
|
20
|
+
/** Text colour. Default `'primary'`. */
|
|
21
|
+
tone?: TextTone;
|
|
22
|
+
/** Font weight, from the theme's `fontWeight` tokens. Default follows `level`: 1 and 2 `bold`, 3 and 4 `semibold`. */
|
|
23
|
+
weight?: TextWeight;
|
|
24
|
+
/** Clip to one line with an ellipsis. Default `false`. */
|
|
25
|
+
truncate?: boolean;
|
|
26
|
+
/** Extra class on the root. Override with `'&&'` specificity, never `!important`. */
|
|
27
|
+
className?: string;
|
|
28
|
+
/** The heading text. */
|
|
29
|
+
children?: ReactNode;
|
|
30
|
+
/** Ref to the root element. */
|
|
31
|
+
ref?: Ref<HTMLHeadingElement>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A heading: `level` picks the element and a default look, props override the look. */
|
|
35
|
+
export const Heading = ({
|
|
36
|
+
level,
|
|
37
|
+
size,
|
|
38
|
+
tone = 'primary',
|
|
39
|
+
weight,
|
|
40
|
+
truncate = false,
|
|
41
|
+
className,
|
|
42
|
+
children,
|
|
43
|
+
ref,
|
|
44
|
+
...rest
|
|
45
|
+
}: HeadingProps) => {
|
|
46
|
+
const style = useStyle();
|
|
47
|
+
const type = useTypography();
|
|
48
|
+
return createElement(
|
|
49
|
+
`h${level}`,
|
|
50
|
+
{
|
|
51
|
+
...rest,
|
|
52
|
+
ref,
|
|
53
|
+
className: cx(
|
|
54
|
+
style.root,
|
|
55
|
+
type[`size-${size ?? LEVELS[level].size}`],
|
|
56
|
+
type[`tone-${tone}`],
|
|
57
|
+
type[`weight-${weight ?? LEVELS[level].weight}`],
|
|
58
|
+
truncate && type.truncate,
|
|
59
|
+
className
|
|
60
|
+
),
|
|
61
|
+
},
|
|
62
|
+
children
|
|
63
|
+
);
|
|
64
|
+
};
|
package/src/component/index.ts
CHANGED
|
@@ -3,6 +3,8 @@ export { CardDivider, type CardDividerAlign, type CardDividerProps } from './car
|
|
|
3
3
|
export { CardRow, type CardRowProps } from './card-row/index.js';
|
|
4
4
|
export { CollapsibleSection, type CollapsibleSectionProps } from './collapsible-section/index.js';
|
|
5
5
|
export { EmptyState, type EmptyStateProps } from './empty-state/index.js';
|
|
6
|
+
export { Heading, type HeadingProps } from './heading/index.js';
|
|
7
|
+
export { Inline, type InlineProps } from './inline/index.js';
|
|
6
8
|
export { MetaLine, type MetaLineProps } from './meta-line/index.js';
|
|
7
9
|
export { MetadataList, type Metadata, type MetadataListProps } from './metadata-list/index.js';
|
|
8
10
|
export { NavDesktop, type NavDesktopProps } from './nav-desktop/index.js';
|
|
@@ -10,6 +12,8 @@ export { NavMobile, type NavMobileProps, type NavPill } from './nav-mobile/index
|
|
|
10
12
|
export type { NavItem } from './nav-types.js';
|
|
11
13
|
export { Page, type PageProps, type PageTypeValue } from './page/index.js';
|
|
12
14
|
export { ProgressIndicator, type ProgressIndicatorProps } from './progress-indicator/index.js';
|
|
15
|
+
export { Stack, type StackProps } from './stack/index.js';
|
|
13
16
|
export { Tag, type TagProps, type TagTone } from './tag/index.js';
|
|
17
|
+
export { Text, type TextProps } from './text/index.js';
|
|
14
18
|
export { ThemeSetting, type ThemeSettingProps } from './theme-setting/index.js';
|
|
15
19
|
export { TopFade, type TopFadeProps } from './top-fade/index.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import cx from 'classnames';
|
|
2
|
+
import type { HTMLAttributes, ReactNode, Ref } from 'react';
|
|
3
|
+
import { createElement } from 'react';
|
|
4
|
+
|
|
5
|
+
import type { Gap } from '../stack/gap.js';
|
|
6
|
+
import { useStyle } from './style.js';
|
|
7
|
+
|
|
8
|
+
export interface InlineProps extends Omit<HTMLAttributes<HTMLElement>, 'style'> {
|
|
9
|
+
/** The element to render. `ul`/`ol` also reset list margin, padding and bullets. Default `'div'`. */
|
|
10
|
+
as?: 'div' | 'span' | 'ul' | 'ol' | 'li' | 'nav';
|
|
11
|
+
/** Space between children, from the theme's `space` tokens, or `'none'`. Default `'sm'`. */
|
|
12
|
+
gap?: Gap;
|
|
13
|
+
/** Cross-axis (vertical) alignment of children. Default `'center'`. */
|
|
14
|
+
align?: 'center' | 'start' | 'end' | 'baseline' | 'stretch';
|
|
15
|
+
/** Main-axis (horizontal) distribution. `'between'` pushes the first and last child to opposite edges. Default `'start'`. */
|
|
16
|
+
justify?: 'start' | 'center' | 'end' | 'between';
|
|
17
|
+
/** Let children wrap onto further lines instead of overflowing. Default `false`. */
|
|
18
|
+
wrap?: boolean;
|
|
19
|
+
/** Extra class on the root. Override with `'&&'` specificity, never `!important`. */
|
|
20
|
+
className?: string;
|
|
21
|
+
/** The children, laid out left to right. */
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
/** Ref to the root element. */
|
|
24
|
+
ref?: Ref<HTMLElement>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Lays children out in a horizontal row with a themed gap between them. */
|
|
28
|
+
export const Inline = ({
|
|
29
|
+
as = 'div',
|
|
30
|
+
gap = 'sm',
|
|
31
|
+
align = 'center',
|
|
32
|
+
justify = 'start',
|
|
33
|
+
wrap = false,
|
|
34
|
+
className,
|
|
35
|
+
children,
|
|
36
|
+
ref,
|
|
37
|
+
...rest
|
|
38
|
+
}: InlineProps) => {
|
|
39
|
+
const style = useStyle();
|
|
40
|
+
return createElement(
|
|
41
|
+
as,
|
|
42
|
+
{
|
|
43
|
+
...rest,
|
|
44
|
+
ref,
|
|
45
|
+
className: cx(
|
|
46
|
+
style.root,
|
|
47
|
+
style[`gap-${gap}`],
|
|
48
|
+
style[`align-${align}`],
|
|
49
|
+
style[`justify-${justify}`],
|
|
50
|
+
wrap && style.wrap,
|
|
51
|
+
(as === 'ul' || as === 'ol') && style.list,
|
|
52
|
+
className
|
|
53
|
+
),
|
|
54
|
+
},
|
|
55
|
+
children
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createUseStyles, type Theme } from '../../theme/index.js';
|
|
2
|
+
import { gapRules } from '../stack/gap.js';
|
|
3
|
+
|
|
4
|
+
export const useStyle = createUseStyles((theme: Theme) => ({
|
|
5
|
+
root: { display: 'flex', flexDirection: 'row', minWidth: 0 },
|
|
6
|
+
list: { margin: 0, padding: 0, listStyle: 'none' },
|
|
7
|
+
wrap: { flexWrap: 'wrap' },
|
|
8
|
+
'align-start': { alignItems: 'flex-start' },
|
|
9
|
+
'align-center': { alignItems: 'center' },
|
|
10
|
+
'align-end': { alignItems: 'flex-end' },
|
|
11
|
+
'align-baseline': { alignItems: 'baseline' },
|
|
12
|
+
'align-stretch': { alignItems: 'stretch' },
|
|
13
|
+
'justify-start': { justifyContent: 'flex-start' },
|
|
14
|
+
'justify-center': { justifyContent: 'center' },
|
|
15
|
+
'justify-end': { justifyContent: 'flex-end' },
|
|
16
|
+
'justify-between': { justifyContent: 'space-between' },
|
|
17
|
+
...gapRules(theme),
|
|
18
|
+
}));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Theme } from '../../theme/index.js';
|
|
2
|
+
|
|
3
|
+
export type Gap = keyof Theme['space'] | 'none';
|
|
4
|
+
|
|
5
|
+
// One static class per space token (shared by Stack and Inline), so a gap is a
|
|
6
|
+
// class swap rather than a per-instance dynamic style sheet.
|
|
7
|
+
export const gapRules = (theme: Theme) =>
|
|
8
|
+
({
|
|
9
|
+
...Object.fromEntries(
|
|
10
|
+
(Object.keys(theme.space) as (keyof Theme['space'])[]).map((key) => [
|
|
11
|
+
`gap-${key}`,
|
|
12
|
+
{ gap: theme.space[key] },
|
|
13
|
+
])
|
|
14
|
+
),
|
|
15
|
+
'gap-none': { gap: 0 },
|
|
16
|
+
}) as Record<`gap-${Gap}`, object>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import cx from 'classnames';
|
|
2
|
+
import type { HTMLAttributes, ReactNode, Ref } from 'react';
|
|
3
|
+
import { createElement } from 'react';
|
|
4
|
+
|
|
5
|
+
import type { Gap } from './gap.js';
|
|
6
|
+
import { useStyle } from './style.js';
|
|
7
|
+
|
|
8
|
+
export interface StackProps extends Omit<HTMLAttributes<HTMLElement>, 'style'> {
|
|
9
|
+
/** The element to render. `ul`/`ol` also reset list margin, padding and bullets. Default `'div'`. */
|
|
10
|
+
as?: 'div' | 'section' | 'ul' | 'ol' | 'li';
|
|
11
|
+
/** Space between children, from the theme's `space` tokens, or `'none'`. Default `'md'`. */
|
|
12
|
+
gap?: Gap;
|
|
13
|
+
/** Cross-axis (horizontal) alignment of children. Default `'stretch'`. */
|
|
14
|
+
align?: 'stretch' | 'start' | 'center' | 'end';
|
|
15
|
+
/** Extra class on the root. Override with `'&&'` specificity, never `!important`. */
|
|
16
|
+
className?: string;
|
|
17
|
+
/** The children, laid out top to bottom. */
|
|
18
|
+
children?: ReactNode;
|
|
19
|
+
/** Ref to the root element. */
|
|
20
|
+
ref?: Ref<HTMLElement>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Lays children out in a vertical column with a themed gap between them. */
|
|
24
|
+
export const Stack = ({
|
|
25
|
+
as = 'div',
|
|
26
|
+
gap = 'md',
|
|
27
|
+
align = 'stretch',
|
|
28
|
+
className,
|
|
29
|
+
children,
|
|
30
|
+
ref,
|
|
31
|
+
...rest
|
|
32
|
+
}: StackProps) => {
|
|
33
|
+
const style = useStyle();
|
|
34
|
+
return createElement(
|
|
35
|
+
as,
|
|
36
|
+
{
|
|
37
|
+
...rest,
|
|
38
|
+
ref,
|
|
39
|
+
className: cx(
|
|
40
|
+
style.root,
|
|
41
|
+
style[`gap-${gap}`],
|
|
42
|
+
style[`align-${align}`],
|
|
43
|
+
(as === 'ul' || as === 'ol') && style.list,
|
|
44
|
+
className
|
|
45
|
+
),
|
|
46
|
+
},
|
|
47
|
+
children
|
|
48
|
+
);
|
|
49
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createUseStyles, type Theme } from '../../theme/index.js';
|
|
2
|
+
import { gapRules } from './gap.js';
|
|
3
|
+
|
|
4
|
+
export const useStyle = createUseStyles((theme: Theme) => ({
|
|
5
|
+
root: { display: 'flex', flexDirection: 'column', minWidth: 0 },
|
|
6
|
+
list: { margin: 0, padding: 0, listStyle: 'none' },
|
|
7
|
+
'align-stretch': { alignItems: 'stretch' },
|
|
8
|
+
'align-start': { alignItems: 'flex-start' },
|
|
9
|
+
'align-center': { alignItems: 'center' },
|
|
10
|
+
'align-end': { alignItems: 'flex-end' },
|
|
11
|
+
...gapRules(theme),
|
|
12
|
+
}));
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import cx from 'classnames';
|
|
2
|
+
import type { HTMLAttributes, ReactNode, Ref } from 'react';
|
|
3
|
+
import { createElement } from 'react';
|
|
4
|
+
|
|
5
|
+
import { useStyle, useTypography, type TextSize, type TextTone, type TextWeight } from './style.js';
|
|
6
|
+
|
|
7
|
+
const INLINE_TAGS = ['span', 'strong', 'em', 'label'];
|
|
8
|
+
|
|
9
|
+
export interface TextProps extends Omit<HTMLAttributes<HTMLElement>, 'style'> {
|
|
10
|
+
/** The element to render. Default `'span'`. */
|
|
11
|
+
as?: 'span' | 'p' | 'div' | 'label' | 'strong' | 'em';
|
|
12
|
+
/** Font size, from the theme's `fontSize` tokens. Unset inherits. */
|
|
13
|
+
size?: TextSize;
|
|
14
|
+
/** Text colour: `primary`, `secondary`, `muted`, `faint`, `description`, or `danger`/`success` for inline error and confirmation text. Unset inherits. */
|
|
15
|
+
tone?: TextTone;
|
|
16
|
+
/** Font weight, from the theme's `fontWeight` tokens. Unset inherits. */
|
|
17
|
+
weight?: TextWeight;
|
|
18
|
+
/** Clip to one line with an ellipsis. Inline elements become `inline-block` so the clip applies. Default `false`. */
|
|
19
|
+
truncate?: boolean;
|
|
20
|
+
/** The id of the control this label describes. Only for `as="label"`. */
|
|
21
|
+
htmlFor?: string;
|
|
22
|
+
/** Extra class on the root. Override with `'&&'` specificity, never `!important`. */
|
|
23
|
+
className?: string;
|
|
24
|
+
/** The text. */
|
|
25
|
+
children?: ReactNode;
|
|
26
|
+
/** Ref to the root element. */
|
|
27
|
+
ref?: Ref<HTMLElement>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A run of text with themed size, tone and weight. Unset props inherit from the parent. */
|
|
31
|
+
export const Text = ({
|
|
32
|
+
as = 'span',
|
|
33
|
+
size,
|
|
34
|
+
tone,
|
|
35
|
+
weight,
|
|
36
|
+
truncate = false,
|
|
37
|
+
className,
|
|
38
|
+
children,
|
|
39
|
+
ref,
|
|
40
|
+
...rest
|
|
41
|
+
}: TextProps) => {
|
|
42
|
+
const style = useStyle();
|
|
43
|
+
const type = useTypography();
|
|
44
|
+
return createElement(
|
|
45
|
+
as,
|
|
46
|
+
{
|
|
47
|
+
...rest,
|
|
48
|
+
ref,
|
|
49
|
+
className: cx(
|
|
50
|
+
style.root,
|
|
51
|
+
size && type[`size-${size}`],
|
|
52
|
+
tone && type[`tone-${tone}`],
|
|
53
|
+
weight && type[`weight-${weight}`],
|
|
54
|
+
truncate && type.truncate,
|
|
55
|
+
truncate && INLINE_TAGS.includes(as) && type.truncateInline,
|
|
56
|
+
className
|
|
57
|
+
),
|
|
58
|
+
},
|
|
59
|
+
children
|
|
60
|
+
);
|
|
61
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createUseStyles, type Theme } from '../../theme/index.js';
|
|
2
|
+
|
|
3
|
+
export type TextSize = keyof Theme['fontSize'];
|
|
4
|
+
export type TextTone =
|
|
5
|
+
| 'primary'
|
|
6
|
+
| 'secondary'
|
|
7
|
+
| 'muted'
|
|
8
|
+
| 'faint'
|
|
9
|
+
| 'description'
|
|
10
|
+
| 'danger'
|
|
11
|
+
| 'success';
|
|
12
|
+
export type TextWeight = keyof Theme['fontWeight'];
|
|
13
|
+
|
|
14
|
+
const toneColor = (theme: Theme, tone: TextTone): string => {
|
|
15
|
+
if (tone === 'danger') return theme.color.chip.danger.text;
|
|
16
|
+
if (tone === 'success') return theme.color.chip.success.text;
|
|
17
|
+
return theme.color.text[tone];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const TONES: TextTone[] = [
|
|
21
|
+
'primary',
|
|
22
|
+
'secondary',
|
|
23
|
+
'muted',
|
|
24
|
+
'faint',
|
|
25
|
+
'description',
|
|
26
|
+
'danger',
|
|
27
|
+
'success',
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
// One static rule per token value, so a prop is a class swap rather than a
|
|
31
|
+
// dynamic style sheet. Shared with Heading.
|
|
32
|
+
const typographyRules = (theme: Theme) => ({
|
|
33
|
+
...(Object.fromEntries(
|
|
34
|
+
(Object.keys(theme.fontSize) as TextSize[]).map((size) => [
|
|
35
|
+
`size-${size}`,
|
|
36
|
+
{ fontSize: theme.fontSize[size] },
|
|
37
|
+
])
|
|
38
|
+
) as Record<`size-${TextSize}`, object>),
|
|
39
|
+
...(Object.fromEntries(
|
|
40
|
+
TONES.map((tone) => [`tone-${tone}`, { color: toneColor(theme, tone) }])
|
|
41
|
+
) as Record<`tone-${TextTone}`, object>),
|
|
42
|
+
...(Object.fromEntries(
|
|
43
|
+
(Object.keys(theme.fontWeight) as TextWeight[]).map((weight) => [
|
|
44
|
+
`weight-${weight}`,
|
|
45
|
+
{ fontWeight: theme.fontWeight[weight] },
|
|
46
|
+
])
|
|
47
|
+
) as Record<`weight-${TextWeight}`, object>),
|
|
48
|
+
truncate: {
|
|
49
|
+
overflow: 'hidden',
|
|
50
|
+
textOverflow: 'ellipsis',
|
|
51
|
+
whiteSpace: 'nowrap',
|
|
52
|
+
minWidth: 0,
|
|
53
|
+
// A start, centre or end aligned flex item sizes to its content, so cap it.
|
|
54
|
+
maxWidth: '100%',
|
|
55
|
+
},
|
|
56
|
+
// Inline elements ignore overflow and width, so they become inline-block.
|
|
57
|
+
truncateInline: {
|
|
58
|
+
display: 'inline-block',
|
|
59
|
+
verticalAlign: 'bottom',
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export const useTypography = createUseStyles((theme: Theme) => typographyRules(theme));
|
|
64
|
+
|
|
65
|
+
export const useStyle = createUseStyles(() => ({
|
|
66
|
+
root: { margin: 0 },
|
|
67
|
+
}));
|
package/src/theme/theme.ts
CHANGED
|
@@ -176,7 +176,13 @@ export interface Theme {
|
|
|
176
176
|
xxl: string;
|
|
177
177
|
};
|
|
178
178
|
fontFamily: { body: string; mono: string };
|
|
179
|
-
fontWeight: {
|
|
179
|
+
fontWeight: {
|
|
180
|
+
regular: number;
|
|
181
|
+
medium: number;
|
|
182
|
+
semibold: number;
|
|
183
|
+
bold: number;
|
|
184
|
+
extrabold: number;
|
|
185
|
+
};
|
|
180
186
|
lineHeight: { tight: number; body: number };
|
|
181
187
|
shadow: {
|
|
182
188
|
card: string;
|
|
@@ -508,7 +514,13 @@ function buildTheme(mode: ThemeMode): Theme {
|
|
|
508
514
|
body: 'system-ui, sans-serif',
|
|
509
515
|
mono: "'Cascadia Code', 'Fira Code', monospace",
|
|
510
516
|
};
|
|
511
|
-
const fontWeight: Theme['fontWeight'] = {
|
|
517
|
+
const fontWeight: Theme['fontWeight'] = {
|
|
518
|
+
regular: 400,
|
|
519
|
+
medium: 500,
|
|
520
|
+
semibold: 600,
|
|
521
|
+
bold: 700,
|
|
522
|
+
extrabold: 800,
|
|
523
|
+
};
|
|
512
524
|
const lineHeight: Theme['lineHeight'] = { tight: 1, body: 1.3 };
|
|
513
525
|
|
|
514
526
|
const lightShadow: Theme['shadow'] = {
|