@datalayer/primer-addons 1.0.40 → 1.0.42

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.
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright (c) 2023-2026 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * The VS Code theme for Primer React: its styles, from
7
+ * `./vscodeThemeStyles`, and the Primer theme object. Theming is done
8
+ * through CSS custom properties, so the object is Primer's unmodified
9
+ * default, kept for `<ThemeProvider theme={…}>`. Code that needs the tokens
10
+ * without Primer React (a native app) imports the styles module instead.
11
+ */
12
+ import { theme as primerTheme } from '@primer/react';
13
+ export * from './vscodeThemeStyles';
14
+ export * from './vscodeEditorsCss';
15
+ /** The Primer theme object: Primer's default. */
16
+ export const vscodeTheme = primerTheme;
17
+ export default vscodeTheme;
@@ -0,0 +1,7 @@
1
+ import { type ThemeColorDefs } from '../css/createThemeCSSVars';
2
+ export declare const vscodeLight: ThemeColorDefs;
3
+ export declare const vscodeDark: ThemeColorDefs;
4
+ /** Comprehensive Primer CSS-variable overrides for light & dark mode. */
5
+ export declare const vscodeThemeStyles: import("../css/createThemeCSSVars").ThemeStyles;
6
+ /** The theme's whole stylesheet (`ThemeStyles.css`). */
7
+ export declare const vscodeControlsCss: string;
@@ -0,0 +1,246 @@
1
+ /*
2
+ * Copyright (c) 2023-2026 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * VS Code Theme for Primer React.
7
+ *
8
+ * The editor's own colours, type and shape: every token is a reference to a
9
+ * `--vscode-*` variable (see `../colors/vscodeColors`), so in a VS Code
10
+ * webview the page is drawn in whatever colour theme the editor has and
11
+ * follows it the moment the person picks another — the browser resolves the
12
+ * references at paint time, nothing re-renders. Outside VS Code the
13
+ * references fall back to Dark Modern and Light Modern, the editor's own
14
+ * defaults, so the theme is a theme anywhere.
15
+ *
16
+ * Shape is the editor's: 2px corners on controls, 26px tall, flat cards and
17
+ * overlays, no motion. Theming is applied via **CSS custom-property
18
+ * overrides**, as every Datalayer theme is.
19
+ */
20
+ import { vscodeFontFamily, vscodeFontSize, vscodeMonoFontFamily, vscodeTint, vscodeVar, } from '../colors/vscodeColors';
21
+ import { buildThemeStyles } from '../css/createThemeCSSVars';
22
+ import { primerComponentSelectors } from '../css/primerComponentsCss';
23
+ import { vscodeEditorsCss } from './vscodeEditorsCss';
24
+ /* ── Colour definitions, one per mode ────────────────────────────────── */
25
+ /**
26
+ * The colour definitions for a mode: the same editor variables in both,
27
+ * only the fallbacks differ.
28
+ *
29
+ * @param mode - The mode whose VS Code defaults are the fallbacks.
30
+ *
31
+ * @returns The definitions.
32
+ */
33
+ function vscodeDefs(mode) {
34
+ const v = (name) => vscodeVar(name, mode);
35
+ const tint = (name, percent) => vscodeTint(name, mode, percent);
36
+ return {
37
+ canvas: {
38
+ default: v('editorBackground'),
39
+ subtle: v('sideBarBackground'),
40
+ },
41
+ fg: {
42
+ default: v('editorForeground'),
43
+ muted: v('descriptionForeground'),
44
+ onEmphasis: v('buttonForeground'),
45
+ },
46
+ // The accent is the primary button's colour, as the editor's own
47
+ // controls are; links keep the editor's link colour (`--fgColor-link`
48
+ // is set apart below).
49
+ accent: {
50
+ fg: v('buttonBackground'),
51
+ emphasis: v('buttonBackground'),
52
+ muted: tint('buttonBackground', 40),
53
+ subtle: tint('buttonBackground', 15),
54
+ },
55
+ success: {
56
+ fg: v('testingIconPassed'),
57
+ emphasis: v('testingIconPassed'),
58
+ muted: v('testingIconPassed'),
59
+ subtle: tint('testingIconPassed', 15),
60
+ },
61
+ attention: {
62
+ fg: v('editorWarningForeground'),
63
+ emphasis: v('editorWarningForeground'),
64
+ muted: v('editorWarningForeground'),
65
+ subtle: tint('editorWarningForeground', 15),
66
+ },
67
+ danger: {
68
+ fg: v('errorForeground'),
69
+ emphasis: v('errorForeground'),
70
+ muted: v('errorForeground'),
71
+ subtle: tint('errorForeground', 15),
72
+ },
73
+ severe: {
74
+ fg: v('terminalAnsiRed'),
75
+ emphasis: v('terminalAnsiRed'),
76
+ muted: v('terminalAnsiRed'),
77
+ subtle: tint('terminalAnsiRed', 15),
78
+ },
79
+ done: {
80
+ fg: v('terminalAnsiMagenta'),
81
+ emphasis: v('terminalAnsiMagenta'),
82
+ muted: v('terminalAnsiMagenta'),
83
+ subtle: tint('terminalAnsiMagenta', 15),
84
+ },
85
+ border: {
86
+ default: v('panelBorder'),
87
+ muted: v('editorWidgetBorder'),
88
+ },
89
+ btn: {
90
+ text: v('buttonSecondaryForeground'),
91
+ bg: v('buttonSecondaryBackground'),
92
+ border: v('buttonBorder'),
93
+ hoverBg: v('buttonSecondaryHoverBackground'),
94
+ hoverBorder: v('buttonBorder'),
95
+ activeBg: v('buttonSecondaryHoverBackground'),
96
+ activeBorder: v('buttonBorder'),
97
+ selectedBg: v('listActiveSelectionBackground'),
98
+ counterBg: tint('foreground', 15),
99
+ primary: {
100
+ text: v('buttonForeground'),
101
+ bg: v('buttonBackground'),
102
+ border: v('buttonBorder'),
103
+ hoverBg: v('buttonHoverBackground'),
104
+ hoverBorder: v('buttonBorder'),
105
+ selectedBg: v('buttonHoverBackground'),
106
+ disabledText: tint('buttonForeground', 60),
107
+ disabledBg: tint('buttonBackground', 50),
108
+ disabledBorder: 'transparent',
109
+ icon: v('buttonForeground'),
110
+ counterBg: tint('buttonForeground', 20),
111
+ },
112
+ outline: {
113
+ text: v('buttonBackground'),
114
+ hoverText: v('buttonForeground'),
115
+ hoverBg: v('buttonBackground'),
116
+ hoverBorder: v('buttonBackground'),
117
+ hoverCounterBg: tint('buttonForeground', 20),
118
+ selectedText: v('buttonForeground'),
119
+ selectedBg: v('buttonHoverBackground'),
120
+ selectedBorder: v('buttonHoverBackground'),
121
+ disabledText: tint('buttonBackground', 50),
122
+ disabledBg: 'transparent',
123
+ disabledCounterBg: tint('buttonBackground', 5),
124
+ counterBg: tint('buttonBackground', 10),
125
+ counterFg: v('buttonBackground'),
126
+ hoverCounterFg: v('buttonForeground'),
127
+ disabledCounterFg: tint('buttonBackground', 50),
128
+ },
129
+ danger: {
130
+ text: v('errorForeground'),
131
+ hoverText: v('buttonForeground'),
132
+ hoverBg: v('errorForeground'),
133
+ hoverBorder: v('errorForeground'),
134
+ hoverCounterBg: tint('buttonForeground', 20),
135
+ selectedText: v('buttonForeground'),
136
+ selectedBg: v('errorForeground'),
137
+ selectedBorder: v('errorForeground'),
138
+ disabledText: tint('errorForeground', 50),
139
+ disabledBg: 'transparent',
140
+ disabledCounterBg: tint('errorForeground', 5),
141
+ counterBg: tint('errorForeground', 10),
142
+ counterFg: v('errorForeground'),
143
+ hoverCounterFg: v('buttonForeground'),
144
+ disabledCounterFg: tint('errorForeground', 50),
145
+ icon: v('errorForeground'),
146
+ },
147
+ },
148
+ };
149
+ }
150
+ export const vscodeLight = vscodeDefs('light');
151
+ export const vscodeDark = vscodeDefs('dark');
152
+ /* ── The editor's own variables, beside the colour definitions ───────── */
153
+ /**
154
+ * What the colour definitions cannot say, per mode: the link colour (the
155
+ * editor's, not the button's), the focus ring, the list rows, the
156
+ * overlays, the type and the controls' size.
157
+ *
158
+ * @param mode - The mode whose VS Code defaults are the fallbacks.
159
+ *
160
+ * @returns The variables.
161
+ */
162
+ function vscodeVariables(mode) {
163
+ const v = (name) => vscodeVar(name, mode);
164
+ return {
165
+ // Links are the editor's link colour; everything else accented wears
166
+ // the button's.
167
+ '--fgColor-link': v('textLinkForeground'),
168
+ '--focus-outlineColor': v('focusBorder'),
169
+ '--underlineNav-borderColor-active': v('focusBorder'),
170
+ // Rows of a list, as the editor's lists hover and select.
171
+ '--control-transparent-bgColor-hover': v('listHoverBackground'),
172
+ '--control-transparent-bgColor-active': v('listActiveSelectionBackground'),
173
+ '--control-transparent-bgColor-selected': v('listActiveSelectionBackground'),
174
+ '--menu-bgColor-active': v('listHoverBackground'),
175
+ // Menus, dialogs and popovers: the editor's widgets.
176
+ '--overlay-bgColor': v('editorWidgetBackground'),
177
+ '--bgColor-muted': v('editorWidgetBackground'),
178
+ '--shadow-floating-small': `0 0 8px 2px ${v('widgetShadow')}`,
179
+ '--shadow-floating-medium': `0 0 8px 2px ${v('widgetShadow')}`,
180
+ '--shadow-floating-large': `0 0 8px 2px ${v('widgetShadow')}`,
181
+ '--shadow-resting-small': 'none',
182
+ '--shadow-resting-medium': 'none',
183
+ // Fields: the editor's inputs.
184
+ '--control-bgColor-rest': v('inputBackground'),
185
+ '--control-fgColor-rest': v('inputForeground'),
186
+ '--control-borderColor-rest': v('inputBorder'),
187
+ '--control-borderColor-emphasis': v('focusBorder'),
188
+ '--control-fgColor-placeholder': v('inputPlaceholderForeground'),
189
+ // The editor's corners: square-ish everywhere.
190
+ '--borderRadius-small': '2px',
191
+ '--borderRadius-medium': '2px',
192
+ '--borderRadius-large': '4px',
193
+ // The editor's controls: 26px tall, tight.
194
+ '--control-medium-size': '26px',
195
+ '--control-medium-paddingBlock': '4px',
196
+ '--control-medium-paddingInline-normal': '8px',
197
+ '--control-small-size': '22px',
198
+ // The editor's type.
199
+ '--text-body-size-medium': vscodeFontSize,
200
+ '--fontStack-monospace': vscodeMonoFontFamily,
201
+ '--fontStack-system': vscodeFontFamily,
202
+ };
203
+ }
204
+ /* ── The theme's own stylesheet ──────────────────────────────────────── */
205
+ const sel = primerComponentSelectors;
206
+ /**
207
+ * What no token says: the editor's focus ring is one pixel, drawn inside
208
+ * the control, in the focus colour. Then the editors' face
209
+ * (`vscodeEditorsCss`): JupyterLab's variables, CodeMirror, Excalidraw.
210
+ */
211
+ const vscodeOwnCss = `
212
+ :scope ${sel.button}:focus-visible,
213
+ :scope ${sel.textInput}:focus-within,
214
+ :scope ${sel.textArea}:focus-visible {
215
+ outline: 1px solid var(--focus-outlineColor);
216
+ outline-offset: -1px;
217
+ box-shadow: none;
218
+ }
219
+ ${vscodeEditorsCss}`;
220
+ /* ── Exports ─────────────────────────────────────────────────────────── */
221
+ /** Comprehensive Primer CSS-variable overrides for light & dark mode. */
222
+ export const vscodeThemeStyles = buildThemeStyles(vscodeLight, vscodeDark, {
223
+ fontFamily: vscodeFontFamily,
224
+ css: vscodeOwnCss,
225
+ // The editor's shape: tight corners, flat surfaces, no motion.
226
+ shape: {
227
+ radiusControl: '2px',
228
+ radiusTable: '2px',
229
+ radiusOverlay: '4px',
230
+ radiusCard: '4px',
231
+ radiusBubble: '6px',
232
+ radiusFrame: '4px',
233
+ shadow: 'none',
234
+ motionStatus: '0ms',
235
+ motionMessage: '0ms',
236
+ motionPane: '0ms',
237
+ // A link in a message: the editor's link colour, not the button's.
238
+ messageLink: 'var(--fgColor-link)',
239
+ },
240
+ variables: {
241
+ light: vscodeVariables('light'),
242
+ dark: vscodeVariables('dark'),
243
+ },
244
+ });
245
+ /** The theme's whole stylesheet (`ThemeStyles.css`). */
246
+ export const vscodeControlsCss = vscodeThemeStyles.css ?? '';
@@ -26,19 +26,6 @@ export declare const setupPrimerPortals: (colormode?: Colormode) => void;
26
26
  * answers `null` rather than inventing one.
