@spark-web/text 1.0.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/CHANGELOG.md +17 -0
- package/README.md +137 -0
- package/dist/declarations/src/Strong.d.ts +5 -0
- package/dist/declarations/src/Text.d.ts +32 -0
- package/dist/declarations/src/context.d.ts +11 -0
- package/dist/declarations/src/defaultTextProps.d.ts +16 -0
- package/dist/declarations/src/index.d.ts +11 -0
- package/dist/declarations/src/useForegroundTone.d.ts +3 -0
- package/dist/declarations/src/useOverflowStrategy.d.ts +27 -0
- package/dist/declarations/src/useText.d.ts +29 -0
- package/dist/spark-web-text.cjs.d.ts +1 -0
- package/dist/spark-web-text.cjs.dev.js +266 -0
- package/dist/spark-web-text.cjs.js +7 -0
- package/dist/spark-web-text.cjs.prod.js +266 -0
- package/dist/spark-web-text.esm.js +250 -0
- package/package.json +21 -0
- package/src/Strong.tsx +13 -0
- package/src/Text.stories.tsx +20 -0
- package/src/Text.tsx +113 -0
- package/src/context.ts +13 -0
- package/src/defaultTextProps.tsx +48 -0
- package/src/index.ts +17 -0
- package/src/useForegroundTone.ts +36 -0
- package/src/useOverflowStrategy.ts +28 -0
- package/src/useText.ts +56 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @spark-web/text
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#27](https://github.com/brighte-labs/spark-web/pull/27)
|
|
8
|
+
[`4c8e398`](https://github.com/brighte-labs/spark-web/commit/4c8e3988f8a59d3dab60a6b67b1128b6ff2a5f2c)
|
|
9
|
+
Thanks [@JedWatson](https://github.com/JedWatson)! - Initial Version
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
[[`4c8e398`](https://github.com/brighte-labs/spark-web/commit/4c8e3988f8a59d3dab60a6b67b1128b6ff2a5f2c)]:
|
|
15
|
+
- @spark-web/box@1.0.0
|
|
16
|
+
- @spark-web/theme@1.0.0
|
|
17
|
+
- @spark-web/utils@1.0.0
|
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Text
|
|
3
|
+
storybookPath: typography-text--default
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Constrained, purposeful text styles as a component.
|
|
7
|
+
|
|
8
|
+
## Examples
|
|
9
|
+
|
|
10
|
+
```jsx live
|
|
11
|
+
<Columns gap="large" collapseBelow="wide">
|
|
12
|
+
<Stack gap="medium">
|
|
13
|
+
<Text size="large">large regular</Text>
|
|
14
|
+
<Text size="large" weight="medium">
|
|
15
|
+
large medium
|
|
16
|
+
</Text>
|
|
17
|
+
<Text size="large" weight="strong">
|
|
18
|
+
large strong
|
|
19
|
+
</Text>
|
|
20
|
+
</Stack>
|
|
21
|
+
<Stack gap="medium">
|
|
22
|
+
<Text size="standard">standard regular</Text>
|
|
23
|
+
<Text size="standard" weight="medium">
|
|
24
|
+
standard medium
|
|
25
|
+
</Text>
|
|
26
|
+
<Text size="standard" weight="strong">
|
|
27
|
+
standard strong
|
|
28
|
+
</Text>
|
|
29
|
+
</Stack>
|
|
30
|
+
<Stack gap="small">
|
|
31
|
+
<Text size="small">small regular</Text>
|
|
32
|
+
<Text size="small" weight="medium">
|
|
33
|
+
small medium
|
|
34
|
+
</Text>
|
|
35
|
+
<Text size="small" weight="strong">
|
|
36
|
+
small strong
|
|
37
|
+
</Text>
|
|
38
|
+
</Stack>
|
|
39
|
+
<Stack gap="small">
|
|
40
|
+
<Text size="xsmall">xsmall regular</Text>
|
|
41
|
+
<Text size="xsmall" weight="medium">
|
|
42
|
+
xsmall medium
|
|
43
|
+
</Text>
|
|
44
|
+
<Text size="xsmall" weight="strong">
|
|
45
|
+
xsmall strong
|
|
46
|
+
</Text>
|
|
47
|
+
</Stack>
|
|
48
|
+
</Columns>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Align
|
|
52
|
+
|
|
53
|
+
Text can be aligned with the `align` prop.
|
|
54
|
+
|
|
55
|
+
```jsx live
|
|
56
|
+
<Stack gap="large" dividers>
|
|
57
|
+
<Text align="left">Left (default)</Text>
|
|
58
|
+
<Text align="center">Center</Text>
|
|
59
|
+
<Text align="right">Right</Text>
|
|
60
|
+
</Stack>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Overflow strategy
|
|
64
|
+
|
|
65
|
+
Use the `overflowStrategy` prop to manage how `Text` behaves with regard to
|
|
66
|
+
overflow.
|
|
67
|
+
|
|
68
|
+
```jsx live
|
|
69
|
+
<Stack gap="large" style={{ width: 200 }}>
|
|
70
|
+
<Stack gap="small">
|
|
71
|
+
<Text weight="strong">Default</Text>
|
|
72
|
+
<Text>The quick brown fox jumps over the lazy dog.</Text>
|
|
73
|
+
</Stack>
|
|
74
|
+
<Stack gap="small">
|
|
75
|
+
<Text weight="strong">Truncate</Text>
|
|
76
|
+
<Text overflowStrategy="truncate">
|
|
77
|
+
The quick brown fox jumps over the lazy dog.
|
|
78
|
+
</Text>
|
|
79
|
+
</Stack>
|
|
80
|
+
<Stack gap="small">
|
|
81
|
+
<Text weight="strong">No wrap</Text>
|
|
82
|
+
<Text overflowStrategy="nowrap">
|
|
83
|
+
The quick brown fox jumps over the lazy dog.
|
|
84
|
+
</Text>
|
|
85
|
+
</Stack>
|
|
86
|
+
<Stack gap="small">
|
|
87
|
+
<Text weight="strong">Break word</Text>
|
|
88
|
+
<Text overflowStrategy="breakword">
|
|
89
|
+
The_quick_brown_fox_jumps_over_the_lazy dog.
|
|
90
|
+
</Text>
|
|
91
|
+
</Stack>
|
|
92
|
+
</Stack>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Tone
|
|
96
|
+
|
|
97
|
+
The foreground colour of text can be set by applying a `tone`. In addition to
|
|
98
|
+
the foundation tones, “muted” provides a way to de-emphasise text.
|
|
99
|
+
|
|
100
|
+
```jsx live
|
|
101
|
+
<Inline gap="small">
|
|
102
|
+
<Text tone="neutral">neutral (default)</Text>
|
|
103
|
+
<Text tone="muted">muted</Text>
|
|
104
|
+
<Text tone="info">info</Text>
|
|
105
|
+
<Text tone="positive">positive</Text>
|
|
106
|
+
<Text tone="caution">caution</Text>
|
|
107
|
+
<Text tone="critical">critical</Text>
|
|
108
|
+
</Inline>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Contrast
|
|
112
|
+
|
|
113
|
+
To ensure text has sufficient contrast, when on a dark background the foreground
|
|
114
|
+
tones “neutral” and “muted” will be inverted.
|
|
115
|
+
|
|
116
|
+
```jsx live
|
|
117
|
+
<Inline gap="large">
|
|
118
|
+
<Box background="neutral" padding="small" borderRadius="small">
|
|
119
|
+
<Text>neutral</Text>
|
|
120
|
+
</Box>
|
|
121
|
+
<Box background="neutral" padding="small" borderRadius="small">
|
|
122
|
+
<Text tone="muted">muted</Text>
|
|
123
|
+
</Box>
|
|
124
|
+
</Inline>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Props
|
|
128
|
+
|
|
129
|
+
| Prop | Type | Default | Description |
|
|
130
|
+
| ----------------- | ------------------------------------- | ------- | ---------------------------------------------------------------------------- |
|
|
131
|
+
| children | React.ReactNode | | The text content to be rendered. |
|
|
132
|
+
| id? | string | | Sets a unique idenitifier for the component. |
|
|
133
|
+
| tabularNumbers? | boolean | | When enabled, numbers will be the same width. Similar to a monospaced font. |
|
|
134
|
+
| transform? | CSSProperties['textTransform'] | | Transforms the text casing. |
|
|
135
|
+
| align? | 'left' \| 'center' \| 'right' | | Sets the horizontal alignment of the component. Used if displaying as block. |
|
|
136
|
+
| inline? | boolean | | Indicates if text should be inline or not. |
|
|
137
|
+
| overflowStrategy? | 'nowrap' \| 'truncate' \| 'breakword' | | Sets how text behaves with regards to overflow. Used if displaying as block. |
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BoxProps } from '@spark-web/box';
|
|
2
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
3
|
+
import type { TextOverflowStrategy } from './useOverflowStrategy';
|
|
4
|
+
import type { UseTextProps } from './useText';
|
|
5
|
+
declare type InlineProps = {
|
|
6
|
+
align?: never;
|
|
7
|
+
/** Display as an inline element. */
|
|
8
|
+
inline?: boolean;
|
|
9
|
+
overflowStrategy?: never;
|
|
10
|
+
};
|
|
11
|
+
declare type BlockProps = {
|
|
12
|
+
/** The horizontal alignment. */
|
|
13
|
+
align?: 'left' | 'center' | 'right';
|
|
14
|
+
inline?: never;
|
|
15
|
+
/** Manage how text behaves with regard to overflow. */
|
|
16
|
+
overflowStrategy?: TextOverflowStrategy;
|
|
17
|
+
};
|
|
18
|
+
export declare type TextProps = Partial<UseTextProps> & {
|
|
19
|
+
/** The text content. */
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
/** An identifier which must be unique in the whole document. */
|
|
22
|
+
id?: BoxProps['id'];
|
|
23
|
+
/** When enabled, numbers will be the same width. Similar to a monospaced font. */
|
|
24
|
+
tabularNumbers?: boolean;
|
|
25
|
+
/** Transform the text casing. */
|
|
26
|
+
transform?: CSSProperties['textTransform'];
|
|
27
|
+
} & (InlineProps | BlockProps);
|
|
28
|
+
export declare const Text: <Comp extends import("react").ElementType<any> = "div">(props: {
|
|
29
|
+
as?: Comp | undefined;
|
|
30
|
+
ref?: import("react").Ref<Comp extends "symbol" | "clipPath" | "filter" | "mask" | "marker" | "text" | "circle" | "svg" | "animate" | "animateMotion" | "animateTransform" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "stop" | "switch" | "textPath" | "tspan" | "use" | "view" | keyof HTMLElementTagNameMap | "set" ? (HTMLElementTagNameMap & Pick<SVGElementTagNameMap, "symbol" | "clipPath" | "filter" | "mask" | "marker" | "text" | "circle" | "svg" | "animate" | "animateMotion" | "animateTransform" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "stop" | "switch" | "textPath" | "tspan" | "use" | "view" | "set">)[Comp] : Comp extends new (...args: any) => any ? InstanceType<Comp> : undefined> | undefined;
|
|
31
|
+
} & Omit<import("react").PropsWithoutRef<import("react").ComponentProps<Comp>>, "as"> & TextProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const TextContext: import("react").Context<{
|
|
3
|
+
size: "large" | "small" | "xsmall" | "standard";
|
|
4
|
+
tone: "disabled" | "link" | "placeholder" | "temporary-green" | "temporary-green-low" | "temporary-green-high" | "temporary-green-soft" | "temporary-yellow" | "temporary-yellow-low" | "temporary-yellow-high" | "temporary-yellow-soft" | "temporary-dark" | "temporary-dark-low" | "temporary-dark-high" | "temporary-dark-soft" | "temporary-blue" | "temporary-blue-low" | "temporary-blue-high" | "temporary-blue-soft" | "temporary-red" | "temporary-red-low" | "temporary-red-high" | "temporary-red-soft" | "muted" | "fieldAccent" | "accent" | "neutral" | "primary" | "secondary" | "caution" | "critical" | "info" | "positive" | "primaryHover" | "primaryActive" | "secondaryHover" | "secondaryActive";
|
|
5
|
+
weight: "medium" | "strong" | "regular";
|
|
6
|
+
} | undefined>;
|
|
7
|
+
export declare function useTextContext(): {
|
|
8
|
+
size: "large" | "small" | "xsmall" | "standard";
|
|
9
|
+
tone: "disabled" | "link" | "placeholder" | "temporary-green" | "temporary-green-low" | "temporary-green-high" | "temporary-green-soft" | "temporary-yellow" | "temporary-yellow-low" | "temporary-yellow-high" | "temporary-yellow-soft" | "temporary-dark" | "temporary-dark-low" | "temporary-dark-high" | "temporary-dark-soft" | "temporary-blue" | "temporary-blue-low" | "temporary-blue-high" | "temporary-blue-soft" | "temporary-red" | "temporary-red-low" | "temporary-red-high" | "temporary-red-soft" | "muted" | "fieldAccent" | "accent" | "neutral" | "primary" | "secondary" | "caution" | "critical" | "info" | "positive" | "primaryHover" | "primaryActive" | "secondaryHover" | "secondaryActive";
|
|
10
|
+
weight: "medium" | "strong" | "regular";
|
|
11
|
+
} | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { UseTextProps } from './useText';
|
|
3
|
+
declare type DefaultTextProps = {
|
|
4
|
+
size?: NonNullable<UseTextProps['size']>;
|
|
5
|
+
tone?: NonNullable<UseTextProps['tone']>;
|
|
6
|
+
weight?: NonNullable<UseTextProps['weight']>;
|
|
7
|
+
};
|
|
8
|
+
export declare function DefaultTextPropsProvider({ children, size, tone, weight, }: DefaultTextProps & {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}): JSX.Element;
|
|
11
|
+
export declare const useDefaultTextProps: ({ size: sizeProp, tone: toneProp, weight: weightProp, }: DefaultTextProps) => {
|
|
12
|
+
size: "large" | "small" | "xsmall" | "standard";
|
|
13
|
+
tone: "disabled" | "link" | "placeholder" | "temporary-green" | "temporary-green-low" | "temporary-green-high" | "temporary-green-soft" | "temporary-yellow" | "temporary-yellow-low" | "temporary-yellow-high" | "temporary-yellow-soft" | "temporary-dark" | "temporary-dark-low" | "temporary-dark-high" | "temporary-dark-soft" | "temporary-blue" | "temporary-blue-low" | "temporary-blue-high" | "temporary-blue-soft" | "temporary-red" | "temporary-red-low" | "temporary-red-high" | "temporary-red-soft" | "muted" | "fieldAccent" | "accent" | "neutral" | "primary" | "secondary" | "caution" | "critical" | "info" | "positive" | "primaryHover" | "primaryActive" | "secondaryHover" | "secondaryActive";
|
|
14
|
+
weight: "medium" | "strong" | "regular";
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { useTextContext } from './context';
|
|
2
|
+
export { DefaultTextPropsProvider, useDefaultTextProps, } from './defaultTextProps';
|
|
3
|
+
export { Strong } from './Strong';
|
|
4
|
+
export { Text } from './Text';
|
|
5
|
+
export { useForegroundTone } from './useForegroundTone';
|
|
6
|
+
export { useOverflowStrategy } from './useOverflowStrategy';
|
|
7
|
+
export { createTextStyles, useText } from './useText';
|
|
8
|
+
export type { StrongProps } from './Strong';
|
|
9
|
+
export type { TextProps } from './Text';
|
|
10
|
+
export type { ForegroundTone } from './useForegroundTone';
|
|
11
|
+
export type { TextOverflowStrategy } from './useOverflowStrategy';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare const strategyMap: {
|
|
2
|
+
readonly truncate: {
|
|
3
|
+
readonly display: "block";
|
|
4
|
+
readonly overflow: "hidden";
|
|
5
|
+
readonly textOverflow: "ellipsis";
|
|
6
|
+
readonly whiteSpace: "nowrap";
|
|
7
|
+
};
|
|
8
|
+
readonly nowrap: {
|
|
9
|
+
readonly whiteSpace: "nowrap";
|
|
10
|
+
};
|
|
11
|
+
readonly breakword: {
|
|
12
|
+
readonly display: "block";
|
|
13
|
+
readonly overflowWrap: "break-word";
|
|
14
|
+
readonly wordBreak: "break-word";
|
|
15
|
+
readonly wordWrap: "break-word";
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare type TextOverflowStrategy = keyof typeof strategyMap;
|
|
19
|
+
export declare function useOverflowStrategy(strategy?: TextOverflowStrategy): {
|
|
20
|
+
readonly whiteSpace: "nowrap";
|
|
21
|
+
} | {
|
|
22
|
+
readonly display: "block";
|
|
23
|
+
readonly overflowWrap: "break-word";
|
|
24
|
+
readonly wordBreak: "break-word";
|
|
25
|
+
readonly wordWrap: "break-word";
|
|
26
|
+
} | null;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BrighteTextDefinition, BrighteTheme } from '@spark-web/theme';
|
|
2
|
+
import type { ForegroundTone } from './useForegroundTone';
|
|
3
|
+
export declare type UseTextProps = {
|
|
4
|
+
/** Apply leading-trim styles. */
|
|
5
|
+
baseline?: boolean;
|
|
6
|
+
/** The size of the text. */
|
|
7
|
+
size: keyof BrighteTheme['typography']['text'];
|
|
8
|
+
/** The tone of the text. */
|
|
9
|
+
tone: ForegroundTone;
|
|
10
|
+
/** The weight of the text. */
|
|
11
|
+
weight: keyof BrighteTheme['typography']['fontWeight'];
|
|
12
|
+
};
|
|
13
|
+
export declare function useText({ baseline, size, tone, weight }: UseTextProps): (import("@emotion/css").CSSObject | undefined)[];
|
|
14
|
+
export declare function createTextStyles({ fontSize, lineHeight, trims }: BrighteTextDefinition, { includeTrims }?: {
|
|
15
|
+
includeTrims?: boolean | undefined;
|
|
16
|
+
}): {
|
|
17
|
+
'::before'?: {
|
|
18
|
+
marginBottom: string;
|
|
19
|
+
content: string;
|
|
20
|
+
display: string;
|
|
21
|
+
} | undefined;
|
|
22
|
+
'::after'?: {
|
|
23
|
+
marginTop: string;
|
|
24
|
+
content: string;
|
|
25
|
+
display: string;
|
|
26
|
+
} | undefined;
|
|
27
|
+
fontSize: string;
|
|
28
|
+
lineHeight: string;
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./declarations/src/index";
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var css = require('@emotion/css');
|
|
7
|
+
var theme = require('@spark-web/theme');
|
|
8
|
+
var box = require('@spark-web/box');
|
|
9
|
+
var ts = require('@spark-web/utils/ts');
|
|
10
|
+
var _defineProperty = require('@babel/runtime/helpers/esm/defineProperty');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
13
|
+
|
|
14
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
15
|
+
|
|
16
|
+
var TextContext = /*#__PURE__*/React.createContext(undefined);
|
|
17
|
+
function useTextContext() {
|
|
18
|
+
return React.useContext(TextContext);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var __jsx$2 = React__default["default"].createElement;
|
|
22
|
+
var DefaultTextPropsContext = /*#__PURE__*/React.createContext({
|
|
23
|
+
size: undefined,
|
|
24
|
+
tone: undefined,
|
|
25
|
+
weight: undefined
|
|
26
|
+
});
|
|
27
|
+
function DefaultTextPropsProvider(_ref) {
|
|
28
|
+
var children = _ref.children,
|
|
29
|
+
size = _ref.size,
|
|
30
|
+
tone = _ref.tone,
|
|
31
|
+
weight = _ref.weight;
|
|
32
|
+
var defaultTextProps = React.useMemo(function () {
|
|
33
|
+
return {
|
|
34
|
+
size: size,
|
|
35
|
+
tone: tone,
|
|
36
|
+
weight: weight
|
|
37
|
+
};
|
|
38
|
+
}, [size, tone, weight]);
|
|
39
|
+
return __jsx$2(DefaultTextPropsContext.Provider, {
|
|
40
|
+
value: defaultTextProps
|
|
41
|
+
}, children);
|
|
42
|
+
}
|
|
43
|
+
var useDefaultTextProps = function useDefaultTextProps(_ref2) {
|
|
44
|
+
var _ref3, _ref4, _ref5;
|
|
45
|
+
|
|
46
|
+
var sizeProp = _ref2.size,
|
|
47
|
+
toneProp = _ref2.tone,
|
|
48
|
+
weightProp = _ref2.weight;
|
|
49
|
+
|
|
50
|
+
var _useContext = React.useContext(DefaultTextPropsContext),
|
|
51
|
+
size = _useContext.size,
|
|
52
|
+
tone = _useContext.tone,
|
|
53
|
+
weight = _useContext.weight;
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
size: (_ref3 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : size) !== null && _ref3 !== void 0 ? _ref3 : 'standard',
|
|
57
|
+
tone: (_ref4 = toneProp !== null && toneProp !== void 0 ? toneProp : tone) !== null && _ref4 !== void 0 ? _ref4 : 'neutral',
|
|
58
|
+
weight: (_ref5 = weightProp !== null && weightProp !== void 0 ? weightProp : weight) !== null && _ref5 !== void 0 ? _ref5 : 'regular'
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
var __jsx$1 = React__default["default"].createElement;
|
|
63
|
+
var Strong = function Strong(_ref) {
|
|
64
|
+
var children = _ref.children;
|
|
65
|
+
|
|
66
|
+
var _useTheme = theme.useTheme(),
|
|
67
|
+
typography = _useTheme.typography;
|
|
68
|
+
|
|
69
|
+
var styles = {
|
|
70
|
+
fontWeight: typography.fontWeight.strong
|
|
71
|
+
};
|
|
72
|
+
return __jsx$1("strong", {
|
|
73
|
+
className: css.css(styles)
|
|
74
|
+
}, children);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
var strategyMap = {
|
|
78
|
+
truncate: {
|
|
79
|
+
display: 'block',
|
|
80
|
+
overflow: 'hidden',
|
|
81
|
+
textOverflow: 'ellipsis',
|
|
82
|
+
whiteSpace: 'nowrap'
|
|
83
|
+
},
|
|
84
|
+
nowrap: {
|
|
85
|
+
whiteSpace: 'nowrap'
|
|
86
|
+
},
|
|
87
|
+
// https://css-tricks.com/better-line-breaks-for-long-urls/
|
|
88
|
+
breakword: {
|
|
89
|
+
display: 'block',
|
|
90
|
+
overflowWrap: 'break-word',
|
|
91
|
+
wordBreak: 'break-word',
|
|
92
|
+
wordWrap: 'break-word'
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
function useOverflowStrategy(strategy) {
|
|
96
|
+
if (!strategy) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return strategyMap[strategy];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
var invertableTones = {
|
|
104
|
+
neutral: {
|
|
105
|
+
dark: 'neutralInverted',
|
|
106
|
+
light: 'neutral'
|
|
107
|
+
},
|
|
108
|
+
muted: {
|
|
109
|
+
dark: 'mutedInverted',
|
|
110
|
+
light: 'muted'
|
|
111
|
+
},
|
|
112
|
+
link: {
|
|
113
|
+
dark: 'neutralInverted',
|
|
114
|
+
light: 'link'
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function useForegroundTone(tone) {
|
|
118
|
+
var theme$1 = theme.useTheme();
|
|
119
|
+
var backgroundLightness = box.useBackgroundLightness();
|
|
120
|
+
|
|
121
|
+
if (tone in invertableTones) {
|
|
122
|
+
return theme$1.color.foreground[invertableTones[tone][backgroundLightness]];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return theme$1.color.foreground[tone];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
129
|
+
|
|
130
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
131
|
+
function useText(_ref) {
|
|
132
|
+
var _ref$baseline = _ref.baseline,
|
|
133
|
+
baseline = _ref$baseline === void 0 ? true : _ref$baseline,
|
|
134
|
+
size = _ref.size,
|
|
135
|
+
tone = _ref.tone,
|
|
136
|
+
weight = _ref.weight;
|
|
137
|
+
|
|
138
|
+
var _useTheme = theme.useTheme(),
|
|
139
|
+
typography = _useTheme.typography,
|
|
140
|
+
utils = _useTheme.utils;
|
|
141
|
+
|
|
142
|
+
var color = useForegroundTone(tone);
|
|
143
|
+
var _typography$text$size = typography.text[size],
|
|
144
|
+
mobile = _typography$text$size.mobile,
|
|
145
|
+
tablet = _typography$text$size.tablet;
|
|
146
|
+
var responsiveStyles = utils.responsiveStyles({
|
|
147
|
+
mobile: createTextStyles(mobile, {
|
|
148
|
+
includeTrims: baseline
|
|
149
|
+
}),
|
|
150
|
+
tablet: createTextStyles(tablet, {
|
|
151
|
+
includeTrims: baseline
|
|
152
|
+
})
|
|
153
|
+
});
|
|
154
|
+
var styles = [{
|
|
155
|
+
color: color,
|
|
156
|
+
fontFamily: typography.fontFamily.sans.name,
|
|
157
|
+
fontWeight: typography.fontWeight[weight]
|
|
158
|
+
}, responsiveStyles];
|
|
159
|
+
return styles;
|
|
160
|
+
}
|
|
161
|
+
function createTextStyles(_ref2) {
|
|
162
|
+
var fontSize = _ref2.fontSize,
|
|
163
|
+
lineHeight = _ref2.lineHeight,
|
|
164
|
+
trims = _ref2.trims;
|
|
165
|
+
|
|
166
|
+
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
167
|
+
_ref3$includeTrims = _ref3.includeTrims,
|
|
168
|
+
includeTrims = _ref3$includeTrims === void 0 ? true : _ref3$includeTrims;
|
|
169
|
+
|
|
170
|
+
var pseudo = {
|
|
171
|
+
content: '" "',
|
|
172
|
+
display: 'table'
|
|
173
|
+
};
|
|
174
|
+
var leadingTrim = includeTrims ? {
|
|
175
|
+
'::before': _objectSpread(_objectSpread({}, pseudo), {}, {
|
|
176
|
+
marginBottom: trims.capHeightTrim
|
|
177
|
+
}),
|
|
178
|
+
'::after': _objectSpread(_objectSpread({}, pseudo), {}, {
|
|
179
|
+
marginTop: trims.baselineTrim
|
|
180
|
+
})
|
|
181
|
+
} : null;
|
|
182
|
+
return _objectSpread({
|
|
183
|
+
fontSize: fontSize,
|
|
184
|
+
lineHeight: lineHeight
|
|
185
|
+
}, leadingTrim);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
var __jsx = React__default["default"].createElement;
|
|
189
|
+
var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
190
|
+
var as = _ref.as,
|
|
191
|
+
children = _ref.children,
|
|
192
|
+
id = _ref.id,
|
|
193
|
+
align = _ref.align,
|
|
194
|
+
baselineProp = _ref.baseline,
|
|
195
|
+
inline = _ref.inline,
|
|
196
|
+
overflowStrategy = _ref.overflowStrategy,
|
|
197
|
+
sizeProp = _ref.size,
|
|
198
|
+
tabularNumbers = _ref.tabularNumbers,
|
|
199
|
+
toneProp = _ref.tone,
|
|
200
|
+
transform = _ref.transform,
|
|
201
|
+
weightProp = _ref.weight;
|
|
202
|
+
var overflowStyles = useOverflowStrategy(overflowStrategy);
|
|
203
|
+
var textContext = useTextContext();
|
|
204
|
+
|
|
205
|
+
var _useDefaultTextProps = useDefaultTextProps({
|
|
206
|
+
size: sizeProp !== null && sizeProp !== void 0 ? sizeProp : textContext === null || textContext === void 0 ? void 0 : textContext.size,
|
|
207
|
+
tone: toneProp !== null && toneProp !== void 0 ? toneProp : textContext === null || textContext === void 0 ? void 0 : textContext.tone,
|
|
208
|
+
weight: weightProp !== null && weightProp !== void 0 ? weightProp : textContext === null || textContext === void 0 ? void 0 : textContext.weight
|
|
209
|
+
}),
|
|
210
|
+
size = _useDefaultTextProps.size,
|
|
211
|
+
tone = _useDefaultTextProps.tone,
|
|
212
|
+
weight = _useDefaultTextProps.weight;
|
|
213
|
+
|
|
214
|
+
var baseline = !inline && baselineProp;
|
|
215
|
+
var textStyles = useText({
|
|
216
|
+
baseline: baseline,
|
|
217
|
+
size: size,
|
|
218
|
+
tone: tone,
|
|
219
|
+
weight: weight
|
|
220
|
+
});
|
|
221
|
+
var styles = [textStyles, {
|
|
222
|
+
display: inline ? 'inline' : 'block',
|
|
223
|
+
fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
|
|
224
|
+
textAlign: align,
|
|
225
|
+
textTransform: transform
|
|
226
|
+
}]; // early exit for inline variant
|
|
227
|
+
|
|
228
|
+
if (inline) {
|
|
229
|
+
return __jsx(box.Box, {
|
|
230
|
+
as: as !== null && as !== void 0 ? as : 'span',
|
|
231
|
+
ref: forwardedRef,
|
|
232
|
+
id: id,
|
|
233
|
+
className: css.css(styles)
|
|
234
|
+
}, children);
|
|
235
|
+
} // prepare block variant
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
var content = overflowStrategy ? __jsx("span", {
|
|
239
|
+
className: css.css(overflowStyles)
|
|
240
|
+
}, children) : children;
|
|
241
|
+
var textContextValue = React.useMemo(function () {
|
|
242
|
+
return {
|
|
243
|
+
size: size,
|
|
244
|
+
tone: tone,
|
|
245
|
+
weight: weight
|
|
246
|
+
};
|
|
247
|
+
}, [size, tone, weight]);
|
|
248
|
+
return __jsx(TextContext.Provider, {
|
|
249
|
+
value: textContextValue
|
|
250
|
+
}, __jsx(box.Box, {
|
|
251
|
+
as: as,
|
|
252
|
+
ref: forwardedRef,
|
|
253
|
+
id: id,
|
|
254
|
+
className: css.css(styles)
|
|
255
|
+
}, content));
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
exports.DefaultTextPropsProvider = DefaultTextPropsProvider;
|
|
259
|
+
exports.Strong = Strong;
|
|
260
|
+
exports.Text = Text;
|
|
261
|
+
exports.createTextStyles = createTextStyles;
|
|
262
|
+
exports.useDefaultTextProps = useDefaultTextProps;
|
|
263
|
+
exports.useForegroundTone = useForegroundTone;
|
|
264
|
+
exports.useOverflowStrategy = useOverflowStrategy;
|
|
265
|
+
exports.useText = useText;
|
|
266
|
+
exports.useTextContext = useTextContext;
|