@redis-ui/components 51.2.0 → 51.3.1
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/dist/ThemeModeSwitch/ThemeModeSwitch.cjs +12 -14
- package/dist/ThemeModeSwitch/ThemeModeSwitch.d.ts +1 -1
- package/dist/ThemeModeSwitch/ThemeModeSwitch.js +12 -14
- package/dist/ThemeModeSwitch/ThemeModeSwitch.types.d.ts +5 -1
- package/dist/ThemeModeSwitch/ThemeModeSwitch.utils.cjs +9 -0
- package/dist/ThemeModeSwitch/ThemeModeSwitch.utils.d.ts +4 -0
- package/dist/ThemeModeSwitch/ThemeModeSwitch.utils.js +8 -0
- package/dist/ThemeModeSwitch/components/ModeSwitch/ModeSwitch.cjs +25 -0
- package/dist/ThemeModeSwitch/components/ModeSwitch/ModeSwitch.d.ts +11 -0
- package/dist/ThemeModeSwitch/components/ModeSwitch/ModeSwitch.js +23 -0
- package/dist/ThemeModeSwitch/components/ModeSwitch/ModeSwitch.types.d.ts +9 -0
- package/dist/ThemeModeSwitch/components/ModeSwitch/ModeSwitch.types.js +1 -0
- package/dist/ThemeModeSwitch/components/SwapButton/SwapButton.cjs +30 -0
- package/dist/ThemeModeSwitch/components/SwapButton/SwapButton.d.ts +5 -0
- package/dist/ThemeModeSwitch/components/SwapButton/SwapButton.js +27 -0
- package/dist/ThemeModeSwitch/components/SwapButton/SwapButton.style.cjs +37 -0
- package/dist/ThemeModeSwitch/components/SwapButton/SwapButton.style.d.ts +4 -0
- package/dist/ThemeModeSwitch/components/SwapButton/SwapButton.style.js +34 -0
- package/dist/ThemeModeSwitch/components/SwapButton/SwapButton.types.d.ts +5 -0
- package/dist/ThemeModeSwitch/components/SwapButton/SwapButton.types.js +1 -0
- package/dist/ThemeModeSwitch/components/SwitchButton/SwitchButton.cjs +23 -0
- package/dist/ThemeModeSwitch/components/SwitchButton/SwitchButton.d.ts +6 -0
- package/dist/ThemeModeSwitch/components/SwitchButton/SwitchButton.js +21 -0
- package/dist/ThemeModeSwitch/{ThemeModeSwitch.style.cjs → components/SwitchButton/SwitchButton.style.cjs} +8 -8
- package/dist/ThemeModeSwitch/{ThemeModeSwitch.style.d.ts → components/SwitchButton/SwitchButton.style.d.ts} +1 -1
- package/dist/ThemeModeSwitch/{ThemeModeSwitch.style.js → components/SwitchButton/SwitchButton.style.js} +7 -7
- package/dist/ThemeModeSwitch/components/SwitchButton/SwitchButton.types.d.ts +6 -0
- package/dist/ThemeModeSwitch/components/SwitchButton/SwitchButton.types.js +1 -0
- package/dist/ThemeModeSwitch/useThemeModeSwitch.cjs +1 -0
- package/dist/ThemeModeSwitch/useThemeModeSwitch.d.ts +1 -0
- package/dist/ThemeModeSwitch/useThemeModeSwitch.js +1 -0
- package/package.json +2 -2
- package/skills/redis-ui-components/references/ThemeModeSwitch.md +16 -3
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
const require_Menu = require("../Menu/Menu.cjs");
|
|
2
|
-
const
|
|
2
|
+
const require_ThemeModeSwitch_utils = require("./ThemeModeSwitch.utils.cjs");
|
|
3
|
+
const require_ModeSwitch = require("./components/ModeSwitch/ModeSwitch.cjs");
|
|
3
4
|
const require_useThemeModeSwitch = require("./useThemeModeSwitch.cjs");
|
|
4
5
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
-
let react = require("react");
|
|
6
6
|
//#region src/ThemeModeSwitch/ThemeModeSwitch.tsx
|
|
7
|
-
var ThemeModeSwitch = ({ onThemeModeChange, switchTimeoutMs =
|
|
8
|
-
const { allowSystemThemeMode, themeMode, setThemeMode, toggleThemeMode } = require_useThemeModeSwitch.useThemeModeSwitch({
|
|
7
|
+
var ThemeModeSwitch = ({ onThemeModeChange, variant = "switch", switchTimeoutMs = require_ThemeModeSwitch_utils.switchTimeoutMsByVariant[variant], ...restProps }) => {
|
|
8
|
+
const { allowSystemThemeMode, themeMode, getNextThemeModeToToggle, setThemeMode, toggleThemeMode } = require_useThemeModeSwitch.useThemeModeSwitch({
|
|
9
9
|
onThemeModeChange,
|
|
10
10
|
switchTimeoutMs
|
|
11
11
|
});
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const modeSwitch = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ModeSwitch.default, {
|
|
13
|
+
variant,
|
|
14
|
+
themeMode,
|
|
15
|
+
allowSystemThemeMode,
|
|
16
|
+
getNextThemeModeToToggle,
|
|
17
|
+
switchTimeoutMs,
|
|
17
18
|
...restProps,
|
|
18
19
|
onClick: toggleThemeMode,
|
|
19
|
-
"data-mounting": !ready ? "" : void 0,
|
|
20
|
-
$durationMs: switchTimeoutMs,
|
|
21
20
|
onPointerDown: allowSystemThemeMode ? (e) => {
|
|
22
|
-
e.currentTarget.focus();
|
|
21
|
+
e.currentTarget.focus({ focusVisible: false });
|
|
23
22
|
e.preventDefault();
|
|
24
|
-
} : void 0
|
|
25
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ThemeModeSwitch_style.Knob, { "data-theme-mode": themeMode })
|
|
23
|
+
} : void 0
|
|
26
24
|
});
|
|
27
25
|
if (allowSystemThemeMode) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Menu.default, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Menu.default.Trigger, { children: modeSwitch }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_Menu.default.Content, {
|
|
28
26
|
placement: "bottom",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ThemeModeSwitchProps } from './ThemeModeSwitch.types';
|
|
2
|
-
export declare const ThemeModeSwitch: ({ onThemeModeChange, switchTimeoutMs, ...restProps }: ThemeModeSwitchProps) => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare const ThemeModeSwitch: ({ onThemeModeChange, variant, switchTimeoutMs, ...restProps }: ThemeModeSwitchProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
import Menu from "../Menu/Menu.js";
|
|
2
|
-
import {
|
|
2
|
+
import { switchTimeoutMsByVariant } from "./ThemeModeSwitch.utils.js";
|
|
3
|
+
import ModeSwitch from "./components/ModeSwitch/ModeSwitch.js";
|
|
3
4
|
import { useThemeModeSwitch } from "./useThemeModeSwitch.js";
|
|
4
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
import { useEffect, useState } from "react";
|
|
6
6
|
//#region src/ThemeModeSwitch/ThemeModeSwitch.tsx
|
|
7
|
-
var ThemeModeSwitch = ({ onThemeModeChange, switchTimeoutMs =
|
|
8
|
-
const { allowSystemThemeMode, themeMode, setThemeMode, toggleThemeMode } = useThemeModeSwitch({
|
|
7
|
+
var ThemeModeSwitch = ({ onThemeModeChange, variant = "switch", switchTimeoutMs = switchTimeoutMsByVariant[variant], ...restProps }) => {
|
|
8
|
+
const { allowSystemThemeMode, themeMode, getNextThemeModeToToggle, setThemeMode, toggleThemeMode } = useThemeModeSwitch({
|
|
9
9
|
onThemeModeChange,
|
|
10
10
|
switchTimeoutMs
|
|
11
11
|
});
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const modeSwitch = /* @__PURE__ */ jsx(ModeSwitch, {
|
|
13
|
+
variant,
|
|
14
|
+
themeMode,
|
|
15
|
+
allowSystemThemeMode,
|
|
16
|
+
getNextThemeModeToToggle,
|
|
17
|
+
switchTimeoutMs,
|
|
17
18
|
...restProps,
|
|
18
19
|
onClick: toggleThemeMode,
|
|
19
|
-
"data-mounting": !ready ? "" : void 0,
|
|
20
|
-
$durationMs: switchTimeoutMs,
|
|
21
20
|
onPointerDown: allowSystemThemeMode ? (e) => {
|
|
22
|
-
e.currentTarget.focus();
|
|
21
|
+
e.currentTarget.focus({ focusVisible: false });
|
|
23
22
|
e.preventDefault();
|
|
24
|
-
} : void 0
|
|
25
|
-
children: /* @__PURE__ */ jsx(Knob, { "data-theme-mode": themeMode })
|
|
23
|
+
} : void 0
|
|
26
24
|
});
|
|
27
25
|
if (allowSystemThemeMode) return /* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(Menu.Trigger, { children: modeSwitch }), /* @__PURE__ */ jsxs(Menu.Content, {
|
|
28
26
|
placement: "bottom",
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { UserThemeMode } from '@redis-ui/styles';
|
|
2
2
|
import { HTMLAttributes } from 'react';
|
|
3
|
+
export type ThemeModeSwitchVariants = 'switch' | 'swap';
|
|
3
4
|
export type UseThemeModeSwitchParams = {
|
|
4
5
|
onThemeModeChange?: (newThemeMode: UserThemeMode) => void;
|
|
5
6
|
switchTimeoutMs?: number;
|
|
6
7
|
};
|
|
7
|
-
export type ThemeModeSwitchProps = Omit<HTMLAttributes<HTMLElement>, 'onClick' | 'onChange'> & UseThemeModeSwitchParams
|
|
8
|
+
export type ThemeModeSwitchProps = Omit<HTMLAttributes<HTMLElement>, 'onClick' | 'onChange'> & UseThemeModeSwitchParams & {
|
|
9
|
+
/** `swap` is a single icon button showing the mode it switches to */
|
|
10
|
+
variant?: ThemeModeSwitchVariants;
|
|
11
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/ThemeModeSwitch/ThemeModeSwitch.utils.ts
|
|
2
|
+
var switchTimeoutMsByVariant = {
|
|
3
|
+
switch: 300,
|
|
4
|
+
swap: 0
|
|
5
|
+
};
|
|
6
|
+
var getCurrentModeLabel = (themeMode) => `Theme mode switch. Current theme mode is ${themeMode || "unknown"}`;
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.getCurrentModeLabel = getCurrentModeLabel;
|
|
9
|
+
exports.switchTimeoutMsByVariant = switchTimeoutMsByVariant;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { UserThemeMode } from '@redis-ui/styles';
|
|
2
|
+
import { ThemeModeSwitchVariants } from './ThemeModeSwitch.types';
|
|
3
|
+
export declare const switchTimeoutMsByVariant: Record<ThemeModeSwitchVariants, number>;
|
|
4
|
+
export declare const getCurrentModeLabel: (themeMode: UserThemeMode | undefined) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/ThemeModeSwitch/ThemeModeSwitch.utils.ts
|
|
2
|
+
var switchTimeoutMsByVariant = {
|
|
3
|
+
switch: 300,
|
|
4
|
+
swap: 0
|
|
5
|
+
};
|
|
6
|
+
var getCurrentModeLabel = (themeMode) => `Theme mode switch. Current theme mode is ${themeMode || "unknown"}`;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getCurrentModeLabel, switchTimeoutMsByVariant };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_SwapButton = require("../SwapButton/SwapButton.cjs");
|
|
3
|
+
const require_SwitchButton = require("../SwitchButton/SwitchButton.cjs");
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
let react = require("react");
|
|
6
|
+
react = require_runtime.__toESM(react, 1);
|
|
7
|
+
//#region src/ThemeModeSwitch/components/ModeSwitch/ModeSwitch.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Picks the control for the requested variant. Adding a variant means adding a branch here.
|
|
10
|
+
* Forwards the ref so `Menu.Trigger` can reach the underlying button.
|
|
11
|
+
*/
|
|
12
|
+
var ModeSwitch = react.default.forwardRef(({ variant, themeMode, allowSystemThemeMode, getNextThemeModeToToggle, switchTimeoutMs, ...restProps }, ref) => variant === "swap" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_SwapButton.default, {
|
|
13
|
+
ref,
|
|
14
|
+
themeMode,
|
|
15
|
+
allowSystemThemeMode,
|
|
16
|
+
getNextThemeModeToToggle,
|
|
17
|
+
...restProps
|
|
18
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_SwitchButton.default, {
|
|
19
|
+
ref,
|
|
20
|
+
themeMode,
|
|
21
|
+
switchTimeoutMs,
|
|
22
|
+
...restProps
|
|
23
|
+
}));
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.default = ModeSwitch;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Picks the control for the requested variant. Adding a variant means adding a branch here.
|
|
4
|
+
* Forwards the ref so `Menu.Trigger` can reach the underlying button.
|
|
5
|
+
*/
|
|
6
|
+
declare const ModeSwitch: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLElement>, "onChange"> & Pick<import("@redis-ui/styles").ThemeModeSwitchingContextParams, "getNextThemeModeToToggle" | "allowSystemThemeMode"> & {
|
|
7
|
+
variant: import("../..").ThemeModeSwitchVariants;
|
|
8
|
+
themeMode: import("@redis-ui/styles").UserThemeMode | undefined;
|
|
9
|
+
switchTimeoutMs: number;
|
|
10
|
+
} & React.RefAttributes<HTMLButtonElement>>;
|
|
11
|
+
export default ModeSwitch;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import SwapButton from "../SwapButton/SwapButton.js";
|
|
2
|
+
import SwitchButton from "../SwitchButton/SwitchButton.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import React from "react";
|
|
5
|
+
//#region src/ThemeModeSwitch/components/ModeSwitch/ModeSwitch.tsx
|
|
6
|
+
/**
|
|
7
|
+
* Picks the control for the requested variant. Adding a variant means adding a branch here.
|
|
8
|
+
* Forwards the ref so `Menu.Trigger` can reach the underlying button.
|
|
9
|
+
*/
|
|
10
|
+
var ModeSwitch = React.forwardRef(({ variant, themeMode, allowSystemThemeMode, getNextThemeModeToToggle, switchTimeoutMs, ...restProps }, ref) => variant === "swap" ? /* @__PURE__ */ jsx(SwapButton, {
|
|
11
|
+
ref,
|
|
12
|
+
themeMode,
|
|
13
|
+
allowSystemThemeMode,
|
|
14
|
+
getNextThemeModeToToggle,
|
|
15
|
+
...restProps
|
|
16
|
+
}) : /* @__PURE__ */ jsx(SwitchButton, {
|
|
17
|
+
ref,
|
|
18
|
+
themeMode,
|
|
19
|
+
switchTimeoutMs,
|
|
20
|
+
...restProps
|
|
21
|
+
}));
|
|
22
|
+
//#endregion
|
|
23
|
+
export { ModeSwitch as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ThemeModeSwitchingContextParams, UserThemeMode } from '@redis-ui/styles';
|
|
2
|
+
import { HTMLAttributes } from 'react';
|
|
3
|
+
import { ThemeModeSwitchVariants } from '../../ThemeModeSwitch.types';
|
|
4
|
+
/** Everything the variants share; each one takes the subset it needs. */
|
|
5
|
+
export type ModeSwitchProps = Omit<HTMLAttributes<HTMLElement>, 'onChange'> & Pick<ThemeModeSwitchingContextParams, 'getNextThemeModeToToggle' | 'allowSystemThemeMode'> & {
|
|
6
|
+
variant: ThemeModeSwitchVariants;
|
|
7
|
+
themeMode: UserThemeMode | undefined;
|
|
8
|
+
switchTimeoutMs: number;
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_ThemeModeSwitch_utils = require("../../ThemeModeSwitch.utils.cjs");
|
|
3
|
+
const require_SwapButton_style = require("./SwapButton.style.cjs");
|
|
4
|
+
let _redislabsdev_redis_ui_styles = require("@redis-ui/styles");
|
|
5
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
|
+
let react = require("react");
|
|
7
|
+
react = require_runtime.__toESM(react, 1);
|
|
8
|
+
//#region src/ThemeModeSwitch/components/SwapButton/SwapButton.tsx
|
|
9
|
+
var SwapButton = react.default.forwardRef(({ themeMode, allowSystemThemeMode, getNextThemeModeToToggle, ...restProps }, ref) => {
|
|
10
|
+
const nextThemeMode = getNextThemeModeToToggle(themeMode);
|
|
11
|
+
const targetThemeMode = (0, _redislabsdev_redis_ui_styles.useTheme)().mode === "dark" ? "light" : "dark";
|
|
12
|
+
const ariaLabel = !allowSystemThemeMode && nextThemeMode ? `Switch to ${targetThemeMode} theme` : require_ThemeModeSwitch_utils.getCurrentModeLabel(themeMode);
|
|
13
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_SwapButton_style.SwapButton, {
|
|
14
|
+
ref,
|
|
15
|
+
"data-theme-mode": themeMode,
|
|
16
|
+
"data-target-theme-mode": targetThemeMode,
|
|
17
|
+
"aria-label": ariaLabel,
|
|
18
|
+
...restProps,
|
|
19
|
+
type: "button",
|
|
20
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_SwapButton_style.ModeIcon, {
|
|
21
|
+
$themeMode: "dark",
|
|
22
|
+
"data-hidden": targetThemeMode === "dark" ? void 0 : ""
|
|
23
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_SwapButton_style.ModeIcon, {
|
|
24
|
+
$themeMode: "light",
|
|
25
|
+
"data-hidden": targetThemeMode === "light" ? void 0 : ""
|
|
26
|
+
})]
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.default = SwapButton;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare const SwapButton: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLElement>, "onChange"> & Pick<import("@redis-ui/styles").ThemeModeSwitchingContextParams, "getNextThemeModeToToggle" | "allowSystemThemeMode"> & {
|
|
3
|
+
themeMode: import("@redis-ui/styles").UserThemeMode | undefined;
|
|
4
|
+
} & React.RefAttributes<HTMLButtonElement>>;
|
|
5
|
+
export default SwapButton;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getCurrentModeLabel } from "../../ThemeModeSwitch.utils.js";
|
|
2
|
+
import { ModeIcon, SwapButton as SwapButton$1 } from "./SwapButton.style.js";
|
|
3
|
+
import { useTheme } from "@redis-ui/styles";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import React from "react";
|
|
6
|
+
//#region src/ThemeModeSwitch/components/SwapButton/SwapButton.tsx
|
|
7
|
+
var SwapButton = React.forwardRef(({ themeMode, allowSystemThemeMode, getNextThemeModeToToggle, ...restProps }, ref) => {
|
|
8
|
+
const nextThemeMode = getNextThemeModeToToggle(themeMode);
|
|
9
|
+
const targetThemeMode = useTheme().mode === "dark" ? "light" : "dark";
|
|
10
|
+
return /* @__PURE__ */ jsxs(SwapButton$1, {
|
|
11
|
+
ref,
|
|
12
|
+
"data-theme-mode": themeMode,
|
|
13
|
+
"data-target-theme-mode": targetThemeMode,
|
|
14
|
+
"aria-label": !allowSystemThemeMode && nextThemeMode ? `Switch to ${targetThemeMode} theme` : getCurrentModeLabel(themeMode),
|
|
15
|
+
...restProps,
|
|
16
|
+
type: "button",
|
|
17
|
+
children: [/* @__PURE__ */ jsx(ModeIcon, {
|
|
18
|
+
$themeMode: "dark",
|
|
19
|
+
"data-hidden": targetThemeMode === "dark" ? void 0 : ""
|
|
20
|
+
}), /* @__PURE__ */ jsx(ModeIcon, {
|
|
21
|
+
$themeMode: "light",
|
|
22
|
+
"data-hidden": targetThemeMode === "light" ? void 0 : ""
|
|
23
|
+
})]
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
//#endregion
|
|
27
|
+
export { SwapButton as default };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let styled_components = require("styled-components");
|
|
3
|
+
styled_components = require_runtime.__toESM(styled_components, 1);
|
|
4
|
+
let _redislabsdev_redis_ui_styles = require("@redis-ui/styles");
|
|
5
|
+
//#region src/ThemeModeSwitch/components/SwapButton/SwapButton.style.ts
|
|
6
|
+
var TRANSITION_MS = 200;
|
|
7
|
+
var SwapButton = styled_components.default.button.withConfig({
|
|
8
|
+
displayName: "SwapButtonstyle__SwapButton",
|
|
9
|
+
componentId: "RedisUI__sc-ds0xfl-0"
|
|
10
|
+
})([
|
|
11
|
+
"all:unset;cursor:pointer;box-sizing:border-box;display:inline-grid;place-items:center;",
|
|
12
|
+
" ",
|
|
13
|
+
""
|
|
14
|
+
], () => {
|
|
15
|
+
const theme = (0, _redislabsdev_redis_ui_styles.useTheme)().components.themeModeSwitch;
|
|
16
|
+
return styled_components.css`
|
|
17
|
+
width: ${theme.height};
|
|
18
|
+
height: ${theme.height};
|
|
19
|
+
border-radius: ${theme.borderRadius};
|
|
20
|
+
`;
|
|
21
|
+
}, (0, _redislabsdev_redis_ui_styles.getFocusStyle)());
|
|
22
|
+
var ModeIcon = styled_components.default.span.withConfig({
|
|
23
|
+
displayName: "SwapButtonstyle__ModeIcon",
|
|
24
|
+
componentId: "RedisUI__sc-ds0xfl-1"
|
|
25
|
+
})([
|
|
26
|
+
"grid-area:1 / 1;height:100%;width:100%;background-size:contain;background-position:center;background-repeat:no-repeat;transition:opacity ",
|
|
27
|
+
"ms ease,transform ",
|
|
28
|
+
"ms ease;@media (prefers-reduced-motion:reduce){transition:none;}&[data-hidden]{opacity:0;transform:rotate(-90deg) scale(0.5);}",
|
|
29
|
+
""
|
|
30
|
+
], TRANSITION_MS, TRANSITION_MS, ({ $themeMode }) => {
|
|
31
|
+
return styled_components.css`
|
|
32
|
+
background-image: ${(0, _redislabsdev_redis_ui_styles.useTheme)().components.themeModeSwitch.modeIcon[$themeMode]};
|
|
33
|
+
`;
|
|
34
|
+
});
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.ModeIcon = ModeIcon;
|
|
37
|
+
exports.SwapButton = SwapButton;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import _styled, { css } from "styled-components";
|
|
2
|
+
import { getFocusStyle, useTheme } from "@redis-ui/styles";
|
|
3
|
+
//#region src/ThemeModeSwitch/components/SwapButton/SwapButton.style.ts
|
|
4
|
+
var TRANSITION_MS = 200;
|
|
5
|
+
var SwapButton = _styled.button.withConfig({
|
|
6
|
+
displayName: "SwapButtonstyle__SwapButton",
|
|
7
|
+
componentId: "RedisUI__sc-ds0xfl-0"
|
|
8
|
+
})([
|
|
9
|
+
"all:unset;cursor:pointer;box-sizing:border-box;display:inline-grid;place-items:center;",
|
|
10
|
+
" ",
|
|
11
|
+
""
|
|
12
|
+
], () => {
|
|
13
|
+
const theme = useTheme().components.themeModeSwitch;
|
|
14
|
+
return css`
|
|
15
|
+
width: ${theme.height};
|
|
16
|
+
height: ${theme.height};
|
|
17
|
+
border-radius: ${theme.borderRadius};
|
|
18
|
+
`;
|
|
19
|
+
}, getFocusStyle());
|
|
20
|
+
var ModeIcon = _styled.span.withConfig({
|
|
21
|
+
displayName: "SwapButtonstyle__ModeIcon",
|
|
22
|
+
componentId: "RedisUI__sc-ds0xfl-1"
|
|
23
|
+
})([
|
|
24
|
+
"grid-area:1 / 1;height:100%;width:100%;background-size:contain;background-position:center;background-repeat:no-repeat;transition:opacity ",
|
|
25
|
+
"ms ease,transform ",
|
|
26
|
+
"ms ease;@media (prefers-reduced-motion:reduce){transition:none;}&[data-hidden]{opacity:0;transform:rotate(-90deg) scale(0.5);}",
|
|
27
|
+
""
|
|
28
|
+
], TRANSITION_MS, TRANSITION_MS, ({ $themeMode }) => {
|
|
29
|
+
return css`
|
|
30
|
+
background-image: ${useTheme().components.themeModeSwitch.modeIcon[$themeMode]};
|
|
31
|
+
`;
|
|
32
|
+
});
|
|
33
|
+
//#endregion
|
|
34
|
+
export { ModeIcon, SwapButton };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ThemeModeSwitchingContextParams, UserThemeMode } from '@redis-ui/styles';
|
|
2
|
+
import { HTMLAttributes } from 'react';
|
|
3
|
+
export type SwapButtonProps = Omit<HTMLAttributes<HTMLElement>, 'onChange'> & Pick<ThemeModeSwitchingContextParams, 'getNextThemeModeToToggle' | 'allowSystemThemeMode'> & {
|
|
4
|
+
themeMode: UserThemeMode | undefined;
|
|
5
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_ThemeModeSwitch_utils = require("../../ThemeModeSwitch.utils.cjs");
|
|
3
|
+
const require_SwitchButton_style = require("./SwitchButton.style.cjs");
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
let react = require("react");
|
|
6
|
+
react = require_runtime.__toESM(react, 1);
|
|
7
|
+
//#region src/ThemeModeSwitch/components/SwitchButton/SwitchButton.tsx
|
|
8
|
+
var SwitchButton = react.default.forwardRef(({ themeMode, switchTimeoutMs, ...restProps }, ref) => {
|
|
9
|
+
const [ready, setReady] = (0, react.useState)(false);
|
|
10
|
+
(0, react.useEffect)(() => setReady(true), []);
|
|
11
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_SwitchButton_style.SwitchButton, {
|
|
12
|
+
ref,
|
|
13
|
+
"data-theme-mode": themeMode,
|
|
14
|
+
"aria-label": require_ThemeModeSwitch_utils.getCurrentModeLabel(themeMode),
|
|
15
|
+
...restProps,
|
|
16
|
+
type: "button",
|
|
17
|
+
"data-mounting": !ready ? "" : void 0,
|
|
18
|
+
$durationMs: switchTimeoutMs,
|
|
19
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_SwitchButton_style.Knob, { "data-theme-mode": themeMode })
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.default = SwitchButton;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare const SwitchButton: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLElement>, "onChange"> & {
|
|
3
|
+
themeMode: import("@redis-ui/styles").UserThemeMode | undefined;
|
|
4
|
+
switchTimeoutMs: number;
|
|
5
|
+
} & React.RefAttributes<HTMLButtonElement>>;
|
|
6
|
+
export default SwitchButton;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getCurrentModeLabel } from "../../ThemeModeSwitch.utils.js";
|
|
2
|
+
import { Knob, SwitchButton as SwitchButton$1 } from "./SwitchButton.style.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import React, { useEffect, useState } from "react";
|
|
5
|
+
//#region src/ThemeModeSwitch/components/SwitchButton/SwitchButton.tsx
|
|
6
|
+
var SwitchButton = React.forwardRef(({ themeMode, switchTimeoutMs, ...restProps }, ref) => {
|
|
7
|
+
const [ready, setReady] = useState(false);
|
|
8
|
+
useEffect(() => setReady(true), []);
|
|
9
|
+
return /* @__PURE__ */ jsx(SwitchButton$1, {
|
|
10
|
+
ref,
|
|
11
|
+
"data-theme-mode": themeMode,
|
|
12
|
+
"aria-label": getCurrentModeLabel(themeMode),
|
|
13
|
+
...restProps,
|
|
14
|
+
type: "button",
|
|
15
|
+
"data-mounting": !ready ? "" : void 0,
|
|
16
|
+
$durationMs: switchTimeoutMs,
|
|
17
|
+
children: /* @__PURE__ */ jsx(Knob, { "data-theme-mode": themeMode })
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
//#endregion
|
|
21
|
+
export { SwitchButton as default };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const require_runtime = require("
|
|
1
|
+
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let styled_components = require("styled-components");
|
|
3
3
|
styled_components = require_runtime.__toESM(styled_components, 1);
|
|
4
4
|
let _redislabsdev_redis_ui_styles = require("@redis-ui/styles");
|
|
5
|
-
//#region src/ThemeModeSwitch/
|
|
6
|
-
var
|
|
7
|
-
displayName: "
|
|
8
|
-
componentId: "RedisUI__sc-
|
|
5
|
+
//#region src/ThemeModeSwitch/components/SwitchButton/SwitchButton.style.ts
|
|
6
|
+
var SwitchButton = styled_components.default.button.withConfig({
|
|
7
|
+
displayName: "SwitchButtonstyle__SwitchButton",
|
|
8
|
+
componentId: "RedisUI__sc-17onqr1-0"
|
|
9
9
|
})([
|
|
10
10
|
"all:unset;cursor:pointer;box-sizing:border-box;transition:all ",
|
|
11
11
|
"ms ease,outline 0ms,outline-offset 0ms;&[data-mounting]{transition:none;}@media (prefers-reduced-motion:reduce){transition:none;}",
|
|
@@ -25,8 +25,8 @@ var ThemeModeSwitch = styled_components.default.button.withConfig({
|
|
|
25
25
|
`;
|
|
26
26
|
}, (0, _redislabsdev_redis_ui_styles.getFocusStyle)());
|
|
27
27
|
var Knob = styled_components.default.div.withConfig({
|
|
28
|
-
displayName: "
|
|
29
|
-
componentId: "RedisUI__sc-
|
|
28
|
+
displayName: "SwitchButtonstyle__Knob",
|
|
29
|
+
componentId: "RedisUI__sc-17onqr1-1"
|
|
30
30
|
})(["height:100%;width:100%;background:none;transition:inherit;&[data-theme-mode='dark']{transform:translateX(100%);:before{transform:translateX(-100%);}}&[data-theme-mode='system']{transform:translateX(50%);:before{transform:translateX(-50%);}}:before{content:'';display:block;transition:inherit;height:100%;background-size:contain;background-position:center;background-repeat:no-repeat;", "}"], () => {
|
|
31
31
|
const theme = (0, _redislabsdev_redis_ui_styles.useTheme)().components.themeModeSwitch.thumb;
|
|
32
32
|
return styled_components.css`
|
|
@@ -38,4 +38,4 @@ var Knob = styled_components.default.div.withConfig({
|
|
|
38
38
|
});
|
|
39
39
|
//#endregion
|
|
40
40
|
exports.Knob = Knob;
|
|
41
|
-
exports.
|
|
41
|
+
exports.SwitchButton = SwitchButton;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const SwitchButton: import("styled-components").StyledComponent<"button", any, {
|
|
2
2
|
$durationMs: number;
|
|
3
3
|
}, never>;
|
|
4
4
|
export declare const Knob: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import _styled, { css } from "styled-components";
|
|
2
2
|
import { getFocusStyle, useTheme } from "@redis-ui/styles";
|
|
3
|
-
//#region src/ThemeModeSwitch/
|
|
4
|
-
var
|
|
5
|
-
displayName: "
|
|
6
|
-
componentId: "RedisUI__sc-
|
|
3
|
+
//#region src/ThemeModeSwitch/components/SwitchButton/SwitchButton.style.ts
|
|
4
|
+
var SwitchButton = _styled.button.withConfig({
|
|
5
|
+
displayName: "SwitchButtonstyle__SwitchButton",
|
|
6
|
+
componentId: "RedisUI__sc-17onqr1-0"
|
|
7
7
|
})([
|
|
8
8
|
"all:unset;cursor:pointer;box-sizing:border-box;transition:all ",
|
|
9
9
|
"ms ease,outline 0ms,outline-offset 0ms;&[data-mounting]{transition:none;}@media (prefers-reduced-motion:reduce){transition:none;}",
|
|
@@ -23,8 +23,8 @@ var ThemeModeSwitch = _styled.button.withConfig({
|
|
|
23
23
|
`;
|
|
24
24
|
}, getFocusStyle());
|
|
25
25
|
var Knob = _styled.div.withConfig({
|
|
26
|
-
displayName: "
|
|
27
|
-
componentId: "RedisUI__sc-
|
|
26
|
+
displayName: "SwitchButtonstyle__Knob",
|
|
27
|
+
componentId: "RedisUI__sc-17onqr1-1"
|
|
28
28
|
})(["height:100%;width:100%;background:none;transition:inherit;&[data-theme-mode='dark']{transform:translateX(100%);:before{transform:translateX(-100%);}}&[data-theme-mode='system']{transform:translateX(50%);:before{transform:translateX(-50%);}}:before{content:'';display:block;transition:inherit;height:100%;background-size:contain;background-position:center;background-repeat:no-repeat;", "}"], () => {
|
|
29
29
|
const theme = useTheme().components.themeModeSwitch.thumb;
|
|
30
30
|
return css`
|
|
@@ -35,4 +35,4 @@ var Knob = _styled.div.withConfig({
|
|
|
35
35
|
`;
|
|
36
36
|
});
|
|
37
37
|
//#endregion
|
|
38
|
-
export { Knob,
|
|
38
|
+
export { Knob, SwitchButton };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -3,6 +3,7 @@ import { UseThemeModeSwitchParams } from './ThemeModeSwitch.types';
|
|
|
3
3
|
export declare function useThemeModeSwitch({ onThemeModeChange, switchTimeoutMs }: UseThemeModeSwitchParams): {
|
|
4
4
|
allowSystemThemeMode: boolean | undefined;
|
|
5
5
|
themeMode: "light" | "dark" | "system" | undefined;
|
|
6
|
+
getNextThemeModeToToggle: (currentThemeMode: UserThemeMode | undefined) => import("@redis-ui/styles").ThemeMode | undefined;
|
|
6
7
|
setThemeMode: (newThemeMode: UserThemeMode | undefined) => void;
|
|
7
8
|
toggleThemeMode: () => void;
|
|
8
9
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redis-ui/components",
|
|
3
3
|
"license": "UNLICENSED",
|
|
4
|
-
"version": "51.
|
|
4
|
+
"version": "51.3.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"repository": "git@github.com:redislabsdev/redis-ui.git",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@redis-ui/icons": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
33
|
-
"@redis-ui/styles": "^21.
|
|
33
|
+
"@redis-ui/styles": "^21.4.0",
|
|
34
34
|
"react": "^18.0.0 || ^19.0.0",
|
|
35
35
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
36
36
|
"styled-components": "^5.0.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ThemeModeSwitch
|
|
2
2
|
|
|
3
|
-
A pre-built control that lets the user switch the app's theme mode.
|
|
3
|
+
A pre-built control that lets the user switch the app's theme mode. It comes in two variants: `switch` (default) is a track whose knob slides between light and dark, and `swap` is a single icon button showing the mode it switches to. When the surrounding provider allows the system mode, either variant becomes a menu offering Light, Dark, and Browser options. It must be rendered inside a `SwitchableModeThemeProvider` (or an equivalent `ThemeModeSwitchingProvider` context) from `@redis-ui/styles`.
|
|
4
4
|
|
|
5
5
|
## Import
|
|
6
6
|
|
|
@@ -18,13 +18,14 @@ import { SwitchableModeThemeProvider } from '@redis-ui/styles';
|
|
|
18
18
|
|
|
19
19
|
| Prop | Type | Default | Description |
|
|
20
20
|
|------|------|---------|-------------|
|
|
21
|
+
| `variant` | `'switch' \| 'swap'` | `'switch'` | `switch` is a track with a sliding knob; `swap` is a single icon button showing the mode it switches to. |
|
|
21
22
|
| `onThemeModeChange` | `(newThemeMode: UserThemeMode) => void` | - | Called after the theme mode change is applied. |
|
|
22
|
-
| `switchTimeoutMs` | `number` | `300` | Delay before the selected mode is applied
|
|
23
|
+
| `switchTimeoutMs` | `number` | `300`, or `0` for `swap` | Delay before the selected mode is applied. It covers the knob travel on `switch`; `swap` has none, so it applies immediately. |
|
|
23
24
|
| `other element attributes` | `Omit<HTMLAttributes<HTMLElement>, 'onClick' \| 'onChange'>` | - | Remaining HTML attributes are forwarded to the control (`onClick`/`onChange` are managed internally). |
|
|
24
25
|
|
|
25
26
|
## Hooks
|
|
26
27
|
|
|
27
|
-
- `useThemeModeSwitch` - Powers `ThemeModeSwitch`; use it to build a custom switcher. Accepts `{ onThemeModeChange?, switchTimeoutMs? }` and returns `{ allowSystemThemeMode, themeMode, setThemeMode, toggleThemeMode }`.
|
|
28
|
+
- `useThemeModeSwitch` - Powers `ThemeModeSwitch`; use it to build a custom switcher. Accepts `{ onThemeModeChange?, switchTimeoutMs? }` and returns `{ allowSystemThemeMode, themeMode, getNextThemeModeToToggle, setThemeMode, toggleThemeMode }`.
|
|
28
29
|
|
|
29
30
|
## Examples
|
|
30
31
|
|
|
@@ -52,6 +53,16 @@ import { ThemeModeSwitch } from '@redis-ui/components';
|
|
|
52
53
|
<ThemeModeSwitch onThemeModeChange={notifyUserSwitchedMode} />;
|
|
53
54
|
```
|
|
54
55
|
|
|
56
|
+
### Swap variant
|
|
57
|
+
|
|
58
|
+
> A single icon button instead of the sliding track - the moon on the light theme, the sun on the dark one. The two icons cross-fade when the mode changes.
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import { ThemeModeSwitch } from '@redis-ui/components';
|
|
62
|
+
|
|
63
|
+
<ThemeModeSwitch variant="swap" />;
|
|
64
|
+
```
|
|
65
|
+
|
|
55
66
|
### Custom switcher with the hook
|
|
56
67
|
|
|
57
68
|
> When the built-in control doesn't fit, build your own from `useThemeModeSwitch` (or the lower-level `useThemeModeSwitchingContext` from the styles package).
|
|
@@ -69,4 +80,6 @@ const { themeMode, toggleThemeMode } = useThemeModeSwitch({ onThemeModeChange })
|
|
|
69
80
|
- `ThemeModeSwitch` requires a `SwitchableModeThemeProvider` (or `ThemeModeSwitchingProvider`) ancestor — it reads and updates the theme mode through that context.
|
|
70
81
|
- When the provider is configured with `allowSystemThemeMode`, the control renders a menu with Light / Dark / Browser choices instead of a two-state toggle.
|
|
71
82
|
- `onThemeModeChange` fires only after the mode is actually applied (after `switchTimeoutMs`).
|
|
83
|
+
- The `swap` variant applies the theme immediately, since `switchTimeoutMs` defaults to `0` there - the delay on `switch` only exists to let the theme land as the knob finishes sliding. Pass an explicit `switchTimeoutMs` to override either.
|
|
84
|
+
- The `swap` variant labels itself with the mode it will switch to (`Switch to dark theme`). In menu mode, or when the provider resolves no next mode, it falls back to the same generic label as `switch`.
|
|
72
85
|
- For fully custom UI, use the exported `useThemeModeSwitch` hook rather than restyling the component internals.
|