@datalayer/primer-addons 1.0.44 → 1.0.46
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/lib/components/appearance/AppearanceControls.d.ts +9 -3
- package/lib/components/appearance/AppearanceControls.js +101 -87
- package/lib/components/appearance/AppearanceControls.stories.d.ts +7 -0
- package/lib/components/appearance/AppearanceControls.stories.js +3 -0
- package/lib/components/appearance/AppearanceMenu.d.ts +5 -2
- package/lib/components/appearance/AppearanceMenu.js +2 -2
- package/lib/components/appearance/AppearanceMenu.stories.d.ts +7 -0
- package/lib/components/appearance/AppearanceMenu.stories.js +4 -1
- package/lib/components/appearance/ColorModeCircle.d.ts +2 -1
- package/lib/components/appearance/ColorModeCircle.js +6 -4
- package/lib/components/appearance/ColorModeCircle.stories.js +1 -1
- package/lib/components/closeable-flash/CloseableFlash.js +1 -1
- package/lib/theme/colors/hueColors.d.ts +29 -0
- package/lib/theme/colors/hueColors.js +77 -0
- package/lib/theme/colors/index.d.ts +1 -0
- package/lib/theme/colors/index.js +1 -0
- package/lib/theme/palettes/ColorPalette.d.ts +43 -1
- package/lib/theme/palettes/ColorPalette.js +77 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ReactElement } from
|
|
2
|
-
import { type ColorMode, type ThemeVariant } from
|
|
1
|
+
import { type ReactElement } from "react";
|
|
2
|
+
import { type ColorMode, type ThemeVariant } from "../../theme";
|
|
3
3
|
export interface AppearanceControlsProps {
|
|
4
4
|
colorMode: ColorMode;
|
|
5
5
|
themeVariant: ThemeVariant;
|
|
@@ -11,6 +11,12 @@ export interface AppearanceControlsProps {
|
|
|
11
11
|
showThemeChooser?: boolean;
|
|
12
12
|
/** With the chooser, the chosen theme's name, description and preview under its swatches. Default: swatches only. */
|
|
13
13
|
showThemePreviews?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The most theme swatches on one line; every line is centred, so a shorter
|
|
16
|
+
* last line sits in the middle under the full ones. Undefined, they wrap
|
|
17
|
+
* freely to the width given, as before.
|
|
18
|
+
*/
|
|
19
|
+
themesPerLine?: number;
|
|
14
20
|
}
|
|
15
|
-
export declare function AppearanceControls({ colorMode, themeVariant, onColorModeChange, onThemeChange, showColorMode, showThemeChooser, showThemePreviews, }: AppearanceControlsProps): ReactElement;
|
|
21
|
+
export declare function AppearanceControls({ colorMode, themeVariant, onColorModeChange, onThemeChange, showColorMode, showThemeChooser, showThemePreviews, themesPerLine, }: AppearanceControlsProps): ReactElement;
|
|
16
22
|
export default AppearanceControls;
|
|
@@ -3,117 +3,131 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
5
5
|
*/
|
|
6
|
-
import { useState } from
|
|
7
|
-
import { SegmentedControl, Tooltip } from
|
|
8
|
-
import { MoonIcon, SunIcon, DeviceDesktopIcon
|
|
9
|
-
import { Box } from
|
|
10
|
-
import { themeVariants, themeConfigs, } from
|
|
11
|
-
import { ThemePreviewCard } from
|
|
12
|
-
export function AppearanceControls({ colorMode, themeVariant, onColorModeChange, onThemeChange, showColorMode = true, showThemeChooser = true, showThemePreviews = false, }) {
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { SegmentedControl, Tooltip } from "@primer/react";
|
|
8
|
+
import { MoonIcon, SunIcon, DeviceDesktopIcon } from "@primer/octicons-react";
|
|
9
|
+
import { Box } from "../box/Box";
|
|
10
|
+
import { themeVariants, themeConfigs, } from "../../theme";
|
|
11
|
+
import { ThemePreviewCard } from "./ThemePreviewCard";
|
|
12
|
+
export function AppearanceControls({ colorMode, themeVariant, onColorModeChange, onThemeChange, showColorMode = true, showThemeChooser = true, showThemePreviews = false, themesPerLine, }) {
|
|
13
|
+
// At most `themesPerLine` swatches on a line when given, each line centred,
|
|
14
|
+
// so a shorter last line sits in the middle under the full ones; one line
|
|
15
|
+
// wrapping freely otherwise. Explicit lines rather than a width: the
|
|
16
|
+
// tooltips' hidden siblings take gaps of their own.
|
|
17
|
+
const swatchLines = themesPerLine !== undefined && themesPerLine > 0
|
|
18
|
+
? Array.from({ length: Math.ceil(themeVariants.length / themesPerLine) }, (_, line) => themeVariants.slice(line * themesPerLine, (line + 1) * themesPerLine))
|
|
19
|
+
: [[...themeVariants]];
|
|
20
|
+
const swatchRow = { display: "grid", rowGap: 2 };
|
|
21
|
+
const swatchLine = {
|
|
22
|
+
display: "flex",
|
|
23
|
+
justifyContent: "center",
|
|
24
|
+
flexWrap: "wrap",
|
|
25
|
+
gap: 2,
|
|
26
|
+
};
|
|
13
27
|
const [isPreviewOpen, setIsPreviewOpen] = useState(false);
|
|
14
28
|
const selectedTheme = themeConfigs[themeVariant];
|
|
15
|
-
return (_jsxs(_Fragment, { children: [showColorMode ? (_jsx(Box, { sx: { px: 2, py: 2, display:
|
|
16
|
-
const modes = [
|
|
29
|
+
return (_jsxs(_Fragment, { children: [showColorMode ? (_jsx(Box, { sx: { px: 2, py: 2, display: "flex", justifyContent: "center" }, children: _jsxs(SegmentedControl, { "aria-label": "Color mode", size: "small", onChange: (index) => {
|
|
30
|
+
const modes = ["light", "dark", "auto"];
|
|
17
31
|
onColorModeChange(modes[index]);
|
|
18
|
-
}, children: [_jsx(SegmentedControl.IconButton, { selected: colorMode ===
|
|
32
|
+
}, children: [_jsx(SegmentedControl.IconButton, { selected: colorMode === "light", icon: SunIcon, "aria-label": "Light" }), _jsx(SegmentedControl.IconButton, { selected: colorMode === "dark", icon: MoonIcon, "aria-label": "Dark" }), _jsx(SegmentedControl.IconButton, { selected: colorMode === "auto", icon: DeviceDesktopIcon, "aria-label": "Auto" })] }) })) : null, !showThemeChooser ? null : showThemePreviews ? (_jsxs(Box, { sx: {
|
|
19
33
|
px: 2,
|
|
20
34
|
// First in the controls when the colour mode is hidden.
|
|
21
35
|
pt: showColorMode ? 0 : 2,
|
|
22
36
|
pb: 2,
|
|
23
|
-
display:
|
|
37
|
+
display: "grid",
|
|
24
38
|
gap: 2,
|
|
25
39
|
}, children: [_jsx(Box, { sx: {
|
|
26
|
-
|
|
27
|
-
justifyContent: 'center',
|
|
40
|
+
...swatchRow,
|
|
28
41
|
gap: 2,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
}, children: swatchLines.map((line) => (_jsx(Box, { sx: swatchLine, children: line.map((variant) => {
|
|
43
|
+
const cfg = themeConfigs[variant];
|
|
44
|
+
const isSelected = themeVariant === variant;
|
|
45
|
+
return (_jsx(Tooltip, { text: `${cfg.label} — ${cfg.description}`, direction: "s", children: _jsx(Box, { as: "button", "aria-label": cfg.label, "aria-pressed": isSelected, onClick: () => onThemeChange(variant), sx: {
|
|
46
|
+
width: 24,
|
|
47
|
+
height: 24,
|
|
48
|
+
flexShrink: 0,
|
|
49
|
+
borderRadius: "50%",
|
|
50
|
+
backgroundColor: cfg.brandColor,
|
|
51
|
+
border: "2px solid",
|
|
52
|
+
borderColor: isSelected
|
|
53
|
+
? "accent.fg"
|
|
54
|
+
: "border.default",
|
|
55
|
+
cursor: "pointer",
|
|
56
|
+
padding: 0,
|
|
57
|
+
outline: "none",
|
|
58
|
+
transition: "border-color 0.15s ease",
|
|
59
|
+
boxShadow: isSelected
|
|
60
|
+
? "0 0 0 2px var(--bgColor-accent-muted, rgba(9,105,218,0.3))"
|
|
61
|
+
: "none",
|
|
62
|
+
"&:hover": {
|
|
63
|
+
borderColor: "accent.fg",
|
|
64
|
+
},
|
|
65
|
+
"&:focus-visible": {
|
|
66
|
+
boxShadow: "0 0 0 2px var(--bgColor-accent-muted, rgba(9,105,218,0.3))",
|
|
67
|
+
},
|
|
68
|
+
} }) }, variant));
|
|
69
|
+
}) }, line.join()))) }), _jsxs(Box, { sx: {
|
|
56
70
|
px: 1,
|
|
57
|
-
display:
|
|
71
|
+
display: "grid",
|
|
58
72
|
gap: 1,
|
|
59
|
-
}, children: [_jsx(Box, { sx: { fontSize: 1, fontWeight:
|
|
73
|
+
}, children: [_jsx(Box, { sx: { fontSize: 1, fontWeight: "semibold", color: "fg.default" }, children: selectedTheme.label }), _jsx(Box, { sx: { fontSize: 0, color: "fg.muted", lineHeight: 1.5 }, children: selectedTheme.description }), _jsx(Box, { as: "button", type: "button", onClick: () => setIsPreviewOpen((open) => !open), "aria-expanded": isPreviewOpen, sx: {
|
|
60
74
|
mt: 1,
|
|
61
|
-
width:
|
|
75
|
+
width: "fit-content",
|
|
62
76
|
px: 2,
|
|
63
|
-
py:
|
|
77
|
+
py: "4px",
|
|
64
78
|
borderRadius: 2,
|
|
65
|
-
border:
|
|
66
|
-
borderColor:
|
|
67
|
-
bg:
|
|
68
|
-
color:
|
|
79
|
+
border: "1px solid",
|
|
80
|
+
borderColor: "border.default",
|
|
81
|
+
bg: "canvas.default",
|
|
82
|
+
color: "fg.default",
|
|
69
83
|
fontSize: 0,
|
|
70
|
-
fontWeight:
|
|
71
|
-
cursor:
|
|
72
|
-
|
|
73
|
-
borderColor:
|
|
74
|
-
color:
|
|
84
|
+
fontWeight: "semibold",
|
|
85
|
+
cursor: "pointer",
|
|
86
|
+
"&:hover": {
|
|
87
|
+
borderColor: "accent.fg",
|
|
88
|
+
color: "accent.fg",
|
|
75
89
|
},
|
|
76
|
-
|
|
77
|
-
outline:
|
|
78
|
-
outlineColor:
|
|
90
|
+
"&:focus-visible": {
|
|
91
|
+
outline: "2px solid",
|
|
92
|
+
outlineColor: "accent.fg",
|
|
79
93
|
outlineOffset: 1,
|
|
80
94
|
},
|
|
81
|
-
}, children: isPreviewOpen ?
|
|
95
|
+
}, children: isPreviewOpen ? "Hide preview" : "Show preview" })] }), isPreviewOpen ? (_jsx(ThemePreviewCard, { variant: themeVariant, colorMode: colorMode, selected: true, compact: true, showDescription: true })) : null] })) : (_jsx(Box, { sx: {
|
|
82
96
|
px: 2,
|
|
83
97
|
// First in the controls when the colour mode is hidden.
|
|
84
98
|
pt: showColorMode ? 0 : 2,
|
|
85
99
|
pb: 2,
|
|
86
|
-
display: 'flex',
|
|
87
|
-
justifyContent: 'center',
|
|
88
100
|
// Narrow, the swatches go on a second line rather than shrink.
|
|
89
|
-
|
|
101
|
+
...swatchRow,
|
|
90
102
|
gap: 2,
|
|
91
|
-
}, children:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
:
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
103
|
+
}, children: swatchLines.map((line) => (_jsx(Box, { sx: swatchLine, children: line.map((variant) => {
|
|
104
|
+
const cfg = themeConfigs[variant];
|
|
105
|
+
const isSelected = themeVariant === variant;
|
|
106
|
+
return (_jsx(Tooltip, { text: cfg.label, direction: "s", children: _jsx(Box, { as: "button", "aria-label": cfg.label, "aria-pressed": isSelected, onClick: () => onThemeChange(variant), sx: {
|
|
107
|
+
width: 24,
|
|
108
|
+
height: 24,
|
|
109
|
+
// A circle at any width: never squeezed into an oval.
|
|
110
|
+
flexShrink: 0,
|
|
111
|
+
borderRadius: "50%",
|
|
112
|
+
backgroundColor: cfg.brandColor,
|
|
113
|
+
border: "2px solid",
|
|
114
|
+
borderColor: isSelected
|
|
115
|
+
? "accent.fg"
|
|
116
|
+
: "border.default",
|
|
117
|
+
cursor: "pointer",
|
|
118
|
+
padding: 0,
|
|
119
|
+
outline: "none",
|
|
120
|
+
transition: "border-color 0.15s ease",
|
|
121
|
+
boxShadow: isSelected
|
|
122
|
+
? "0 0 0 2px var(--bgColor-accent-muted, rgba(9,105,218,0.3))"
|
|
123
|
+
: "none",
|
|
124
|
+
"&:hover": {
|
|
125
|
+
borderColor: "accent.fg",
|
|
126
|
+
},
|
|
127
|
+
"&:focus-visible": {
|
|
128
|
+
boxShadow: "0 0 0 2px var(--bgColor-accent-muted, rgba(9,105,218,0.3))",
|
|
129
|
+
},
|
|
130
|
+
} }) }, variant));
|
|
131
|
+
}) }, line.join()))) }))] }));
|
|
118
132
|
}
|
|
119
133
|
export default AppearanceControls;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ReactElement } from 'react';
|
|
2
|
+
import { type HoverOverlayPlacement } from './ColorModeCircle';
|
|
2
3
|
import type { ColorMode, ThemeVariant } from '../../theme';
|
|
3
4
|
export interface AppearanceMenuProps {
|
|
4
5
|
/** Current color mode. */
|
|
@@ -14,9 +15,11 @@ export interface AppearanceMenuProps {
|
|
|
14
15
|
/** Visual shape of the trigger control. */
|
|
15
16
|
shape?: 'square' | 'circle';
|
|
16
17
|
/** Overlay placement relative to the circle. */
|
|
17
|
-
hoverOverlayPlacement?:
|
|
18
|
+
hoverOverlayPlacement?: HoverOverlayPlacement;
|
|
18
19
|
/** Whether the overlay shows the live theme previews. */
|
|
19
20
|
showThemePreviews?: boolean;
|
|
21
|
+
/** The most theme swatches on one line in the overlay; undefined, they wrap freely. */
|
|
22
|
+
themesPerLine?: number;
|
|
20
23
|
}
|
|
21
24
|
/**
|
|
22
25
|
* A single color-mode circle that reveals, on hover, an appearance overlay
|
|
@@ -26,5 +29,5 @@ export interface AppearanceMenuProps {
|
|
|
26
29
|
* {@link AppearanceControls} overlay so the whole appearance menu can be
|
|
27
30
|
* dropped into any header with a single component.
|
|
28
31
|
*/
|
|
29
|
-
export declare function AppearanceMenu({ colorMode, themeVariant, onColorModeChange, onThemeChange, size, shape, hoverOverlayPlacement, showThemePreviews, }: AppearanceMenuProps): ReactElement;
|
|
32
|
+
export declare function AppearanceMenu({ colorMode, themeVariant, onColorModeChange, onThemeChange, size, shape, hoverOverlayPlacement, showThemePreviews, themesPerLine, }: AppearanceMenuProps): ReactElement;
|
|
30
33
|
export default AppearanceMenu;
|
|
@@ -9,7 +9,7 @@ import { AppearanceControls } from './AppearanceControls';
|
|
|
9
9
|
* {@link AppearanceControls} overlay so the whole appearance menu can be
|
|
10
10
|
* dropped into any header with a single component.
|
|
11
11
|
*/
|
|
12
|
-
export function AppearanceMenu({ colorMode, themeVariant, onColorModeChange, onThemeChange, size = 26, shape = 'square', hoverOverlayPlacement = 'bottom-end', showThemePreviews = true, }) {
|
|
13
|
-
return (_jsx(ColorModeCircle, { colorMode: colorMode, onColorModeChange: onColorModeChange, cycleOnClick: false, themeVariant: themeVariant, hoverOverlayPlacement: hoverOverlayPlacement, shape: shape, size: size, hoverOverlay: _jsx(AppearanceControls, { colorMode: colorMode, themeVariant: themeVariant, onColorModeChange: onColorModeChange, onThemeChange: onThemeChange, showThemePreviews: showThemePreviews }) }));
|
|
12
|
+
export function AppearanceMenu({ colorMode, themeVariant, onColorModeChange, onThemeChange, size = 26, shape = 'square', hoverOverlayPlacement = 'bottom-end', showThemePreviews = true, themesPerLine, }) {
|
|
13
|
+
return (_jsx(ColorModeCircle, { colorMode: colorMode, onColorModeChange: onColorModeChange, cycleOnClick: false, themeVariant: themeVariant, hoverOverlayPlacement: hoverOverlayPlacement, shape: shape, size: size, hoverOverlay: _jsx(AppearanceControls, { colorMode: colorMode, themeVariant: themeVariant, onColorModeChange: onColorModeChange, onThemeChange: onThemeChange, showThemePreviews: showThemePreviews, themesPerLine: themesPerLine }) }));
|
|
14
14
|
}
|
|
15
15
|
export default AppearanceMenu;
|
|
@@ -14,6 +14,9 @@ const meta = {
|
|
|
14
14
|
layout: "fullscreen",
|
|
15
15
|
},
|
|
16
16
|
argTypes: {
|
|
17
|
+
themesPerLine: {
|
|
18
|
+
control: { type: "number", min: 1, max: 12 },
|
|
19
|
+
},
|
|
17
20
|
colorMode: {
|
|
18
21
|
options: ["light", "dark", "auto"],
|
|
19
22
|
control: "radio",
|
|
@@ -27,7 +30,7 @@ const meta = {
|
|
|
27
30
|
control: "radio",
|
|
28
31
|
},
|
|
29
32
|
hoverOverlayPlacement: {
|
|
30
|
-
options: ["bottom-start", "bottom-end"],
|
|
33
|
+
options: ["bottom-start", "bottom-end", "right-start"],
|
|
31
34
|
control: "radio",
|
|
32
35
|
},
|
|
33
36
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ReactElement, type ReactNode } from 'react';
|
|
2
2
|
import { type ColorMode, type ThemeVariant } from '../../theme';
|
|
3
|
-
|
|
3
|
+
/** Where the hover overlay opens: under the circle (aligned at its start or end), or to its right, aligned at its top. */
|
|
4
|
+
export type HoverOverlayPlacement = 'bottom-start' | 'bottom-end' | 'right-start';
|
|
4
5
|
type ColorModeCircleShape = 'square' | 'circle';
|
|
5
6
|
export interface ColorModeCircleProps {
|
|
6
7
|
/** Current color mode. */
|
|
@@ -39,6 +39,7 @@ export function ColorModeCircle({ colorMode, onColorModeChange, size = 28, hover
|
|
|
39
39
|
const [isHoverOpen, setIsHoverOpen] = useState(false);
|
|
40
40
|
const closeTimerRef = useRef(null);
|
|
41
41
|
const isBottomStart = hoverOverlayPlacement === 'bottom-start';
|
|
42
|
+
const isRight = hoverOverlayPlacement === 'right-start';
|
|
42
43
|
const themeConfig = themeVariant ? themeConfigs[themeVariant] : undefined;
|
|
43
44
|
const themeBorderColor = themeConfig?.brandColor;
|
|
44
45
|
const hasThemeColor = Boolean(themeBorderColor);
|
|
@@ -113,9 +114,10 @@ export function ColorModeCircle({ colorMode, onColorModeChange, size = 28, hover
|
|
|
113
114
|
}
|
|
114
115
|
return (_jsxs(Box, { sx: { position: 'relative', display: 'inline-flex', alignItems: 'center' }, onMouseEnter: openHoverOverlay, onMouseLeave: scheduleCloseHoverOverlay, children: [circle, _jsx(Box, { sx: {
|
|
115
116
|
position: 'absolute',
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
// To the right: beside the circle, its top level with the circle's.
|
|
118
|
+
top: isRight ? 0 : `calc(100% + 8px)`,
|
|
119
|
+
left: isRight ? `calc(100% + 8px)` : isBottomStart ? 0 : 'auto',
|
|
120
|
+
right: isRight || isBottomStart ? 'auto' : 0,
|
|
119
121
|
zIndex: 220,
|
|
120
122
|
minWidth: 340,
|
|
121
123
|
bg: 'canvas.overlay',
|
|
@@ -124,7 +126,7 @@ export function ColorModeCircle({ colorMode, onColorModeChange, size = 28, hover
|
|
|
124
126
|
borderRadius: 2,
|
|
125
127
|
boxShadow: 'shadow.large',
|
|
126
128
|
opacity: isHoverOpen ? 1 : 0,
|
|
127
|
-
transform: isHoverOpen ? '
|
|
129
|
+
transform: isHoverOpen ? 'none' : isRight ? 'translateX(-6px)' : 'translateY(-6px)',
|
|
128
130
|
pointerEvents: isHoverOpen ? 'auto' : 'none',
|
|
129
131
|
transition: 'opacity 0.16s ease, transform 0.16s ease',
|
|
130
132
|
}, children: hoverOverlay })] }));
|
|
@@ -89,7 +89,7 @@ export const CloseableFlash = (props) => {
|
|
|
89
89
|
? { borderColor: 'danger.emphasis', borderWidth: 2, borderStyle: 'solid' }
|
|
90
90
|
: {}),
|
|
91
91
|
...sx,
|
|
92
|
-
}, ...otherProps, children: _jsxs(Box, { display:
|
|
92
|
+
}, ...otherProps, children: _jsxs(Box, { sx: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' }, children: [_jsxs(Box, { sx: { flexGrow: 1 }, children: [leadingVisual && _jsx(CircleOcticon, { icon: leadingVisual }), _jsx(Text, { color: textColorForVariant(resolvedVariant), sx: isCritical ? { fontWeight: 'bold' } : undefined, children: props.children })] }), dismissible && (_jsx(Box, { as: "button", type: "button", "aria-label": "Close", onClick: handleClose, sx: {
|
|
93
93
|
flex: '0 0 auto',
|
|
94
94
|
p: 0,
|
|
95
95
|
m: 0,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hue colours – a colour named by its hue, in every theme and both modes.
|
|
3
|
+
*
|
|
4
|
+
* The palette's other names are roles (`primary`, `glow`, `surge`…): what
|
|
5
|
+
* they are changes with the theme, so `surge` is blue in one theme and sage
|
|
6
|
+
* in another. A hue name keeps its hue: `teal` is a teal in every theme, a
|
|
7
|
+
* deep one that reads on a light background and a bright one that reads on
|
|
8
|
+
* a dark background. A spec names its colour by hue (an agent's `color:
|
|
9
|
+
* indigo`), and the drawing follows the theme and its mode.
|
|
10
|
+
*
|
|
11
|
+
* Every theme takes the base values; a theme with hues of its own (`loop`'s
|
|
12
|
+
* pastels, `vscode`'s terminal colours) gives them for the hues it has.
|
|
13
|
+
*/
|
|
14
|
+
import type { ThemeVariant } from '../themeTokens';
|
|
15
|
+
/** The hue names, in the order of the colour wheel, then the neutrals: slate (cool), gray, stone (warm). */
|
|
16
|
+
export declare const hueNames: readonly ["red", "orange", "amber", "yellow", "lime", "green", "emerald", "teal", "cyan", "sky", "blue", "indigo", "violet", "purple", "fuchsia", "pink", "rose", "slate", "gray", "stone"];
|
|
17
|
+
/** A hue name. */
|
|
18
|
+
export type HueName = (typeof hueNames)[number];
|
|
19
|
+
/** A hue's value on a light background and on a dark one. */
|
|
20
|
+
export interface HueColor {
|
|
21
|
+
/** Deep enough to read on a light background. */
|
|
22
|
+
light: string;
|
|
23
|
+
/** Bright enough to read on a dark background. */
|
|
24
|
+
dark: string;
|
|
25
|
+
}
|
|
26
|
+
/** The hues every theme takes, unless it gives its own. */
|
|
27
|
+
export declare const baseHueColors: Record<HueName, HueColor>;
|
|
28
|
+
/** Every hue of a theme, in a mode. */
|
|
29
|
+
export declare function hueColorsOf(variant: ThemeVariant, mode: 'light' | 'dark'): Record<HueName, string>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2026 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/** The hue names, in the order of the colour wheel, then the neutrals: slate (cool), gray, stone (warm). */
|
|
6
|
+
export const hueNames = [
|
|
7
|
+
'red',
|
|
8
|
+
'orange',
|
|
9
|
+
'amber',
|
|
10
|
+
'yellow',
|
|
11
|
+
'lime',
|
|
12
|
+
'green',
|
|
13
|
+
'emerald',
|
|
14
|
+
'teal',
|
|
15
|
+
'cyan',
|
|
16
|
+
'sky',
|
|
17
|
+
'blue',
|
|
18
|
+
'indigo',
|
|
19
|
+
'violet',
|
|
20
|
+
'purple',
|
|
21
|
+
'fuchsia',
|
|
22
|
+
'pink',
|
|
23
|
+
'rose',
|
|
24
|
+
'slate',
|
|
25
|
+
'gray',
|
|
26
|
+
'stone',
|
|
27
|
+
];
|
|
28
|
+
/** The hues every theme takes, unless it gives its own. */
|
|
29
|
+
export const baseHueColors = {
|
|
30
|
+
red: { light: '#B91C1C', dark: '#F87171' },
|
|
31
|
+
orange: { light: '#C2410C', dark: '#FB923C' },
|
|
32
|
+
amber: { light: '#B45309', dark: '#FBBF24' },
|
|
33
|
+
yellow: { light: '#A16207', dark: '#FACC15' },
|
|
34
|
+
lime: { light: '#4D7C0F', dark: '#A3E635' },
|
|
35
|
+
green: { light: '#15803D', dark: '#4ADE80' },
|
|
36
|
+
emerald: { light: '#047857', dark: '#34D399' },
|
|
37
|
+
teal: { light: '#0F766E', dark: '#2DD4BF' },
|
|
38
|
+
cyan: { light: '#0E7490', dark: '#22D3EE' },
|
|
39
|
+
sky: { light: '#0369A1', dark: '#38BDF8' },
|
|
40
|
+
blue: { light: '#1D4ED8', dark: '#60A5FA' },
|
|
41
|
+
indigo: { light: '#4338CA', dark: '#818CF8' },
|
|
42
|
+
violet: { light: '#6D28D9', dark: '#A78BFA' },
|
|
43
|
+
purple: { light: '#7E22CE', dark: '#C084FC' },
|
|
44
|
+
fuchsia: { light: '#A21CAF', dark: '#E879F9' },
|
|
45
|
+
pink: { light: '#BE185D', dark: '#F472B6' },
|
|
46
|
+
rose: { light: '#BE123C', dark: '#FB7185' },
|
|
47
|
+
slate: { light: '#475569', dark: '#94A3B8' },
|
|
48
|
+
gray: { light: '#4B5563', dark: '#9CA3AF' },
|
|
49
|
+
stone: { light: '#57534E', dark: '#A8A29E' },
|
|
50
|
+
};
|
|
51
|
+
/** The hues a theme gives of its own. */
|
|
52
|
+
const themeHueColors = {
|
|
53
|
+
// Loop's soft accents, deep on light, the pastels on dark (`themeAccents`).
|
|
54
|
+
loop: {
|
|
55
|
+
green: { light: '#248462', dark: '#8FE5C6' },
|
|
56
|
+
rose: { light: '#B83A6B', dark: '#F6A5C1' },
|
|
57
|
+
sky: { light: '#1F6FB0', dark: '#8CCBF9' },
|
|
58
|
+
lime: { light: '#5F7A00', dark: '#BEDC55' },
|
|
59
|
+
yellow: { light: '#8A6A00', dark: '#F8D469' },
|
|
60
|
+
violet: { light: '#6B53C9', dark: '#C0AEF6' },
|
|
61
|
+
orange: { light: '#B4571A', dark: '#F4A261' },
|
|
62
|
+
},
|
|
63
|
+
// The terminal's ANSI colours.
|
|
64
|
+
vscode: {
|
|
65
|
+
red: { light: '#CD3131', dark: '#F14C4C' },
|
|
66
|
+
green: { light: '#107C10', dark: '#0DBC79' },
|
|
67
|
+
yellow: { light: '#858800', dark: '#E5E510' }, // the ANSI yellow, a shade deeper to read on white
|
|
68
|
+
blue: { light: '#0451A5', dark: '#2472C8' },
|
|
69
|
+
cyan: { light: '#0598BC', dark: '#11A8CD' },
|
|
70
|
+
purple: { light: '#BC05BC', dark: '#BC3FBC' },
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
/** Every hue of a theme, in a mode. */
|
|
74
|
+
export function hueColorsOf(variant, mode) {
|
|
75
|
+
const own = themeHueColors[variant] ?? {};
|
|
76
|
+
return Object.fromEntries(hueNames.map(name => [name, (own[name] ?? baseHueColors[name])[mode]]));
|
|
77
|
+
}
|
|
@@ -9,6 +9,7 @@ export { sunColors } from './sunColors';
|
|
|
9
9
|
export { loopColors } from './loopColors';
|
|
10
10
|
export { vscodeColors, vscodeVars, vscodeVar, vscodeTint, vscodeFontFamily, vscodeMonoFontFamily, vscodeFontSize, type VSCodeColor, type VSCodeVarName, } from './vscodeColors';
|
|
11
11
|
export { themeAccents, themeAccentNames, themeAccentVars, themeAccentTints, themeStageGradient, themeTintVars, type ThemeAccent, type ThemeAccentName, } from './themeAccents';
|
|
12
|
+
export { hueNames, baseHueColors, hueColorsOf, type HueName, type HueColor, } from './hueColors';
|
|
12
13
|
import type { ThemeVariant } from '../themeRegistry';
|
|
13
14
|
/**
|
|
14
15
|
* Themed color palettes — maps each `ThemeVariant` to its corresponding
|
|
@@ -13,6 +13,7 @@ export { sunColors } from './sunColors';
|
|
|
13
13
|
export { loopColors } from './loopColors';
|
|
14
14
|
export { vscodeColors, vscodeVars, vscodeVar, vscodeTint, vscodeFontFamily, vscodeMonoFontFamily, vscodeFontSize, } from './vscodeColors';
|
|
15
15
|
export { themeAccents, themeAccentNames, themeAccentVars, themeAccentTints, themeStageGradient, themeTintVars, } from './themeAccents';
|
|
16
|
+
export { hueNames, baseHueColors, hueColorsOf, } from './hueColors';
|
|
16
17
|
import { datalayerColors } from './datalayerColors';
|
|
17
18
|
import { spatialColors } from './spatialColors';
|
|
18
19
|
import { lovelyColors } from './lovelyColors';
|
|
@@ -1,5 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared palette types, theme-aware colour resolution, and reusable
|
|
3
|
+
* gradient / grid definitions.
|
|
4
|
+
*/
|
|
5
|
+
import { type HueName } from '../colors';
|
|
1
6
|
import { type ThemeVariant } from '../themeRegistry';
|
|
2
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The palette's role names: what each is changes with the theme (`surge` is
|
|
9
|
+
* blue in one theme and sage in another).
|
|
10
|
+
*/
|
|
11
|
+
export declare const paletteRoleNames: readonly ["bg", "bgPanel", "bgAlt", "primary", "secondary", "accent", "glow", "pop", "spark", "blaze", "surge", "flame", "gold", "textLight", "textMuted"];
|
|
12
|
+
/** A role name of the palette. */
|
|
13
|
+
export type PaletteRoleName = (typeof paletteRoleNames)[number];
|
|
14
|
+
/**
|
|
15
|
+
* Every name of the palette: its roles, then its hues (`hueNames`: `red`
|
|
16
|
+
* … `rose`, then `slate`, `gray`, `stone`, each in every theme). A spec's colour names one of
|
|
17
|
+
* these, and is drawn in the value the current theme and mode give it.
|
|
18
|
+
*
|
|
19
|
+
* This list is the one source of the names: agentspecs keeps a copy
|
|
20
|
+
* (`agentspecs/colors.py`), and its tests check the copy against this file.
|
|
21
|
+
*/
|
|
22
|
+
export declare const paletteColorNames: readonly ["bg", "bgPanel", "bgAlt", "primary", "secondary", "accent", "glow", "pop", "spark", "blaze", "surge", "flame", "gold", "textLight", "textMuted", "red", "orange", "amber", "yellow", "lime", "green", "emerald", "teal", "cyan", "sky", "blue", "indigo", "violet", "purple", "fuchsia", "pink", "rose", "slate", "gray", "stone"];
|
|
23
|
+
/** A name of the palette. */
|
|
24
|
+
export type PaletteColorName = PaletteRoleName | HueName;
|
|
25
|
+
export interface ColorPalette extends Record<HueName, string> {
|
|
3
26
|
bg: string;
|
|
4
27
|
bgPanel: string;
|
|
5
28
|
bgAlt: string;
|
|
@@ -18,6 +41,25 @@ export interface ColorPalette {
|
|
|
18
41
|
isLight: boolean;
|
|
19
42
|
}
|
|
20
43
|
export declare function getColorPalette(theme?: ThemeVariant, colorMode?: 'light' | 'dark' | 'auto'): ColorPalette;
|
|
44
|
+
/** A hex colour, `#RGB` or `#RRGGBB`: what a spec may give where no name fits. */
|
|
45
|
+
export declare const HEX_COLOR_PATTERN: RegExp;
|
|
46
|
+
/** Whether a value is a name of the palette. */
|
|
47
|
+
export declare const isPaletteColorName: (value: string) => value is PaletteColorName;
|
|
48
|
+
/** Whether a value is a hex colour, `#RGB` or `#RRGGBB`. */
|
|
49
|
+
export declare const isHexColor: (value: string) => boolean;
|
|
50
|
+
/**
|
|
51
|
+
* A spec's colour as a CSS colour in a palette: a name of the palette is
|
|
52
|
+
* the value the palette's theme and mode give it, a hex colour is itself.
|
|
53
|
+
* Nothing, an empty string or anything else is `undefined`: the caller
|
|
54
|
+
* draws its own default.
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolvePaletteColor(value: string | null | undefined, palette: ColorPalette): string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* `resolvePaletteColor` in the current theme and mode: a function that
|
|
59
|
+
* turns a spec's colour (a palette name, or a hex) into the CSS colour to
|
|
60
|
+
* draw, and is a new function when the theme or the mode changes.
|
|
61
|
+
*/
|
|
62
|
+
export declare function usePaletteColor(): (value: string | null | undefined) => string | undefined;
|
|
21
63
|
export declare function useColorPalette(): ColorPalette;
|
|
22
64
|
/** @deprecated Use `useColorPalette` instead. */
|
|
23
65
|
export declare const useBlogColorPalette: typeof useColorPalette;
|
|
@@ -7,9 +7,44 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
* Shared palette types, theme-aware colour resolution, and reusable
|
|
8
8
|
* gradient / grid definitions.
|
|
9
9
|
*/
|
|
10
|
-
import { datalayerColors, spatialColors, lovelyColors, matrixColors, earthColors, sandColors, ivoryColors, sunColors, loopColors, vscodeColors, } from '../colors';
|
|
10
|
+
import { datalayerColors, spatialColors, lovelyColors, matrixColors, earthColors, sandColors, ivoryColors, sunColors, loopColors, vscodeColors, hueColorsOf, hueNames, } from '../colors';
|
|
11
11
|
import { getBrightPalette, } from '../themeRegistry';
|
|
12
|
+
import { useCallback } from 'react';
|
|
12
13
|
import { useThemeStore } from '../useThemeStore';
|
|
14
|
+
/**
|
|
15
|
+
* The palette's role names: what each is changes with the theme (`surge` is
|
|
16
|
+
* blue in one theme and sage in another).
|
|
17
|
+
*/
|
|
18
|
+
export const paletteRoleNames = [
|
|
19
|
+
'bg',
|
|
20
|
+
'bgPanel',
|
|
21
|
+
'bgAlt',
|
|
22
|
+
'primary',
|
|
23
|
+
'secondary',
|
|
24
|
+
'accent',
|
|
25
|
+
'glow',
|
|
26
|
+
'pop',
|
|
27
|
+
'spark',
|
|
28
|
+
'blaze',
|
|
29
|
+
'surge',
|
|
30
|
+
'flame',
|
|
31
|
+
'gold',
|
|
32
|
+
'textLight',
|
|
33
|
+
'textMuted',
|
|
34
|
+
];
|
|
35
|
+
/**
|
|
36
|
+
* Every name of the palette: its roles, then its hues (`hueNames`: `red`
|
|
37
|
+
* … `rose`, then `slate`, `gray`, `stone`, each in every theme). A spec's colour names one of
|
|
38
|
+
* these, and is drawn in the value the current theme and mode give it.
|
|
39
|
+
*
|
|
40
|
+
* This list is the one source of the names: agentspecs keeps a copy
|
|
41
|
+
* (`agentspecs/colors.py`), and its tests check the copy against this file.
|
|
42
|
+
*/
|
|
43
|
+
// palette-color-names:start
|
|
44
|
+
export const paletteColorNames = [
|
|
45
|
+
...paletteRoleNames,
|
|
46
|
+
...hueNames,
|
|
47
|
+
];
|
|
13
48
|
const dlBrightDark = getBrightPalette('datalayer');
|
|
14
49
|
const dlBrightLight = getBrightPalette('datalayer', 'light');
|
|
15
50
|
const spBrightDark = getBrightPalette('spatial');
|
|
@@ -30,7 +65,7 @@ const loBrightDark = getBrightPalette('loop');
|
|
|
30
65
|
const loBrightLight = getBrightPalette('loop', 'light');
|
|
31
66
|
const vsBrightDark = getBrightPalette('vscode');
|
|
32
67
|
const vsBrightLight = getBrightPalette('vscode', 'light');
|
|
33
|
-
const
|
|
68
|
+
const rolePalettes = {
|
|
34
69
|
datalayer: {
|
|
35
70
|
light: {
|
|
36
71
|
bg: '#f6f8fa',
|
|
@@ -412,15 +447,55 @@ const palettes = {
|
|
|
412
447
|
},
|
|
413
448
|
},
|
|
414
449
|
};
|
|
450
|
+
/** Each theme's roles with its hues, light and dark. */
|
|
451
|
+
const palettes = Object.fromEntries(Object.keys(rolePalettes).map(variant => [
|
|
452
|
+
variant,
|
|
453
|
+
{
|
|
454
|
+
light: { ...rolePalettes[variant].light, ...hueColorsOf(variant, 'light') },
|
|
455
|
+
dark: { ...rolePalettes[variant].dark, ...hueColorsOf(variant, 'dark') },
|
|
456
|
+
},
|
|
457
|
+
]));
|
|
415
458
|
export function getColorPalette(theme = 'datalayer', colorMode = 'auto') {
|
|
416
459
|
const mode = colorMode === 'auto'
|
|
417
460
|
? typeof window !== 'undefined' &&
|
|
461
|
+
typeof window.matchMedia === 'function' &&
|
|
418
462
|
window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
419
463
|
? 'dark'
|
|
420
464
|
: 'light'
|
|
421
465
|
: colorMode;
|
|
422
466
|
return palettes[theme]?.[mode] ?? palettes.datalayer.dark;
|
|
423
467
|
}
|
|
468
|
+
const PALETTE_NAMES = new Set(paletteColorNames);
|
|
469
|
+
/** A hex colour, `#RGB` or `#RRGGBB`: what a spec may give where no name fits. */
|
|
470
|
+
export const HEX_COLOR_PATTERN = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
471
|
+
/** Whether a value is a name of the palette. */
|
|
472
|
+
export const isPaletteColorName = (value) => PALETTE_NAMES.has(value);
|
|
473
|
+
/** Whether a value is a hex colour, `#RGB` or `#RRGGBB`. */
|
|
474
|
+
export const isHexColor = (value) => HEX_COLOR_PATTERN.test(value);
|
|
475
|
+
/**
|
|
476
|
+
* A spec's colour as a CSS colour in a palette: a name of the palette is
|
|
477
|
+
* the value the palette's theme and mode give it, a hex colour is itself.
|
|
478
|
+
* Nothing, an empty string or anything else is `undefined`: the caller
|
|
479
|
+
* draws its own default.
|
|
480
|
+
*/
|
|
481
|
+
export function resolvePaletteColor(value, palette) {
|
|
482
|
+
if (!value) {
|
|
483
|
+
return undefined;
|
|
484
|
+
}
|
|
485
|
+
if (isPaletteColorName(value)) {
|
|
486
|
+
return palette[value];
|
|
487
|
+
}
|
|
488
|
+
return isHexColor(value) ? value : undefined;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* `resolvePaletteColor` in the current theme and mode: a function that
|
|
492
|
+
* turns a spec's colour (a palette name, or a hex) into the CSS colour to
|
|
493
|
+
* draw, and is a new function when the theme or the mode changes.
|
|
494
|
+
*/
|
|
495
|
+
export function usePaletteColor() {
|
|
496
|
+
const palette = useColorPalette();
|
|
497
|
+
return useCallback(value => resolvePaletteColor(value, palette), [palette]);
|
|
498
|
+
}
|
|
424
499
|
export function useColorPalette() {
|
|
425
500
|
const { colorMode, theme } = useThemeStore();
|
|
426
501
|
return getColorPalette(theme, colorMode);
|