@sentry/scraps 0.1.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/LICENSE.md +105 -0
- package/README.md +67 -0
- package/dist/code/inlineCode.d.ts +7 -0
- package/dist/code/inlineCode.js +38 -0
- package/dist/cssTypes.d.ts +57 -0
- package/dist/cssTypes.js +0 -0
- package/dist/hotkey/kbd.d.ts +8 -0
- package/dist/hotkey/kbd.js +31 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/layout/container.d.ts +114 -0
- package/dist/layout/container.js +161 -0
- package/dist/layout/flex.d.ts +42 -0
- package/dist/layout/flex.js +42 -0
- package/dist/layout/grid.d.ts +65 -0
- package/dist/layout/grid.js +83 -0
- package/dist/layout/index.d.ts +13 -0
- package/dist/layout/index.js +6 -0
- package/dist/layout/stack.d.ts +15 -0
- package/dist/layout/stack.js +55 -0
- package/dist/layout/styles.d.ts +118 -0
- package/dist/layout/styles.js +237 -0
- package/dist/layout/surface.d.ts +27 -0
- package/dist/layout/surface.js +28 -0
- package/dist/loader/indeterminateLoader.d.ts +5 -0
- package/dist/loader/indeterminateLoader.js +122 -0
- package/dist/loader/index.d.ts +1 -0
- package/dist/loader/index.js +1 -0
- package/dist/quote/index.d.ts +1 -0
- package/dist/quote/index.js +1 -0
- package/dist/quote/quote.d.ts +13 -0
- package/dist/quote/quote.js +73 -0
- package/dist/separator/index.d.ts +1 -0
- package/dist/separator/index.js +1 -0
- package/dist/separator/separator.d.ts +15 -0
- package/dist/separator/separator.js +29 -0
- package/dist/text/heading.d.ts +44 -0
- package/dist/text/heading.js +69 -0
- package/dist/text/index.d.ts +2 -0
- package/dist/text/index.js +2 -0
- package/dist/text/styles.d.ts +5 -0
- package/dist/text/styles.js +18 -0
- package/dist/text/text.d.ts +152 -0
- package/dist/text/text.js +81 -0
- package/dist/theme/base.d.ts +106 -0
- package/dist/theme/base.js +7 -0
- package/dist/theme/dark.d.ts +1904 -0
- package/dist/theme/dark.js +430 -0
- package/dist/theme/index.d.ts +14 -0
- package/dist/theme/index.js +3 -0
- package/dist/theme/light.d.ts +1904 -0
- package/dist/theme/light.js +430 -0
- package/dist/theme/types.d.ts +80 -0
- package/dist/theme/types.js +0 -0
- package/dist/tokens/color.d.ts +3309 -0
- package/dist/tokens/color.js +453 -0
- package/dist/tokens/index.d.ts +3 -0
- package/dist/tokens/index.js +3 -0
- package/dist/tokens/size.d.ts +372 -0
- package/dist/tokens/size.js +75 -0
- package/dist/tokens/typography.d.ts +88 -0
- package/dist/tokens/typography.js +35 -0
- package/package.json +83 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import styled from "@emotion/styled";
|
|
3
|
+
import { Container } from "./container.js";
|
|
4
|
+
import { getBorder, getRadius, rc } from "./styles.js";
|
|
5
|
+
function isRenderFunction(props) {
|
|
6
|
+
return 'function' == typeof props.children;
|
|
7
|
+
}
|
|
8
|
+
const Surface = styled((props)=>{
|
|
9
|
+
if (isRenderFunction(props)) return props.children({
|
|
10
|
+
className: props.className ?? ''
|
|
11
|
+
});
|
|
12
|
+
const { variant, elevation: _, ...rest } = props;
|
|
13
|
+
if ('overlay' === variant) return /*#__PURE__*/ jsx(Container, {
|
|
14
|
+
border: "primary",
|
|
15
|
+
radius: rest.radius ?? 'md',
|
|
16
|
+
...rest
|
|
17
|
+
});
|
|
18
|
+
return /*#__PURE__*/ jsx(Container, {
|
|
19
|
+
radius: rest.radius,
|
|
20
|
+
...rest
|
|
21
|
+
});
|
|
22
|
+
})`
|
|
23
|
+
${(p)=>rc('background', p.variant, p.theme, (v)=>v ? p.theme.tokens.background[v] : void 0)};
|
|
24
|
+
${(p)=>rc('border', 'overlay' === p.variant ? 'primary' : void 0, p.theme, getBorder)};
|
|
25
|
+
${(p)=>rc('border-radius', p.radius ?? ('overlay' === p.variant ? 'md' : void 0), p.theme, getRadius)};
|
|
26
|
+
${(p)=>rc('box-shadow', p.elevation ?? ('overlay' === p.variant ? 'low' : void 0), p.theme, (v)=>v ? p.theme.shadow[v] : void 0)};
|
|
27
|
+
`;
|
|
28
|
+
export { Surface };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
interface IndeterminateLoaderProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
2
|
+
variant?: 'vibrant' | 'monochrome';
|
|
3
|
+
}
|
|
4
|
+
export declare function IndeterminateLoader({ variant, ...props }: IndeterminateLoaderProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import { keyframes, useTheme } from "@emotion/react";
|
|
4
|
+
import styled from "@emotion/styled";
|
|
5
|
+
import { useResizeObserver } from "@react-aria/utils";
|
|
6
|
+
const SQUIGGLE_TILE = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='1 0 16 8'%3E%3Cpath stroke='%23fff' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M17 6c-4 0-4-4-8-4S5 6 1 6'/%3E%3C/svg%3E\")";
|
|
7
|
+
const indeterminateSlow = keyframes`
|
|
8
|
+
0% { left: -35%; right: 100%; }
|
|
9
|
+
60% { left: 100%; right: -90%; }
|
|
10
|
+
100% { left: 100%; right: -90%; }
|
|
11
|
+
`;
|
|
12
|
+
const indeterminateFast = keyframes`
|
|
13
|
+
0% { left: -200%; right: 100%; }
|
|
14
|
+
60% { left: 107%; right: -8%; }
|
|
15
|
+
100% { left: 107%; right: -8%; }
|
|
16
|
+
`;
|
|
17
|
+
const WIDTH = {
|
|
18
|
+
MIN: 128,
|
|
19
|
+
MAX: 400
|
|
20
|
+
};
|
|
21
|
+
const DURATION = {
|
|
22
|
+
MIN: 2,
|
|
23
|
+
MAX: 2.8
|
|
24
|
+
};
|
|
25
|
+
const DELAY = {
|
|
26
|
+
MIN: 0.8,
|
|
27
|
+
MAX: 1.2
|
|
28
|
+
};
|
|
29
|
+
function lerp(min, max, t) {
|
|
30
|
+
return min + (max - min) * Math.min(1, Math.max(0, t));
|
|
31
|
+
}
|
|
32
|
+
function useAnimationTiming() {
|
|
33
|
+
const ref = useRef(null);
|
|
34
|
+
const [duration, setDuration] = useState(DURATION.MAX);
|
|
35
|
+
const [delay, setDelay] = useState(DELAY.MAX);
|
|
36
|
+
useResizeObserver({
|
|
37
|
+
ref,
|
|
38
|
+
onResize () {
|
|
39
|
+
const w = ref.current?.offsetWidth ?? WIDTH.MAX;
|
|
40
|
+
const t = (w - WIDTH.MIN) / (WIDTH.MAX - WIDTH.MIN);
|
|
41
|
+
setDuration(lerp(DURATION.MIN, DURATION.MAX, t));
|
|
42
|
+
setDelay(lerp(DELAY.MIN, DELAY.MAX, t));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
ref,
|
|
47
|
+
duration,
|
|
48
|
+
delay
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function IndeterminateLoader({ variant = 'vibrant', ...props }) {
|
|
52
|
+
const theme = useTheme();
|
|
53
|
+
const { ref, duration, delay } = useAnimationTiming();
|
|
54
|
+
return /*#__PURE__*/ jsx(Track, {
|
|
55
|
+
ref: ref,
|
|
56
|
+
role: "progressbar",
|
|
57
|
+
"aria-label": "Loading",
|
|
58
|
+
opacity: 'monochrome' === variant ? '0.2' : '1',
|
|
59
|
+
color: 'monochrome' === variant ? 'currentColor' : theme.tokens.border.secondary,
|
|
60
|
+
...props,
|
|
61
|
+
children: /*#__PURE__*/ jsxs(ColorMask, {
|
|
62
|
+
children: [
|
|
63
|
+
/*#__PURE__*/ jsx(Bar, {
|
|
64
|
+
color: 'monochrome' === variant ? 'currentColor' : theme.tokens.border.accent.vibrant,
|
|
65
|
+
animation: indeterminateSlow,
|
|
66
|
+
timing: "cubic-bezier(0.4, 0.0, 0.2, 1)",
|
|
67
|
+
duration: `${duration}s`,
|
|
68
|
+
delay: "0s"
|
|
69
|
+
}),
|
|
70
|
+
/*#__PURE__*/ jsx(Bar, {
|
|
71
|
+
color: 'monochrome' === variant ? 'currentColor' : theme.tokens.border.accent.vibrant,
|
|
72
|
+
animation: indeterminateFast,
|
|
73
|
+
timing: "cubic-bezier(0.4, 0.0, 0.2, 1)",
|
|
74
|
+
duration: `${duration}s`,
|
|
75
|
+
delay: `${delay}s`
|
|
76
|
+
})
|
|
77
|
+
]
|
|
78
|
+
})
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const Track = styled('div')`
|
|
82
|
+
position: relative;
|
|
83
|
+
overflow: hidden;
|
|
84
|
+
width: 100%;
|
|
85
|
+
width: calc(round(down, 100% - 16px, 8px) + 16px);
|
|
86
|
+
height: 8px;
|
|
87
|
+
|
|
88
|
+
&::before {
|
|
89
|
+
content: '';
|
|
90
|
+
position: absolute;
|
|
91
|
+
inset: 0;
|
|
92
|
+
background: ${(p)=>p.color};
|
|
93
|
+
opacity: ${(p)=>p.opacity};
|
|
94
|
+
mask-image: ${SQUIGGLE_TILE};
|
|
95
|
+
mask-repeat: repeat-x;
|
|
96
|
+
mask-size: 16px 8px;
|
|
97
|
+
-webkit-mask-image: ${SQUIGGLE_TILE};
|
|
98
|
+
-webkit-mask-repeat: repeat-x;
|
|
99
|
+
-webkit-mask-size: 16px 8px;
|
|
100
|
+
}
|
|
101
|
+
`;
|
|
102
|
+
const ColorMask = styled('span')`
|
|
103
|
+
position: absolute;
|
|
104
|
+
inset: 0;
|
|
105
|
+
mask-image: ${SQUIGGLE_TILE};
|
|
106
|
+
mask-repeat: repeat-x;
|
|
107
|
+
mask-size: 16px 8px;
|
|
108
|
+
-webkit-mask-image: ${SQUIGGLE_TILE};
|
|
109
|
+
-webkit-mask-repeat: repeat-x;
|
|
110
|
+
-webkit-mask-size: 16px 8px;
|
|
111
|
+
`;
|
|
112
|
+
const Bar = styled('span')`
|
|
113
|
+
position: absolute;
|
|
114
|
+
top: 0;
|
|
115
|
+
bottom: 0;
|
|
116
|
+
left: 0;
|
|
117
|
+
right: 0;
|
|
118
|
+
background: ${(p)=>p.color};
|
|
119
|
+
animation: ${(p)=>p.animation} ${(p)=>p.duration} ${(p)=>p.timing} ${(p)=>p.delay}
|
|
120
|
+
infinite backwards;
|
|
121
|
+
`;
|
|
122
|
+
export { IndeterminateLoader };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IndeterminateLoader } from './indeterminateLoader.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IndeterminateLoader } from "./indeterminateLoader.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Quote, type QuoteProps } from './quote.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Quote } from "./quote.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { StackProps } from '../layout/index.js';
|
|
3
|
+
interface QuoteBaseProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
source?: {
|
|
6
|
+
author?: string;
|
|
7
|
+
href?: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export type QuoteProps = QuoteBaseProps & Omit<StackProps<'blockquote'>, 'children'>;
|
|
12
|
+
export declare function Quote(props: QuoteProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Fragment } from "react";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { Stack } from "../layout/index.js";
|
|
5
|
+
import { Text } from "../text/index.js";
|
|
6
|
+
function Quote(props) {
|
|
7
|
+
const { children, ...spreadProps } = props;
|
|
8
|
+
return /*#__PURE__*/ jsxs(Stack, {
|
|
9
|
+
gap: "md",
|
|
10
|
+
as: "figure",
|
|
11
|
+
position: "relative",
|
|
12
|
+
...spreadProps,
|
|
13
|
+
children: [
|
|
14
|
+
/*#__PURE__*/ jsx(Line, {
|
|
15
|
+
"aria-orientation": "vertical"
|
|
16
|
+
}),
|
|
17
|
+
/*#__PURE__*/ jsx(Blockquote, {
|
|
18
|
+
cite: props.source?.href,
|
|
19
|
+
as: "blockquote",
|
|
20
|
+
children: children
|
|
21
|
+
}),
|
|
22
|
+
props.source ? /*#__PURE__*/ jsx(Caption, {
|
|
23
|
+
children: /*#__PURE__*/ jsxs(Text, {
|
|
24
|
+
as: "p",
|
|
25
|
+
children: [
|
|
26
|
+
"–\xa0",
|
|
27
|
+
props.source.author,
|
|
28
|
+
props.source?.label ? /*#__PURE__*/ jsxs(Fragment, {
|
|
29
|
+
children: [
|
|
30
|
+
", ",
|
|
31
|
+
/*#__PURE__*/ jsx("cite", {
|
|
32
|
+
children: props.source.label
|
|
33
|
+
})
|
|
34
|
+
]
|
|
35
|
+
}) : null
|
|
36
|
+
]
|
|
37
|
+
})
|
|
38
|
+
}) : null
|
|
39
|
+
]
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const Line = styled('hr')`
|
|
43
|
+
position: absolute;
|
|
44
|
+
top: 0;
|
|
45
|
+
bottom: 0;
|
|
46
|
+
left: 0;
|
|
47
|
+
margin: 0;
|
|
48
|
+
border: none;
|
|
49
|
+
height: 100%;
|
|
50
|
+
width: 1px;
|
|
51
|
+
padding-left: ${(p)=>p.theme.space.xl};
|
|
52
|
+
margin-left: ${(p)=>p.theme.space.lg};
|
|
53
|
+
border-left: 1px solid ${(p)=>p.theme.tokens.border.primary};
|
|
54
|
+
`;
|
|
55
|
+
const Blockquote = styled('blockquote')`
|
|
56
|
+
/**
|
|
57
|
+
* Reset any properties that might be set by the global CSS styles.
|
|
58
|
+
*/
|
|
59
|
+
margin: 0;
|
|
60
|
+
padding: 0;
|
|
61
|
+
border: none;
|
|
62
|
+
padding-left: calc(${(p)=>`${p.theme.space.xl} + ${p.theme.space.lg}`});
|
|
63
|
+
`;
|
|
64
|
+
const Caption = styled('figcaption')`
|
|
65
|
+
/**
|
|
66
|
+
* Reset any properties that might be set by the global CSS styles.
|
|
67
|
+
*/
|
|
68
|
+
margin: 0;
|
|
69
|
+
padding: 0;
|
|
70
|
+
border: none;
|
|
71
|
+
padding-left: calc(${(p)=>`${p.theme.space.xl} + ${p.theme.space.lg}`});
|
|
72
|
+
`;
|
|
73
|
+
export { Quote };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Separator, type SeparatorProps } from './separator.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Separator } from "./separator.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ContainerProps } from '../layout/index.js';
|
|
2
|
+
export type SeparatorProps = Pick<ContainerProps, 'border' | 'margin' | 'padding'> & {
|
|
3
|
+
orientation: 'horizontal' | 'vertical';
|
|
4
|
+
children?: never;
|
|
5
|
+
} & Omit<React.HTMLAttributes<HTMLHRElement>, 'aria-orientation'>;
|
|
6
|
+
/**
|
|
7
|
+
* We require a wrapper if we want to use the orientation context,
|
|
8
|
+
* otherwise the styling won't work as override needs to come from the parent.
|
|
9
|
+
*/
|
|
10
|
+
export declare const Separator: import("@emotion/styled").StyledComponent<Pick<ContainerProps, "border" | "padding" | "margin"> & {
|
|
11
|
+
orientation: "horizontal" | "vertical";
|
|
12
|
+
children?: never;
|
|
13
|
+
} & Omit<import("react").HTMLAttributes<HTMLHRElement>, "aria-orientation"> & {
|
|
14
|
+
theme?: import("@emotion/react").Theme;
|
|
15
|
+
}, {}, {}>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import is_prop_valid from "@emotion/is-prop-valid";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { getBorder, getMargin, getSpacing, rc } from "../layout/index.js";
|
|
5
|
+
const omitSeparatorProps = new Set([
|
|
6
|
+
'border'
|
|
7
|
+
]);
|
|
8
|
+
const Separator = styled(({ orientation, ...props })=>/*#__PURE__*/ jsx("hr", {
|
|
9
|
+
"aria-orientation": orientation,
|
|
10
|
+
...props
|
|
11
|
+
}), {
|
|
12
|
+
shouldForwardProp: (prop)=>{
|
|
13
|
+
if (omitSeparatorProps.has(prop)) return false;
|
|
14
|
+
return is_prop_valid(prop);
|
|
15
|
+
}
|
|
16
|
+
})`
|
|
17
|
+
width: ${(p)=>'horizontal' === p.orientation ? 'auto' : '1px'};
|
|
18
|
+
height: ${(p)=>'horizontal' === p.orientation ? '1px' : 'auto'};
|
|
19
|
+
|
|
20
|
+
${(p)=>rc('padding', p.padding, p.theme, getSpacing)};
|
|
21
|
+
${(p)=>rc('margin', p.margin ?? '0', p.theme, getMargin)};
|
|
22
|
+
|
|
23
|
+
flex-shrink: 0;
|
|
24
|
+
align-self: stretch;
|
|
25
|
+
|
|
26
|
+
border: none;
|
|
27
|
+
${(p)=>rc('horizontal' === p.orientation ? 'border-bottom' : 'border-left', p.border ?? 'primary', p.theme, (...args)=>`${getBorder(...args)} !important`)};
|
|
28
|
+
`;
|
|
29
|
+
export { Separator };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Responsive } from '../layout/index.js';
|
|
2
|
+
import type { HeadingSize } from '../theme/index.js';
|
|
3
|
+
import { type BaseTextProps } from './text.js';
|
|
4
|
+
type BaseHeadingProps = Omit<BaseTextProps, 'bold' | 'uppercase'>;
|
|
5
|
+
type ExclusiveHeadingEllipsisProps = {
|
|
6
|
+
ellipsis?: true;
|
|
7
|
+
wrap?: never;
|
|
8
|
+
} | {
|
|
9
|
+
ellipsis?: never;
|
|
10
|
+
wrap?: BaseTextProps['wrap'];
|
|
11
|
+
};
|
|
12
|
+
export type HeadingProps = BaseHeadingProps & {
|
|
13
|
+
/**
|
|
14
|
+
* The HTML element to render the title as.
|
|
15
|
+
* @required
|
|
16
|
+
*/
|
|
17
|
+
as: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
18
|
+
ref?: React.Ref<HTMLHeadingElement | null> | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The size of the text.
|
|
21
|
+
* @default md
|
|
22
|
+
*/
|
|
23
|
+
size?: Responsive<HeadingSize>;
|
|
24
|
+
/**
|
|
25
|
+
* Deprecated in favor of the Text component API.
|
|
26
|
+
* If you have an is an unsupported use-case, please contact design engineering for support.
|
|
27
|
+
* @deprecated
|
|
28
|
+
*/
|
|
29
|
+
style?: React.CSSProperties;
|
|
30
|
+
} & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, 'style'> & ExclusiveHeadingEllipsisProps;
|
|
31
|
+
export type HeadingPropsWithRenderFunction = BaseHeadingProps & ExclusiveHeadingEllipsisProps & {
|
|
32
|
+
children: (props: {
|
|
33
|
+
className: string;
|
|
34
|
+
}) => React.ReactNode | undefined;
|
|
35
|
+
as?: never;
|
|
36
|
+
ref?: never;
|
|
37
|
+
size?: Responsive<HeadingSize>;
|
|
38
|
+
} & Partial<Record<Exclude<keyof React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, 'children'>, never>>;
|
|
39
|
+
export declare const Heading: import("@emotion/styled").StyledComponent<((HeadingProps | HeadingPropsWithRenderFunction) & {
|
|
40
|
+
className?: string;
|
|
41
|
+
}) & {
|
|
42
|
+
theme?: import("@emotion/react").Theme;
|
|
43
|
+
}, {}, {}>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import is_prop_valid from "@emotion/is-prop-valid";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { rc } from "../layout/index.js";
|
|
5
|
+
import { getFontSize, getLineHeight, getTextDecoration } from "./styles.js";
|
|
6
|
+
const Heading = styled((props)=>{
|
|
7
|
+
if ('function' == typeof props.children) return props.children({
|
|
8
|
+
className: props.className ?? ''
|
|
9
|
+
});
|
|
10
|
+
const { children, as, ...rest } = props;
|
|
11
|
+
const HeadingComponent = as;
|
|
12
|
+
return /*#__PURE__*/ jsx(HeadingComponent, {
|
|
13
|
+
...rest,
|
|
14
|
+
children: children
|
|
15
|
+
});
|
|
16
|
+
}, {
|
|
17
|
+
shouldForwardProp: (p)=>is_prop_valid(p)
|
|
18
|
+
})`
|
|
19
|
+
${(p)=>'inherit' === p.variant && void 0 === p.size ? 'font-size: inherit' : rc('font-size', p.size ?? (p.as ? getDefaultHeadingFontSize(p.as) : void 0), p.theme, (v)=>getFontSize(v, p.theme))};
|
|
20
|
+
${(p)=>'inherit' === p.variant && void 0 === p.density ? 'line-height: inherit' : rc('line-height', p.density, p.theme, (v)=>getLineHeight(v, p.theme))};
|
|
21
|
+
${(p)=>rc('text-align', p.align, p.theme)};
|
|
22
|
+
|
|
23
|
+
font-style: ${(p)=>p.italic ? 'italic' : void 0};
|
|
24
|
+
|
|
25
|
+
text-decoration: ${(p)=>getTextDecoration(p)};
|
|
26
|
+
|
|
27
|
+
color: ${(p)=>'inherit' === p.variant ? void 0 : p.theme.tokens.content['muted' === p.variant ? 'secondary' : p.variant ?? 'primary']};
|
|
28
|
+
|
|
29
|
+
overflow: ${(p)=>p.ellipsis ? 'hidden' : void 0};
|
|
30
|
+
text-overflow: ${(p)=>p.ellipsis ? 'ellipsis' : void 0};
|
|
31
|
+
white-space: ${(p)=>p.wrap ? p.wrap : p.ellipsis ? 'nowrap' : void 0};
|
|
32
|
+
text-wrap: ${(p)=>p.textWrap ?? void 0};
|
|
33
|
+
word-break: ${(p)=>p.wordBreak ?? void 0};
|
|
34
|
+
|
|
35
|
+
font-family: ${(p)=>p.theme.font.family[p.monospace ? 'mono' : 'sans']};
|
|
36
|
+
font-weight: ${(p)=>'inherit' === p.variant ? 'inherit' : p.theme.font.weight[p.monospace ? 'mono' : 'sans'].medium};
|
|
37
|
+
font-variant-numeric: ${(p)=>[
|
|
38
|
+
p.tabular ? 'tabular-nums' : void 0,
|
|
39
|
+
p.fraction ? 'diagonal-fractions' : void 0
|
|
40
|
+
].filter(Boolean).join(' ')};
|
|
41
|
+
|
|
42
|
+
text-box-edge: text text;
|
|
43
|
+
text-box-trim: trim-both;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Reset any margin or padding that might be set by the global CSS styles.
|
|
47
|
+
*/
|
|
48
|
+
margin: 0;
|
|
49
|
+
padding: 0;
|
|
50
|
+
`;
|
|
51
|
+
function getDefaultHeadingFontSize(as) {
|
|
52
|
+
switch(as){
|
|
53
|
+
case 'h1':
|
|
54
|
+
return '2xl';
|
|
55
|
+
case 'h2':
|
|
56
|
+
return 'xl';
|
|
57
|
+
case 'h3':
|
|
58
|
+
return 'lg';
|
|
59
|
+
case 'h4':
|
|
60
|
+
return 'md';
|
|
61
|
+
case 'h5':
|
|
62
|
+
return 'sm';
|
|
63
|
+
case 'h6':
|
|
64
|
+
return 'xs';
|
|
65
|
+
default:
|
|
66
|
+
return '2xl';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export { Heading };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { HeadingSize, TextSize, Theme } from '../theme/index.js';
|
|
2
|
+
import type { BaseTextProps } from './text.js';
|
|
3
|
+
export declare function getTextDecoration(p: Pick<BaseTextProps, 'strikethrough' | 'underline'>): string;
|
|
4
|
+
export declare function getLineHeight(density: keyof Theme['font']['lineHeight'] | undefined, theme: Theme): string | undefined;
|
|
5
|
+
export declare function getFontSize(size: TextSize | HeadingSize | undefined, theme: Theme): string | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function getTextDecoration(p) {
|
|
2
|
+
const decorations = [];
|
|
3
|
+
if (p.strikethrough) decorations.push('line-through');
|
|
4
|
+
if (p.underline) {
|
|
5
|
+
decorations.push('underline');
|
|
6
|
+
if ('dotted' === p.underline) decorations.push('dotted');
|
|
7
|
+
}
|
|
8
|
+
return decorations.join(' ');
|
|
9
|
+
}
|
|
10
|
+
function getLineHeight(density, theme) {
|
|
11
|
+
if (void 0 === density) return;
|
|
12
|
+
return theme.font.lineHeight[density].toString();
|
|
13
|
+
}
|
|
14
|
+
function getFontSize(size, theme) {
|
|
15
|
+
if (void 0 === size) return;
|
|
16
|
+
return theme.font.size[size];
|
|
17
|
+
}
|
|
18
|
+
export { getFontSize, getLineHeight, getTextDecoration };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { type Responsive } from '../layout/index.js';
|
|
2
|
+
import type { ContentVariant, TextSize, Theme } from '../theme/index.js';
|
|
3
|
+
export interface BaseTextProps {
|
|
4
|
+
/**
|
|
5
|
+
* Horizontal alignment of the text.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
align?: Responsive<'left' | 'center' | 'right' | 'justify'>;
|
|
9
|
+
bold?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Determines the cursor style when hovering over the text.
|
|
12
|
+
* @default 'default'
|
|
13
|
+
*/
|
|
14
|
+
cursor?: 'default' | 'pointer' | 'text' | 'move' | 'not-allowed' | 'wait' | 'help';
|
|
15
|
+
/**
|
|
16
|
+
* Density determines the line height of the text.
|
|
17
|
+
* Defaults to 1.2, but supports the following density variants:
|
|
18
|
+
* - compressed: 1
|
|
19
|
+
* - default: 1.2
|
|
20
|
+
* - comfortable: 1.4
|
|
21
|
+
* - fixed: 1rem
|
|
22
|
+
*/
|
|
23
|
+
density?: Responsive<keyof Theme['font']['lineHeight']>;
|
|
24
|
+
/**
|
|
25
|
+
* If true, the text will be truncated with an ellipsis,
|
|
26
|
+
* overflow will be hidden and white-space will be set to nowrap.
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
ellipsis?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Determines if fractional numbers should be displayed using diagonal fractions.
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
fraction?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Determines if the text should be italic.
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
italic?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* If true, the text will be displayed in a monospace font.
|
|
42
|
+
*/
|
|
43
|
+
monospace?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Strikethrough the text.
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
strikethrough?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* If true, the text will be displayed in a tabular font (fixed width numbers)
|
|
51
|
+
*/
|
|
52
|
+
tabular?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Determines how text wrapping is handled using the CSS text-wrap property.
|
|
55
|
+
* @default undefined
|
|
56
|
+
*/
|
|
57
|
+
textWrap?: 'wrap' | 'nowrap' | 'balance' | 'pretty' | 'stable';
|
|
58
|
+
/**
|
|
59
|
+
* Determines how text should be underlined.
|
|
60
|
+
* @default undefined
|
|
61
|
+
*/
|
|
62
|
+
underline?: boolean | 'dotted';
|
|
63
|
+
/**
|
|
64
|
+
* Uppercase the text.
|
|
65
|
+
*/
|
|
66
|
+
uppercase?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Variant determines the style of the text.
|
|
69
|
+
* - Use a semantic variant (e.g. `primary`, `muted`) to apply a token-based color.
|
|
70
|
+
* - Use `inherit` to explicitly inherit the color from the parent element.
|
|
71
|
+
* @default primary
|
|
72
|
+
*/
|
|
73
|
+
variant?: ContentVariant | 'muted' | 'inherit';
|
|
74
|
+
/**
|
|
75
|
+
* Determines where line breaks appear when wrapping the text.
|
|
76
|
+
* @default undefined
|
|
77
|
+
*/
|
|
78
|
+
wordBreak?: 'normal' | 'break-all' | 'keep-all' | 'break-word';
|
|
79
|
+
/**
|
|
80
|
+
* Determines text wrapping.
|
|
81
|
+
*/
|
|
82
|
+
wrap?: 'nowrap' | 'normal' | 'pre' | 'pre-line' | 'pre-wrap';
|
|
83
|
+
}
|
|
84
|
+
type ExclusiveTextEllipsisProps = {
|
|
85
|
+
display?: never;
|
|
86
|
+
ellipsis?: true;
|
|
87
|
+
wrap?: never;
|
|
88
|
+
} | {
|
|
89
|
+
display?: Responsive<DisplayValue>;
|
|
90
|
+
ellipsis?: never;
|
|
91
|
+
wrap?: BaseTextProps['wrap'];
|
|
92
|
+
};
|
|
93
|
+
interface TextAttributes<T extends TextPrimitive = 'span'> extends BaseTextProps, Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElementTagNameMap[T]>, HTMLElementTagNameMap[T]>, 'style'> {
|
|
94
|
+
/**
|
|
95
|
+
* Our decision to make children required conflicts with the optional signature of the React.DetailedHTMLProps type.
|
|
96
|
+
* To resolve it, we move the children definition after the React.DetailedHTMLProps type,
|
|
97
|
+
* which narrows the type from optional to required as expected.
|
|
98
|
+
*/
|
|
99
|
+
children: React.ReactNode;
|
|
100
|
+
/**
|
|
101
|
+
* The HTML element to render the text as - defaults to span.
|
|
102
|
+
* @default span
|
|
103
|
+
*/
|
|
104
|
+
as?: T;
|
|
105
|
+
/**
|
|
106
|
+
* Forbid color HTML attribute from being passed to the component, all usage should be variant-based.
|
|
107
|
+
*/
|
|
108
|
+
color?: never;
|
|
109
|
+
dateTime?: T extends 'time' ? string : never;
|
|
110
|
+
/**
|
|
111
|
+
* This could have been avoided by using React.JSX.IntrinsicElements<T>, however doing so would be
|
|
112
|
+
* grosely inefficient, as it would cause type helpers like DistributedOmit to traverse the entire
|
|
113
|
+
* type HTML Attribute set of each element, slowing down our type compilation. In my test, using
|
|
114
|
+
* React.JSX.IntrinsicElements<T> caused native ts compilation to take 2x longer.
|
|
115
|
+
*
|
|
116
|
+
*/
|
|
117
|
+
htmlFor?: T extends 'label' ? string : never;
|
|
118
|
+
/**
|
|
119
|
+
* The size of the text.
|
|
120
|
+
* @default md
|
|
121
|
+
*/
|
|
122
|
+
size?: Responsive<TextSize>;
|
|
123
|
+
/**
|
|
124
|
+
* Deprecated in favor of the Text component API.
|
|
125
|
+
* If you have an is an unsupported use-case, please contact design engineering for support.
|
|
126
|
+
* @deprecated
|
|
127
|
+
*/
|
|
128
|
+
style?: React.CSSProperties;
|
|
129
|
+
}
|
|
130
|
+
type TextPrimitive = 'span' | 'p' | 'label' | 'div' | 'time' | 'legend';
|
|
131
|
+
type DisplayValue = 'inline' | 'block' | 'inline-block' | 'none';
|
|
132
|
+
type TextStyleProps = BaseTextProps & {
|
|
133
|
+
theme: Theme;
|
|
134
|
+
as?: TextPrimitive;
|
|
135
|
+
display?: Responsive<DisplayValue>;
|
|
136
|
+
size?: Responsive<TextSize>;
|
|
137
|
+
};
|
|
138
|
+
export declare const getTextStyles: (p: TextStyleProps) => import("@emotion/react").SerializedStyles;
|
|
139
|
+
export type TextProps<T extends TextPrimitive> = TextAttributes<T> & ExclusiveTextEllipsisProps;
|
|
140
|
+
export type TextPropsWithRenderFunction<T extends TextPrimitive = 'span'> = BaseTextProps & ExclusiveTextEllipsisProps & {
|
|
141
|
+
children: (props: {
|
|
142
|
+
className: string;
|
|
143
|
+
}) => React.ReactNode | undefined;
|
|
144
|
+
as?: never;
|
|
145
|
+
color?: never;
|
|
146
|
+
dateTime?: never;
|
|
147
|
+
htmlFor?: never;
|
|
148
|
+
ref?: never;
|
|
149
|
+
size?: Responsive<TextSize>;
|
|
150
|
+
} & Partial<Record<Exclude<keyof React.DetailedHTMLProps<React.HTMLAttributes<HTMLElementTagNameMap[T]>, HTMLElementTagNameMap[T]>, 'children'>, never>>;
|
|
151
|
+
export declare const Text: <T extends TextPrimitive = "span">(props: TextProps<T> | TextPropsWithRenderFunction<T>) => React.ReactElement;
|
|
152
|
+
export {};
|