@fibery/ui-kit 1.0.5 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/ui-kit",
3
- "version": "1.0.5",
3
+ "version": "1.2.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",
@@ -33,13 +35,14 @@
33
35
  "@linaria/core": "3.0.0-beta.15",
34
36
  "@linaria/react": "3.0.0-beta.15",
35
37
  "@popperjs/core": "2.9.3",
36
- "@radix-ui/react-dropdown-menu": "0.1.1",
38
+ "@radix-ui/react-dropdown-menu": "1.0.0",
37
39
  "antd": "4.18.8",
38
40
  "chroma-js": "2.1.2",
39
41
  "classnames": "2.3.1",
40
42
  "color-hash": "1.0.3",
41
43
  "d3-shape": "1.3.7",
42
44
  "emoji-mart": "3.0.1",
45
+ "invariant": "2.2.4",
43
46
  "lodash": "4.17.21",
44
47
  "md5": "2.2.1",
45
48
  "moment": "2.20.1",
@@ -61,7 +64,7 @@
61
64
  },
62
65
  "devDependencies": {
63
66
  "@fibery/babel-preset": "7.2.0",
64
- "@fibery/eslint-config": "7.1.0",
67
+ "@fibery/eslint-config": "8.1.0",
65
68
  "@fibery/text-editor": "1.0.0",
66
69
  "@linaria/babel-preset": "3.0.0-beta.15",
67
70
  "@types/chroma-js": "2.1.3",
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<{inverted?: boolean; onClick?: Props["onClick"]}>;
24
+ export const ActionsButtonCompact: FunctionComponent<
25
+ {inverted?: boolean} & Omit<Props, "color" | "borderless" | "Icon" | "size">
26
+ >;
package/src/Button.js CHANGED
@@ -87,9 +87,6 @@ const getMainColor = ({color, dangerous, theme}) => {
87
87
  if (!theme) {
88
88
  return colors.primary;
89
89
  }
90
- if (theme.mode === "old") {
91
- return theme.primary;
92
- }
93
90
  return theme.buttonColor;
94
91
  };
95
92
 
@@ -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 function ActionsButtonCompact({inverted, onClick}) {
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
- onClick={onClick}
357
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,28 @@ 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;
242
+
243
+ export const opacity = {
244
+ opacity100: 1,
245
+ opacity95: 0.95,
246
+ opacity90: 0.9,
247
+ opacity85: 0.85,
248
+ opacity80: 0.8,
249
+ opacity75: 0.75,
250
+ opacity70: 0.7,
251
+ opacity65: 0.65,
252
+ opacity60: 0.6,
253
+ opacity55: 0.55,
254
+ opacity50: 0.5,
255
+ opacity45: 0.45,
256
+ opacity40: 0.4,
257
+ opacity35: 0.35,
258
+ opacity30: 0.3,
259
+ opacity25: 0.25,
260
+ opacity20: 0.2,
261
+ opacity15: 0.15,
262
+ opacity10: 0.1,
263
+ opacity5: 0.05,
264
+ opacity0: 0,
265
+ } 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 ArrowBottom from "../icons/react/ArrowBottom";
9
- import {dropdownIndicatorSize, expanderStyle} from "./styles";
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
- className={expanderStyle}
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
  }
@@ -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,
@@ -128,6 +127,7 @@ export const componentsStyles: StylesConfig = {
128
127
  }),
