@datalayer/primer-addons 1.0.49 → 1.0.51
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/README.md +32 -0
- package/lib/components/appearance/AppearanceControls.d.ts +38 -9
- package/lib/components/appearance/AppearanceControls.js +56 -31
- package/lib/components/appearance/AppearanceControls.stories.d.ts +4 -3
- package/lib/components/appearance/AppearanceControls.stories.js +15 -12
- package/lib/components/appearance/AppearanceMenu.js +1 -1
- package/lib/components/appearance/AppearanceMenuWithStore.d.ts +1 -1
- package/lib/components/appearance/AppearanceMenuWithStore.js +1 -1
- package/lib/components/appearance/ColorModeCircle.d.ts +0 -1
- package/lib/components/appearance/ColorModeCircle.js +32 -2
- package/lib/components/appearance/ColorModeCircle.stories.js +1 -1
- package/lib/components/appearance/ThemePalettePreview.js +2 -9
- package/lib/components/appearance/ThemePreviewCard.js +9 -37
- package/lib/components/appearance/index.d.ts +0 -1
- package/lib/components/appearance/index.js +0 -1
- package/lib/components/icons/CircleIcon.d.ts +13 -3
- package/lib/components/icons/CircleIcon.js +28 -9
- package/lib/components/icons/CircleIcon.stories.d.ts +1 -1
- package/lib/components/index.d.ts +1 -1
- package/lib/components/index.js +1 -1
- package/lib/components/scroll-area/ScrollArea.d.ts +46 -0
- package/lib/components/scroll-area/ScrollArea.js +32 -0
- package/lib/components/scroll-area/index.d.ts +1 -0
- package/lib/components/scroll-area/index.js +5 -0
- package/lib/components/toolbar/Toolbar.d.ts +11 -2
- package/lib/components/toolbar/Toolbar.js +0 -0
- package/lib/components/toolbar/types.d.ts +51 -0
- package/package.json +1 -1
- package/lib/components/appearance/AppearanceControlsWithStore.d.ts +0 -12
- package/lib/components/appearance/AppearanceControlsWithStore.js +0 -21
package/README.md
CHANGED
|
@@ -40,6 +40,38 @@ visual values. For example, toolbar icon buttons and dropdown triggers read
|
|
|
40
40
|
`--theme-radius-control`: they retain the regular Primer corner in the default
|
|
41
41
|
themes and become fully rounded controls in `loop`.
|
|
42
42
|
|
|
43
|
+
### Toolbar overflow
|
|
44
|
+
|
|
45
|
+
`Toolbar` keeps to one line: what does not fit moves into a menu behind a
|
|
46
|
+
"…" button at the end of the line, measured with a `ResizeObserver` on the
|
|
47
|
+
toolbar, its parent and every item (an item that draws nothing takes no room).
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
<Toolbar
|
|
51
|
+
variant="inline" // no ground, border or padding: inside a header row of yours
|
|
52
|
+
gap={4}
|
|
53
|
+
items={[
|
|
54
|
+
{ key: 'lead', type: 'spacer' }, // push the actions to the trailing edge
|
|
55
|
+
{ key: 'chip', type: 'custom', priority: -1, render: () => <Label>Connected</Label>,
|
|
56
|
+
overflow: { label: 'Connected', onSelect: openAccounts } }, // a row in the menu
|
|
57
|
+
{ key: 'new', type: 'button', icon: PlusIcon, ariaLabel: 'New chat', onClick: newChat },
|
|
58
|
+
{ key: 'close', type: 'button', icon: XIcon, ariaLabel: 'Close', pinned: true, onClick: close },
|
|
59
|
+
]}
|
|
60
|
+
/>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- `pinned: true` never leaves the line; `priority` orders who leaves first
|
|
64
|
+
(lowest first, then the last on the line); the menu lists them in line order.
|
|
65
|
+
- In the menu a button shows its icon and name and closes the menu once
|
|
66
|
+
chosen; a custom item becomes its `overflow` — `{ label, icon, onSelect }`
|
|
67
|
+
(a row), `{ render }` (a node of its own) — or itself when it has none.
|
|
68
|
+
- Arrow keys, Home and End move the focus between the controls
|
|
69
|
+
(`keyboardNavigation={false}` to opt out); `overflowAriaLabel` names the
|
|
70
|
+
"…" button; `overflow={false}` lays every item on the line.
|
|
71
|
+
- In a row with other things, wrap the toolbar in a box of its own
|
|
72
|
+
(`flex: 1 1 0; min-width: 0`): that box's width is the room it measures.
|
|
73
|
+
- The gallery's *Toolbar* page shows an editor strip and a header row narrowing.
|
|
74
|
+
|
|
43
75
|
## Reactor Plugins
|
|
44
76
|
|
|
45
77
|
Three plugins for hosts built on [`@datalayer/reactor`](https://github.com/datalayer/reactor), imported by path so a page without a reactor never pulls it in:
|
|
@@ -1,22 +1,51 @@
|
|
|
1
1
|
import { type ReactElement } from "react";
|
|
2
|
+
import type { StoreApi, UseBoundStore } from "zustand";
|
|
3
|
+
import { type ThemeState } from "../../theme/useThemeStore";
|
|
2
4
|
import { type ColorMode, type ThemeVariant } from "../../theme";
|
|
5
|
+
/**
|
|
6
|
+
* How the controls are laid out:
|
|
7
|
+
* - `stacked` — the light / dark / auto switch centred above the theme
|
|
8
|
+
* swatches (lines of `themesPerLine`), optionally the chosen theme's
|
|
9
|
+
* preview under them: the appearance menu's panel.
|
|
10
|
+
* - `inline` — one row: a small round button per theme, then the switch: a
|
|
11
|
+
* page header's trailing controls.
|
|
12
|
+
*/
|
|
13
|
+
export type AppearanceControlsLayout = "stacked" | "inline";
|
|
3
14
|
export interface AppearanceControlsProps {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Read and write the theme store, on by default; `false` to drive the
|
|
17
|
+
* controls from `colorMode`, `themeVariant` and the two callbacks alone.
|
|
18
|
+
*/
|
|
19
|
+
withStore?: boolean;
|
|
20
|
+
/** The store read and written with `withStore`: the shared one by default. */
|
|
21
|
+
useStore?: UseBoundStore<StoreApi<ThemeState>>;
|
|
22
|
+
/**
|
|
23
|
+
* With the store, whether choosing a theme also switches to its default
|
|
24
|
+
* colour mode. Off by default: a person who chose dark keeps dark.
|
|
25
|
+
*/
|
|
26
|
+
applyThemeColorMode?: boolean;
|
|
27
|
+
/** The colour mode shown; required without the store, the store's otherwise. */
|
|
28
|
+
colorMode?: ColorMode;
|
|
29
|
+
/** The theme shown; required without the store, the store's otherwise. */
|
|
30
|
+
themeVariant?: ThemeVariant;
|
|
31
|
+
/** Called on a new colour mode; required without the store, called after it with the store. */
|
|
32
|
+
onColorModeChange?: (mode: ColorMode) => void;
|
|
33
|
+
/** Called on a new theme; required without the store, called after it with the store. */
|
|
34
|
+
onThemeChange?: (theme: ThemeVariant) => void;
|
|
35
|
+
/** `stacked` by default; see {@link AppearanceControlsLayout}. */
|
|
36
|
+
layout?: AppearanceControlsLayout;
|
|
8
37
|
/** Show the light / dark / auto switch. Default: shown. */
|
|
9
38
|
showColorMode?: boolean;
|
|
10
39
|
/** Show the theme chooser. Default: shown. */
|
|
11
40
|
showThemeChooser?: boolean;
|
|
12
|
-
/**
|
|
41
|
+
/** Stacked, with the chooser: the chosen theme's name, description and preview under its swatches. Default: swatches only. */
|
|
13
42
|
showThemePreviews?: boolean;
|
|
14
43
|
/**
|
|
15
|
-
*
|
|
16
|
-
* last line sits in the middle under the full ones. Undefined,
|
|
17
|
-
* freely to the width given
|
|
44
|
+
* Stacked: the most theme swatches on one line; every line is centred, so
|
|
45
|
+
* a shorter last line sits in the middle under the full ones. Undefined,
|
|
46
|
+
* they wrap freely to the width given.
|
|
18
47
|
*/
|
|
19
48
|
themesPerLine?: number;
|
|
20
49
|
}
|
|
21
|
-
export declare function AppearanceControls({ colorMode, themeVariant, onColorModeChange, onThemeChange, showColorMode, showThemeChooser, showThemePreviews, themesPerLine, }: AppearanceControlsProps): ReactElement;
|
|
50
|
+
export declare function AppearanceControls({ withStore, useStore, applyThemeColorMode, colorMode: givenColorMode, themeVariant: givenThemeVariant, onColorModeChange: givenOnColorModeChange, onThemeChange: givenOnThemeChange, layout, showColorMode, showThemeChooser, showThemePreviews, themesPerLine, }: AppearanceControlsProps): ReactElement;
|
|
22
51
|
export default AppearanceControls;
|
|
@@ -1,16 +1,48 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c) 2023-
|
|
3
|
+
* Copyright (c) 2023-2026 Datalayer, Inc.
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
5
5
|
*/
|
|
6
6
|
import { useState } from "react";
|
|
7
|
-
import { SegmentedControl, Tooltip } from "@primer/react";
|
|
8
|
-
import { MoonIcon, SunIcon,
|
|
7
|
+
import { Button, IconButton, SegmentedControl, Tooltip } from "@primer/react";
|
|
8
|
+
import { CircleIcon as SwatchIcon, DeviceDesktopIcon, MoonIcon, SunIcon, } from "@primer/octicons-react";
|
|
9
9
|
import { Box } from "../box/Box";
|
|
10
|
+
import { useThemeStore } from "../../theme/useThemeStore";
|
|
10
11
|
import { themeVariants, themeConfigs, } from "../../theme";
|
|
11
12
|
import { ThemePreviewCard } from "./ThemePreviewCard";
|
|
12
13
|
import { ThemePalettePreview } from "./ThemePalettePreview";
|
|
13
|
-
export function AppearanceControls({ colorMode, themeVariant, onColorModeChange, onThemeChange, showColorMode = true, showThemeChooser = true, showThemePreviews = false, themesPerLine, }) {
|
|
14
|
+
export function AppearanceControls({ withStore = true, useStore = useThemeStore, applyThemeColorMode = false, colorMode: givenColorMode, themeVariant: givenThemeVariant, onColorModeChange: givenOnColorModeChange, onThemeChange: givenOnThemeChange, layout = "stacked", showColorMode = true, showThemeChooser = true, showThemePreviews = false, themesPerLine, }) {
|
|
15
|
+
// The store is read whatever `withStore` says: a hook is called on every render.
|
|
16
|
+
const storeColorMode = useStore((state) => state.colorMode);
|
|
17
|
+
const storeTheme = useStore((state) => state.theme);
|
|
18
|
+
let colorMode;
|
|
19
|
+
let themeVariant;
|
|
20
|
+
let onColorModeChange;
|
|
21
|
+
let onThemeChange;
|
|
22
|
+
if (withStore) {
|
|
23
|
+
colorMode = storeColorMode;
|
|
24
|
+
themeVariant = storeTheme;
|
|
25
|
+
onColorModeChange = (mode) => {
|
|
26
|
+
useStore.getState().setColorMode(mode);
|
|
27
|
+
givenOnColorModeChange?.(mode);
|
|
28
|
+
};
|
|
29
|
+
onThemeChange = (theme) => {
|
|
30
|
+
useStore.getState().setTheme(theme, applyThemeColorMode);
|
|
31
|
+
givenOnThemeChange?.(theme);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
if (givenColorMode === undefined ||
|
|
36
|
+
givenThemeVariant === undefined ||
|
|
37
|
+
!givenOnColorModeChange ||
|
|
38
|
+
!givenOnThemeChange) {
|
|
39
|
+
throw new Error("AppearanceControls without the store needs colorMode, themeVariant, onColorModeChange and onThemeChange.");
|
|
40
|
+
}
|
|
41
|
+
colorMode = givenColorMode;
|
|
42
|
+
themeVariant = givenThemeVariant;
|
|
43
|
+
onColorModeChange = givenOnColorModeChange;
|
|
44
|
+
onThemeChange = givenOnThemeChange;
|
|
45
|
+
}
|
|
14
46
|
// At most `themesPerLine` swatches on a line when given, each line centred,
|
|
15
47
|
// so a shorter last line sits in the middle under the full ones; one line
|
|
16
48
|
// wrapping freely otherwise. Explicit lines rather than a width: the
|
|
@@ -27,10 +59,23 @@ export function AppearanceControls({ colorMode, themeVariant, onColorModeChange,
|
|
|
27
59
|
};
|
|
28
60
|
const [isPreviewOpen, setIsPreviewOpen] = useState(false);
|
|
29
61
|
const selectedTheme = themeConfigs[themeVariant];
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
62
|
+
const colorModeSwitch = (_jsxs(SegmentedControl, { "aria-label": "Color mode", size: "small", onChange: (index) => {
|
|
63
|
+
const modes = ["light", "dark", "auto"];
|
|
64
|
+
onColorModeChange(modes[index]);
|
|
65
|
+
}, 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" })] }));
|
|
66
|
+
if (layout === "inline") {
|
|
67
|
+
// One row, as a page header carries it: a round button per theme, then the switch.
|
|
68
|
+
return (_jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 3 }, children: [showThemeChooser ? (_jsx(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: themeVariants.map((variant) => {
|
|
69
|
+
const cfg = themeConfigs[variant];
|
|
70
|
+
const isSelected = themeVariant === variant;
|
|
71
|
+
return (_jsx(Tooltip, { text: cfg.label, direction: "s", children: _jsx(IconButton, { "aria-label": cfg.label, "aria-pressed": isSelected, icon: () => _jsx(SwatchIcon, { size: 16, fill: cfg.brandColor }), size: "small", variant: isSelected ? "default" : "invisible", onClick: () => onThemeChange(variant), sx: {
|
|
72
|
+
border: isSelected ? "2px solid" : "1px solid",
|
|
73
|
+
borderColor: isSelected ? "accent.fg" : "border.muted",
|
|
74
|
+
borderRadius: "50%",
|
|
75
|
+
} }) }, variant));
|
|
76
|
+
}) })) : null, showColorMode ? colorModeSwitch : null] }));
|
|
77
|
+
}
|
|
78
|
+
return (_jsxs(_Fragment, { children: [showColorMode ? (_jsx(Box, { sx: { px: 2, py: 2, display: "flex", justifyContent: "center" }, children: colorModeSwitch })) : null, !showThemeChooser ? null : showThemePreviews ? (_jsxs(Box, { sx: {
|
|
34
79
|
px: 2,
|
|
35
80
|
// First in the controls when the colour mode is hidden.
|
|
36
81
|
pt: showColorMode ? 0 : 2,
|
|
@@ -71,29 +116,9 @@ export function AppearanceControls({ colorMode, themeVariant, onColorModeChange,
|
|
|
71
116
|
px: 1,
|
|
72
117
|
display: "grid",
|
|
73
118
|
gap: 1,
|
|
74
|
-
}, 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, {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
px: 2,
|
|
78
|
-
py: "4px",
|
|
79
|
-
borderRadius: 2,
|
|
80
|
-
border: "1px solid",
|
|
81
|
-
borderColor: "border.default",
|
|
82
|
-
bg: "canvas.default",
|
|
83
|
-
color: "fg.default",
|
|
84
|
-
fontSize: 0,
|
|
85
|
-
fontWeight: "semibold",
|
|
86
|
-
cursor: "pointer",
|
|
87
|
-
"&:hover": {
|
|
88
|
-
borderColor: "accent.fg",
|
|
89
|
-
color: "accent.fg",
|
|
90
|
-
},
|
|
91
|
-
"&:focus-visible": {
|
|
92
|
-
outline: "2px solid",
|
|
93
|
-
outlineColor: "accent.fg",
|
|
94
|
-
outlineOffset: 1,
|
|
95
|
-
},
|
|
96
|
-
}, children: isPreviewOpen ? "Hide preview" : "Show preview" })] }), isPreviewOpen ? (_jsxs(_Fragment, { children: [_jsx(ThemePreviewCard, { variant: themeVariant, colorMode: colorMode, compact: true, showDescription: true }), _jsx(ThemePalettePreview, { variant: themeVariant, colorMode: colorMode })] })) : null] })) : (_jsx(Box, { sx: {
|
|
119
|
+
}, 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, { sx: { mt: 1 }, children: _jsx(Button, { size: "small", onClick: () => setIsPreviewOpen((open) => !open), "aria-expanded": isPreviewOpen,
|
|
120
|
+
// The theme's control corner (Loop's pill), wherever the menu is drawn.
|
|
121
|
+
sx: { borderRadius: "var(--theme-radius-control, 6px)" }, children: isPreviewOpen ? "Hide preview" : "Show preview" }) })] }), isPreviewOpen ? (_jsxs(_Fragment, { children: [_jsx(ThemePreviewCard, { variant: themeVariant, colorMode: colorMode, compact: true, showDescription: true }), _jsx(ThemePalettePreview, { variant: themeVariant, colorMode: colorMode })] })) : null] })) : (_jsx(Box, { sx: {
|
|
97
122
|
px: 2,
|
|
98
123
|
// First in the controls when the colour mode is hidden.
|
|
99
124
|
pt: showColorMode ? 0 : 2,
|
|
@@ -45,8 +45,9 @@ export declare const ColorModeOnly: Story;
|
|
|
45
45
|
/** The theme chooser alone. */
|
|
46
46
|
export declare const ThemeChooserOnly: Story;
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* `ThemedProvider` from that store.
|
|
48
|
+
* With the store (the default): the controls read and write a theme store
|
|
49
|
+
* (`useThemeStore` here), the story drawn by `ThemedProvider` from it.
|
|
51
50
|
*/
|
|
52
51
|
export declare const WithStore: Story;
|
|
52
|
+
/** Inline, with the store: one round button per theme, then the switch, as a page header carries them. */
|
|
53
|
+
export declare const Inline: Story;
|
|
@@ -5,7 +5,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
5
5
|
*/
|
|
6
6
|
import { useEffect, useState } from "react";
|
|
7
7
|
import { Box, Text } from "@primer/react";
|
|
8
|
-
import { AppearanceControls,
|
|
8
|
+
import { AppearanceControls, DatalayerThemeProvider, ThemedProvider, themeConfigs, themeVariants, useThemeStore, } from "../..";
|
|
9
9
|
const meta = {
|
|
10
10
|
title: "Components/Appearance/AppearanceControls",
|
|
11
11
|
component: AppearanceControls,
|
|
@@ -42,21 +42,21 @@ export default meta;
|
|
|
42
42
|
* re-themes the story around the controls.
|
|
43
43
|
*/
|
|
44
44
|
const ThemedAppearanceControls = (props) => {
|
|
45
|
-
const [colorMode, setColorMode] = useState(props.colorMode);
|
|
46
|
-
const [themeVariant, setThemeVariant] = useState(props.themeVariant);
|
|
47
|
-
useEffect(() => setColorMode(props.colorMode), [props.colorMode]);
|
|
48
|
-
useEffect(() => setThemeVariant(props.themeVariant), [props.themeVariant]);
|
|
45
|
+
const [colorMode, setColorMode] = useState(props.colorMode ?? "light");
|
|
46
|
+
const [themeVariant, setThemeVariant] = useState(props.themeVariant ?? "datalayer");
|
|
47
|
+
useEffect(() => setColorMode(props.colorMode ?? "light"), [props.colorMode]);
|
|
48
|
+
useEffect(() => setThemeVariant(props.themeVariant ?? "datalayer"), [props.themeVariant]);
|
|
49
49
|
const config = themeConfigs[themeVariant];
|
|
50
50
|
return (_jsx(DatalayerThemeProvider, { colorMode: colorMode, theme: config.primerTheme, themeStyles: config.themeStyles, children: _jsxs(Box, { p: 3, bg: "canvas.default", children: [_jsx(Box, { maxWidth: 360, sx: {
|
|
51
51
|
border: "1px solid",
|
|
52
52
|
borderColor: "border.default",
|
|
53
53
|
borderRadius: 2,
|
|
54
|
-
}, children: _jsx(AppearanceControls, { ...props, colorMode: colorMode, themeVariant: themeVariant, onColorModeChange: (mode) => {
|
|
54
|
+
}, children: _jsx(AppearanceControls, { ...props, withStore: false, colorMode: colorMode, themeVariant: themeVariant, onColorModeChange: (mode) => {
|
|
55
55
|
setColorMode(mode);
|
|
56
|
-
props.onColorModeChange(mode);
|
|
56
|
+
props.onColorModeChange?.(mode);
|
|
57
57
|
}, onThemeChange: (variant) => {
|
|
58
58
|
setThemeVariant(variant);
|
|
59
|
-
props.onThemeChange(variant);
|
|
59
|
+
props.onThemeChange?.(variant);
|
|
60
60
|
} }) }), _jsxs(Text, { as: "p", sx: { mt: 2, fontSize: 0, color: "fg.muted" }, children: [config.label, ", ", colorMode, ": ", config.description] })] }) }));
|
|
61
61
|
};
|
|
62
62
|
/** Both parts, the theme as one swatch per theme (the default). */
|
|
@@ -85,10 +85,13 @@ export const ThemeChooserOnly = {
|
|
|
85
85
|
render: (args) => _jsx(ThemedAppearanceControls, { ...args }),
|
|
86
86
|
};
|
|
87
87
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* `ThemedProvider` from that store.
|
|
88
|
+
* With the store (the default): the controls read and write a theme store
|
|
89
|
+
* (`useThemeStore` here), the story drawn by `ThemedProvider` from it.
|
|
91
90
|
*/
|
|
92
91
|
export const WithStore = {
|
|
93
|
-
render: (args) => (_jsx(ThemedProvider, { useStore: useThemeStore, children: _jsx(Box, { p: 3, bg: "canvas.default", maxWidth: 400, children: _jsx(
|
|
92
|
+
render: (args) => (_jsx(ThemedProvider, { useStore: useThemeStore, children: _jsx(Box, { p: 3, bg: "canvas.default", maxWidth: 400, children: _jsx(AppearanceControls, { useStore: useThemeStore, showColorMode: args.showColorMode, showThemeChooser: args.showThemeChooser, showThemePreviews: args.showThemePreviews }) }) })),
|
|
93
|
+
};
|
|
94
|
+
/** Inline, with the store: one round button per theme, then the switch, as a page header carries them. */
|
|
95
|
+
export const Inline = {
|
|
96
|
+
render: (args) => (_jsx(ThemedProvider, { useStore: useThemeStore, children: _jsx(Box, { p: 3, bg: "canvas.default", children: _jsx(AppearanceControls, { layout: "inline", useStore: useThemeStore, showColorMode: args.showColorMode, showThemeChooser: args.showThemeChooser }) }) })),
|
|
94
97
|
};
|
|
@@ -10,6 +10,6 @@ import { AppearanceControls } from './AppearanceControls';
|
|
|
10
10
|
* dropped into any header with a single component.
|
|
11
11
|
*/
|
|
12
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 }) }));
|
|
13
|
+
return (_jsx(ColorModeCircle, { colorMode: colorMode, onColorModeChange: onColorModeChange, cycleOnClick: false, themeVariant: themeVariant, hoverOverlayPlacement: hoverOverlayPlacement, shape: shape, size: size, hoverOverlay: _jsx(AppearanceControls, { withStore: false, colorMode: colorMode, themeVariant: themeVariant, onColorModeChange: onColorModeChange, onThemeChange: onThemeChange, showThemePreviews: showThemePreviews, themesPerLine: themesPerLine }) }));
|
|
14
14
|
}
|
|
15
15
|
export default AppearanceMenu;
|
|
@@ -19,7 +19,7 @@ export interface AppearanceMenuWithStoreProps extends Omit<AppearanceMenuProps,
|
|
|
19
19
|
* The menu itself is controlled: a page with its own idea of where the theme
|
|
20
20
|
* lives hands it values and callbacks. Most pages have no such idea — the
|
|
21
21
|
* theme lives in the store — and this reads it from there and writes the
|
|
22
|
-
* choices back. The same shape as {@link
|
|
22
|
+
* choices back. The same shape as {@link AppearanceControls} with its store, for
|
|
23
23
|
* the whole menu: the trigger, the overlay, the description, the preview.
|
|
24
24
|
*/
|
|
25
25
|
export declare function AppearanceMenuWithStore({ useStore, applyThemeColorMode, ...menu }: AppearanceMenuWithStoreProps): ReactElement;
|
|
@@ -8,7 +8,7 @@ import { AppearanceMenu } from './AppearanceMenu';
|
|
|
8
8
|
* The menu itself is controlled: a page with its own idea of where the theme
|
|
9
9
|
* lives hands it values and callbacks. Most pages have no such idea — the
|
|
10
10
|
* theme lives in the store — and this reads it from there and writes the
|
|
11
|
-
* choices back. The same shape as {@link
|
|
11
|
+
* choices back. The same shape as {@link AppearanceControls} with its store, for
|
|
12
12
|
* the whole menu: the trigger, the overlay, the description, the preview.
|
|
13
13
|
*/
|
|
14
14
|
export function AppearanceMenuWithStore({ useStore = useThemeStore, applyThemeColorMode = false, ...menu }) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type ReactElement, type ReactNode } from 'react';
|
|
2
2
|
import { type ColorMode, type ThemeVariant } from '../../theme';
|
|
3
|
-
/** Where the hover overlay opens: under the circle (aligned at its start or end), or to its right, aligned at its top. */
|
|
4
3
|
export type HoverOverlayPlacement = 'bottom-start' | 'bottom-end' | 'right-start';
|
|
5
4
|
type ColorModeCircleShape = 'square' | 'circle';
|
|
6
5
|
export interface ColorModeCircleProps {
|
|
@@ -3,10 +3,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
5
5
|
*/
|
|
6
|
-
import { useEffect, useRef, useState } from 'react';
|
|
6
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
7
7
|
import { IconButton, Tooltip } from '@primer/react';
|
|
8
8
|
import { MoonIcon, SunIcon, DeviceDesktopIcon } from '@primer/octicons-react';
|
|
9
9
|
import { Box } from '../box/Box';
|
|
10
|
+
import { thinScrollbarSx } from '../scroll-area/ScrollArea';
|
|
10
11
|
import { themeConfigs } from '../../theme';
|
|
11
12
|
/** Order in which a click cycles through the color modes. */
|
|
12
13
|
const COLOR_MODE_CYCLE = {
|
|
@@ -26,6 +27,9 @@ const COLOR_MODE_ICON_Y_OFFSET = {
|
|
|
26
27
|
dark: 0,
|
|
27
28
|
auto: -0.5,
|
|
28
29
|
};
|
|
30
|
+
/** Where the hover overlay opens: under the circle (aligned at its start or end), or to its right, aligned at its top. */
|
|
31
|
+
/** The space kept between the panel and the window's bottom edge, in pixels. */
|
|
32
|
+
const OVERLAY_MARGIN = 12;
|
|
29
33
|
/**
|
|
30
34
|
* A single clickable circle that cycles the color mode through
|
|
31
35
|
* light → dark → system (auto). The icon reflects the current mode.
|
|
@@ -38,6 +42,27 @@ export function ColorModeCircle({ colorMode, onColorModeChange, size = 28, hover
|
|
|
38
42
|
const iconYOffset = COLOR_MODE_ICON_Y_OFFSET[colorMode] ?? 0;
|
|
39
43
|
const [isHoverOpen, setIsHoverOpen] = useState(false);
|
|
40
44
|
const closeTimerRef = useRef(null);
|
|
45
|
+
// The panel never runs past the window: it is held to the room under its
|
|
46
|
+
// top, measured each time it opens and when the window changes, and scrolls
|
|
47
|
+
// inside — Show preview's palette and accents stay reachable.
|
|
48
|
+
const overlayRef = useRef(null);
|
|
49
|
+
const [overlayMaxHeight, setOverlayMaxHeight] = useState(undefined);
|
|
50
|
+
useLayoutEffect(() => {
|
|
51
|
+
if (!isHoverOpen || typeof window === 'undefined') {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const measure = () => {
|
|
55
|
+
const node = overlayRef.current;
|
|
56
|
+
if (!node) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const top = Math.max(0, node.getBoundingClientRect().top);
|
|
60
|
+
setOverlayMaxHeight(Math.max(200, Math.floor(window.innerHeight - top - OVERLAY_MARGIN)));
|
|
61
|
+
};
|
|
62
|
+
measure();
|
|
63
|
+
window.addEventListener('resize', measure);
|
|
64
|
+
return () => window.removeEventListener('resize', measure);
|
|
65
|
+
}, [isHoverOpen]);
|
|
41
66
|
const isBottomStart = hoverOverlayPlacement === 'bottom-start';
|
|
42
67
|
const isRight = hoverOverlayPlacement === 'right-start';
|
|
43
68
|
const themeConfig = themeVariant ? themeConfigs[themeVariant] : undefined;
|
|
@@ -113,7 +138,7 @@ export function ColorModeCircle({ colorMode, onColorModeChange, size = 28, hover
|
|
|
113
138
|
if (!hoverOverlay) {
|
|
114
139
|
return (_jsx(Tooltip, { text: `Color mode: ${meta.label} — click for ${nextMeta.label}`, direction: "s", children: circle }));
|
|
115
140
|
}
|
|
116
|
-
return (_jsxs(Box, { sx: { position: 'relative', display: 'inline-flex', alignItems: 'center' }, onMouseEnter: openHoverOverlay, onMouseLeave: scheduleCloseHoverOverlay, children: [circle, _jsx(Box, { sx: {
|
|
141
|
+
return (_jsxs(Box, { sx: { position: 'relative', display: 'inline-flex', alignItems: 'center' }, onMouseEnter: openHoverOverlay, onMouseLeave: scheduleCloseHoverOverlay, children: [circle, _jsx(Box, { ref: overlayRef, "data-appearance-overlay": "", sx: {
|
|
117
142
|
position: 'absolute',
|
|
118
143
|
// To the right: beside the circle, its top level with the circle's.
|
|
119
144
|
top: isRight ? 0 : `calc(100% + 8px)`,
|
|
@@ -121,6 +146,11 @@ export function ColorModeCircle({ colorMode, onColorModeChange, size = 28, hover
|
|
|
121
146
|
right: isRight || isBottomStart ? 'auto' : 0,
|
|
122
147
|
zIndex: 220,
|
|
123
148
|
minWidth: 340,
|
|
149
|
+
maxHeight: overlayMaxHeight ?? `calc(100vh - ${OVERLAY_MARGIN * 2}px)`,
|
|
150
|
+
overflowY: 'auto',
|
|
151
|
+
overscrollBehavior: 'contain',
|
|
152
|
+
// The tiny scrollbar, as the left sidebar's (13 November 2026).
|
|
153
|
+
...thinScrollbarSx,
|
|
124
154
|
bg: 'canvas.overlay',
|
|
125
155
|
border: '1px solid',
|
|
126
156
|
borderColor: 'border.default',
|
|
@@ -54,7 +54,7 @@ const ThemedColorModeCircle = ({ withOverlay = false, ...props }) => {
|
|
|
54
54
|
setColorMode(mode);
|
|
55
55
|
props.onColorModeChange(mode);
|
|
56
56
|
};
|
|
57
|
-
return (_jsx(Box, { p: 3, bg: "canvas.default", minHeight: withOverlay ? 360 : undefined, children: _jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 3 }, children: [_jsx(ColorModeCircle, { ...props, colorMode: colorMode, themeVariant: themeVariant, onColorModeChange: onColorModeChange, hoverOverlay: withOverlay ? (_jsx(AppearanceControls, { colorMode: colorMode, themeVariant: themeVariant, onColorModeChange: onColorModeChange, onThemeChange: setThemeVariant })) : undefined }), _jsx(Text, { sx: { fontSize: 1, color: "fg.muted" }, children: withOverlay
|
|
57
|
+
return (_jsx(Box, { p: 3, bg: "canvas.default", minHeight: withOverlay ? 360 : undefined, children: _jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 3 }, children: [_jsx(ColorModeCircle, { ...props, colorMode: colorMode, themeVariant: themeVariant, onColorModeChange: onColorModeChange, hoverOverlay: withOverlay ? (_jsx(AppearanceControls, { withStore: false, colorMode: colorMode, themeVariant: themeVariant, onColorModeChange: onColorModeChange, onThemeChange: setThemeVariant })) : undefined }), _jsx(Text, { sx: { fontSize: 1, color: "fg.muted" }, children: withOverlay
|
|
58
58
|
? `Hover to reveal the appearance controls (${colorMode}).`
|
|
59
59
|
: `Click to cycle light → dark → auto (now ${colorMode}).` })] }) }));
|
|
60
60
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Text } from '@primer/react';
|
|
3
3
|
import { Box } from '../box/Box';
|
|
4
|
+
import { Card } from '../card/Card';
|
|
4
5
|
import { DatalayerThemeProvider } from '../../theme/DatalayerThemeProvider';
|
|
5
6
|
import { themeConfigs } from '../../theme/themeRegistry';
|
|
6
7
|
import { useSystemColorMode } from '../../theme/useSystemColorMode';
|
|
@@ -11,14 +12,6 @@ export function ThemePalettePreview({ variant, colorMode }) {
|
|
|
11
12
|
const systemMode = useSystemColorMode();
|
|
12
13
|
const mode = colorMode === 'auto' ? systemMode : colorMode === 'dark' ? 'dark' : 'light';
|
|
13
14
|
const heading = { m: 0, fontSize: 1, fontWeight: 600, color: 'fg.default' };
|
|
14
|
-
return (_jsx(DatalayerThemeProvider, { colorMode: mode, theme: cfg.primerTheme, themeStyles: cfg.themeStyles, children: _jsxs(
|
|
15
|
-
display: 'grid',
|
|
16
|
-
gap: 3,
|
|
17
|
-
p: 2,
|
|
18
|
-
bg: 'canvas.default',
|
|
19
|
-
border: '1px solid',
|
|
20
|
-
borderColor: 'border.default',
|
|
21
|
-
borderRadius: 'var(--theme-radius-card)',
|
|
22
|
-
}, children: [_jsxs(Box, { as: "section", sx: { display: 'grid', gap: 2 }, children: [_jsx(Text, { as: "h3", sx: heading, children: "Color palette" }), _jsx(ThemePaletteSwatches, { variant: variant, colorMode: mode, compact: true })] }), _jsxs(Box, { as: "section", sx: { display: 'grid', gap: 2 }, children: [_jsx(Text, { as: "h3", sx: heading, children: "Theme accents" }), _jsx(ThemeAccentSwatches, { mode: mode })] })] }, `${variant}-${mode}`) }));
|
|
15
|
+
return (_jsx(DatalayerThemeProvider, { colorMode: mode, theme: cfg.primerTheme, themeStyles: cfg.themeStyles, children: _jsxs(Card, { "data-testid": "theme-palette-preview", "data-theme-variant": variant, "data-theme-mode": mode, border: true, shadow: "none", display: "grid", sx: { gap: 3, p: 2 }, children: [_jsxs(Box, { as: "section", sx: { display: 'grid', gap: 2 }, children: [_jsx(Text, { as: "h3", sx: heading, children: "Color palette" }), _jsx(ThemePaletteSwatches, { variant: variant, colorMode: mode, compact: true })] }), _jsxs(Box, { as: "section", sx: { display: 'grid', gap: 2 }, children: [_jsx(Text, { as: "h3", sx: heading, children: "Theme accents" }), _jsx(ThemeAccentSwatches, { mode: mode })] })] }, `${variant}-${mode}`) }));
|
|
23
16
|
}
|
|
24
17
|
export default ThemePalettePreview;
|
|
@@ -1,56 +1,28 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { CheckCircleFillIcon } from '@primer/octicons-react';
|
|
3
3
|
import { Box } from '../box/Box';
|
|
4
|
+
import { Card } from '../card/Card';
|
|
4
5
|
import { matrixColors } from '../../theme/colors';
|
|
5
6
|
import { DatalayerThemeProvider, themeConfigs, useSystemColorMode } from '../../theme';
|
|
6
7
|
export function ThemePreviewCard({ variant, colorMode, selected = false, onSelect, compact = false, showDescription = true, }) {
|
|
7
8
|
const cfg = themeConfigs[variant];
|
|
8
9
|
const systemMode = useSystemColorMode();
|
|
9
10
|
const resolvedMode = colorMode === 'auto' ? systemMode : colorMode;
|
|
10
|
-
return (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
cursor: onSelect ? 'pointer' : 'default',
|
|
15
|
-
bg: 'canvas.default',
|
|
16
|
-
border: '2px solid',
|
|
17
|
-
borderColor: selected ? 'accent.fg' : 'border.default',
|
|
18
|
-
borderRadius: 2,
|
|
19
|
-
p: compact ? 2 : 4,
|
|
20
|
-
transition: 'border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease',
|
|
21
|
-
boxShadow: selected
|
|
22
|
-
? '0 0 0 1px var(--fgColor-accent, var(--color-accent-fg))'
|
|
23
|
-
: 'none',
|
|
24
|
-
':hover': onSelect
|
|
25
|
-
? {
|
|
26
|
-
borderColor: selected ? 'accent.fg' : 'border.muted',
|
|
27
|
-
bg: 'canvas.default',
|
|
28
|
-
}
|
|
29
|
-
: undefined,
|
|
30
|
-
':focus-visible': onSelect
|
|
31
|
-
? {
|
|
32
|
-
outline: '2px solid',
|
|
33
|
-
outlineColor: 'accent.fg',
|
|
34
|
-
outlineOffset: 2,
|
|
35
|
-
}
|
|
36
|
-
: undefined,
|
|
37
|
-
}, children: [selected ? (_jsx(Box, { sx: {
|
|
11
|
+
return (
|
|
12
|
+
// A Card of this package: the theme's surface, hairline, corner and, when
|
|
13
|
+
// it is picked from, its hover, focus and selected states (13 November 2026).
|
|
14
|
+
_jsxs(Card, { as: onSelect ? 'button' : 'div', onClick: onSelect ? () => onSelect(variant) : undefined, border: true, shadow: "none", interactive: Boolean(onSelect), selected: selected, display: "block", sx: { position: 'relative', width: '100%', textAlign: 'left', p: compact ? 2 : 4 }, children: [selected ? (_jsx(Box, { sx: {
|
|
38
15
|
position: 'absolute',
|
|
39
16
|
top: 2,
|
|
40
17
|
right: 2,
|
|
41
18
|
color: 'accent.fg',
|
|
42
|
-
}, children: _jsx(CheckCircleFillIcon, { size: compact ? 16 : 20 }) })) : null, _jsx(DatalayerThemeProvider, { colorMode: resolvedMode, theme: cfg.primerTheme, themeStyles: cfg.themeStyles, children: _jsxs(Box, { sx: {
|
|
43
|
-
borderRadius: 2,
|
|
44
|
-
border: '1px solid',
|
|
45
|
-
borderColor: 'border.default',
|
|
46
|
-
overflow: 'hidden',
|
|
47
|
-
mb: compact ? 2 : 3,
|
|
48
|
-
}, children: [_jsxs(Box, { sx: {
|
|
19
|
+
}, children: _jsx(CheckCircleFillIcon, { size: compact ? 16 : 20 }) })) : null, _jsx(DatalayerThemeProvider, { colorMode: resolvedMode, theme: cfg.primerTheme, themeStyles: cfg.themeStyles, children: _jsxs(Card, { border: true, shadow: "none", display: "block", sx: { overflow: 'hidden', mb: compact ? 2 : 3 }, children: [_jsxs(Box, { sx: {
|
|
49
20
|
display: 'flex',
|
|
50
21
|
alignItems: 'center',
|
|
51
22
|
gap: 1,
|
|
52
|
-
|
|
53
|
-
|
|
23
|
+
// Clear of the card's corner, however round the theme draws it (Loop's).
|
|
24
|
+
px: `calc(var(--theme-radius-card, 6px) / 2 + ${compact ? 6 : 8}px)`,
|
|
25
|
+
py: compact ? '6px' : '8px',
|
|
54
26
|
bg: 'canvas.default',
|
|
55
27
|
borderBottom: '1px solid',
|
|
56
28
|
borderColor: 'border.muted',
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Distributed under the terms of the Modified BSD License.
|
|
4
4
|
*/
|
|
5
5
|
export * from './AppearanceControls';
|
|
6
|
-
export * from './AppearanceControlsWithStore';
|
|
7
6
|
export * from './AppearanceMenu';
|
|
8
7
|
export * from './AppearanceMenuWithStore';
|
|
9
8
|
export * from './CollaboratorPalette';
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
/** Primer's colour roles: a circle in one of them takes the theme's colour for it. */
|
|
2
|
+
export declare const CIRCLE_ICON_ROLES: readonly ["accent", "success", "attention", "severe", "danger", "done", "sponsors", "neutral", "open", "closed"];
|
|
3
|
+
export type CircleIconRole = (typeof CIRCLE_ICON_ROLES)[number];
|
|
1
4
|
export type CircleIconProps = {
|
|
2
|
-
|
|
3
|
-
|
|
5
|
+
/** A colour role (`accent`, `success`…), which follows the theme, or any CSS colour. */
|
|
6
|
+
color?: CircleIconRole | (string & {});
|
|
7
|
+
/** Which of the role's colours: its foreground by default, or its emphasis, muted or subtle background. */
|
|
8
|
+
variant?: 'fg' | 'default' | 'muted' | 'onEmphasis' | 'subtle' | 'emphasis';
|
|
4
9
|
};
|
|
5
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The theme's colour of a role, as a CSS custom property, so the circle
|
|
12
|
+
* changes with the theme and the colour mode without a re-render.
|
|
13
|
+
*/
|
|
14
|
+
export declare function circleIconColor(color: string, variant?: CircleIconProps['variant']): string;
|
|
15
|
+
export declare const CircleIcon: ({ color, variant }: CircleIconProps) => import("react").JSX.Element;
|
|
6
16
|
export default CircleIcon;
|
|
@@ -3,15 +3,34 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
* Copyright (c) 2021-2026 Datalayer, Inc.
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
5
5
|
*/
|
|
6
|
-
import { useTheme } from '@primer/react';
|
|
7
6
|
import { CircleCurrentColorIcon } from '@datalayer/icons-react';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
/** Primer's colour roles: a circle in one of them takes the theme's colour for it. */
|
|
8
|
+
export const CIRCLE_ICON_ROLES = ['accent', 'success', 'attention', 'severe', 'danger', 'done', 'sponsors', 'neutral', 'open', 'closed'];
|
|
9
|
+
const isRole = (color) => CIRCLE_ICON_ROLES.includes(color);
|
|
10
|
+
/**
|
|
11
|
+
* The theme's colour of a role, as a CSS custom property, so the circle
|
|
12
|
+
* changes with the theme and the colour mode without a re-render.
|
|
13
|
+
*/
|
|
14
|
+
export function circleIconColor(color, variant = 'fg') {
|
|
15
|
+
if (!isRole(color)) {
|
|
16
|
+
return color;
|
|
17
|
+
}
|
|
18
|
+
switch (variant) {
|
|
19
|
+
case 'onEmphasis':
|
|
20
|
+
return 'var(--fgColor-onEmphasis)';
|
|
21
|
+
case 'emphasis':
|
|
22
|
+
case 'default':
|
|
23
|
+
return `var(--bgColor-${color}-emphasis)`;
|
|
24
|
+
case 'muted':
|
|
25
|
+
return `var(--bgColor-${color}-muted)`;
|
|
26
|
+
case 'subtle':
|
|
27
|
+
return `var(--bgColor-${color}-muted, var(--bgColor-${color}-subtle))`;
|
|
28
|
+
default:
|
|
29
|
+
return `var(--fgColor-${color})`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export const CircleIcon = ({ color = 'accent', variant = 'fg' }) => {
|
|
33
|
+
const fill = circleIconColor(color, variant);
|
|
34
|
+
return (_jsx("span", { style: { color: fill, display: 'inline-flex' }, children: _jsx(CircleCurrentColorIcon, {}) }));
|
|
16
35
|
};
|
|
17
36
|
export default CircleIcon;
|
|
@@ -2,7 +2,7 @@ import type { StoryObj } from '@storybook/react';
|
|
|
2
2
|
import { CircleIconProps } from '../..';
|
|
3
3
|
declare const meta: {
|
|
4
4
|
title: string;
|
|
5
|
-
component: ({ color, variant
|
|
5
|
+
component: ({ color, variant }: CircleIconProps) => import("react").JSX.Element;
|
|
6
6
|
tags: string[];
|
|
7
7
|
parameters: {
|
|
8
8
|
layout: string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from "./appearance/AppearanceControls";
|
|
2
|
-
export * from "./appearance/AppearanceControlsWithStore";
|
|
3
2
|
export * from "./appearance/AppearanceMenu";
|
|
4
3
|
export * from "./appearance/AppearanceMenuWithStore";
|
|
5
4
|
export * from "./appearance/CollaboratorPalette";
|
|
@@ -11,6 +10,7 @@ export * from "./calendar-picker";
|
|
|
11
10
|
export * from "./card/Card";
|
|
12
11
|
export * from "./hover-card";
|
|
13
12
|
export * from "./entity-avatar";
|
|
13
|
+
export * from "./scroll-area";
|
|
14
14
|
export * from "./sheet/Sheet";
|
|
15
15
|
export * from "./color";
|
|
16
16
|
export * from "./color-picker";
|
package/lib/components/index.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Distributed under the terms of the Modified BSD License.
|
|
4
4
|
*/
|
|
5
5
|
export * from "./appearance/AppearanceControls";
|
|
6
|
-
export * from "./appearance/AppearanceControlsWithStore";
|
|
7
6
|
export * from "./appearance/AppearanceMenu";
|
|
8
7
|
export * from "./appearance/AppearanceMenuWithStore";
|
|
9
8
|
export * from "./appearance/CollaboratorPalette";
|
|
@@ -15,6 +14,7 @@ export * from "./calendar-picker";
|
|
|
15
14
|
export * from "./card/Card";
|
|
16
15
|
export * from "./hover-card";
|
|
17
16
|
export * from "./entity-avatar";
|
|
17
|
+
export * from "./scroll-area";
|
|
18
18
|
export * from "./sheet/Sheet";
|
|
19
19
|
export * from "./color";
|
|
20
20
|
export * from "./color-picker";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type ComponentProps } from 'react';
|
|
2
|
+
import { Box } from '../box/Box';
|
|
3
|
+
/**
|
|
4
|
+
* A tiny scrollbar: thin, its thumb in the theme's border colour on a clear
|
|
5
|
+
* track, darker on hover. Spread it into any scrolling element's `sx`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const thinScrollbarSx: {
|
|
8
|
+
readonly scrollbarWidth: "thin";
|
|
9
|
+
readonly scrollbarColor: "var(--borderColor-default, rgba(127, 127, 127, 0.4)) transparent";
|
|
10
|
+
readonly '&::-webkit-scrollbar': {
|
|
11
|
+
readonly width: "6px";
|
|
12
|
+
readonly height: "6px";
|
|
13
|
+
};
|
|
14
|
+
readonly '&::-webkit-scrollbar-track': {
|
|
15
|
+
readonly background: "transparent";
|
|
16
|
+
};
|
|
17
|
+
readonly '&::-webkit-scrollbar-thumb': {
|
|
18
|
+
readonly background: "var(--borderColor-default, rgba(127, 127, 127, 0.4))";
|
|
19
|
+
readonly borderRadius: "999px";
|
|
20
|
+
};
|
|
21
|
+
readonly '&::-webkit-scrollbar-thumb:hover': {
|
|
22
|
+
readonly background: "var(--fgColor-muted, rgba(127, 127, 127, 0.7))";
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type ScrollAreaProps = ComponentProps<typeof Box>;
|
|
26
|
+
/**
|
|
27
|
+
* A Box that scrolls (vertically by default) with the tiny scrollbar, its
|
|
28
|
+
* scroll kept to itself. Any `sx` given is applied over it.
|
|
29
|
+
*/
|
|
30
|
+
export declare const ScrollArea: import("react").ForwardRefExoticComponent<Omit<import("../box/boxCss").BoxStyleProps & {
|
|
31
|
+
hover?: import("../box/boxCss").BoxStyleProps | undefined;
|
|
32
|
+
focus?: import("../box/boxCss").BoxStyleProps | undefined;
|
|
33
|
+
focusVisible?: import("../box/boxCss").BoxStyleProps | undefined;
|
|
34
|
+
focusWithin?: import("../box/boxCss").BoxStyleProps | undefined;
|
|
35
|
+
active?: import("../box/boxCss").BoxStyleProps | undefined;
|
|
36
|
+
} & {
|
|
37
|
+
reducedMotion?: import("../box/boxCss").BoxStyleProps;
|
|
38
|
+
} & Omit<import("react").HTMLAttributes<HTMLElement>, "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "animationDelay" | "appearance" | "aspectRatio" | "backdropFilter" | "backgroundColor" | "backgroundImage" | "backgroundRepeat" | "backgroundSize" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "bottom" | "boxSizing" | "clipPath" | "color" | "columnGap" | "cursor" | "display" | "fill" | "filter" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "float" | "fontFamily" | "fontSize" | "fontStyle" | "fontVariantNumeric" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridColumnEnd" | "gridColumnStart" | "gridRowEnd" | "gridRowStart" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "isolation" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "listStylePosition" | "listStyleType" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "mixBlendMode" | "objectFit" | "objectPosition" | "opacity" | "order" | "outlineColor" | "outlineOffset" | "overflowWrap" | "overflowX" | "overflowY" | "overscrollBehaviorY" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "pointerEvents" | "position" | "resize" | "right" | "rowGap" | "scrollMarginTop" | "scrollbarGutter" | "scrollbarWidth" | "stroke" | "tableLayout" | "textAlign" | "textOverflow" | "textShadow" | "textTransform" | "textUnderlineOffset" | "top" | "touchAction" | "transform" | "transformOrigin" | "userSelect" | "verticalAlign" | "visibility" | "whiteSpace" | "width" | "willChange" | "wordBreak" | "wordWrap" | "all" | "animation" | "background" | "backgroundPosition" | "border" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderStyle" | "borderTop" | "borderWidth" | "flex" | "flexFlow" | "font" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "gridTemplate" | "inset" | "listStyle" | "margin" | "outline" | "overflow" | "overscrollBehavior" | "padding" | "paddingBlock" | "paddingInline" | "placeContent" | "placeItems" | "placeSelf" | "textDecoration" | "textWrap" | "transition" | "clip" | "WebkitLineClamp" | "bg" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "p" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "size" | "gridColumnGap" | "gridGap" | "gridRowGap" | "WebkitBoxOrient" | "borderX" | "borderY" | "as"> & {
|
|
39
|
+
[prop: string]: unknown;
|
|
40
|
+
as?: import("react").ElementType;
|
|
41
|
+
sx?: import("../box/sx").BetterSystemStyleObject;
|
|
42
|
+
className?: string;
|
|
43
|
+
style?: import("react").CSSProperties;
|
|
44
|
+
children?: import("react").ReactNode;
|
|
45
|
+
} & import("react").RefAttributes<any>, "ref"> & import("react").RefAttributes<HTMLElement>>;
|
|
46
|
+
export default ScrollArea;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2021-2026 Datalayer, Inc.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
import { forwardRef } from 'react';
|
|
7
|
+
import { Box } from '../box/Box';
|
|
8
|
+
/**
|
|
9
|
+
* A tiny scrollbar: thin, its thumb in the theme's border colour on a clear
|
|
10
|
+
* track, darker on hover. Spread it into any scrolling element's `sx`.
|
|
11
|
+
*/
|
|
12
|
+
export const thinScrollbarSx = {
|
|
13
|
+
scrollbarWidth: 'thin',
|
|
14
|
+
scrollbarColor: 'var(--borderColor-default, rgba(127, 127, 127, 0.4)) transparent',
|
|
15
|
+
'&::-webkit-scrollbar': { width: '6px', height: '6px' },
|
|
16
|
+
'&::-webkit-scrollbar-track': { background: 'transparent' },
|
|
17
|
+
'&::-webkit-scrollbar-thumb': {
|
|
18
|
+
background: 'var(--borderColor-default, rgba(127, 127, 127, 0.4))',
|
|
19
|
+
borderRadius: '999px'
|
|
20
|
+
},
|
|
21
|
+
'&::-webkit-scrollbar-thumb:hover': {
|
|
22
|
+
background: 'var(--fgColor-muted, rgba(127, 127, 127, 0.7))'
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A Box that scrolls (vertically by default) with the tiny scrollbar, its
|
|
27
|
+
* scroll kept to itself. Any `sx` given is applied over it.
|
|
28
|
+
*/
|
|
29
|
+
export const ScrollArea = forwardRef(function ScrollArea({ sx, ...props }, ref) {
|
|
30
|
+
return (_jsx(Box, { ref: ref, ...props, sx: { overflowY: 'auto', overscrollBehavior: 'contain', ...thinScrollbarSx, ...sx } }));
|
|
31
|
+
});
|
|
32
|
+
export default ScrollArea;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ScrollArea';
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
import type { ToolbarProps } from "./types";
|
|
2
|
-
|
|
1
|
+
import type { ToolbarProps, ToolbarItem } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* The keys to take off the line so the rest fits in `available`.
|
|
4
|
+
*
|
|
5
|
+
* Exported for tests. Pinned items, spacers and items that take no room
|
|
6
|
+
* never leave; the others leave lowest `priority` first, the last on the
|
|
7
|
+
* line first among equals — with every priority equal, the tail of the
|
|
8
|
+
* line, as a reader expects.
|
|
9
|
+
*/
|
|
10
|
+
export declare function overflowKeys(ordered: ToolbarItem[], widthOf: (key: string) => number, available: number, gap?: number, triggerWidth?: number): Set<string>;
|
|
11
|
+
export declare function Toolbar({ items, extraItems, className, disabled, ariaLabel, overflow, variant, gap, overflowAriaLabel, keyboardNavigation, }: ToolbarProps): import("react").JSX.Element;
|
|
3
12
|
export default Toolbar;
|
|
Binary file
|
|
@@ -20,6 +20,36 @@ export interface ToolbarItemBase {
|
|
|
20
20
|
disabled?: boolean;
|
|
21
21
|
/** Whether to hide the item */
|
|
22
22
|
hidden?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Never moved into the overflow menu, however narrow the line: the
|
|
25
|
+
* controls a reader must always find where they left them (a close
|
|
26
|
+
* button, a session menu). Pinned items count against the room first.
|
|
27
|
+
*/
|
|
28
|
+
pinned?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Which items leave the line first when the room runs out: the lowest
|
|
31
|
+
* priority goes first, and among equals the last item on the line.
|
|
32
|
+
* Default: 0. The menu lists what left in the line's own order.
|
|
33
|
+
*/
|
|
34
|
+
priority?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* What a custom item becomes in the overflow menu.
|
|
38
|
+
*
|
|
39
|
+
* - `onSelect`: a labelled menu row (`label`, `icon`) that runs it and
|
|
40
|
+
* closes the menu — for a control whose node only makes sense on the line.
|
|
41
|
+
* - `render`: a node of its own for the menu.
|
|
42
|
+
* - neither: the item's own `render()` is drawn in the menu as on the line.
|
|
43
|
+
*/
|
|
44
|
+
export interface ToolbarOverflowRepresentation {
|
|
45
|
+
/** The menu row's name (required with `onSelect`). */
|
|
46
|
+
label?: string;
|
|
47
|
+
/** The menu row's icon. */
|
|
48
|
+
icon?: React.ComponentType<IconProps> | ReactNode;
|
|
49
|
+
/** Run when the menu row is chosen; the menu closes after. */
|
|
50
|
+
onSelect?: () => void;
|
|
51
|
+
/** A node of its own for the menu instead of a row. */
|
|
52
|
+
render?: () => ReactNode;
|
|
23
53
|
}
|
|
24
54
|
/**
|
|
25
55
|
* Toolbar button item definition.
|
|
@@ -104,6 +134,8 @@ export interface ToolbarCustomItem extends ToolbarItemBase {
|
|
|
104
134
|
type: "custom";
|
|
105
135
|
/** Custom render function */
|
|
106
136
|
render: () => ReactNode;
|
|
137
|
+
/** What it becomes in the overflow menu — see `ToolbarOverflowRepresentation`. */
|
|
138
|
+
overflow?: ToolbarOverflowRepresentation;
|
|
107
139
|
}
|
|
108
140
|
/**
|
|
109
141
|
* Union of all toolbar item types.
|
|
@@ -130,6 +162,25 @@ export interface ToolbarProps {
|
|
|
130
162
|
* up to the host to leave room for them.
|
|
131
163
|
*/
|
|
132
164
|
overflow?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* `bar` (the default): an editor's strip — its own ground, a hairline
|
|
167
|
+
* under it, sticky at the top. `inline`: the items alone, no ground, no
|
|
168
|
+
* border, no padding — for a toolbar inside a header row of the host's.
|
|
169
|
+
*/
|
|
170
|
+
variant?: "bar" | "inline";
|
|
171
|
+
/** Space between two items, in px. Default: 2. */
|
|
172
|
+
gap?: number;
|
|
173
|
+
/**
|
|
174
|
+
* The name of the button opening the overflow menu. Default:
|
|
175
|
+
* "N more toolbar items".
|
|
176
|
+
*/
|
|
177
|
+
overflowAriaLabel?: string;
|
|
178
|
+
/**
|
|
179
|
+
* Arrow keys, Home and End move the focus between the toolbar's controls
|
|
180
|
+
* (Tab still leaves it); keys typed into a field are left alone. On by
|
|
181
|
+
* default.
|
|
182
|
+
*/
|
|
183
|
+
keyboardNavigation?: boolean;
|
|
133
184
|
}
|
|
134
185
|
/**
|
|
135
186
|
* Props for the extensible FloatingToolbar component.
|
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { UseBoundStore, StoreApi } from 'zustand';
|
|
3
|
-
import type { ThemeState } from '../../theme/useThemeStore';
|
|
4
|
-
export interface AppearanceControlsWithStoreProps {
|
|
5
|
-
useStore: UseBoundStore<StoreApi<ThemeState>>;
|
|
6
|
-
/** Show the light / dark / auto switch. Default: shown. */
|
|
7
|
-
showColorMode?: boolean;
|
|
8
|
-
/** Show the theme chooser (one swatch per theme). Default: shown. */
|
|
9
|
-
showThemeChooser?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare const AppearanceControlsWithStore: React.FC<AppearanceControlsWithStoreProps>;
|
|
12
|
-
export default AppearanceControlsWithStore;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { IconButton, SegmentedControl, Tooltip } from '@primer/react';
|
|
3
|
-
import { SunIcon, MoonIcon, DeviceDesktopIcon, CircleIcon, } from '@primer/octicons-react';
|
|
4
|
-
import { Box } from '../box/Box';
|
|
5
|
-
import { themeConfigs, themeVariants } from '../../theme/themeRegistry';
|
|
6
|
-
export const AppearanceControlsWithStore = ({ useStore, showColorMode = true, showThemeChooser = true, }) => {
|
|
7
|
-
const { colorMode, theme: themeVariant } = useStore();
|
|
8
|
-
return (_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 3 }, children: [showThemeChooser ? (_jsx(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1 }, children: themeVariants.map(variant => {
|
|
9
|
-
const tcfg = themeConfigs[variant];
|
|
10
|
-
const isSelected = themeVariant === variant;
|
|
11
|
-
return (_jsx(Tooltip, { text: tcfg.label, direction: "s", children: _jsx(IconButton, { "aria-label": tcfg.label, "aria-pressed": isSelected, icon: () => _jsx(CircleIcon, { size: 16, fill: tcfg.brandColor }), size: "small", variant: isSelected ? 'default' : 'invisible', onClick: () => useStore.getState().setTheme(variant, false), sx: {
|
|
12
|
-
border: isSelected ? '2px solid' : '1px solid',
|
|
13
|
-
borderColor: isSelected ? 'accent.fg' : 'border.muted',
|
|
14
|
-
borderRadius: '50%',
|
|
15
|
-
} }) }, variant));
|
|
16
|
-
}) })) : null, showColorMode ? (_jsxs(SegmentedControl, { "aria-label": "Color mode", size: "small", onChange: (index) => {
|
|
17
|
-
const modes = ['light', 'dark', 'auto'];
|
|
18
|
-
useStore.getState().setColorMode(modes[index]);
|
|
19
|
-
}, 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] }));
|
|
20
|
-
};
|
|
21
|
-
export default AppearanceControlsWithStore;
|