onecart-ui 1.0.1 → 1.0.2
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/README.md +64 -27
- package/dist/components/Button/Button.d.ts.map +1 -1
- package/dist/components/Button/index.d.ts +2 -2
- package/dist/components/Button/index.d.ts.map +1 -1
- package/dist/components/Icon/Icon.d.ts +40 -0
- package/dist/components/Icon/Icon.d.ts.map +1 -0
- package/dist/components/Icon/IconList.d.ts +21 -0
- package/dist/components/Icon/IconList.d.ts.map +1 -0
- package/dist/components/Icon/index.d.ts +6 -0
- package/dist/components/Icon/index.d.ts.map +1 -0
- package/dist/components/Typography/Body.d.ts +4 -0
- package/dist/components/Typography/Body.d.ts.map +1 -0
- package/dist/components/Typography/Display.d.ts +4 -0
- package/dist/components/Typography/Display.d.ts.map +1 -0
- package/dist/components/Typography/Heading.d.ts +4 -0
- package/dist/components/Typography/Heading.d.ts.map +1 -0
- package/dist/components/Typography/Utility.d.ts +4 -0
- package/dist/components/Typography/Utility.d.ts.map +1 -0
- package/dist/components/Typography/index.d.ts +4 -2
- package/dist/components/Typography/index.d.ts.map +1 -1
- package/dist/index.d.ts +4 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/styles/tokens/typography.d.ts +11 -0
- package/dist/styles/tokens/typography.d.ts.map +1 -1
- package/dist/types/Button.d.ts +17 -40
- package/dist/types/Button.d.ts.map +1 -1
- package/dist/types/Typography.d.ts +20 -55
- package/dist/types/Typography.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/components/Button/Button.tsx +235 -136
- package/src/components/Button/index.ts +7 -2
- package/src/components/Icon/Icon.tsx +113 -0
- package/src/components/Icon/IconList.tsx +110 -0
- package/src/components/Icon/icons.json +81 -0
- package/src/components/Icon/index.ts +5 -0
- package/src/components/Typography/Body.tsx +94 -0
- package/src/components/Typography/Display.tsx +79 -0
- package/src/components/Typography/Heading.tsx +110 -0
- package/src/components/Typography/Utility.tsx +107 -0
- package/src/components/Typography/index.ts +4 -7
- package/src/index.ts +8 -17
- package/src/styles/tokens/tokens-autocomplete-config.json +2 -2
- package/src/styles/tokens/tokens.css +1 -1
- package/src/styles/tokens/typography.ts +11 -0
- package/src/types/Button.ts +19 -48
- package/src/types/Typography.ts +21 -81
- package/src/components/Heading/Heading.tsx +0 -48
- package/src/components/Heading/index.ts +0 -2
- package/src/components/Paragraph/Paragraph.tsx +0 -93
- package/src/components/Paragraph/index.ts +0 -6
- package/src/components/Text/Text.tsx +0 -96
- package/src/components/Text/index.ts +0 -2
- package/src/components/Typography/Typography.tsx +0 -123
- package/src/types/Heading.ts +0 -27
- package/src/types/Paragraph.ts +0 -40
- package/src/types/Text.ts +0 -40
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"icons": [
|
|
3
|
+
{
|
|
4
|
+
"name": "arrow-up",
|
|
5
|
+
"path": "M8 3.33325L8 12.6666 M3.33331 7.99992L8 3.33325L12.6666 7.99992",
|
|
6
|
+
"viewBox": "0 0 16 16"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"name": "arrow-down",
|
|
10
|
+
"path": "M8 12.6666L8 3.33325 M12.6667 8.00008L8 12.6667L3.33335 8.00008",
|
|
11
|
+
"viewBox": "0 0 16 16"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "arrow-left",
|
|
15
|
+
"path": "M12.6666 8.00008L3.33331 8.00008 M7.99998 3.33341L3.33331 8.00008L7.99998 12.6667",
|
|
16
|
+
"viewBox": "0 0 16 16"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "arrow-right",
|
|
20
|
+
"path": "M3.33331 8.00008L12.6666 8.00008 M7.99998 12.6667L12.6666 8.00008L7.99998 3.33341",
|
|
21
|
+
"viewBox": "0 0 16 16"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "check",
|
|
25
|
+
"path": "M13.3333 4.66675L6.66667 11.3334L3.33333 8.00008",
|
|
26
|
+
"viewBox": "0 0 16 16"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "cross",
|
|
30
|
+
"path": "M12 4L4 12 M4 4L12 12",
|
|
31
|
+
"viewBox": "0 0 16 16"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"name": "plus",
|
|
35
|
+
"path": "M8 3.33325V12.6666 M3.33331 7.99992H12.6666",
|
|
36
|
+
"viewBox": "0 0 16 16"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "minus",
|
|
40
|
+
"path": "M3.33331 7.99992H12.6666",
|
|
41
|
+
"viewBox": "0 0 16 16"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "search",
|
|
45
|
+
"path": "M7.33333 12.6667C10.2789 12.6667 12.6667 10.2789 12.6667 7.33333C12.6667 4.38781 10.2789 2 7.33333 2C4.38781 2 2 4.38781 2 7.33333C2 10.2789 4.38781 12.6667 7.33333 12.6667Z M12.6667 12.6667L14 14",
|
|
46
|
+
"viewBox": "0 0 16 16"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"name": "home",
|
|
50
|
+
"path": "M2 6L8 2L14 6V14H10V10H6V14H2V6Z",
|
|
51
|
+
"viewBox": "0 0 16 16",
|
|
52
|
+
"fill": "currentColor"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"name": "settings",
|
|
56
|
+
"path": "M6.4 14H9.6C9.6 14 9.8 13.1 10.4 12.8C11 12.5 11.9 12.8 12.4 12.3C12.8 11.9 12.6 10.9 12.8 10.4C13.1 9.8 14 9.6 14 9.6V6.4C14 6.4 13.1 6.2 12.8 5.6C12.5 5 12.8 4.1 12.3 3.6C11.9 3.2 10.9 3.4 10.4 3.2C9.8 2.9 9.6 2 9.6 2H6.4C6.4 2 6.2 2.9 5.6 3.2C5 3.5 4.1 3.2 3.6 3.7C3.2 4.1 3.4 5.1 3.2 5.6C2.9 6.2 2 6.4 2 6.4V9.6C2 9.6 2.9 9.8 3.2 10.4C3.5 11 3.2 11.9 3.7 12.4C4.1 12.8 5.1 12.6 5.6 12.8C6.2 13.1 6.4 14 6.4 14Z M10 8C10 9.1 9.1 10 8 10C6.9 10 6 9.1 6 8C6 6.9 6.9 6 8 6C9.1 6 10 6.9 10 8Z",
|
|
57
|
+
"viewBox": "0 0 16 16"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "user",
|
|
61
|
+
"path": "M11 4C11 5.65685 9.65685 7 8 7C6.34315 7 5 5.65685 5 4C5 2.34315 6.34315 1 8 1C9.65685 1 11 2.34315 11 4Z M1 14C1 14 1 12 3 11C5 10 11 10 13 11C15 12 15 14 15 14",
|
|
62
|
+
"viewBox": "0 0 16 16"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "cart",
|
|
66
|
+
"path": "M5.5 14C5.77614 14 6 13.7761 6 13.5C6 13.2239 5.77614 13 5.5 13C5.22386 13 5 13.2239 5 13.5C5 13.7761 5.22386 14 5.5 14Z M12.5 14C12.7761 14 13 13.7761 13 13.5C13 13.2239 12.7761 13 12.5 13C12.2239 13 12 13.2239 12 13.5C12 13.7761 12.2239 14 12.5 14Z M1 1H3L4.6 9.6C4.63333 9.74056 4.7247 9.86412 4.85172 9.94984C4.97873 10.0356 5.13221 10.0769 5.28571 10.0714H12.1429C12.2964 10.0769 12.4499 10.0356 12.5769 9.94984C12.7039 9.86412 12.7952 9.74056 12.8286 9.6L14 4H4",
|
|
67
|
+
"viewBox": "0 0 16 16"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"name": "heart",
|
|
71
|
+
"path": "M13.6319 3.36825C13.2475 2.98368 12.7898 2.67897 12.2843 2.47298C11.7788 2.267 11.2371 2.16341 10.69 2.16797C10.1429 2.16341 9.60127 2.267 9.09575 2.47298C8.59023 2.67897 8.13254 2.98368 7.74805 3.36825L7.00005 4.11625L6.25205 3.36825C5.4676 2.58281 4.40687 2.16036 3.31005 2.16797C2.21322 2.16036 1.1525 2.58281 0.368046 3.36825C-0.41646 4.15369 -0.838915 5.21442 -0.83131 6.31125C-0.838915 7.40807 -0.41646 8.4688 0.368046 9.25425L7.00005 15.8862L13.6319 9.25425C14.0165 8.86975 14.3212 8.41207 14.5272 7.90655C14.7332 7.40102 14.8368 6.85936 14.8322 6.31225C14.8368 5.76513 14.7332 5.22347 14.5272 4.71795C14.3212 4.21242 14.0165 3.75474 13.6319 3.37025V3.36825Z",
|
|
72
|
+
"viewBox": "0 0 16 16"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"name": "star",
|
|
76
|
+
"path": "M7.99998 1.33325L10.06 5.5066L14.6666 6.17994L11.3333 9.42661L12.12 14.0133L7.99998 11.8466L3.87998 14.0133L4.66665 9.42661L1.33331 6.17994L5.93998 5.5066L7.99998 1.33325Z",
|
|
77
|
+
"viewBox": "0 0 16 16",
|
|
78
|
+
"fill": "currentColor"
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import typographyTokens from "../../styles/tokens/typography";
|
|
3
|
+
import { BodyProps } from "../../types/Typography";
|
|
4
|
+
|
|
5
|
+
export const Body: React.FC<BodyProps> = ({
|
|
6
|
+
size = "lg",
|
|
7
|
+
element = "p",
|
|
8
|
+
align = "left",
|
|
9
|
+
weight,
|
|
10
|
+
color,
|
|
11
|
+
truncate = false,
|
|
12
|
+
lineClamp,
|
|
13
|
+
children,
|
|
14
|
+
className = "",
|
|
15
|
+
style = {},
|
|
16
|
+
onClick,
|
|
17
|
+
testID,
|
|
18
|
+
...rest
|
|
19
|
+
}) => {
|
|
20
|
+
const getStyles = (): React.CSSProperties => {
|
|
21
|
+
let tokenSet;
|
|
22
|
+
switch (size) {
|
|
23
|
+
case "xl":
|
|
24
|
+
tokenSet = typographyTokens.bodyXl;
|
|
25
|
+
break;
|
|
26
|
+
case "lg":
|
|
27
|
+
tokenSet = typographyTokens.bodyLg;
|
|
28
|
+
break;
|
|
29
|
+
case "md":
|
|
30
|
+
tokenSet = typographyTokens.bodyMd;
|
|
31
|
+
break;
|
|
32
|
+
case "sm":
|
|
33
|
+
tokenSet = typographyTokens.bodySm;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let fontWeightValue = parseInt(tokenSet.fontWeight);
|
|
38
|
+
if (weight) {
|
|
39
|
+
if (weight === "normal") fontWeightValue = 400;
|
|
40
|
+
else if (weight === "medium") fontWeightValue = 500;
|
|
41
|
+
else if (weight === "semibold") fontWeightValue = 600;
|
|
42
|
+
else if (weight === "bold") fontWeightValue = 700;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const baseStyles: React.CSSProperties = {
|
|
46
|
+
fontFamily: tokenSet.fontFamily,
|
|
47
|
+
fontSize: `${tokenSet.fontSize}px`,
|
|
48
|
+
lineHeight: `${tokenSet.lineHeight}px`,
|
|
49
|
+
fontWeight: fontWeightValue,
|
|
50
|
+
color: color || tokenSet.color,
|
|
51
|
+
textAlign: align,
|
|
52
|
+
letterSpacing: tokenSet.letterSpacing,
|
|
53
|
+
textDecoration: tokenSet.textDecoration || "none",
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
if (truncate) {
|
|
57
|
+
baseStyles.whiteSpace = "nowrap";
|
|
58
|
+
baseStyles.overflow = "hidden";
|
|
59
|
+
baseStyles.textOverflow = "ellipsis";
|
|
60
|
+
baseStyles.display = "block";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (lineClamp && lineClamp > 0) {
|
|
64
|
+
baseStyles.display = "-webkit-box";
|
|
65
|
+
baseStyles.WebkitLineClamp = lineClamp;
|
|
66
|
+
baseStyles.WebkitBoxOrient = "vertical";
|
|
67
|
+
baseStyles.overflow = "hidden";
|
|
68
|
+
baseStyles.textOverflow = "ellipsis";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return baseStyles;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const combinedStyles = {
|
|
75
|
+
...getStyles(),
|
|
76
|
+
...style,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const linkProps = element === "a" ? rest : {};
|
|
80
|
+
|
|
81
|
+
const Component = element as React.ElementType;
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<Component
|
|
85
|
+
style={combinedStyles}
|
|
86
|
+
className={className}
|
|
87
|
+
data-testid={testID}
|
|
88
|
+
onClick={onClick}
|
|
89
|
+
{...linkProps}
|
|
90
|
+
>
|
|
91
|
+
{children}
|
|
92
|
+
</Component>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import typographyTokens from "../../styles/tokens/typography";
|
|
3
|
+
import { DisplayProps } from "../../types/Typography";
|
|
4
|
+
|
|
5
|
+
export const Display: React.FC<DisplayProps> = ({
|
|
6
|
+
size = "2xl",
|
|
7
|
+
element = "h1",
|
|
8
|
+
align = "left",
|
|
9
|
+
weight,
|
|
10
|
+
color,
|
|
11
|
+
truncate = false,
|
|
12
|
+
lineClamp,
|
|
13
|
+
children,
|
|
14
|
+
className = "",
|
|
15
|
+
style = {},
|
|
16
|
+
onClick,
|
|
17
|
+
testID,
|
|
18
|
+
...rest
|
|
19
|
+
}) => {
|
|
20
|
+
const getStyles = (): React.CSSProperties => {
|
|
21
|
+
const tokenSet =
|
|
22
|
+
size === "2xl" ? typographyTokens.display2xl : typographyTokens.displayXl;
|
|
23
|
+
|
|
24
|
+
let fontWeightValue = parseInt(tokenSet.fontWeight);
|
|
25
|
+
if (weight) {
|
|
26
|
+
if (weight === "normal") fontWeightValue = 400;
|
|
27
|
+
else if (weight === "medium") fontWeightValue = 500;
|
|
28
|
+
else if (weight === "semibold") fontWeightValue = 600;
|
|
29
|
+
else if (weight === "bold") fontWeightValue = 700;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const baseStyles: React.CSSProperties = {
|
|
33
|
+
fontFamily: tokenSet.fontFamily,
|
|
34
|
+
fontSize: `${tokenSet.fontSize}px`,
|
|
35
|
+
lineHeight: `${tokenSet.lineHeight}px`,
|
|
36
|
+
fontWeight: fontWeightValue,
|
|
37
|
+
color: color || tokenSet.color,
|
|
38
|
+
textAlign: align,
|
|
39
|
+
letterSpacing: tokenSet.letterSpacing,
|
|
40
|
+
textDecoration: tokenSet.textDecoration || "none",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
if (truncate) {
|
|
44
|
+
baseStyles.whiteSpace = "nowrap";
|
|
45
|
+
baseStyles.overflow = "hidden";
|
|
46
|
+
baseStyles.textOverflow = "ellipsis";
|
|
47
|
+
baseStyles.display = "block";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (lineClamp && lineClamp > 0) {
|
|
51
|
+
baseStyles.display = "-webkit-box";
|
|
52
|
+
baseStyles.WebkitLineClamp = lineClamp;
|
|
53
|
+
baseStyles.WebkitBoxOrient = "vertical";
|
|
54
|
+
baseStyles.overflow = "hidden";
|
|
55
|
+
baseStyles.textOverflow = "ellipsis";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return baseStyles;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const combinedStyles = {
|
|
62
|
+
...getStyles(),
|
|
63
|
+
...style,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const Component = element as React.ElementType;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<Component
|
|
70
|
+
style={combinedStyles}
|
|
71
|
+
className={className}
|
|
72
|
+
data-testid={testID}
|
|
73
|
+
onClick={onClick}
|
|
74
|
+
{...rest}
|
|
75
|
+
>
|
|
76
|
+
{children}
|
|
77
|
+
</Component>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import typographyTokens from "../../styles/tokens/typography";
|
|
3
|
+
import { HeadingProps, TypographyWeight } from "../../types/Typography";
|
|
4
|
+
|
|
5
|
+
type HeadingTokenKey =
|
|
6
|
+
| "headingXl"
|
|
7
|
+
| "headingLg"
|
|
8
|
+
| "headingMd"
|
|
9
|
+
| "headingSm"
|
|
10
|
+
| "headingXs";
|
|
11
|
+
|
|
12
|
+
export const Heading: React.FC<HeadingProps> = ({
|
|
13
|
+
size = "xl",
|
|
14
|
+
element = "h2",
|
|
15
|
+
align = "left",
|
|
16
|
+
weight,
|
|
17
|
+
color,
|
|
18
|
+
truncate = false,
|
|
19
|
+
lineClamp,
|
|
20
|
+
children,
|
|
21
|
+
className = "",
|
|
22
|
+
style = {},
|
|
23
|
+
onClick,
|
|
24
|
+
testID,
|
|
25
|
+
...rest
|
|
26
|
+
}) => {
|
|
27
|
+
const getStyles = (): React.CSSProperties => {
|
|
28
|
+
const tokenKeyMap: Record<string, HeadingTokenKey> = {
|
|
29
|
+
xl: "headingXl",
|
|
30
|
+
lg: "headingLg",
|
|
31
|
+
md: "headingMd",
|
|
32
|
+
sm: "headingSm",
|
|
33
|
+
xs: "headingXs",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const tokenSet = typographyTokens[tokenKeyMap[size]];
|
|
37
|
+
|
|
38
|
+
const fontWeightValue = weight
|
|
39
|
+
? parseInt(typographyTokens.weights[weight])
|
|
40
|
+
: parseInt(tokenSet.fontWeight);
|
|
41
|
+
|
|
42
|
+
const baseStyles: React.CSSProperties = {
|
|
43
|
+
fontFamily: tokenSet.fontFamily,
|
|
44
|
+
fontSize: `${tokenSet.fontSize}px`,
|
|
45
|
+
lineHeight: `${tokenSet.lineHeight}px`,
|
|
46
|
+
fontWeight: fontWeightValue,
|
|
47
|
+
color: color || tokenSet.color,
|
|
48
|
+
textAlign: align,
|
|
49
|
+
letterSpacing: tokenSet.letterSpacing,
|
|
50
|
+
textDecoration: tokenSet.textDecoration || "none",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const truncationStyles: React.CSSProperties = truncate
|
|
54
|
+
? {
|
|
55
|
+
whiteSpace: "nowrap",
|
|
56
|
+
overflow: "hidden",
|
|
57
|
+
textOverflow: "ellipsis",
|
|
58
|
+
display: "block",
|
|
59
|
+
}
|
|
60
|
+
: {};
|
|
61
|
+
|
|
62
|
+
const lineClampStyles: React.CSSProperties =
|
|
63
|
+
lineClamp && lineClamp > 0
|
|
64
|
+
? {
|
|
65
|
+
display: "-webkit-box",
|
|
66
|
+
WebkitLineClamp: lineClamp,
|
|
67
|
+
WebkitBoxOrient: "vertical",
|
|
68
|
+
overflow: "hidden",
|
|
69
|
+
textOverflow: "ellipsis",
|
|
70
|
+
}
|
|
71
|
+
: {};
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
...baseStyles,
|
|
75
|
+
...truncationStyles,
|
|
76
|
+
...lineClampStyles,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const combinedStyles = {
|
|
81
|
+
...getStyles(),
|
|
82
|
+
...style,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const linkProps = element === "a" ? rest : {};
|
|
86
|
+
|
|
87
|
+
const headingElementMap: Record<string, React.ElementType> = {
|
|
88
|
+
xl: "h1",
|
|
89
|
+
lg: "h2",
|
|
90
|
+
md: "h3",
|
|
91
|
+
sm: "h4",
|
|
92
|
+
xs: "h5",
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const defaultElement = element === "h2" ? headingElementMap[size] : element;
|
|
96
|
+
|
|
97
|
+
const Component = defaultElement as React.ElementType;
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<Component
|
|
101
|
+
style={combinedStyles}
|
|
102
|
+
className={className}
|
|
103
|
+
data-testid={testID}
|
|
104
|
+
onClick={onClick}
|
|
105
|
+
{...linkProps}
|
|
106
|
+
>
|
|
107
|
+
{children}
|
|
108
|
+
</Component>
|
|
109
|
+
);
|
|
110
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import typographyTokens from "../../styles/tokens/typography";
|
|
3
|
+
import { UtilityProps } from "../../types/Typography";
|
|
4
|
+
|
|
5
|
+
export const Utility: React.FC<UtilityProps> = ({
|
|
6
|
+
variant = "button",
|
|
7
|
+
element,
|
|
8
|
+
align = "left",
|
|
9
|
+
weight,
|
|
10
|
+
color,
|
|
11
|
+
truncate = false,
|
|
12
|
+
lineClamp,
|
|
13
|
+
children,
|
|
14
|
+
className = "",
|
|
15
|
+
style = {},
|
|
16
|
+
onClick,
|
|
17
|
+
testID,
|
|
18
|
+
...rest
|
|
19
|
+
}) => {
|
|
20
|
+
const getDefaultElement = () => {
|
|
21
|
+
switch (variant) {
|
|
22
|
+
case "button":
|
|
23
|
+
return "span";
|
|
24
|
+
case "link":
|
|
25
|
+
return "a";
|
|
26
|
+
case "caption":
|
|
27
|
+
return "span";
|
|
28
|
+
default:
|
|
29
|
+
return "span";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const elementToUse = element || getDefaultElement();
|
|
34
|
+
|
|
35
|
+
const getStyles = (): React.CSSProperties => {
|
|
36
|
+
let tokenSet;
|
|
37
|
+
switch (variant) {
|
|
38
|
+
case "button":
|
|
39
|
+
tokenSet = typographyTokens.labelLg;
|
|
40
|
+
break;
|
|
41
|
+
case "link":
|
|
42
|
+
tokenSet = typographyTokens.labelMd;
|
|
43
|
+
break;
|
|
44
|
+
case "caption":
|
|
45
|
+
tokenSet = typographyTokens.labelSm;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let fontWeightValue = parseInt(tokenSet.fontWeight);
|
|
50
|
+
if (weight) {
|
|
51
|
+
if (weight === "normal") fontWeightValue = 400;
|
|
52
|
+
else if (weight === "medium") fontWeightValue = 500;
|
|
53
|
+
else if (weight === "semibold") fontWeightValue = 600;
|
|
54
|
+
else if (weight === "bold") fontWeightValue = 700;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const baseStyles: React.CSSProperties = {
|
|
58
|
+
fontFamily: tokenSet.fontFamily,
|
|
59
|
+
fontSize: `${tokenSet.fontSize}px`,
|
|
60
|
+
lineHeight: `${tokenSet.lineHeight}px`,
|
|
61
|
+
fontWeight: fontWeightValue,
|
|
62
|
+
color: color || tokenSet.color,
|
|
63
|
+
textAlign: align,
|
|
64
|
+
letterSpacing: tokenSet.letterSpacing,
|
|
65
|
+
textDecoration:
|
|
66
|
+
variant === "link" ? "underline" : tokenSet.textDecoration || "none",
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (truncate) {
|
|
70
|
+
baseStyles.whiteSpace = "nowrap";
|
|
71
|
+
baseStyles.overflow = "hidden";
|
|
72
|
+
baseStyles.textOverflow = "ellipsis";
|
|
73
|
+
baseStyles.display = "block";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (lineClamp && lineClamp > 0) {
|
|
77
|
+
baseStyles.display = "-webkit-box";
|
|
78
|
+
baseStyles.WebkitLineClamp = lineClamp;
|
|
79
|
+
baseStyles.WebkitBoxOrient = "vertical";
|
|
80
|
+
baseStyles.overflow = "hidden";
|
|
81
|
+
baseStyles.textOverflow = "ellipsis";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return baseStyles;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const combinedStyles = {
|
|
88
|
+
...getStyles(),
|
|
89
|
+
...style,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const linkProps = elementToUse === "a" ? rest : {};
|
|
93
|
+
|
|
94
|
+
const Component = elementToUse as React.ElementType;
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<Component
|
|
98
|
+
style={combinedStyles}
|
|
99
|
+
className={className}
|
|
100
|
+
data-testid={testID}
|
|
101
|
+
onClick={onClick}
|
|
102
|
+
{...linkProps}
|
|
103
|
+
>
|
|
104
|
+
{children}
|
|
105
|
+
</Component>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
TypographyAlign,
|
|
6
|
-
TypographyWeight,
|
|
7
|
-
} from "../../types/Typography";
|
|
1
|
+
export { Display } from "./Display";
|
|
2
|
+
export { Heading } from "./Heading";
|
|
3
|
+
export { Body } from "./Body";
|
|
4
|
+
export { Utility } from "./Utility";
|
package/src/index.ts
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
// Components
|
|
2
2
|
export { Button } from "./components/Button";
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export { Heading } from "./components/Heading";
|
|
6
|
-
export { Paragraph } from "./components/Paragraph";
|
|
3
|
+
export { Display, Heading, Body, Utility } from "./components/Typography";
|
|
4
|
+
export { Icon, IconList, icons } from "./components/Icon";
|
|
7
5
|
|
|
8
6
|
// Types
|
|
9
|
-
export type { ButtonProps } from "./types/Button";
|
|
10
7
|
export type {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from "./types/
|
|
16
|
-
export type {
|
|
17
|
-
export type { HeadingProps, HeadingLevel } from "./types/Heading";
|
|
18
|
-
export type {
|
|
19
|
-
ParagraphProps,
|
|
20
|
-
ParagraphSize,
|
|
21
|
-
ParagraphSpacing,
|
|
22
|
-
} from "./types/Paragraph";
|
|
8
|
+
ButtonProps,
|
|
9
|
+
ButtonType,
|
|
10
|
+
ButtonSize,
|
|
11
|
+
ButtonState,
|
|
12
|
+
} from "./types/Button";
|
|
13
|
+
export type { IconProps, IconData, IconListProps } from "./components/Icon";
|
|
23
14
|
|
|
24
15
|
// Theme
|
|
25
16
|
export { ThemeProvider, useTheme } from "./theme/ThemeProvider";
|
|
@@ -79,6 +79,17 @@ export const typographyTokens = {
|
|
|
79
79
|
},
|
|
80
80
|
|
|
81
81
|
// Body text variants
|
|
82
|
+
bodyXl: {
|
|
83
|
+
fontFamily: tokens.BODY_XL_FONT_FAMILY,
|
|
84
|
+
fontSize: pxToNumber(tokens.BODY_XL_FONT_SIZE),
|
|
85
|
+
fontWeight: normalizeFontWeight(tokens.BODY_XL_FONT_WEIGHT),
|
|
86
|
+
lineHeight: pxToNumber(tokens.BODY_XL_LINE_HEIGHT),
|
|
87
|
+
color: tokens.TEXT_BODY,
|
|
88
|
+
letterSpacing: tokens.BODY_XL_LETTER_SPACING,
|
|
89
|
+
textDecoration: tokens.BODY_XL_TEXT_DECORATION,
|
|
90
|
+
textCase: tokens.BODY_XL_TEXT_CASE,
|
|
91
|
+
paragraphIndent: tokens.BODY_XL_PARAGRAPH_INDENT,
|
|
92
|
+
},
|
|
82
93
|
bodyLg: {
|
|
83
94
|
fontFamily: tokens.BODY_LG_FONT_FAMILY,
|
|
84
95
|
fontSize: pxToNumber(tokens.BODY_LG_FONT_SIZE),
|
package/src/types/Button.ts
CHANGED
|
@@ -1,56 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* The content to display inside the button
|
|
4
|
-
*/
|
|
5
|
-
children: React.ReactNode;
|
|
1
|
+
import React from "react";
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
* The variant of the button
|
|
9
|
-
*/
|
|
10
|
-
variant?: "primary" | "secondary" | "outline" | "ghost";
|
|
3
|
+
export type ButtonType = "primary" | "outline" | "ghost" | "destructive";
|
|
11
4
|
|
|
12
|
-
|
|
13
|
-
* The size of the button
|
|
14
|
-
*/
|
|
15
|
-
size?: "sm" | "md" | "lg";
|
|
5
|
+
export type ButtonSize = "medium" | "large";
|
|
16
6
|
|
|
17
|
-
|
|
18
|
-
* Whether the button is disabled
|
|
19
|
-
*/
|
|
20
|
-
disabled?: boolean;
|
|
7
|
+
export type ButtonState = "default" | "hover" | "active" | "disabled";
|
|
21
8
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
export interface ButtonProps {
|
|
10
|
+
label: string;
|
|
11
|
+
type?: ButtonType;
|
|
12
|
+
size?: ButtonSize;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
leftIcon?: string;
|
|
15
|
+
rightIcon?: string;
|
|
16
|
+
icon?: string;
|
|
25
17
|
fullWidth?: boolean;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Loading state
|
|
29
|
-
*/
|
|
30
|
-
loading?: boolean;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Custom style override
|
|
34
|
-
*/
|
|
35
|
-
style?: import("react-native").ViewStyle;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Custom text style override
|
|
39
|
-
*/
|
|
40
|
-
textStyle?: import("react-native").TextStyle;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Accessibility label
|
|
44
|
-
*/
|
|
18
|
+
style?: React.CSSProperties;
|
|
45
19
|
accessibilityLabel?: string;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Test ID for testing
|
|
49
|
-
*/
|
|
50
20
|
testID?: string;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
21
|
+
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
|
22
|
+
className?: string;
|
|
23
|
+
onMouseEnter?: React.MouseEventHandler<HTMLButtonElement>;
|
|
24
|
+
onMouseLeave?: React.MouseEventHandler<HTMLButtonElement>;
|
|
25
|
+
onMouseDown?: React.MouseEventHandler<HTMLButtonElement>;
|
|
26
|
+
onMouseUp?: React.MouseEventHandler<HTMLButtonElement>;
|
|
56
27
|
}
|