129
128
  menu: (provided) => ({
130
129
  ...provided,
130
+ color: themeVars.disabledTextColor,
131
131
  zIndex: 1050,
132
132
  backgroundColor: themeVars.actionMenuInnerBg,
133
133
  boxShadow: themeVars.actionMenuShadow as unknown as Property.BoxShadow,
@@ -1,83 +1,113 @@
1
- import {createContext, ReactNode, useContext, useEffect, useMemo, useState} from "react";
2
- import {colors, createInlineTheme, getThemeColors, ThemeColors} from "./designSystem";
1
+ import invariant from "invariant";
2
+ import {themeStyles} from "@fibery/ui-kit/src/theme-styles";
3
+ import {createContext, ReactNode, useContext, useEffect, useState} from "react";
4
+ import {colors, getThemeColors, ThemeColors} from "./designSystem";
3
5
  import {
6
+ subscribeOnThemeMenuPreferenceChange,
4
7
  subscribeOnThemeModeChange,
5
8
  subscribeOnThemePreferenceChange,
9
+ ThemeMenuPreference,
6
10
  ThemeMode,
7
11
  ThemePreference,
8
12
  } from "./theme-settings";
9
13
 
10
- const FiberyThemeModeContext = createContext<{themeMode: ThemeMode; themePreference: ThemePreference}>({
11
- themeMode: "light",
12
- themePreference: "auto",
13
- });
14
+ const FiberyThemePreferenceContext = createContext<ThemePreference | null>(null);
15
+ const FiberyThemeMenuPreferenceContext = createContext<ThemeMenuPreference | null>(null);
16
+
14
17
  const FiberyThemeContext = createContext<ThemeColors>(getThemeColors(colors.brandColors.blue, "light"));
15
18
 
16
19
  function ThemeProvider({theme, children}: {theme: ThemeColors; children: ReactNode}): JSX.Element {
17
20
  return <FiberyThemeContext.Provider value={theme}>{children}</FiberyThemeContext.Provider>;
18
21
  }
19
22
 
20
- function ThemeModeProvider({
21
- oldTheming = true,
23
+ export function useTheme(): ThemeColors {
24
+ return useContext(FiberyThemeContext);
25
+ }
26
+
27
+ export function useThemeMode(): ThemeMode {
28
+ const theme = useTheme();
29
+ return theme.mode;
30
+ }
31
+
32
+ export function useThemePreference(): ThemePreference {
33
+ const themePreference = useContext(FiberyThemePreferenceContext);
34
+
35
+ invariant(
36
+ themePreference,
37
+ "could not find theme preference context value; please ensure the component is wrapped in a <FiberyThemePreferenceContext>"
38
+ );
39
+
40
+ return themePreference;
41
+ }
42
+
43
+ export function useThemeMenuPreference(): ThemeMenuPreference {
44
+ const themeMenuPreference = useContext(FiberyThemeMenuPreferenceContext);
45
+
46
+ invariant(
47
+ themeMenuPreference,
48
+ "could not find theme menu preference context value; please ensure the component is wrapped in a <FiberyThemeMenuPreferenceContext>"
49
+ );
50
+
51
+ return themeMenuPreference;
52
+ }
53
+
54
+ export function RootThemeProvider({
22
55
  initialThemeMode,
23
56
  initialPreference,
57
+ initialMenuPreference,
24
58
  children,
25
59
  }: {
26
- oldTheming: boolean;
27
60
  initialThemeMode: ThemeMode;
28
61
  initialPreference: ThemePreference;
62
+ initialMenuPreference: ThemeMenuPreference;
29
63
  children: ReactNode;
30
64
  }): JSX.Element {
31
65
  const [themeMode, setThemeMode] = useState<ThemeMode>(initialThemeMode);
32
66
  const [themePreference, setThemePreference] = useState<ThemePreference>(initialPreference);
67
+ const [themeMenuPreference, setThemeMenuPreference] = useState<ThemeMenuPreference>(initialMenuPreference);
68
+ const theme = getThemeColors(colors.brandColors.blue, themeMode);
69
+ useEffect(() => {
70
+ const unsubscribeMode = subscribeOnThemeModeChange(setThemeMode);
71
+ const unsubscribePreference = subscribeOnThemePreferenceChange(setThemePreference);
72
+ const unsubscribeMenuPreference = subscribeOnThemeMenuPreferenceChange(setThemeMenuPreference);
73
+ return () => {
74
+ unsubscribeMode();
75
+ unsubscribePreference();
76
+ unsubscribeMenuPreference();
77
+ };
78
+ }, []);
33
79
  useEffect(() => {
34
- if (!oldTheming) {
35
- const unsubscribeMode = subscribeOnThemeModeChange(setThemeMode);
36
- const unsubscribePreference = subscribeOnThemePreferenceChange(setThemePreference);
37
- return () => {
38
- unsubscribeMode();
39
- unsubscribePreference();
40
- };
80
+ const darkThemeClassName = "dark-theme";
81
+ const lightThemeAndDarkMenuClassName = "light-theme-and-dark-menu";
82
+ const meta = document.querySelector('meta[name="color-scheme"]');
83
+ let colorScheme = "light";
84
+ const documentElement = document.documentElement;
85
+ documentElement.classList.remove(darkThemeClassName);
86
+ documentElement.classList.remove(lightThemeAndDarkMenuClassName);
87
+ documentElement.classList.add(themeStyles);
88
+ if (themeMode === "dark") {
89
+ documentElement.classList.add(darkThemeClassName);
90
+ colorScheme = "dark";
91
+ } else if (themeMode === "light2") {
92
+ documentElement.classList.add(lightThemeAndDarkMenuClassName);
41
93
  }
42
- // eslint-disable-next-line @typescript-eslint/no-empty-function
43
- return () => {};
44
- }, [oldTheming]);
45
- const value = useMemo(
46
- () => ({
47
- themeMode,
48
- themePreference,
49
- }),
50
- [themeMode, themePreference]
51
- );
52
- return <FiberyThemeModeContext.Provider value={value}>{children}</FiberyThemeModeContext.Provider>;
53
- }
54
-
55
- export function useTheme(): ThemeColors {
56
- return useContext(FiberyThemeContext);
57
- }
58
94
 
59
- export function useThemeMode(): ThemeMode {
60
- return useContext(FiberyThemeModeContext).themeMode;
61
- }
95
+ documentElement.style.colorScheme = colorScheme;
96
+ meta?.setAttribute("content", colorScheme);
62
97
 
63
- export function useThemePreference(): ThemePreference {
64
- return useContext(FiberyThemeModeContext).themePreference;
65
- }
98
+ return () => {
99
+ documentElement.classList.remove(darkThemeClassName);
100
+ documentElement.classList.remove(lightThemeAndDarkMenuClassName);
101
+ };
102
+ }, [themeMode]);
66
103
 
67
- export function applyThemeToRoot(theme: ThemeColors) {
68
- const inlineTheme = createInlineTheme(theme);
69
- Object.entries(inlineTheme).forEach(([p, v]) => {
70
- document.body.style.setProperty(p, v);
71
- });
72
- }
73
-
74
- export function RootThemeProvider({children}: {children: JSX.Element}): JSX.Element {
75
- const themeMode = useThemeMode();
76
- const theme = getThemeColors(colors.brandColors.blue, themeMode);
77
- useEffect(() => {
78
- applyThemeToRoot(theme);
79
- }, [theme]);
80
- return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
104
+ return (
105
+ <FiberyThemePreferenceContext.Provider value={themePreference}>
106
+ <FiberyThemeMenuPreferenceContext.Provider value={themeMenuPreference}>
107
+ <ThemeProvider theme={theme}>{children}</ThemeProvider>
108
+ </FiberyThemeMenuPreferenceContext.Provider>
109
+ </FiberyThemePreferenceContext.Provider>
110
+ );
81
111
  }
82
112
 
83
113
  interface WithThemeModeProps {
@@ -100,4 +130,4 @@ export function withThemeMode<T extends WithThemeModeProps = WithThemeModeProps>
100
130
  return ComponentWithThemeMode;
101
131
  }
102
132
 
103
- export {ThemeProvider, ThemeModeProvider};
133
+ export {ThemeProvider};
@@ -32,15 +32,15 @@ export const inputOverrides = {
32
32
  transition: `box-shadow ${transition}`,
33
33
  },
34
34
  disabled: {
35
- color: `${themeVars.accentTextColor}`,
35
+ color: `${themeVars.accentTextColor} !important`,
36
36
  backgroundColor: `${themeVars.inputDisabledBgColor} !important`,
37
37
  borderColor: colors.transparent,
38
- boxShadow: `${themeVars.inputBorderColor} !important`,
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.inputBorderColor}`,
43
+ boxShadow: `${themeVars.inputDisabledBorderColor}`,
44
44
  },
45
45
  },
46
46
  };
@@ -1,5 +1,12 @@
1
- export function createInlineTheme<T extends Record<string, unknown>>(themes: T): Record<string, string> {
1
+ export function createInlineTheme<T extends Record<string, unknown>>(
2
+ themes: T,
3
+ rejectKeys: Array<string>
4
+ ): Record<string, string> {
2
5
  return Object.entries(themes).reduce<Record<string, string>>((inlineTheme, [key, value]) => {
6
+ if (rejectKeys.includes(key)) {
7
+ return inlineTheme;
8
+ }
9
+
3
10
  if (key === "opacity") {
4
11
  Object.entries(themes.opacity as Record<string, string>).forEach(([opacityKey, opacityValue]) => {
5
12
  inlineTheme[`--fibery-opacity-${opacityKey}`] = opacityValue;