reshaped 3.6.0-canary.3 → 3.6.0-canary.4
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 +3 -0
- package/dist/bundle.css +1 -1
- package/dist/bundle.d.ts +1 -0
- package/dist/bundle.js +5 -5
- package/dist/components/Avatar/Avatar.module.css +1 -1
- package/dist/components/Reshaped/Reshaped.js +2 -2
- package/dist/components/Reshaped/Reshaped.types.d.ts +1 -0
- package/dist/components/Reshaped/tests/Reshaped.stories.d.ts +1 -0
- package/dist/components/Reshaped/tests/Reshaped.stories.js +20 -0
- package/dist/components/Theme/GlobalColorMode.js +6 -11
- package/dist/components/Theme/Theme.types.d.ts +1 -0
- package/dist/components/Theme/index.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
.root{align-items:center;aspect-ratio:1;display:flex;font-size:calc(var(--rs-h) / 3);font-weight:
|
1
|
+
.root{align-items:center;aspect-ratio:1;display:flex;font-size:calc(var(--rs-h) / 3);font-weight:var(--rs-font-weight-bold);justify-content:center;line-height:100%}.img{border-radius:inherit;height:100%;object-fit:cover;width:100%}.--variant-faded.--color-neutral{color:var(--rs-color-foreground-neutral)}.--variant-faded.--color-critical{color:var(--rs-color-foreground-critical)}.--variant-faded.--color-positive{color:var(--rs-color-foreground-positive)}.--variant-faded.--color-warning{color:var(--rs-color-foreground-warning)}.--variant-faded.--color-primary{color:var(--rs-color-foreground-primary)}
|
@@ -16,11 +16,11 @@ const ReshapedInner = (props) => {
|
|
16
16
|
return (_jsx(SingletonKeyboardModeProvider, { children: _jsx(SingletonEnvironmentContext.Provider, { value: { rtl: rtlState, defaultViewport }, children: _jsx(SingletonHotkeysProvider, { children: _jsx(ToastProvider, { options: toastOptions, children: children }) }) }) }));
|
17
17
|
};
|
18
18
|
const Reshaped = (props) => {
|
19
|
-
const { theme, defaultTheme = "reshaped", defaultColorMode, scoped, className } = props;
|
19
|
+
const { theme, defaultTheme = "reshaped", colorMode, defaultColorMode, scoped, className, } = props;
|
20
20
|
const rootClassNames = classNames(s.root, className);
|
21
21
|
const scopeRef = React.useRef(null);
|
22
22
|
const parentGlobalColorMode = useGlobalColorMode();
|
23
|
-
return (_jsx(GlobalColorMode, { defaultMode: defaultColorMode || parentGlobalColorMode.mode || "light", scopeRef: !!parentGlobalColorMode && scoped ? scopeRef : undefined, children: _jsx(PrivateTheme, { name: theme, defaultName: defaultTheme, className: rootClassNames, scoped: scoped, scopeRef: !!parentGlobalColorMode && scoped ? scopeRef : undefined, children: _jsx(ReshapedInner, { ...props, children: props.children }) }) }));
|
23
|
+
return (_jsx(GlobalColorMode, { defaultMode: defaultColorMode || parentGlobalColorMode.mode || "light", mode: colorMode, scopeRef: !!parentGlobalColorMode && scoped ? scopeRef : undefined, children: _jsx(PrivateTheme, { name: theme, defaultName: defaultTheme, className: rootClassNames, scoped: scoped, scopeRef: !!parentGlobalColorMode && scoped ? scopeRef : undefined, children: _jsx(ReshapedInner, { ...props, children: props.children }) }) }));
|
24
24
|
};
|
25
25
|
Reshaped.displayName = "Reshaped";
|
26
26
|
export default Reshaped;
|
@@ -7,6 +7,7 @@ export type Props = {
|
|
7
7
|
theme?: NonNullable<ThemeProps["name"]>;
|
8
8
|
defaultTheme?: NonNullable<ThemeProps["defaultName"]>;
|
9
9
|
defaultRTL?: boolean;
|
10
|
+
colorMode?: GlobalColorModeProps["mode"];
|
10
11
|
defaultColorMode?: GlobalColorModeProps["defaultMode"];
|
11
12
|
defaultViewport?: G.Viewport;
|
12
13
|
toastOptions?: ToastProviderProps["options"];
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { useState } from "react";
|
1
2
|
import { expect, userEvent } from "storybook/test";
|
2
3
|
import { useTheme } from "../../Theme/index.js";
|
3
4
|
import Button from "../../Button/index.js";
|
@@ -14,6 +15,25 @@ export const rtl = {
|
|
14
15
|
Hello
|
15
16
|
</Reshaped>),
|
16
17
|
};
|
18
|
+
export const controlledMode = {
|
19
|
+
name: "colorMode, controlled",
|
20
|
+
render: () => {
|
21
|
+
const [mode, setMode] = useState("dark");
|
22
|
+
return (<Reshaped theme="reshaped" colorMode={mode}>
|
23
|
+
<Button onClick={() => {
|
24
|
+
setMode(mode === "dark" ? "light" : "dark");
|
25
|
+
}}>
|
26
|
+
Toggle color mode
|
27
|
+
</Button>
|
28
|
+
</Reshaped>);
|
29
|
+
},
|
30
|
+
play: async ({ canvas }) => {
|
31
|
+
const button = canvas.getAllByRole("button")[0];
|
32
|
+
expect(document.documentElement.getAttribute("data-rs-color-mode")).toEqual("dark");
|
33
|
+
await userEvent.click(button);
|
34
|
+
expect(document.documentElement.getAttribute("data-rs-color-mode")).toEqual("light");
|
35
|
+
},
|
36
|
+
};
|
17
37
|
export const lightMode = {
|
18
38
|
name: "defaultColorMode=light",
|
19
39
|
render: () => <Reshaped theme="reshaped">Hello</Reshaped>,
|
@@ -7,7 +7,7 @@ import { useGlobalColorMode } from "./useTheme.js";
|
|
7
7
|
import { GlobalColorModeContext } from "./Theme.context.js";
|
8
8
|
import { getRootThemeEl } from "./Theme.utilities.js";
|
9
9
|
const GlobalColorMode = (props) => {
|
10
|
-
const { defaultMode, scopeRef, children } = props;
|
10
|
+
const { defaultMode, mode: passedMode, scopeRef, children } = props;
|
11
11
|
const [mode, setMode] = React.useState(defaultMode);
|
12
12
|
const parentGlobalColorMode = useGlobalColorMode();
|
13
13
|
const changeColorMode = React.useCallback((targetMode) => {
|
@@ -15,19 +15,14 @@ const GlobalColorMode = (props) => {
|
|
15
15
|
if (parentGlobalColorMode.mode && !scopeRef) {
|
16
16
|
parentGlobalColorMode.setMode(targetMode);
|
17
17
|
}
|
18
|
-
setMode(
|
19
|
-
if (prevMode !== targetMode) {
|
20
|
-
// Avoid components styles animating when switching to another color mode
|
21
|
-
disableTransitions();
|
22
|
-
}
|
23
|
-
return targetMode;
|
24
|
-
});
|
18
|
+
setMode(targetMode);
|
25
19
|
}, [scopeRef, parentGlobalColorMode]);
|
26
20
|
useIsomorphicLayoutEffect(() => {
|
21
|
+
disableTransitions();
|
27
22
|
onNextFrame(() => {
|
28
23
|
enableTransitions();
|
29
24
|
});
|
30
|
-
}, [mode]);
|
25
|
+
}, [mode, passedMode]);
|
31
26
|
/**
|
32
27
|
* In case color mode was set in html but was not provided to the provider - hydrate the state
|
33
28
|
* This could happen if we're receiving the mode on the client but before React hydration
|
@@ -38,12 +33,12 @@ const GlobalColorMode = (props) => {
|
|
38
33
|
changeColorMode(nextColorMode);
|
39
34
|
}, [changeColorMode, scopeRef]);
|
40
35
|
const value = React.useMemo(() => ({
|
41
|
-
mode,
|
36
|
+
mode: passedMode || mode,
|
42
37
|
setMode: changeColorMode,
|
43
38
|
invertMode: () => {
|
44
39
|
changeColorMode(mode === "light" ? "dark" : "light");
|
45
40
|
},
|
46
|
-
}), [mode, changeColorMode]);
|
41
|
+
}), [mode, passedMode, changeColorMode]);
|
47
42
|
return (_jsx(GlobalColorModeContext.Provider, { value: value, children: children }));
|
48
43
|
};
|
49
44
|
GlobalColorMode.displayName = "GlobalColorMode";
|
@@ -25,6 +25,7 @@ export type PrivateProps = Props & {
|
|
25
25
|
scopeRef?: React.RefObject<HTMLDivElement | null>;
|
26
26
|
};
|
27
27
|
export type GlobalColorModeProps = {
|
28
|
+
mode?: ColorMode;
|
28
29
|
defaultMode: ColorMode;
|
29
30
|
scopeRef?: React.RefObject<HTMLDivElement | null>;
|
30
31
|
children?: React.ReactNode;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
export { default, PrivateTheme } from "./Theme";
|
2
2
|
export { default as GlobalColorMode } from "./GlobalColorMode";
|
3
3
|
export { useTheme } from "./useTheme";
|
4
|
-
export type { Props as ThemeProps, GlobalColorModeProps } from "./Theme.types";
|
4
|
+
export type { Props as ThemeProps, GlobalColorModeProps, ColorMode } from "./Theme.types";
|
package/dist/index.d.ts
CHANGED
@@ -127,6 +127,7 @@ export type { ViewProps, ViewItemProps } from "./components/View";
|
|
127
127
|
*/
|
128
128
|
export { useFormControl } from "./components/FormControl";
|
129
129
|
export { default as Theme, useTheme, type ThemeProps } from "./components/Theme";
|
130
|
+
export type { ColorMode } from "./components/Theme";
|
130
131
|
export { default as useHandlerRef } from "./hooks/useHandlerRef";
|
131
132
|
export { default as useHotkeys } from "./hooks/useHotkeys";
|
132
133
|
export { default as useIsomorphicLayoutEffect } from "./hooks/useIsomorphicLayoutEffect";
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "reshaped",
|
3
3
|
"description": "Professionally crafted design system in React & Figma for building products of any scale and complexity",
|
4
|
-
"version": "3.6.0-canary.
|
4
|
+
"version": "3.6.0-canary.4",
|
5
5
|
"license": "MIT",
|
6
6
|
"email": "hello@reshaped.so",
|
7
7
|
"homepage": "https://reshaped.so",
|