@scalewing/react 0.2.0 → 0.4.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/CHANGELOG.md +48 -0
- package/README.md +13 -2
- package/dist/components/Accordion.d.ts +8 -0
- package/dist/components/Accordion.js +14 -0
- package/dist/components/AppHeader.d.ts +5 -0
- package/dist/components/AppHeader.js +7 -0
- package/dist/components/Badge.d.ts +13 -0
- package/dist/components/Badge.js +7 -0
- package/dist/components/BarChart.d.ts +16 -0
- package/dist/components/BarChart.js +13 -0
- package/dist/components/Box.d.ts +1 -1
- package/dist/components/Button.d.ts +1 -1
- package/dist/components/Dialog.d.ts +8 -0
- package/dist/components/Dialog.js +36 -0
- package/dist/components/Field.d.ts +4 -1
- package/dist/components/Field.js +2 -2
- package/dist/components/Nav.d.ts +3 -0
- package/dist/components/Nav.js +7 -0
- package/dist/components/SegmentedControl.d.ts +19 -0
- package/dist/components/SegmentedControl.js +28 -0
- package/dist/components/Select.d.ts +17 -0
- package/dist/components/Select.js +107 -0
- package/dist/components/Split.d.ts +8 -0
- package/dist/components/Split.js +117 -0
- package/dist/components/Table.d.ts +32 -0
- package/dist/components/Table.js +24 -0
- package/dist/components/Text.d.ts +3 -3
- package/dist/components/Text.js +2 -1
- package/dist/components/Toast.d.ts +10 -0
- package/dist/components/Toast.js +61 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +11 -0
- package/dist/palette/amber.css +21 -0
- package/dist/palette/capri.css +21 -0
- package/dist/palette/cerulean.css +21 -0
- package/dist/palette/cornflower.css +21 -0
- package/dist/palette/fuchsia.css +21 -0
- package/dist/palette/harvest.css +31 -0
- package/dist/palette/ink.css +21 -0
- package/dist/palette/mocha.css +31 -0
- package/dist/palette/navy.css +21 -0
- package/dist/palette/postcard.css +31 -0
- package/dist/palette/raspberry.css +21 -0
- package/dist/palette/sky.css +21 -0
- package/dist/palette/soft-blue.css +21 -0
- package/dist/palette/sunburst.css +31 -0
- package/dist/palette/synthwave.css +26 -0
- package/dist/palette/tangerine.css +21 -0
- package/dist/select-list.d.ts +7 -0
- package/dist/select-list.js +24 -0
- package/dist/split-size.d.ts +18 -0
- package/dist/split-size.js +94 -0
- package/dist/styles.css +1084 -12
- package/dist/theme/ThemeProvider.d.ts +4 -3
- package/dist/theme/ThemeProvider.js +8 -3
- package/dist/toast-travel.d.ts +16 -0
- package/dist/toast-travel.js +42 -0
- package/package.json +10 -6
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
|
-
import { type ColorScheme, type
|
|
2
|
+
import { type ColorScheme, type PaletteId, type Theme, type ThemeColors } from '@scalewing/tokens';
|
|
3
3
|
export type ThemeProviderProps = {
|
|
4
4
|
colorScheme?: ColorScheme | 'system';
|
|
5
|
-
|
|
5
|
+
palette?: PaletteId;
|
|
6
|
+
colors?: ThemeColors;
|
|
6
7
|
children: ReactNode;
|
|
7
8
|
};
|
|
8
|
-
export declare function ThemeProvider({ colorScheme, colors, children, }: ThemeProviderProps): import("react").JSX.Element;
|
|
9
|
+
export declare function ThemeProvider({ colorScheme, palette, colors, children, }: ThemeProviderProps): import("react").JSX.Element;
|
|
9
10
|
export declare function useTheme(): Theme;
|
|
@@ -16,9 +16,14 @@ function themeCssVars(theme) {
|
|
|
16
16
|
for (const key of semanticColorKeys) {
|
|
17
17
|
vars[`--sw-color-${key}`] = theme.colors[key];
|
|
18
18
|
}
|
|
19
|
+
vars['--sw-glass-blur'] = `${theme.glass.blur}px`;
|
|
20
|
+
vars['--sw-glass-saturate'] = String(theme.glass.saturate);
|
|
21
|
+
vars['--sw-glass-fill'] = theme.glass.fill;
|
|
22
|
+
vars['--sw-glass-border'] = theme.glass.border;
|
|
23
|
+
vars['--sw-glass-specular'] = theme.glass.specular;
|
|
19
24
|
return vars;
|
|
20
25
|
}
|
|
21
|
-
export function ThemeProvider({ colorScheme = 'system', colors, children, }) {
|
|
26
|
+
export function ThemeProvider({ colorScheme = 'system', palette, colors, children, }) {
|
|
22
27
|
const [systemScheme, setSystemScheme] = useState(schemeFromMedia);
|
|
23
28
|
useEffect(() => {
|
|
24
29
|
if (colorScheme !== 'system' || typeof window.matchMedia !== 'function') {
|
|
@@ -33,8 +38,8 @@ export function ThemeProvider({ colorScheme = 'system', colors, children, }) {
|
|
|
33
38
|
return () => media.removeEventListener('change', onChange);
|
|
34
39
|
}, [colorScheme]);
|
|
35
40
|
const resolvedScheme = colorScheme === 'system' ? systemScheme : colorScheme;
|
|
36
|
-
const theme = useMemo(() => createTheme({ colorScheme: resolvedScheme, colors }), [colors, resolvedScheme]);
|
|
37
|
-
return (_jsx(ThemeContext.Provider, { value: theme, children: _jsx("div", { "data-theme": theme.colorScheme, style: themeCssVars(theme), children: children }) }));
|
|
41
|
+
const theme = useMemo(() => createTheme({ colorScheme: resolvedScheme, palette, colors }), [colors, palette, resolvedScheme]);
|
|
42
|
+
return (_jsx(ThemeContext.Provider, { value: theme, children: _jsx("div", { "data-palette": palette, "data-theme": theme.colorScheme, style: themeCssVars(theme), children: children }) }));
|
|
38
43
|
}
|
|
39
44
|
export function useTheme() {
|
|
40
45
|
const theme = useContext(ThemeContext);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type TravelBox = {
|
|
2
|
+
height: number;
|
|
3
|
+
left: number;
|
|
4
|
+
top: number;
|
|
5
|
+
width: number;
|
|
6
|
+
};
|
|
7
|
+
export type TravelTranslate = {
|
|
8
|
+
fromX: number;
|
|
9
|
+
fromY: number;
|
|
10
|
+
toX: number;
|
|
11
|
+
toY: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function travelTranslate(origin: TravelBox, destination: TravelBox, toast: TravelBox): TravelTranslate;
|
|
14
|
+
export declare function applyTravelVars(node: HTMLElement, travel: TravelTranslate): void;
|
|
15
|
+
export declare function clearTravelVars(node: HTMLElement): void;
|
|
16
|
+
export declare function cssDurationMs(value: string): number;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function centerOffset(box, toast) {
|
|
2
|
+
return {
|
|
3
|
+
x: box.left + box.width / 2 - toast.width / 2,
|
|
4
|
+
y: box.top + box.height / 2 - toast.height / 2,
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export function travelTranslate(origin, destination, toast) {
|
|
8
|
+
const from = centerOffset(origin, toast);
|
|
9
|
+
const to = centerOffset(destination, toast);
|
|
10
|
+
return {
|
|
11
|
+
fromX: from.x,
|
|
12
|
+
fromY: from.y,
|
|
13
|
+
toX: to.x,
|
|
14
|
+
toY: to.y,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function applyTravelVars(node, travel) {
|
|
18
|
+
node.style.setProperty('--sw-toast-from-x', `${travel.fromX}px`);
|
|
19
|
+
node.style.setProperty('--sw-toast-from-y', `${travel.fromY}px`);
|
|
20
|
+
node.style.setProperty('--sw-toast-to-x', `${travel.toX}px`);
|
|
21
|
+
node.style.setProperty('--sw-toast-to-y', `${travel.toY}px`);
|
|
22
|
+
}
|
|
23
|
+
export function clearTravelVars(node) {
|
|
24
|
+
node.style.removeProperty('--sw-toast-from-x');
|
|
25
|
+
node.style.removeProperty('--sw-toast-from-y');
|
|
26
|
+
node.style.removeProperty('--sw-toast-to-x');
|
|
27
|
+
node.style.removeProperty('--sw-toast-to-y');
|
|
28
|
+
}
|
|
29
|
+
export function cssDurationMs(value) {
|
|
30
|
+
const first = value.split(',')[0]?.trim() ?? '';
|
|
31
|
+
if (!first) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
const amount = Number.parseFloat(first);
|
|
35
|
+
if (!Number.isFinite(amount) || amount <= 0) {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
if (first.endsWith('ms')) {
|
|
39
|
+
return amount;
|
|
40
|
+
}
|
|
41
|
+
return amount * 1000;
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalewing/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Scalewing DOM components and package-owned CSS utilities.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://
|
|
9
|
+
"url": "git+https://github.com/nestor-garcia-dev/scalewing.git",
|
|
10
10
|
"directory": "packages/react"
|
|
11
11
|
},
|
|
12
|
-
"homepage": "https://
|
|
12
|
+
"homepage": "https://github.com/nestor-garcia-dev/scalewing#readme",
|
|
13
13
|
"bugs": {
|
|
14
|
-
"url": "https://
|
|
14
|
+
"url": "https://github.com/nestor-garcia-dev/scalewing/issues"
|
|
15
15
|
},
|
|
16
16
|
"sideEffects": [
|
|
17
17
|
"*.css"
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
"./styles.css": {
|
|
25
25
|
"types": "./styles.css.d.ts",
|
|
26
26
|
"default": "./dist/styles.css"
|
|
27
|
+
},
|
|
28
|
+
"./palette/*.css": {
|
|
29
|
+
"types": "./styles.css.d.ts",
|
|
30
|
+
"default": "./dist/palette/*.css"
|
|
27
31
|
}
|
|
28
32
|
},
|
|
29
33
|
"files": [
|
|
@@ -34,7 +38,7 @@
|
|
|
34
38
|
"README.md"
|
|
35
39
|
],
|
|
36
40
|
"dependencies": {
|
|
37
|
-
"@scalewing/tokens": "0.
|
|
41
|
+
"@scalewing/tokens": "0.4.0"
|
|
38
42
|
},
|
|
39
43
|
"peerDependencies": {
|
|
40
44
|
"react": "^19.0.0",
|
|
@@ -52,7 +56,7 @@
|
|
|
52
56
|
"access": "public"
|
|
53
57
|
},
|
|
54
58
|
"scripts": {
|
|
55
|
-
"build": "rm -rf dist && tsc -p tsconfig.json && cp ../tokens/dist/styles.css dist/styles.css",
|
|
59
|
+
"build": "rm -rf dist && tsc -p tsconfig.json && cp ../tokens/dist/styles.css dist/styles.css && rm -rf dist/palette && mkdir -p dist/palette && cp ../tokens/dist/palette/*.css dist/palette/",
|
|
56
60
|
"test": "vitest run",
|
|
57
61
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
58
62
|
},
|