@fibery/ui-kit 1.0.4 → 1.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/package.json +9 -3
- package/src/Button.d.ts +3 -1
- package/src/Button.js +10 -12
- package/src/Pallete.ts +16 -16
- package/src/Select/components.tsx +5 -9
- package/src/Select/styles.ts +14 -4
- package/src/ThemeProvider.tsx +131 -5
- package/src/antd/styles.ts +4 -4
- package/src/designSystem.ts +165 -193
- package/src/error-alert.tsx +55 -0
- package/src/icons/Icon.tsx +2 -2
- package/src/icons/ast/AppStoreOneColor.ts +1 -1
- package/src/icons/ast/Checked.ts +1 -1
- package/src/icons/ast/Email.ts +8 -0
- package/src/icons/ast/ExtensionAvatar.ts +1 -1
- package/src/icons/ast/Integration.ts +1 -1
- package/src/icons/ast/RicheditorImageAlignCenter.ts +1 -1
- package/src/icons/ast/RicheditorImageAlignLeft.ts +1 -1
- package/src/icons/ast/RicheditorImageAlignRight.ts +1 -1
- package/src/icons/ast/RicheditorImageUpload.ts +1 -1
- package/src/icons/ast/RicheditorImageWrapCenter.ts +1 -1
- package/src/icons/ast/RicheditorImageWrapLeft.ts +1 -1
- package/src/icons/ast/RicheditorImageWrapRight.ts +1 -1
- package/src/icons/ast/SidebarFields.ts +8 -0
- package/src/icons/ast/SidebarFieldsOpened.ts +8 -0
- package/src/icons/ast/SlackIcon.ts +8 -0
- package/src/icons/ast/SlideMenu.ts +8 -0
- package/src/icons/ast/SlideMenuOpened.ts +8 -0
- package/src/icons/ast/index.tsx +6 -0
- package/src/icons/react/Email.tsx +12 -0
- package/src/icons/react/SidebarFields.tsx +12 -0
- package/src/icons/react/SidebarFieldsOpened.tsx +12 -0
- package/src/icons/react/SlackIcon.tsx +12 -0
- package/src/icons/react/SlideMenu.tsx +12 -0
- package/src/icons/react/SlideMenuOpened.tsx +12 -0
- package/src/icons/react/index.tsx +6 -0
- package/src/loading-sausage.tsx +1 -1
- package/src/media-query-utils.ts +24 -0
- package/src/theme-settings.ts +164 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/ui-kit",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"private": false,
|
|
6
6
|
"files": [
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
"src/Button.d.ts",
|
|
9
9
|
"src/Button.js",
|
|
10
10
|
"src/designSystem.ts",
|
|
11
|
+
"src/theme-settings.ts",
|
|
12
|
+
"src/media-query-utils.ts",
|
|
11
13
|
"src/create-inline-theme.ts",
|
|
12
14
|
"src/form-field-loader.tsx",
|
|
13
15
|
"src/ThemeProvider.tsx",
|
|
@@ -17,6 +19,7 @@
|
|
|
17
19
|
"src/loading-sausage.tsx",
|
|
18
20
|
"src/icons/**/*.ts*",
|
|
19
21
|
"src/Select",
|
|
22
|
+
"src/error-alert.tsx",
|
|
20
23
|
"src/Pallete.ts"
|
|
21
24
|
],
|
|
22
25
|
"license": "UNLICENSED",
|
|
@@ -32,17 +35,19 @@
|
|
|
32
35
|
"@linaria/core": "3.0.0-beta.15",
|
|
33
36
|
"@linaria/react": "3.0.0-beta.15",
|
|
34
37
|
"@popperjs/core": "2.9.3",
|
|
35
|
-
"@radix-ui/react-dropdown-menu": "0.
|
|
38
|
+
"@radix-ui/react-dropdown-menu": "1.0.0",
|
|
36
39
|
"antd": "4.18.8",
|
|
37
40
|
"chroma-js": "2.1.2",
|
|
38
41
|
"classnames": "2.3.1",
|
|
39
42
|
"color-hash": "1.0.3",
|
|
40
43
|
"d3-shape": "1.3.7",
|
|
41
44
|
"emoji-mart": "3.0.1",
|
|
45
|
+
"invariant": "2.2.4",
|
|
42
46
|
"lodash": "4.17.21",
|
|
43
47
|
"md5": "2.2.1",
|
|
44
48
|
"moment": "2.20.1",
|
|
45
49
|
"prop-types": "15.7.2",
|
|
50
|
+
"rc-input-number": "^7.3.4",
|
|
46
51
|
"rc-menu": "9.3.2",
|
|
47
52
|
"rc-progress": "3.2.4",
|
|
48
53
|
"react-color": "2.13.8",
|
|
@@ -59,7 +64,7 @@
|
|
|
59
64
|
},
|
|
60
65
|
"devDependencies": {
|
|
61
66
|
"@fibery/babel-preset": "7.2.0",
|
|
62
|
-
"@fibery/eslint-config": "
|
|
67
|
+
"@fibery/eslint-config": "8.1.0",
|
|
63
68
|
"@fibery/text-editor": "1.0.0",
|
|
64
69
|
"@linaria/babel-preset": "3.0.0-beta.15",
|
|
65
70
|
"@types/chroma-js": "2.1.3",
|
|
@@ -74,6 +79,7 @@
|
|
|
74
79
|
"jest-junit": "13.0.0",
|
|
75
80
|
"svg-parser": "2.0.4",
|
|
76
81
|
"svgo": "2.8.0",
|
|
82
|
+
"typescript": "4.7.4",
|
|
77
83
|
"unist-util-reduce": "0.2.2"
|
|
78
84
|
},
|
|
79
85
|
"jest": {
|
package/src/Button.d.ts
CHANGED
|
@@ -21,4 +21,6 @@ export const ActionsButton: FunctionComponent<{
|
|
|
21
21
|
color?: string;
|
|
22
22
|
onClick?: Props["onClick"];
|
|
23
23
|
}>;
|
|
24
|
-
export const ActionsButtonCompact: FunctionComponent<
|
|
24
|
+
export const ActionsButtonCompact: FunctionComponent<
|
|
25
|
+
{inverted?: boolean} & Omit<Props, "color" | "borderless" | "Icon" | "size">
|
|
26
|
+
>;
|
package/src/Button.js
CHANGED
|
@@ -82,15 +82,12 @@ const getMainColor = ({color, dangerous, theme}) => {
|
|
|
82
82
|
return color;
|
|
83
83
|
}
|
|
84
84
|
if (dangerous) {
|
|
85
|
-
return
|
|
85
|
+
return theme.danger;
|
|
86
86
|
}
|
|
87
87
|
if (!theme) {
|
|
88
88
|
return colors.primary;
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
return theme.primary;
|
|
92
|
-
}
|
|
93
|
-
return theme.iconColor;
|
|
90
|
+
return theme.buttonColor;
|
|
94
91
|
};
|
|
95
92
|
|
|
96
93
|
const getBorderColor = ({mainColor, borderless, primary}) => {
|
|
@@ -100,7 +97,7 @@ const getBorderColor = ({mainColor, borderless, primary}) => {
|
|
|
100
97
|
if (primary) {
|
|
101
98
|
return mainColor;
|
|
102
99
|
}
|
|
103
|
-
return getOpacities(mainColor).
|
|
100
|
+
return getOpacities(mainColor).opacity15;
|
|
104
101
|
};
|
|
105
102
|
|
|
106
103
|
const getHoverBorderColor = ({mainColor, borderless, primary, hoverBgColor}) => {
|
|
@@ -115,7 +112,7 @@ const getHoverBorderColor = ({mainColor, borderless, primary, hoverBgColor}) =>
|
|
|
115
112
|
|
|
116
113
|
const getTextColor = ({mainColor, primary}) => {
|
|
117
114
|
if (primary) {
|
|
118
|
-
return
|
|
115
|
+
return themeVars.buttonPrimaryTextColor;
|
|
119
116
|
}
|
|
120
117
|
return mainColor;
|
|
121
118
|
};
|
|
@@ -139,7 +136,7 @@ const getHoverBgColor = ({mainColor, borderless, primary}) => {
|
|
|
139
136
|
|
|
140
137
|
const getSpinnerColor = ({mainColor, primary}) => {
|
|
141
138
|
if (primary) {
|
|
142
|
-
return
|
|
139
|
+
return colors.inversedTextColor;
|
|
143
140
|
}
|
|
144
141
|
return mainColor;
|
|
145
142
|
};
|
|
@@ -347,15 +344,16 @@ export function ActionsButton({onClick, label = ``, disabled}) {
|
|
|
347
344
|
return <Button Icon={MoreIcon} onClick={onClick} borderless aria-label={label} disabled={disabled} />;
|
|
348
345
|
}
|
|
349
346
|
|
|
350
|
-
export
|
|
347
|
+
export const ActionsButtonCompact = forwardRef(({inverted, ...rest}, ref) => {
|
|
351
348
|
const theme = useTheme();
|
|
352
349
|
return (
|
|
353
350
|
<Button
|
|
351
|
+
ref={ref}
|
|
354
352
|
size={":button-size/small"}
|
|
355
353
|
Icon={MoreCompactIcon}
|
|
356
|
-
|
|
357
|
-
color={inverted ? colors.inversedTextColor : theme.primary}
|
|
354
|
+
color={inverted ? colors.inversedTextColor : theme.buttonColor}
|
|
358
355
|
borderless
|
|
356
|
+
{...rest}
|
|
359
357
|
/>
|
|
360
358
|
);
|
|
361
|
-
}
|
|
359
|
+
});
|
package/src/Pallete.ts
CHANGED
|
@@ -11,7 +11,7 @@ export const slate = {
|
|
|
11
11
|
slate10: "hsl(205, 9.0%, 47.3%)",
|
|
12
12
|
slate11: "hsl(204, 14.0%, 37.3%)",
|
|
13
13
|
slate12: "hsl(200, 7.0%, 8.8%)",
|
|
14
|
-
};
|
|
14
|
+
} as const;
|
|
15
15
|
|
|
16
16
|
export const slateDark = {
|
|
17
17
|
slate1: "hsl(200, 7.0%, 8.8%)",
|
|
@@ -26,7 +26,7 @@ export const slateDark = {
|
|
|
26
26
|
slate10: "hsl(206, 5.2%, 49.5%)",
|
|
27
27
|
slate11: "hsl(206, 6.0%, 63.0%)",
|
|
28
28
|
slate12: "hsl(210, 6.0%, 93.0%)",
|
|
29
|
-
};
|
|
29
|
+
} as const;
|
|
30
30
|
|
|
31
31
|
export const sage = {
|
|
32
32
|
sage1: "hsl(155, 30.0%, 98.8%)",
|
|
@@ -41,7 +41,7 @@ export const sage = {
|
|
|
41
41
|
sage10: "hsl(154, 2.8%, 51.7%)",
|
|
42
42
|
sage11: "hsl(155, 3.0%, 43.0%)",
|
|
43
43
|
sage12: "hsl(155, 24.0%, 9.0%)",
|
|
44
|
-
};
|
|
44
|
+
} as const;
|
|
45
45
|
|
|
46
46
|
export const sageDark = {
|
|
47
47
|
sage1: "hsl(160, 7.0%, 8.4%)",
|
|
@@ -56,7 +56,7 @@ export const sageDark = {
|
|
|
56
56
|
sage10: "hsl(153, 4.8%, 48.2%)",
|
|
57
57
|
sage11: "hsl(155, 5.0%, 61.8%)",
|
|
58
58
|
sage12: "hsl(155, 6.0%, 93.0%)",
|
|
59
|
-
};
|
|
59
|
+
} as const;
|
|
60
60
|
|
|
61
61
|
export const teal = {
|
|
62
62
|
teal1: "hsl(165, 60.0%, 98.8%)",
|
|
@@ -71,7 +71,7 @@ export const teal = {
|
|
|
71
71
|
teal10: "hsl(173, 83.4%, 32.5%)",
|
|
72
72
|
teal11: "hsl(174, 90.0%, 25.2%)",
|
|
73
73
|
teal12: "hsl(170, 50.0%, 12.5%)",
|
|
74
|
-
};
|
|
74
|
+
} as const;
|
|
75
75
|
|
|
76
76
|
export const tealDark = {
|
|
77
77
|
teal1: "hsl(168, 48.0%, 6.5%)",
|
|
@@ -86,7 +86,7 @@ export const tealDark = {
|
|
|
86
86
|
teal10: "hsl(174, 83.9%, 38.2%)",
|
|
87
87
|
teal11: "hsl(174, 90.0%, 40.7%)",
|
|
88
88
|
teal12: "hsl(166, 73.0%, 93.1%)",
|
|
89
|
-
};
|
|
89
|
+
} as const;
|
|
90
90
|
|
|
91
91
|
export const indigo = {
|
|
92
92
|
indigo1: "hsl(225, 60.0%, 99.4%)",
|
|
@@ -101,7 +101,7 @@ export const indigo = {
|
|
|
101
101
|
indigo10: "hsl(226, 58.6%, 51.3%)",
|
|
102
102
|
indigo11: "hsl(226, 55.0%, 45.0%)",
|
|
103
103
|
indigo12: "hsl(226, 62.0%, 17.0%)",
|
|
104
|
-
};
|
|
104
|
+
} as const;
|
|
105
105
|
|
|
106
106
|
export const indigoDark = {
|
|
107
107
|
indigo1: "hsl(229, 24.0%, 10.0%)",
|
|
@@ -116,7 +116,7 @@ export const indigoDark = {
|
|
|
116
116
|
indigo10: "hsl(227, 75.2%, 61.6%)",
|
|
117
117
|
indigo11: "hsl(228, 100%, 75.9%)",
|
|
118
118
|
indigo12: "hsl(226, 83.0%, 96.3%)",
|
|
119
|
-
};
|
|
119
|
+
} as const;
|
|
120
120
|
|
|
121
121
|
export const red = {
|
|
122
122
|
red1: "hsl(359, 100%, 99.4%)",
|
|
@@ -131,7 +131,7 @@ export const red = {
|
|
|
131
131
|
red10: "hsl(358, 69.4%, 55.2%)",
|
|
132
132
|
red11: "hsl(358, 65.0%, 48.7%)",
|
|
133
133
|
red12: "hsl(354, 50.0%, 14.6%)",
|
|
134
|
-
};
|
|
134
|
+
} as const;
|
|
135
135
|
|
|
136
136
|
export const redDark = {
|
|
137
137
|
red1: "hsl(353, 23.0%, 9.8%)",
|
|
@@ -146,7 +146,7 @@ export const redDark = {
|
|
|
146
146
|
red10: "hsl(358, 85.3%, 64.0%)",
|
|
147
147
|
red11: "hsl(358, 100%, 69.5%)",
|
|
148
148
|
red12: "hsl(351, 89.0%, 96.0%)",
|
|
149
|
-
};
|
|
149
|
+
} as const;
|
|
150
150
|
|
|
151
151
|
export const blue = {
|
|
152
152
|
blue1: "hsl(206, 100%, 99.2%)",
|
|
@@ -161,7 +161,7 @@ export const blue = {
|
|
|
161
161
|
blue10: "hsl(208, 100%, 47.3%)",
|
|
162
162
|
blue11: "hsl(211, 100%, 43.2%)",
|
|
163
163
|
blue12: "hsl(211, 100%, 15.0%)",
|
|
164
|
-
};
|
|
164
|
+
} as const;
|
|
165
165
|
|
|
166
166
|
export const blueDark = {
|
|
167
167
|
blue1: "hsl(212, 35.0%, 9.2%)",
|
|
@@ -176,7 +176,7 @@ export const blueDark = {
|
|
|
176
176
|
blue10: "hsl(209, 100%, 60.6%)",
|
|
177
177
|
blue11: "hsl(210, 100%, 66.1%)",
|
|
178
178
|
blue12: "hsl(206, 98.0%, 95.8%)",
|
|
179
|
-
};
|
|
179
|
+
} as const;
|
|
180
180
|
|
|
181
181
|
export const yellow = {
|
|
182
182
|
yellow1: "hsl(60, 54.0%, 98.5%)",
|
|
@@ -191,7 +191,7 @@ export const yellow = {
|
|
|
191
191
|
yellow10: "hsl(50, 100%, 48.5%)",
|
|
192
192
|
yellow11: "hsl(42, 100%, 29.0%)",
|
|
193
193
|
yellow12: "hsl(40, 55.0%, 13.5%)",
|
|
194
|
-
};
|
|
194
|
+
} as const;
|
|
195
195
|
|
|
196
196
|
export const yellowDark = {
|
|
197
197
|
yellow1: "hsl(45, 100%, 5.5%)",
|
|
@@ -206,7 +206,7 @@ export const yellowDark = {
|
|
|
206
206
|
yellow10: "hsl(54, 100%, 68.0%)",
|
|
207
207
|
yellow11: "hsl(48, 100%, 47.0%)",
|
|
208
208
|
yellow12: "hsl(53, 100%, 91.0%)",
|
|
209
|
-
};
|
|
209
|
+
} as const;
|
|
210
210
|
|
|
211
211
|
export const blackA = {
|
|
212
212
|
blackA0: "#000000",
|
|
@@ -222,7 +222,7 @@ export const blackA = {
|
|
|
222
222
|
blackA10: "hsla(0, 0%, 0%, 0.478)",
|
|
223
223
|
blackA11: "hsla(0, 0%, 0%, 0.565)",
|
|
224
224
|
blackA12: "hsla(0, 0%, 0%, 0.910)",
|
|
225
|
-
};
|
|
225
|
+
} as const;
|
|
226
226
|
|
|
227
227
|
export const whiteA = {
|
|
228
228
|
whiteA0: "#FFFFFF",
|
|
@@ -238,4 +238,4 @@ export const whiteA = {
|
|
|
238
238
|
whiteA10: "hsla(0, 0%, 100%, 0.446)",
|
|
239
239
|
whiteA11: "hsla(0, 0%, 100%, 0.592)",
|
|
240
240
|
whiteA12: "hsla(0, 0%, 100%, 0.923)",
|
|
241
|
-
};
|
|
241
|
+
} as const;
|
|
@@ -5,8 +5,9 @@ import RemoveIcon from "../icons/react/Remove";
|
|
|
5
5
|
import {OptionProps, DropdownIndicatorProps, ClearIndicatorProps, MultiValueRemoveProps, GroupBase} from "react-select";
|
|
6
6
|
import {Button} from "../Button";
|
|
7
7
|
import {themeVars, space} from "../designSystem";
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
8
|
+
import ArrowCollapseVertical from "../icons/react/ArrowCollapseVertical";
|
|
9
|
+
import {expanderStyle, expanderExpandedStyle} from "./styles";
|
|
10
|
+
import cn from "classnames";
|
|
10
11
|
|
|
11
12
|
export const Option = <
|
|
12
13
|
TOption,
|
|
@@ -28,13 +29,8 @@ export function DropdownIndicator<
|
|
|
28
29
|
Group extends GroupBase<TOption> = GroupBase<TOption>
|
|
29
30
|
>(props: DropdownIndicatorProps<TOption, IsMulti, Group>) {
|
|
30
31
|
return (
|
|
31
|
-
<div
|
|
32
|
-
|
|
33
|
-
style={{
|
|
34
|
-
transform: props.selectProps.menuIsOpen ? "rotate(180deg)" : "",
|
|
35
|
-
}}
|
|
36
|
-
>
|
|
37
|
-
<ArrowBottom iconSize={dropdownIndicatorSize} color={themeVars.disabledTextColor} />
|
|
32
|
+
<div className={cn(expanderStyle, props.selectProps.menuIsOpen && expanderExpandedStyle)}>
|
|
33
|
+
<ArrowCollapseVertical color={themeVars.disabledTextColor} />
|
|
38
34
|
</div>
|
|
39
35
|
);
|
|
40
36
|
}
|
package/src/Select/styles.ts
CHANGED
|
@@ -4,15 +4,14 @@ import type {StylesConfig, CSSObjectWithLabel, ControlProps} from "react-select"
|
|
|
4
4
|
import {inputOverrides} from "../antd/styles";
|
|
5
5
|
import {border, layout, space, textStyles, themeVars, transition} from "../designSystem";
|
|
6
6
|
|
|
7
|
-
export const dropdownIndicatorSize = 16;
|
|
8
|
-
|
|
9
7
|
export const expanderStyle = css`
|
|
10
8
|
${{
|
|
11
9
|
transition: `transform ${transition}`,
|
|
12
|
-
width: dropdownIndicatorSize,
|
|
13
|
-
height: dropdownIndicatorSize,
|
|
14
10
|
}}
|
|
15
11
|
`;
|
|
12
|
+
export const expanderExpandedStyle = css`
|
|
13
|
+
transform: rotate(180deg);
|
|
14
|
+
`;
|
|
16
15
|
|
|
17
16
|
function createControlStyle({
|
|
18
17
|
isSingleLine,
|
|
@@ -90,6 +89,12 @@ export const componentsStyles: StylesConfig = {
|
|
|
90
89
|
overflow: "visible",
|
|
91
90
|
color: themeVars.textColor,
|
|
92
91
|
}),
|
|
92
|
+
valueContainer(provided) {
|
|
93
|
+
return {
|
|
94
|
+
...provided,
|
|
95
|
+
minWidth: 10,
|
|
96
|
+
};
|
|
97
|
+
},
|
|
93
98
|
multiValue: (provided) => ({
|
|
94
99
|
...provided,
|
|
95
100
|
color: themeVars.textColor,
|
|
@@ -122,6 +127,7 @@ export const componentsStyles: StylesConfig = {
|
|
|
122
127
|
}),
|
|
123
128
|
menu: (provided) => ({
|
|
124
129
|
...provided,
|
|
130
|
+
color: themeVars.disabledTextColor,
|
|
125
131
|
zIndex: 1050,
|
|
126
132
|
backgroundColor: themeVars.actionMenuInnerBg,
|
|
127
133
|
boxShadow: themeVars.actionMenuShadow as unknown as Property.BoxShadow,
|
|
@@ -133,6 +139,10 @@ export const componentsStyles: StylesConfig = {
|
|
|
133
139
|
cursor: state.isDisabled ? "not-allowed" : "default",
|
|
134
140
|
}),
|
|
135
141
|
indicatorSeparator: () => ({}),
|
|
142
|
+
input: (provided) => ({
|
|
143
|
+
...provided,
|
|
144
|
+
color: themeVars.textColor,
|
|
145
|
+
}),
|
|
136
146
|
};
|
|
137
147
|
|
|
138
148
|
export const singleLineComponentsStyle: StylesConfig = {
|
package/src/ThemeProvider.tsx
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import {createContext, ReactNode, useContext, useEffect, useState} from "react";
|
|
3
|
+
import {colors, createInlineTheme, getThemeColors, ThemeColors} from "./designSystem";
|
|
4
|
+
import {
|
|
5
|
+
subscribeOnThemeMenuPreferenceChange,
|
|
6
|
+
subscribeOnThemeModeChange,
|
|
7
|
+
subscribeOnThemePreferenceChange,
|
|
8
|
+
ThemeMenuPreference,
|
|
9
|
+
ThemeMode,
|
|
10
|
+
ThemePreference,
|
|
11
|
+
} from "./theme-settings";
|
|
3
12
|
|
|
4
|
-
const
|
|
13
|
+
const FiberyThemePreferenceContext = createContext<ThemePreference | null>(null);
|
|
14
|
+
const FiberyThemeMenuPreferenceContext = createContext<ThemeMenuPreference | null>(null);
|
|
5
15
|
|
|
6
|
-
|
|
16
|
+
const FiberyThemeContext = createContext<ThemeColors>(getThemeColors(colors.brandColors.blue, "light"));
|
|
17
|
+
|
|
18
|
+
function ThemeProvider({theme, children}: {theme: ThemeColors; children: ReactNode}): JSX.Element {
|
|
7
19
|
return <FiberyThemeContext.Provider value={theme}>{children}</FiberyThemeContext.Provider>;
|
|
8
20
|
}
|
|
9
21
|
|
|
@@ -11,4 +23,118 @@ export function useTheme(): ThemeColors {
|
|
|
11
23
|
return useContext(FiberyThemeContext);
|
|
12
24
|
}
|
|
13
25
|
|
|
14
|
-
export
|
|
26
|
+
export function useThemeMode(): ThemeMode {
|
|
27
|
+
const theme = useTheme();
|
|
28
|
+
return theme.mode;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useThemePreference(): ThemePreference {
|
|
32
|
+
const themePreference = useContext(FiberyThemePreferenceContext);
|
|
33
|
+
|
|
34
|
+
invariant(
|
|
35
|
+
themePreference,
|
|
36
|
+
"could not find theme preference context value; please ensure the component is wrapped in a <FiberyThemePreferenceContext>"
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return themePreference;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function useThemeMenuPreference(): ThemeMenuPreference {
|
|
43
|
+
const themeMenuPreference = useContext(FiberyThemeMenuPreferenceContext);
|
|
44
|
+
|
|
45
|
+
invariant(
|
|
46
|
+
themeMenuPreference,
|
|
47
|
+
"could not find theme menu preference context value; please ensure the component is wrapped in a <FiberyThemeMenuPreferenceContext>"
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return themeMenuPreference;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function applyThemeToRoot(theme: ThemeColors) {
|
|
54
|
+
const inlineTheme = createInlineTheme(theme);
|
|
55
|
+
Object.entries(inlineTheme).forEach(([p, v]) => {
|
|
56
|
+
document.body.style.setProperty(p, v);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function RootThemeProvider({
|
|
61
|
+
initialThemeMode,
|
|
62
|
+
initialPreference,
|
|
63
|
+
initialMenuPreference,
|
|
64
|
+
children,
|
|
65
|
+
}: {
|
|
66
|
+
initialThemeMode: ThemeMode;
|
|
67
|
+
initialPreference: ThemePreference;
|
|
68
|
+
initialMenuPreference: ThemeMenuPreference;
|
|
69
|
+
children: ReactNode;
|
|
70
|
+
}): JSX.Element {
|
|
71
|
+
const [themeMode, setThemeMode] = useState<ThemeMode>(initialThemeMode);
|
|
72
|
+
const [themePreference, setThemePreference] = useState<ThemePreference>(initialPreference);
|
|
73
|
+
const [themeMenuPreference, setThemeMenuPreference] = useState<ThemeMenuPreference>(initialMenuPreference);
|
|
74
|
+
const theme = getThemeColors(colors.brandColors.blue, themeMode);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const unsubscribeMode = subscribeOnThemeModeChange(setThemeMode);
|
|
77
|
+
const unsubscribePreference = subscribeOnThemePreferenceChange(setThemePreference);
|
|
78
|
+
const unsubscribeMenuPreference = subscribeOnThemeMenuPreferenceChange(setThemeMenuPreference);
|
|
79
|
+
return () => {
|
|
80
|
+
unsubscribeMode();
|
|
81
|
+
unsubscribePreference();
|
|
82
|
+
unsubscribeMenuPreference();
|
|
83
|
+
};
|
|
84
|
+
}, []);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
const darkThemeClassName = "dark-theme";
|
|
87
|
+
const lightThemeAndDarkMenuClassName = "light-theme-and-dark-menu";
|
|
88
|
+
const meta = document.querySelector('meta[name="color-scheme"]');
|
|
89
|
+
let colorScheme = "light";
|
|
90
|
+
const documentElement = document.documentElement;
|
|
91
|
+
documentElement.classList.remove(darkThemeClassName);
|
|
92
|
+
documentElement.classList.remove(lightThemeAndDarkMenuClassName);
|
|
93
|
+
if (themeMode === "dark") {
|
|
94
|
+
documentElement.classList.add(darkThemeClassName);
|
|
95
|
+
colorScheme = "dark";
|
|
96
|
+
} else if (themeMode === "light2") {
|
|
97
|
+
documentElement.classList.add(lightThemeAndDarkMenuClassName);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
documentElement.style.colorScheme = colorScheme;
|
|
101
|
+
meta?.setAttribute("content", colorScheme);
|
|
102
|
+
|
|
103
|
+
return () => {
|
|
104
|
+
documentElement.classList.remove(darkThemeClassName);
|
|
105
|
+
documentElement.classList.remove(lightThemeAndDarkMenuClassName);
|
|
106
|
+
};
|
|
107
|
+
}, [themeMode]);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
applyThemeToRoot(theme);
|
|
110
|
+
}, [theme]);
|
|
111
|
+
return (
|
|
112
|
+
<FiberyThemePreferenceContext.Provider value={themePreference}>
|
|
113
|
+
<FiberyThemeMenuPreferenceContext.Provider value={themeMenuPreference}>
|
|
114
|
+
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
|
115
|
+
</FiberyThemeMenuPreferenceContext.Provider>
|
|
116
|
+
</FiberyThemePreferenceContext.Provider>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface WithThemeModeProps {
|
|
121
|
+
themeMode: ThemeMode;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function withThemeMode<T extends WithThemeModeProps = WithThemeModeProps>(
|
|
125
|
+
WrappedComponent: React.ComponentType<T>
|
|
126
|
+
) {
|
|
127
|
+
const displayName = WrappedComponent.displayName || WrappedComponent.name || "Component";
|
|
128
|
+
|
|
129
|
+
const ComponentWithThemeMode = (props: Omit<T, keyof WithThemeModeProps>) => {
|
|
130
|
+
const themeMode = useThemeMode();
|
|
131
|
+
|
|
132
|
+
return <WrappedComponent {...(props as T)} themeMode={themeMode} />;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
ComponentWithThemeMode.displayName = `withThemeMode(${displayName})`;
|
|
136
|
+
|
|
137
|
+
return ComponentWithThemeMode;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export {ThemeProvider};
|
package/src/antd/styles.ts
CHANGED
|
@@ -32,15 +32,15 @@ export const inputOverrides = {
|
|
|
32
32
|
transition: `box-shadow ${transition}`,
|
|
33
33
|
},
|
|
34
34
|
disabled: {
|
|
35
|
-
color: themeVars.accentTextColor
|
|
36
|
-
backgroundColor: themeVars.inputDisabledBgColor
|
|
35
|
+
color: `${themeVars.accentTextColor} !important`,
|
|
36
|
+
backgroundColor: `${themeVars.inputDisabledBgColor} !important`,
|
|
37
37
|
borderColor: colors.transparent,
|
|
38
|
-
boxShadow: `${themeVars.
|
|
38
|
+
boxShadow: `${themeVars.inputDisabledBorderColor} !important`,
|
|
39
39
|
transition: `box-shadow ${transition}`,
|
|
40
40
|
WebkitTextFillColor: "currentColor",
|
|
41
41
|
cursor: "default",
|
|
42
42
|
":hover": {
|
|
43
|
-
boxShadow: `${themeVars.
|
|
43
|
+
boxShadow: `${themeVars.inputDisabledBorderColor}`,
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
46
|
};
|