@basic-ui/material 0.1.11 → 0.1.14
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/build/cjs/index.js +33 -28
- package/build/cjs/index.js.map +1 -1
- package/build/esm/Alert/Alert.d.ts +1 -1
- package/build/esm/AppBar/AppBar.d.ts +1 -1
- package/build/esm/AppBar/AppBarButton.d.ts +1 -1
- package/build/esm/Badge/Badge.d.ts +1 -1
- package/build/esm/BottomSheet/BottomSheet.d.ts +1 -1
- package/build/esm/BottomSheet/BottomSheetSurface.d.ts +1 -1
- package/build/esm/Button/BaseButton.d.ts +1 -1
- package/build/esm/Button/Button.d.ts +1 -1
- package/build/esm/Button/FilledButton.d.ts +1 -1
- package/build/esm/Button/FloatingActionButton.d.ts +7 -0
- package/build/esm/Button/FloatingActionButton.js +8 -0
- package/build/esm/Button/FloatingActionButton.js.map +1 -0
- package/build/esm/Button/OutlinedButton.d.ts +1 -1
- package/build/esm/Button/TransparentButton.d.ts +1 -1
- package/build/esm/CheckBox/CheckBox.d.ts +1 -1
- package/build/esm/CheckBox/CheckBoxIcon.d.ts +1 -1
- package/build/esm/Chip/ButtonChip.d.ts +1 -1
- package/build/esm/Chip/ChoiceChip.d.ts +1 -1
- package/build/esm/ColorMode/ColorModeProvider.js +10 -3
- package/build/esm/ColorMode/ColorModeProvider.js.map +1 -1
- package/build/esm/Combobox/Combobox.d.ts +7 -7
- package/build/esm/Dialog/Dialog.d.ts +1 -1
- package/build/esm/Dialog/DialogBackdrop.d.ts +1 -1
- package/build/esm/Dialog/DialogSurface.d.ts +1 -1
- package/build/esm/Dialog/useDialogAnimation.js +1 -1
- package/build/esm/Dialog/useDialogAnimation.js.map +1 -1
- package/build/esm/Divider/Divider.d.ts +1 -1
- package/build/esm/LineRipple/LineRipple.d.ts +1 -1
- package/build/esm/Link/Link.d.ts +1 -1
- package/build/esm/List/List.d.ts +1 -1
- package/build/esm/ListItem/ListItem.d.ts +1 -1
- package/build/esm/Menu/Menu.d.ts +4 -4
- package/build/esm/Paper/Paper.d.ts +1 -1
- package/build/esm/RadioButton/RadioGroup.d.ts +1 -1
- package/build/esm/Ripple/keyframes.js +0 -2
- package/build/esm/Ripple/keyframes.js.map +1 -1
- package/build/esm/Ripple/useRipple.js +1 -1
- package/build/esm/Ripple/useRipple.js.map +1 -1
- package/build/esm/Select/SelectIcon.d.ts +1 -1
- package/build/esm/SelectItem/SelectItem.d.ts +1 -1
- package/build/esm/SelectionControl/SelectionControlLabel.d.ts +1 -1
- package/build/esm/SelectionControl/SelectionControlText.d.ts +1 -1
- package/build/esm/Skeleton/DelayAppearance.d.ts +1 -1
- package/build/esm/Skeleton/Skeleton.d.ts +1 -1
- package/build/esm/Snackbar/Snackbar.d.ts +1 -1
- package/build/esm/Switch/Switch.d.ts +1 -1
- package/build/esm/Tab/Tab.d.ts +1 -1
- package/build/esm/Tab/TabList.d.ts +1 -1
- package/build/esm/Tab/TabPanel.d.ts +1 -1
- package/build/esm/TabIndicator/TabIndicator.d.ts +1 -1
- package/build/esm/Table/Table.d.ts +1 -1
- package/build/esm/Table/TableHead.d.ts +1 -1
- package/build/esm/Table/TableRow.d.ts +1 -1
- package/build/esm/Text/Text.d.ts +1 -1
- package/build/esm/TextField/FilledContainer.d.ts +1 -1
- package/build/esm/TextField/HelperText.d.ts +1 -1
- package/build/esm/TextField/Input.d.ts +1 -1
- package/build/esm/TextField/OutlinedContainer.d.ts +1 -1
- package/build/esm/TextField/TextField.d.ts +1 -1
- package/build/esm/ThemeExplorer/ColorPicker.d.ts +8 -0
- package/build/esm/ThemeExplorer/ColorPicker.js +76 -0
- package/build/esm/ThemeExplorer/ColorPicker.js.map +1 -0
- package/build/esm/ThemeExplorer/TextFieldColorPicker.d.ts +9 -0
- package/build/esm/ThemeExplorer/TextFieldColorPicker.js +100 -0
- package/build/esm/ThemeExplorer/TextFieldColorPicker.js.map +1 -0
- package/build/esm/ThemeExplorer/ThemeColors.d.ts +5 -0
- package/build/esm/ThemeExplorer/ThemeColors.js +80 -0
- package/build/esm/ThemeExplorer/ThemeColors.js.map +1 -0
- package/build/esm/ThemeExplorer/components.d.ts +31 -0
- package/build/esm/ThemeExplorer/components.js +184 -0
- package/build/esm/ThemeExplorer/components.js.map +1 -0
- package/build/esm/ThemeExplorer/makeColorScheme.d.ts +66 -0
- package/build/esm/ThemeExplorer/makeColorScheme.js +66 -0
- package/build/esm/ThemeExplorer/makeColorScheme.js.map +1 -0
- package/build/esm/ThemeExplorer/useDeferredColor.d.ts +3 -0
- package/build/esm/ThemeExplorer/useDeferredColor.js +11 -0
- package/build/esm/ThemeExplorer/useDeferredColor.js.map +1 -0
- package/build/esm/ThemeExplorer/useLocalStorageCachedState.d.ts +1 -0
- package/build/esm/ThemeExplorer/useLocalStorageCachedState.js +11 -0
- package/build/esm/ThemeExplorer/useLocalStorageCachedState.js.map +1 -0
- package/build/esm/Tooltip/Tooltip.d.ts +1 -1
- package/build/esm/hooks/useAnimation.js +22 -21
- package/build/esm/hooks/useAnimation.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +54 -54
- package/package.json +3 -3
- package/src/Alert/Alert.story.tsx +5 -6
- package/src/AppBar/AppBar.story.tsx +11 -20
- package/src/BottomSheet/BottomSheet.story.tsx +5 -6
- package/src/Button/Button.story.tsx +14 -14
- package/src/Button/SpinnerButton.story.tsx +6 -6
- package/src/CheckBox/CheckBox.story.tsx +7 -6
- package/src/Chip/Chip.story.tsx +5 -7
- package/src/ColorMode/ColorModeProvider.tsx +9 -3
- package/src/Combobox/Combobox.story.tsx +12 -10
- package/src/Dialog/Dialog.story.tsx +7 -8
- package/src/Dialog/useDialogAnimation.tsx +1 -1
- package/src/Divider/Divider.story.tsx +6 -5
- package/src/FloatingLabel/FloatingLabel.story.tsx +10 -9
- package/src/LineRipple/LineRipple.story.tsx +5 -4
- package/src/Link/Link.story.tsx +3 -4
- package/src/ListItem/ListItem.story.tsx +6 -5
- package/src/Menu/Menu.story.tsx +8 -7
- package/src/NotchedOutline/NotchedOutline.story.tsx +5 -4
- package/src/Paper/Paper.story.tsx +5 -4
- package/src/ProgressSpinner/ProgressSpinner.story.tsx +5 -4
- package/src/RadioButton/RadioButton.story.tsx +12 -10
- package/src/Ripple/Ripple.story.tsx +5 -4
- package/src/Ripple/keyframes.ts +0 -2
- package/src/Ripple/useRipple.ts +3 -1
- package/src/Select/Select.story.tsx +8 -7
- package/src/Skeleton/Skeleton.story.tsx +7 -6
- package/src/Snackbar/Snackbar.story.tsx +7 -6
- package/src/Switch/Switch.story.tsx +5 -4
- package/src/Tab/Tab.story.tsx +7 -5
- package/src/Table/Table.story.tsx +5 -4
- package/src/Text/Text.story.tsx +5 -4
- package/src/TextField/TextField.story.tsx +7 -6
- package/src/Tooltip/Tooltip.story.tsx +5 -4
- package/src/hooks/useAnimation.ts +42 -32
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import React, { memo, useState } from 'react';
|
|
2
|
+
import { Box, Text, Tooltip } from '../';
|
|
3
|
+
import { rgb, parseToHsl, parseToRgb } from 'polished';
|
|
4
|
+
import { hexFromArgb, TonalPalette } from '@material/material-color-utilities';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
8
|
+
export const ColorItem = /*#__PURE__*/memo(props => {
|
|
9
|
+
const {
|
|
10
|
+
token,
|
|
11
|
+
style,
|
|
12
|
+
height = 50,
|
|
13
|
+
width
|
|
14
|
+
} = props;
|
|
15
|
+
const [computedColor, setComputedColor] = useState();
|
|
16
|
+
const hslColor = computedColor ? parseToHsl(computedColor) : {
|
|
17
|
+
hue: 0,
|
|
18
|
+
saturation: 0,
|
|
19
|
+
lightness: 0
|
|
20
|
+
};
|
|
21
|
+
const rgbColor = computedColor ? parseToRgb(computedColor) : {
|
|
22
|
+
red: 0,
|
|
23
|
+
green: 0,
|
|
24
|
+
blue: 0
|
|
25
|
+
};
|
|
26
|
+
return /*#__PURE__*/_jsx(Tooltip, {
|
|
27
|
+
label: computedColor ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
28
|
+
children: [/*#__PURE__*/_jsx("p", {
|
|
29
|
+
children: token
|
|
30
|
+
}), /*#__PURE__*/_jsx("p", {
|
|
31
|
+
children: rgb(rgbColor)
|
|
32
|
+
}), /*#__PURE__*/_jsxs("p", {
|
|
33
|
+
children: ["rgb(", rgbColor.red, ", ", rgbColor.green, ", ", rgbColor.blue, ")"]
|
|
34
|
+
}), /*#__PURE__*/_jsxs("p", {
|
|
35
|
+
children: ["hsl(", Math.round(hslColor.hue), ",", ' ', Math.round(hslColor.saturation * 100), "%,", ' ', Math.round(hslColor.lightness * 100), "%)"]
|
|
36
|
+
})]
|
|
37
|
+
}) : /*#__PURE__*/_jsx("p", {
|
|
38
|
+
children: token
|
|
39
|
+
}),
|
|
40
|
+
children: /*#__PURE__*/_jsx(Box, {
|
|
41
|
+
width: width,
|
|
42
|
+
height: height,
|
|
43
|
+
style: style,
|
|
44
|
+
pl: "10px",
|
|
45
|
+
pt: "10px",
|
|
46
|
+
ref: ref => {
|
|
47
|
+
if (ref) {
|
|
48
|
+
setComputedColor(window.getComputedStyle(ref).backgroundColor);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
52
|
+
variant: "body2",
|
|
53
|
+
as: "span",
|
|
54
|
+
fontSize: "11px",
|
|
55
|
+
lineHeight: "11px",
|
|
56
|
+
children: token
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
export const ColorRow = /*#__PURE__*/memo(props => {
|
|
62
|
+
const {
|
|
63
|
+
colors,
|
|
64
|
+
height = 50
|
|
65
|
+
} = props;
|
|
66
|
+
return /*#__PURE__*/_jsx(Box, {
|
|
67
|
+
width: "100%",
|
|
68
|
+
display: "flex",
|
|
69
|
+
sx: {
|
|
70
|
+
':first-of-type': {
|
|
71
|
+
borderTopLeftRadius: 24,
|
|
72
|
+
borderTopRightRadius: 24,
|
|
73
|
+
overflow: 'hidden'
|
|
74
|
+
},
|
|
75
|
+
':last-of-type': {
|
|
76
|
+
borderBottomLeftRadius: 24,
|
|
77
|
+
borderBottomRightRadius: 24,
|
|
78
|
+
overflow: 'hidden'
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
children: colors.map(({
|
|
82
|
+
token,
|
|
83
|
+
bg,
|
|
84
|
+
color
|
|
85
|
+
}, idx) => /*#__PURE__*/_jsx(ColorItem, {
|
|
86
|
+
width: colors.length % 2 === 1 ? idx === colors.length - 1 ? '50%' : '25%' : '33.33%',
|
|
87
|
+
token: token,
|
|
88
|
+
style: {
|
|
89
|
+
backgroundColor: bg,
|
|
90
|
+
color: color
|
|
91
|
+
},
|
|
92
|
+
height: height
|
|
93
|
+
}, token))
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
export const TonalColorItem = /*#__PURE__*/memo(props => {
|
|
97
|
+
const {
|
|
98
|
+
level,
|
|
99
|
+
color
|
|
100
|
+
} = props;
|
|
101
|
+
const hslColor = parseToHsl(color);
|
|
102
|
+
const rgbColor = parseToRgb(color);
|
|
103
|
+
return /*#__PURE__*/_jsx(Tooltip, {
|
|
104
|
+
label: /*#__PURE__*/_jsxs(_Fragment, {
|
|
105
|
+
children: [/*#__PURE__*/_jsxs("p", {
|
|
106
|
+
children: ["Luminance: ", level]
|
|
107
|
+
}), /*#__PURE__*/_jsx("p", {
|
|
108
|
+
children: rgb(rgbColor)
|
|
109
|
+
}), /*#__PURE__*/_jsxs("p", {
|
|
110
|
+
children: ["rgb(", rgbColor.red, ", ", rgbColor.green, ", ", rgbColor.blue, ")"]
|
|
111
|
+
}), /*#__PURE__*/_jsxs("p", {
|
|
112
|
+
children: ["hsl(", Math.round(hslColor.hue), ",", ' ', Math.round(hslColor.saturation * 100), "%,", ' ', Math.round(hslColor.lightness * 100), "%)"]
|
|
113
|
+
})]
|
|
114
|
+
}),
|
|
115
|
+
children: /*#__PURE__*/_jsx(Box, {
|
|
116
|
+
flex: 1,
|
|
117
|
+
display: "flex",
|
|
118
|
+
alignItems: "center",
|
|
119
|
+
justifyContent: "center",
|
|
120
|
+
style: {
|
|
121
|
+
backgroundColor: color,
|
|
122
|
+
color: level <= 50 ? '#fff' : '#000'
|
|
123
|
+
},
|
|
124
|
+
children: level
|
|
125
|
+
}, level)
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
export const TonalColorsFromToken = /*#__PURE__*/memo(props => {
|
|
129
|
+
const [computedColor, setComputedColor] = useState();
|
|
130
|
+
|
|
131
|
+
if (!computedColor) {
|
|
132
|
+
return /*#__PURE__*/_jsx(Box, {
|
|
133
|
+
ref: ref => {
|
|
134
|
+
if (ref) {
|
|
135
|
+
setComputedColor(window.getComputedStyle(ref).backgroundColor);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
bg: props.token,
|
|
139
|
+
style: {
|
|
140
|
+
position: 'fixed',
|
|
141
|
+
left: -5000,
|
|
142
|
+
top: -5000
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const colorInt = parseInt(rgb(parseToRgb(computedColor)).slice(1), 16);
|
|
148
|
+
const tonal = TonalPalette.fromInt(colorInt);
|
|
149
|
+
return /*#__PURE__*/_jsx(TonalColors, {
|
|
150
|
+
palette: tonal
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
export const TonalColors = /*#__PURE__*/memo(props => {
|
|
154
|
+
const luminanceLevels = [0, 10, 20, 25, 30, 35, 40, 50, 60, 70, 80, 90, 95, 98, 99, 100];
|
|
155
|
+
return /*#__PURE__*/_jsx(Box, {
|
|
156
|
+
display: "flex",
|
|
157
|
+
height: "72px",
|
|
158
|
+
width: "100%",
|
|
159
|
+
children: luminanceLevels.map(level => /*#__PURE__*/_jsx(TonalColorItem, {
|
|
160
|
+
level: level,
|
|
161
|
+
color: hexFromArgb(props.palette.tone(level))
|
|
162
|
+
}, level))
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
export function makeColorArrayForToken(token) {
|
|
166
|
+
return [{
|
|
167
|
+
token,
|
|
168
|
+
bg: token,
|
|
169
|
+
color: 'on.' + token
|
|
170
|
+
}, {
|
|
171
|
+
token,
|
|
172
|
+
bg: 'on.' + token,
|
|
173
|
+
color: token
|
|
174
|
+
}, {
|
|
175
|
+
token,
|
|
176
|
+
bg: token + '-container',
|
|
177
|
+
color: 'on.' + token + '-container'
|
|
178
|
+
}, {
|
|
179
|
+
token,
|
|
180
|
+
bg: 'on.' + token + '-container',
|
|
181
|
+
color: token + '-container'
|
|
182
|
+
}];
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/ThemeExplorer/components.tsx"],"names":["React","memo","useState","Box","Text","Tooltip","rgb","parseToHsl","parseToRgb","hexFromArgb","TonalPalette","ColorItem","props","token","style","height","width","computedColor","setComputedColor","hslColor","hue","saturation","lightness","rgbColor","red","green","blue","Math","round","ref","window","getComputedStyle","backgroundColor","ColorRow","colors","borderTopLeftRadius","borderTopRightRadius","overflow","borderBottomLeftRadius","borderBottomRightRadius","map","bg","color","idx","length","TonalColorItem","level","TonalColorsFromToken","position","left","top","colorInt","parseInt","slice","tonal","fromInt","TonalColors","luminanceLevels","palette","tone","makeColorArrayForToken"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,IAAhB,EAAsBC,QAAtB,QAAqD,OAArD;AACA,SAASC,GAAT,EAAcC,IAAd,EAAoBC,OAApB,QAAmC,KAAnC;AACA,SAASC,GAAT,EAAcC,UAAd,EAA0BC,UAA1B,QAA4C,UAA5C;AACA,SAASC,WAAT,EAAsBC,YAAtB,QAA0C,oCAA1C;;;;AAEA,OAAO,MAAMC,SAAS,gBAAGV,IAAI,CAC1BW,KAAD,IAKM;AAC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A,sBACE,KAAC,GAAD;AAAK,IAAA,OAAO,EAAC,MAAb;AAAoB,IAAA,MAAM,EAAC,MAA3B;AAAkC,IAAA,KAAK,EAAC,MAAxC;AAAA,cACGA,eAAe,CAACjB,GAAhB,CAAqBM,KAAD,iBACnB,KAAC,cAAD;AAEE,MAAA,KAAK,EAAEA,KAFT;AAGE,MAAA,KAAK,EAAErC,WAAW,CAACG,KAAK,CAAC8C,OAAN,CAAcC,IAAd,CAAmBb,KAAnB,CAAD;AAHpB,OACOA,KADP,CADD;AADH,IADF;AAWD,CA9B8B,CAAxB;AAgCP,OAAO,SAASc,sBAAT,CACL/C,KADK,EAE2C;AAChD,SAAO,CACL;AAAEA,IAAAA,KAAF;AAAS4B,IAAAA,EAAE,EAAE5B,KAAb;AAAoB6B,IAAAA,KAAK,EAAE,QAAQ7B;AAAnC,GADK,EAEL;AAAEA,IAAAA,KAAF;AAAS4B,IAAAA,EAAE,EAAE,QAAQ5B,KAArB;AAA4B6B,IAAAA,KAAK,EAAE7B;AAAnC,GAFK,EAGL;AAAEA,IAAAA,KAAF;AAAS4B,IAAAA,EAAE,EAAE5B,KAAK,GAAG,YAArB;AAAmC6B,IAAAA,KAAK,EAAE,QAAQ7B,KAAR,GAAgB;AAA1D,GAHK,EAIL;AAAEA,IAAAA,KAAF;AAAS4B,IAAAA,EAAE,EAAE,QAAQ5B,KAAR,GAAgB,YAA7B;AAA2C6B,IAAAA,KAAK,EAAE7B,KAAK,GAAG;AAA1D,GAJK,CAAP;AAMD","sourcesContent":["import React, { memo, useState, CSSProperties } from 'react';\nimport { Box, Text, Tooltip } from '../';\nimport { rgb, parseToHsl, parseToRgb } from 'polished';\nimport { hexFromArgb, TonalPalette } from '@material/material-color-utilities';\n\nexport const ColorItem = memo(\n (props: {\n token: string;\n style: CSSProperties;\n height: number;\n width: string;\n }) => {\n const { token, style, height = 50, width } = props;\n const [computedColor, setComputedColor] = useState<string>();\n const hslColor = computedColor\n ? parseToHsl(computedColor)\n : { hue: 0, saturation: 0, lightness: 0 };\n const rgbColor = computedColor\n ? parseToRgb(computedColor)\n : { red: 0, green: 0, blue: 0 };\n return (\n <Tooltip\n label={\n computedColor ? (\n <>\n <p>{token}</p>\n <p>{rgb(rgbColor)}</p>\n <p>\n rgb({rgbColor.red}, {rgbColor.green}, {rgbColor.blue})\n </p>\n <p>\n hsl({Math.round(hslColor.hue)},{' '}\n {Math.round(hslColor.saturation * 100)}%,{' '}\n {Math.round(hslColor.lightness * 100)}%)\n </p>\n </>\n ) : (\n <p>{token}</p>\n )\n }\n >\n <Box\n width={width}\n height={height}\n style={style}\n pl=\"10px\"\n pt=\"10px\"\n ref={(ref: HTMLDivElement | null) => {\n if (ref) {\n setComputedColor(window.getComputedStyle(ref).backgroundColor);\n }\n }}\n >\n <Text variant=\"body2\" as=\"span\" fontSize=\"11px\" lineHeight=\"11px\">\n {token}\n </Text>\n </Box>\n </Tooltip>\n );\n }\n);\n\nexport const ColorRow = memo(\n (props: {\n colors: { token: string; bg: string; color: string }[];\n height?: number;\n }) => {\n const { colors, height = 50 } = props;\n return (\n <Box\n width=\"100%\"\n display=\"flex\"\n sx={{\n ':first-of-type': {\n borderTopLeftRadius: 24,\n borderTopRightRadius: 24,\n overflow: 'hidden',\n },\n ':last-of-type': {\n borderBottomLeftRadius: 24,\n borderBottomRightRadius: 24,\n overflow: 'hidden',\n },\n }}\n >\n {colors.map(({ token, bg, color }, idx) => (\n <ColorItem\n width={\n colors.length % 2 === 1\n ? idx === colors.length - 1\n ? '50%'\n : '25%'\n : '33.33%'\n }\n key={token}\n token={token}\n style={{ backgroundColor: bg, color: color }}\n height={height}\n />\n ))}\n </Box>\n );\n }\n);\n\nexport const TonalColorItem = memo(\n (props: { color: string; level: number }) => {\n const { level, color } = props;\n const hslColor = parseToHsl(color);\n const rgbColor = parseToRgb(color);\n return (\n <Tooltip\n label={\n <>\n <p>Luminance: {level}</p>\n <p>{rgb(rgbColor)}</p>\n <p>\n rgb({rgbColor.red}, {rgbColor.green}, {rgbColor.blue})\n </p>\n <p>\n hsl({Math.round(hslColor.hue)},{' '}\n {Math.round(hslColor.saturation * 100)}%,{' '}\n {Math.round(hslColor.lightness * 100)}%)\n </p>\n </>\n }\n >\n <Box\n key={level}\n flex={1}\n display=\"flex\"\n alignItems=\"center\"\n justifyContent=\"center\"\n style={{\n backgroundColor: color,\n color: level <= 50 ? '#fff' : '#000',\n }}\n >\n {level}\n </Box>\n </Tooltip>\n );\n }\n);\n\nexport const TonalColorsFromToken = memo((props: { token: string }) => {\n const [computedColor, setComputedColor] = useState<string>();\n if (!computedColor) {\n return (\n <Box\n ref={(ref: HTMLDivElement | null) => {\n if (ref) {\n setComputedColor(window.getComputedStyle(ref).backgroundColor);\n }\n }}\n bg={props.token}\n style={{ position: 'fixed', left: -5000, top: -5000 }}\n />\n );\n }\n const colorInt = parseInt(rgb(parseToRgb(computedColor)).slice(1), 16);\n const tonal = TonalPalette.fromInt(colorInt);\n\n return <TonalColors palette={tonal} />;\n});\n\nexport const TonalColors = memo((props: { palette: TonalPalette }) => {\n const luminanceLevels = [\n 0,\n 10,\n 20,\n 25,\n 30,\n 35,\n 40,\n 50,\n 60,\n 70,\n 80,\n 90,\n 95,\n 98,\n 99,\n 100,\n ];\n return (\n <Box display=\"flex\" height=\"72px\" width=\"100%\">\n {luminanceLevels.map((level) => (\n <TonalColorItem\n key={level}\n level={level}\n color={hexFromArgb(props.palette.tone(level))}\n />\n ))}\n </Box>\n );\n});\n\nexport function makeColorArrayForToken(\n token: string\n): { token: string; bg: string; color: string }[] {\n return [\n { token, bg: token, color: 'on.' + token },\n { token, bg: 'on.' + token, color: token },\n { token, bg: token + '-container', color: 'on.' + token + '-container' },\n { token, bg: 'on.' + token + '-container', color: token + '-container' },\n ];\n}\n"],"file":"components.js"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { TonalPalette } from '@material/material-color-utilities';
|
|
2
|
+
export declare function makeColorScheme(opts: {
|
|
3
|
+
primary: TonalPalette;
|
|
4
|
+
secondary: TonalPalette;
|
|
5
|
+
tertiary: TonalPalette;
|
|
6
|
+
error: TonalPalette;
|
|
7
|
+
neutral: TonalPalette;
|
|
8
|
+
neutralVariant: TonalPalette;
|
|
9
|
+
}): {
|
|
10
|
+
primary: string;
|
|
11
|
+
secondary: string;
|
|
12
|
+
tertiary: string;
|
|
13
|
+
error: string;
|
|
14
|
+
'primary-container': string;
|
|
15
|
+
'secondary-container': string;
|
|
16
|
+
'tertiary-container': string;
|
|
17
|
+
'error-container': string;
|
|
18
|
+
background: string;
|
|
19
|
+
surface: string;
|
|
20
|
+
'surface-variant': string;
|
|
21
|
+
outline: string;
|
|
22
|
+
on: {
|
|
23
|
+
primary: string;
|
|
24
|
+
secondary: string;
|
|
25
|
+
tertiary: string;
|
|
26
|
+
error: string;
|
|
27
|
+
'primary-container': string;
|
|
28
|
+
'secondary-container': string;
|
|
29
|
+
'tertiary-container': string;
|
|
30
|
+
'error-container': string;
|
|
31
|
+
background: string;
|
|
32
|
+
surface: string;
|
|
33
|
+
'surface-variant': string;
|
|
34
|
+
outline: string;
|
|
35
|
+
};
|
|
36
|
+
modes: {
|
|
37
|
+
dark: {
|
|
38
|
+
primary: string;
|
|
39
|
+
secondary: string;
|
|
40
|
+
tertiary: string;
|
|
41
|
+
error: string;
|
|
42
|
+
'primary-container': string;
|
|
43
|
+
'secondary-container': string;
|
|
44
|
+
'tertiary-container': string;
|
|
45
|
+
'error-container': string;
|
|
46
|
+
background: string;
|
|
47
|
+
surface: string;
|
|
48
|
+
'surface-variant': string;
|
|
49
|
+
outline: string;
|
|
50
|
+
on: {
|
|
51
|
+
primary: string;
|
|
52
|
+
secondary: string;
|
|
53
|
+
tertiary: string;
|
|
54
|
+
error: string;
|
|
55
|
+
'primary-container': string;
|
|
56
|
+
'secondary-container': string;
|
|
57
|
+
'tertiary-container': string;
|
|
58
|
+
'error-container': string;
|
|
59
|
+
background: string;
|
|
60
|
+
surface: string;
|
|
61
|
+
'surface-variant': string;
|
|
62
|
+
outline: string;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { hexFromArgb } from '@material/material-color-utilities';
|
|
2
|
+
export function makeColorScheme(opts) {
|
|
3
|
+
function c(palette, tone) {
|
|
4
|
+
return hexFromArgb(palette.tone(tone));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
primary: c(opts.primary, 40),
|
|
9
|
+
secondary: c(opts.secondary, 40),
|
|
10
|
+
tertiary: c(opts.tertiary, 40),
|
|
11
|
+
error: c(opts.error, 40),
|
|
12
|
+
'primary-container': c(opts.primary, 90),
|
|
13
|
+
'secondary-container': c(opts.secondary, 90),
|
|
14
|
+
'tertiary-container': c(opts.tertiary, 90),
|
|
15
|
+
'error-container': c(opts.error, 90),
|
|
16
|
+
background: c(opts.neutral, 99),
|
|
17
|
+
surface: c(opts.neutral, 99),
|
|
18
|
+
'surface-variant': c(opts.neutralVariant, 90),
|
|
19
|
+
outline: c(opts.neutralVariant, 50),
|
|
20
|
+
on: {
|
|
21
|
+
primary: c(opts.primary, 100),
|
|
22
|
+
secondary: c(opts.secondary, 100),
|
|
23
|
+
tertiary: c(opts.tertiary, 100),
|
|
24
|
+
error: c(opts.error, 100),
|
|
25
|
+
'primary-container': c(opts.primary, 10),
|
|
26
|
+
'secondary-container': c(opts.secondary, 10),
|
|
27
|
+
'tertiary-container': c(opts.tertiary, 10),
|
|
28
|
+
'error-container': c(opts.error, 10),
|
|
29
|
+
background: c(opts.neutral, 10),
|
|
30
|
+
surface: c(opts.neutral, 10),
|
|
31
|
+
'surface-variant': c(opts.neutralVariant, 30),
|
|
32
|
+
outline: c(opts.neutralVariant, 95)
|
|
33
|
+
},
|
|
34
|
+
modes: {
|
|
35
|
+
dark: {
|
|
36
|
+
primary: c(opts.primary, 80),
|
|
37
|
+
secondary: c(opts.secondary, 80),
|
|
38
|
+
tertiary: c(opts.tertiary, 80),
|
|
39
|
+
error: c(opts.error, 80),
|
|
40
|
+
'primary-container': c(opts.primary, 30),
|
|
41
|
+
'secondary-container': c(opts.secondary, 30),
|
|
42
|
+
'tertiary-container': c(opts.tertiary, 30),
|
|
43
|
+
'error-container': c(opts.error, 30),
|
|
44
|
+
background: c(opts.neutral, 10),
|
|
45
|
+
surface: c(opts.neutral, 10),
|
|
46
|
+
'surface-variant': c(opts.neutralVariant, 30),
|
|
47
|
+
outline: c(opts.neutralVariant, 60),
|
|
48
|
+
on: {
|
|
49
|
+
primary: c(opts.primary, 20),
|
|
50
|
+
secondary: c(opts.secondary, 20),
|
|
51
|
+
tertiary: c(opts.tertiary, 20),
|
|
52
|
+
error: c(opts.error, 20),
|
|
53
|
+
'primary-container': c(opts.primary, 90),
|
|
54
|
+
'secondary-container': c(opts.secondary, 90),
|
|
55
|
+
'tertiary-container': c(opts.tertiary, 90),
|
|
56
|
+
'error-container': c(opts.error, 90),
|
|
57
|
+
background: c(opts.neutral, 90),
|
|
58
|
+
surface: c(opts.neutral, 90),
|
|
59
|
+
'surface-variant': c(opts.neutralVariant, 80),
|
|
60
|
+
outline: c(opts.neutralVariant, 10)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=makeColorScheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/ThemeExplorer/makeColorScheme.tsx"],"names":["hexFromArgb","makeColorScheme","opts","c","palette","tone","primary","secondary","tertiary","error","background","neutral","surface","neutralVariant","outline","on","modes","dark"],"mappings":"AAAA,SAAuBA,WAAvB,QAA0C,oCAA1C;AAEA,OAAO,SAASC,eAAT,CAAyBC,IAAzB,EAOJ;AACD,WAASC,CAAT,CAAWC,OAAX,EAAkCC,IAAlC,EAAgD;AAC9C,WAAOL,WAAW,CAACI,OAAO,CAACC,IAAR,CAAaA,IAAb,CAAD,CAAlB;AACD;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ATT;AAUJC,QAAAA,OAAO,EAAET,CAAC,CAACD,IAAI,CAACS,OAAN,EAAe,EAAf,CAVN;AAWJ,2BAAmBR,CAAC,CAACD,IAAI,CAACW,cAAN,EAAsB,EAAtB,CAXhB;AAYJC,QAAAA,OAAO,EAAEX,CAAC,CAACD,IAAI,CAACW,cAAN,EAAsB,EAAtB,CAZN;AAaJE,QAAAA,EAAE,EAAE;AACFT,UAAAA,OAAO,EAAEH,CAAC,CAACD,IAAI,CAACI,OAAN,EAAe,EAAf,CADR;AAEFC,UAAAA,SAAS,EAAEJ,CAAC,CAACD,IAAI,CAACK,SAAN,EAAiB,EAAjB,CAFV;AAGFC,UAAAA,QAAQ,EAAEL,CAAC,CAACD,IAAI,CAACM,QAAN,EAAgB,EAAhB,CAHT;AAIFC,UAAAA,KAAK,EAAEN,CAAC,CAACD,IAAI,CAACO,KAAN,EAAa,EAAb,CAJN;AAKF,+BAAqBN,CAAC,CAACD,IAAI,CAACI,OAAN,EAAe,EAAf,CALpB;AAMF,iCAAuBH,CAAC,CAACD,IAAI,CAACK,SAAN,EAAiB,EAAjB,CANtB;AAOF,gCAAsBJ,CAAC,CAACD,IAAI,CAACM,QAAN,EAAgB,EAAhB,CAPrB;AAQF,6BAAmBL,CAAC,CAACD,IAAI,CAACO,KAAN,EAAa,EAAb,CARlB;AASFC,UAAAA,UAAU,EAAEP,CAAC,CAACD,IAAI,CAACS,OAAN,EAAe,EAAf,CATX;AAUFC,UAAAA,OAAO,EAAET,CAAC,CAACD,IAAI,CAACS,OAAN,EAAe,EAAf,CAVR;AAWF,6BAAmBR,CAAC,CAACD,IAAI,CAACW,cAAN,EAAsB,EAAtB,CAXlB;AAYFC,UAAAA,OAAO,EAAEX,CAAC,CAACD,IAAI,CAACW,cAAN,EAAsB,EAAtB;AAZR;AAbA;AADD;AA3BF,GAAP;AA0DD","sourcesContent":["import { TonalPalette, hexFromArgb } from '@material/material-color-utilities';\n\nexport function makeColorScheme(opts: {\n primary: TonalPalette;\n secondary: TonalPalette;\n tertiary: TonalPalette;\n error: TonalPalette;\n neutral: TonalPalette;\n neutralVariant: TonalPalette;\n}) {\n function c(palette: TonalPalette, tone: number) {\n return hexFromArgb(palette.tone(tone));\n }\n\n return {\n primary: c(opts.primary, 40),\n secondary: c(opts.secondary, 40),\n tertiary: c(opts.tertiary, 40),\n error: c(opts.error, 40),\n 'primary-container': c(opts.primary, 90),\n 'secondary-container': c(opts.secondary, 90),\n 'tertiary-container': c(opts.tertiary, 90),\n 'error-container': c(opts.error, 90),\n background: c(opts.neutral, 99),\n surface: c(opts.neutral, 99),\n 'surface-variant': c(opts.neutralVariant, 90),\n outline: c(opts.neutralVariant, 50),\n on: {\n primary: c(opts.primary, 100),\n secondary: c(opts.secondary, 100),\n tertiary: c(opts.tertiary, 100),\n error: c(opts.error, 100),\n 'primary-container': c(opts.primary, 10),\n 'secondary-container': c(opts.secondary, 10),\n 'tertiary-container': c(opts.tertiary, 10),\n 'error-container': c(opts.error, 10),\n background: c(opts.neutral, 10),\n surface: c(opts.neutral, 10),\n 'surface-variant': c(opts.neutralVariant, 30),\n outline: c(opts.neutralVariant, 95),\n },\n modes: {\n dark: {\n primary: c(opts.primary, 80),\n secondary: c(opts.secondary, 80),\n tertiary: c(opts.tertiary, 80),\n error: c(opts.error, 80),\n 'primary-container': c(opts.primary, 30),\n 'secondary-container': c(opts.secondary, 30),\n 'tertiary-container': c(opts.tertiary, 30),\n 'error-container': c(opts.error, 30),\n background: c(opts.neutral, 10),\n surface: c(opts.neutral, 10),\n 'surface-variant': c(opts.neutralVariant, 30),\n outline: c(opts.neutralVariant, 60),\n on: {\n primary: c(opts.primary, 20),\n secondary: c(opts.secondary, 20),\n tertiary: c(opts.tertiary, 20),\n error: c(opts.error, 20),\n 'primary-container': c(opts.primary, 90),\n 'secondary-container': c(opts.secondary, 90),\n 'tertiary-container': c(opts.tertiary, 90),\n 'error-container': c(opts.error, 90),\n background: c(opts.neutral, 90),\n surface: c(opts.neutral, 90),\n 'surface-variant': c(opts.neutralVariant, 80),\n outline: c(opts.neutralVariant, 10),\n },\n },\n },\n };\n}\n"],"file":"makeColorScheme.js"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useMemo, useDeferredValue } from 'react';
|
|
2
|
+
import { TonalPalette, argbFromHex } from '@material/material-color-utilities';
|
|
3
|
+
import { useLocalStorageCachedState } from './useLocalStorageCachedState'; // import './styles.css';
|
|
4
|
+
|
|
5
|
+
export function useDeferredColor(key, fallbackValue) {
|
|
6
|
+
const [color, setColor] = useLocalStorageCachedState('theme-builder.' + key, null);
|
|
7
|
+
const deferredColor = useDeferredValue(color);
|
|
8
|
+
const colorTonal = useMemo(() => deferredColor != null && deferredColor.hex ? TonalPalette.fromInt(argbFromHex(deferredColor.hex)) : fallbackValue, [deferredColor == null ? void 0 : deferredColor.hex, fallbackValue]);
|
|
9
|
+
return [color, colorTonal, setColor];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=useDeferredColor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/ThemeExplorer/useDeferredColor.tsx"],"names":["useMemo","useDeferredValue","TonalPalette","argbFromHex","useLocalStorageCachedState","useDeferredColor","key","fallbackValue","color","setColor","deferredColor","colorTonal","hex","fromInt"],"mappings":"AAAA,SAASA,OAAT,EAAkBC,gBAAlB,QAA0C,OAA1C;AACA,SAASC,YAAT,EAAuBC,WAAvB,QAA0C,oCAA1C;AAEA,SAASC,0BAAT,QAA2C,8BAA3C,C,CAEA;;AACA,OAAO,SAASC,gBAAT,CACLC,GADK,EAELC,aAFK,EAGoD;AACzD,QAAM,CAACC,KAAD,EAAQC,QAAR,IAAoBL,0BAA0B,CAClD,mBAAmBE,GAD+B,EAElD,IAFkD,CAApD;AAIA,QAAMI,aAAa,GAAGT,gBAAgB,CAACO,KAAD,CAAtC;AACA,QAAMG,UAAU,GAAGX,OAAO,CACxB,MACEU,aAAa,QAAb,IAAAA,aAAa,CAAEE,GAAf,GACIV,YAAY,CAACW,OAAb,CAAqBV,WAAW,CAACO,aAAa,CAACE,GAAf,CAAhC,CADJ,GAEIL,aAJkB,EAKxB,CAACG,aAAD,oBAACA,aAAa,CAAEE,GAAhB,EAAqBL,aAArB,CALwB,CAA1B;AAOA,SAAO,CAACC,KAAD,EAAQG,UAAR,EAAoBF,QAApB,CAAP;AACD","sourcesContent":["import { useMemo, useDeferredValue } from 'react';\nimport { TonalPalette, argbFromHex } from '@material/material-color-utilities';\nimport { Color } from '@basic-ui/color-picker';\nimport { useLocalStorageCachedState } from './useLocalStorageCachedState';\n\n// import './styles.css';\nexport function useDeferredColor(\n key: string,\n fallbackValue: TonalPalette\n): [Color | null, TonalPalette, (c: Color | null) => void] {\n const [color, setColor] = useLocalStorageCachedState<Color | null>(\n 'theme-builder.' + key,\n null\n );\n const deferredColor = useDeferredValue(color);\n const colorTonal = useMemo(\n () =>\n deferredColor?.hex\n ? TonalPalette.fromInt(argbFromHex(deferredColor.hex))\n : fallbackValue,\n [deferredColor?.hex, fallbackValue]\n );\n return [color, colorTonal, setColor];\n}\n"],"file":"useDeferredColor.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useLocalStorageCachedState<T>(key: string, initialValue: T): [T, (c: T) => void];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
export function useLocalStorageCachedState(key, initialValue) {
|
|
3
|
+
const [state, _setState] = useState(() => JSON.parse(localStorage.getItem(key) || 'null') || initialValue);
|
|
4
|
+
const setState = useCallback(c => {
|
|
5
|
+
_setState(c);
|
|
6
|
+
|
|
7
|
+
localStorage.setItem(key, JSON.stringify(c));
|
|
8
|
+
}, [key]);
|
|
9
|
+
return [state, setState];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=useLocalStorageCachedState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/ThemeExplorer/useLocalStorageCachedState.ts"],"names":["useCallback","useState","useLocalStorageCachedState","key","initialValue","state","_setState","JSON","parse","localStorage","getItem","setState","c","setItem","stringify"],"mappings":"AAAA,SAASA,WAAT,EAAsBC,QAAtB,QAAsC,OAAtC;AAEA,OAAO,SAASC,0BAAT,CACLC,GADK,EAELC,YAFK,EAGgB;AACrB,QAAM,CAACC,KAAD,EAAQC,SAAR,IAAqBL,QAAQ,CACjC,MAAMM,IAAI,CAACC,KAAL,CAAWC,YAAY,CAACC,OAAb,CAAqBP,GAArB,KAA6B,MAAxC,KAAmDC,YADxB,CAAnC;AAGA,QAAMO,QAAQ,GAAGX,WAAW,CACzBY,CAAD,IAAgB;AACdN,IAAAA,SAAS,CAACM,CAAD,CAAT;;AACAH,IAAAA,YAAY,CAACI,OAAb,CAAqBV,GAArB,EAA0BI,IAAI,CAACO,SAAL,CAAeF,CAAf,CAA1B;AACD,GAJyB,EAK1B,CAACT,GAAD,CAL0B,CAA5B;AAOA,SAAO,CAACE,KAAD,EAAQM,QAAR,CAAP;AACD","sourcesContent":["import { useCallback, useState } from 'react';\n\nexport function useLocalStorageCachedState<T>(\n key: string,\n initialValue: T\n): [T, (c: T) => void] {\n const [state, _setState] = useState<T>(\n () => JSON.parse(localStorage.getItem(key) || 'null') || initialValue\n );\n const setState = useCallback(\n (c: T): void => {\n _setState(c);\n localStorage.setItem(key, JSON.stringify(c));\n },\n [key]\n );\n return [state, setState];\n}\n"],"file":"useLocalStorageCachedState.js"}
|
|
@@ -5,4 +5,4 @@ export interface TooltipProps extends BoxProps, Omit<PopperProps, 'color' | 'anc
|
|
|
5
5
|
label: React.ReactNode;
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
}
|
|
8
|
-
export declare const Tooltip: React.ForwardRefExoticComponent<Pick<TooltipProps, "
|
|
8
|
+
export declare const Tooltip: React.ForwardRefExoticComponent<Pick<TooltipProps, "children" | "label" | "p" | "slot" | "style" | "title" | "alignContent" | "alignItems" | "alignSelf" | "backgroundColor" | "backgroundImage" | "backgroundPosition" | "backgroundRepeat" | "backgroundSize" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "bottom" | "boxShadow" | "color" | "display" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "opacity" | "order" | "overflowX" | "overflowY" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "textAlign" | "textShadow" | "top" | "translate" | "verticalAlign" | "width" | "zIndex" | "background" | "border" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderStyle" | "borderTop" | "borderWidth" | "flex" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "overflow" | "padding" | "gridColumnGap" | "gridGap" | "gridRowGap" | "hidden" | "as" | "sx" | "__css" | "variant" | "tx" | "theme" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "size" | "bg" | "borderX" | "borderY" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key" | "disabled" | "innerAs" | "placement" | "strategy" | "modifiers" | "usePortal" | "portalSelector" | "skidding" | "distance" | "offsetFn" | "arrowPadding"> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -21,45 +21,46 @@ export function useAnimation(opts) {
|
|
|
21
21
|
open: openProp
|
|
22
22
|
});
|
|
23
23
|
const handleClose = useCallback(() => {
|
|
24
|
-
setAnimation(animation => _extends({}, animation, {
|
|
24
|
+
setAnimation(animation => animation.state === 'closed' ? animation : _extends({}, animation, {
|
|
25
25
|
state: 'close',
|
|
26
26
|
style: animationStyle.close || animationStyle.closed,
|
|
27
27
|
timing: closeTimeoutInMilliseconds
|
|
28
28
|
}));
|
|
29
|
-
return setTimeout(() => {
|
|
30
|
-
setAnimation({
|
|
31
|
-
state: 'closed',
|
|
32
|
-
style: animationStyle.closed,
|
|
33
|
-
open: false,
|
|
34
|
-
timing: closeTimeoutInMilliseconds
|
|
35
|
-
});
|
|
36
|
-
}, closeTimeoutInMilliseconds);
|
|
37
29
|
}, [animationStyle, closeTimeoutInMilliseconds]);
|
|
38
30
|
const handleOpen = useCallback(() => {
|
|
39
|
-
setAnimation(animation => _extends({}, animation, {
|
|
31
|
+
setAnimation(animation => animation.state === 'open' ? animation : _extends({}, animation, {
|
|
40
32
|
open: true,
|
|
41
33
|
state: 'opening',
|
|
42
34
|
style: animationStyle.opening || animationStyle.closed
|
|
43
35
|
}));
|
|
44
|
-
|
|
36
|
+
}, [animationStyle]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (state === 'opening') {
|
|
45
39
|
setAnimation(animation => _extends({}, animation, {
|
|
46
40
|
state: 'open',
|
|
47
41
|
style: animationStyle.open,
|
|
48
42
|
timing: openTimeoutInMilliseconds
|
|
49
43
|
}));
|
|
50
|
-
}
|
|
51
|
-
}, [animationStyle, openTimeoutInMilliseconds]);
|
|
44
|
+
}
|
|
45
|
+
}, [animationStyle.open, openTimeoutInMilliseconds, state]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (state === 'close') {
|
|
48
|
+
const timeout = setTimeout(() => {
|
|
49
|
+
setAnimation({
|
|
50
|
+
state: 'closed',
|
|
51
|
+
style: animationStyle.closed,
|
|
52
|
+
open: false,
|
|
53
|
+
timing: closeTimeoutInMilliseconds
|
|
54
|
+
});
|
|
55
|
+
}, closeTimeoutInMilliseconds);
|
|
56
|
+
return () => clearTimeout(timeout);
|
|
57
|
+
}
|
|
58
|
+
}, [animationStyle.closed, closeTimeoutInMilliseconds, state]);
|
|
52
59
|
useEffect(() => {
|
|
53
60
|
if (openProp) {
|
|
54
|
-
|
|
55
|
-
return () => {
|
|
56
|
-
cancelAnimationFrame(frameHandler);
|
|
57
|
-
};
|
|
61
|
+
handleOpen();
|
|
58
62
|
} else {
|
|
59
|
-
|
|
60
|
-
return () => {
|
|
61
|
-
clearTimeout(timeoutHandler);
|
|
62
|
-
};
|
|
63
|
+
handleClose();
|
|
63
64
|
}
|
|
64
65
|
}, [handleClose, handleOpen, openProp]);
|
|
65
66
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/useAnimation.ts"],"names":["useState","useEffect","useCallback","useAnimation","opts","styles","mode","open","openProp","openTimeoutInMilliseconds","closeTimeoutInMilliseconds","animationStyle","timing","state","style","setAnimation","closed","handleClose","animation","close","
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useAnimation.ts"],"names":["useState","useEffect","useCallback","useAnimation","opts","styles","mode","open","openProp","openTimeoutInMilliseconds","closeTimeoutInMilliseconds","animationStyle","timing","state","style","setAnimation","closed","handleClose","animation","close","handleOpen","opening","timeout","setTimeout","clearTimeout"],"mappings":";AAAA,SAASA,QAAT,EAAmBC,SAAnB,EAA8BC,WAA9B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Z;AAUD,GAX6B,EAW3B,CAACL,cAAD,CAX2B,CAA9B;AAaAV,EAAAA,SAAS,CAAC,MAAM;AACd,QAAIY,KAAK,KAAK,SAAd,EAAyB;AACvBE,MAAAA,YAAY,CAAEG,SAAD,iBACRA,SADQ;AAEXL,QAAAA,KAAK,EAAE,MAFI;AAGXC,QAAAA,KAAK,EAAEH,cAAc,CAACJ,IAHX;AAIXK,QAAAA,MAAM,EAAEH;AAJG,QAAD,CAAZ;AAMD;AACF,GATQ,EASN,CAACE,cAAc,CAACJ,IAAhB,EAAsBE,yBAAtB,EAAiDI,KAAjD,CATM,CAAT;AAWAZ,EAAAA,SAAS,CAAC,MAAM;AACd,QAAIY,KAAK,KAAK,OAAd,EAAuB;AACrB,YAAMS,OAAO,GAAGC,UAAU,CAAC,MAAM;AAC/BR,QAAAA,YAAY,CAAC;AACXF,UAAAA,KAAK,EAAE,QADI;AAEXC,UAAAA,KAAK,EAAEH,cAAc,CAACK,MAFX;AAGXT,UAAAA,IAAI,EAAE,KAHK;AAIXK,UAAAA,MAAM,EAAEF;AAJG,SAAD,CAAZ;AAMD,OAPyB,EAOvBA,0BAPuB,CAA1B;AAQA,aAAO,MAAMc,YAAY,CAACF,OAAD,CAAzB;AACD;AACF,GAZQ,EAYN,CAACX,cAAc,CAACK,MAAhB,EAAwBN,0BAAxB,EAAoDG,KAApD,CAZM,CAAT;AAcAZ,EAAAA,SAAS,CAAC,MAAM;AACd,QAAIO,QAAJ,EAAc;AACZY,MAAAA,UAAU;AACX,KAFD,MAEO;AACLH,MAAAA,WAAW;AACZ;AACF,GANQ,EAMN,CAACA,WAAD,EAAcG,UAAd,EAA0BZ,QAA1B,CANM,CAAT;AAQA,SAAO;AACLK,IAAAA,KADK;AAELC,IAAAA,KAFK;AAGLF,IAAAA,MAHK;AAILL,IAAAA;AAJK,GAAP;AAMD","sourcesContent":["import { useState, useEffect, useCallback, CSSProperties } from 'react';\n\nexport type AnimationStateStyles<TStyleProps extends CSSProperties> = {\n closed: TStyleProps;\n opening?: TStyleProps;\n open: TStyleProps;\n close?: TStyleProps;\n};\n\nexport type AnimationStyles<TStyleProps extends CSSProperties> = Record<\n string,\n AnimationStateStyles<TStyleProps>\n>;\n\nexport function useAnimation<\n TStyles extends AnimationStyles<TStyleProps>,\n TStyleProps extends CSSProperties\n>(opts: {\n open: boolean;\n styles: TStyles;\n mode: keyof TStyles;\n openTimeoutInMilliseconds?: number;\n closeTimeoutInMilliseconds?: number;\n}) {\n const {\n styles,\n mode,\n open: openProp,\n openTimeoutInMilliseconds = 225,\n closeTimeoutInMilliseconds = 110,\n } = opts;\n const animationStyle = styles[mode];\n const [{ timing, open, state, style }, setAnimation] = useState<{\n state: keyof AnimationStateStyles<TStyleProps>;\n timing: number;\n open: boolean;\n style: CSSProperties;\n }>({\n state: 'closed',\n style: animationStyle.closed,\n timing: closeTimeoutInMilliseconds,\n open: openProp,\n });\n\n const handleClose = useCallback(() => {\n setAnimation((animation) =>\n animation.state === 'closed'\n ? animation\n : {\n ...animation,\n state: 'close',\n style: animationStyle.close || animationStyle.closed,\n timing: closeTimeoutInMilliseconds,\n }\n );\n }, [animationStyle, closeTimeoutInMilliseconds]);\n\n const handleOpen = useCallback(() => {\n setAnimation((animation) =>\n animation.state === 'open'\n ? animation\n : {\n ...animation,\n open: true,\n state: 'opening',\n style: animationStyle.opening || animationStyle.closed,\n }\n );\n }, [animationStyle]);\n\n useEffect(() => {\n if (state === 'opening') {\n setAnimation((animation) => ({\n ...animation,\n state: 'open',\n style: animationStyle.open,\n timing: openTimeoutInMilliseconds,\n }));\n }\n }, [animationStyle.open, openTimeoutInMilliseconds, state]);\n\n useEffect(() => {\n if (state === 'close') {\n const timeout = setTimeout(() => {\n setAnimation({\n state: 'closed',\n style: animationStyle.closed,\n open: false,\n timing: closeTimeoutInMilliseconds,\n });\n }, closeTimeoutInMilliseconds);\n return () => clearTimeout(timeout);\n }\n }, [animationStyle.closed, closeTimeoutInMilliseconds, state]);\n\n useEffect(() => {\n if (openProp) {\n handleOpen();\n } else {\n handleClose();\n }\n }, [handleClose, handleOpen, openProp]);\n\n return {\n state,\n style,\n timing,\n open,\n };\n}\n"],"file":"useAnimation.js"}
|