27
27
  */
28
28
  export declare const getPrimerPortalRoot: () => HTMLElement | null;
29
- /**
30
- * Sync a set of CSS properties (including CSS custom properties) to
31
- * `document.body` so that Primer portal content — which is a DOM child
32
- * of `<body>`, not of the React-tree `<BaseStyles>` element — inherits
33
- * the same theme tokens and cascade properties (font, color, background)
34
- * as the rest of the application.
35
- *
36
- * This function is **idempotent**: calling it again replaces the
37
- * properties from the previous call and removes any stale ones.
38
- *
39
- * Typical usage: call from `DatalayerThemeProvider`'s `useEffect` so
40
- * portals stay in sync whenever theme or color-mode changes.
41
- */
42
29
  export declare function syncPortalThemeStyles(styles: CSSProperties): void;
43
30
  /**
44
31
  * The attribute every theme provider stamps on its own element, its value
@@ -137,6 +137,26 @@ const camelToKebab = (s) => s.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
137
137
  * Typical usage: call from `DatalayerThemeProvider`'s `useEffect` so
138
138
  * portals stay in sync whenever theme or color-mode changes.
139
139
  */
140
+ /**
141
+ * What the body and the portal root take of a theme's styles, besides its
142
+ * custom properties: what a portal inherits or paints with — colour, type,
143
+ * background — and nothing of layout. A provider's `baseStyles` may size its
144
+ * own box (`height: 100%`, `display: contents`); written on the portal root,
145
+ * a fixed layer at the top of the page with the theme's background, the same
146
+ * height covered the whole page.
147
+ */
148
+ const PORTAL_PROPERTIES = new Set([
149
+ 'color',
150
+ 'backgroundColor',
151
+ 'fontFamily',
152
+ 'fontSize',
153
+ 'fontWeight',
154
+ 'lineHeight',
155
+ 'letterSpacing',
156
+ 'colorScheme',
157
+ 'WebkitFontSmoothing',
158
+ 'textRendering',
159
+ ]);
140
160
  export function syncPortalThemeStyles(styles) {
141
161
  /*
142
162
  * On the portal root as well as on the body, and that is the point.
@@ -171,6 +191,8 @@ export function syncPortalThemeStyles(styles) {
171
191
  for (const [key, value] of Object.entries(styles)) {
172
192
  if (value == null)
173
193
  continue;
194
+ if (!key.startsWith('--') && !PORTAL_PROPERTIES.has(key))
195
+ continue;
174
196
  const strVal = String(value);
175
197
  if (key.startsWith('--')) {
176
198
  // CSS custom property — must use setProperty
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/primer-addons",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "license": "BSD-3-Clause",
5
5
  "scripts": {
6
6
  "build": "npm run build:lib",
@@ -78,6 +78,7 @@
78
78
  "prop-types": "^15.8.1",
79
79
  "storybook": "^9.0.15",
80
80
  "typescript": "5.9.3",
81
- "vite": "7.3.6"
81
+ "vite": "7.3.6",
82
+ "babel-plugin-styled-components": "^2.1.4"
82
83
  }
83
84
  }