@datalayer/primer-addons 1.0.20 → 1.0.21

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.
@@ -1,3 +1,3 @@
1
1
  import type { ToolbarProps } from './types';
2
- export declare function Toolbar({ items, extraItems, className, disabled, ariaLabel, }: ToolbarProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function Toolbar({ items, extraItems, className, disabled, ariaLabel, overflow, }: ToolbarProps): import("react/jsx-runtime").JSX.Element;
3
3
  export default Toolbar;
Binary file
@@ -123,6 +123,13 @@ export interface ToolbarProps {
123
123
  extraItems?: ToolbarItem[];
124
124
  /** Aria label for the toolbar */
125
125
  ariaLabel?: string;
126
+ /**
127
+ * Keep the toolbar to one line, moving what does not fit into a menu.
128
+ *
129
+ * On by default. Turned off, the items are all laid on the line and it is
130
+ * up to the host to leave room for them.
131
+ */
132
+ overflow?: boolean;
126
133
  }
127
134
  /**
128
135
  * Props for the extensible FloatingToolbar component.
@@ -1,4 +1,12 @@
1
1
  import { type CSSProperties } from 'react';
2
+ /**
3
+ * Id of the element Primer portals render under.
4
+ *
5
+ * Exported because a host may need to mark that element as its own — the
6
+ * JupyterLab theming of jupyter-react adds `jp-ThemedContainer` to it, so
7
+ * the rules JupyterLab scopes to that class reach portaled content too.
8
+ */
9
+ export declare const PRIMER_PORTAL_ROOT_ID = "__primerPortalRoot__";
2
10
  type Colormode = 'light' | 'dark' | 'auto';
3
11
  /**
4
12
  * Ensure we define a root for Primer portal root.
@@ -11,6 +19,13 @@ type Colormode = 'light' | 'dark' | 'auto';
11
19
  * @see https://github.com/primer/react/blob/030fe020b48b7f12c2994c6614e5d4191fe764ee/src/Portal/Portal.tsx#L33
12
20
  */
13
21
  export declare const setupPrimerPortals: (colormode?: Colormode) => void;
22
+ /**
23
+ * The element Primer portals render under, when it has been set up.
24
+ *
25
+ * `setupPrimerPortals` creates it; before that call there is none, and this
26
+ * answers `null` rather than inventing one.
27
+ */
28
+ export declare const getPrimerPortalRoot: () => HTMLElement | null;
14
29
  /**
15
30
  * Sync a set of CSS properties (including CSS custom properties) to
16
31
  * `document.body` so that Primer portal content — which is a DOM child
@@ -3,7 +3,14 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  import { registerPortalRoot } from '@primer/react';
6
- const PRIMER_PORTAL_ROOT_ID = '__primerPortalRoot__';
6
+ /**
7
+ * Id of the element Primer portals render under.
8
+ *
9
+ * Exported because a host may need to mark that element as its own — the
10
+ * JupyterLab theming of jupyter-react adds `jp-ThemedContainer` to it, so
11
+ * the rules JupyterLab scopes to that class reach portaled content too.
12
+ */
13
+ export const PRIMER_PORTAL_ROOT_ID = '__primerPortalRoot__';
7
14
  /**
8
15
  * Key used on `document.body` to track the CSS-property names we
9
16
  * previously applied so we can remove stale entries on theme switch.
@@ -81,11 +88,38 @@ export const setupPrimerPortals = (colormode) => {
81
88
  portalRoot.dataset['colorMode'] = resolved;
82
89
  portalRoot.dataset['lightTheme'] = lightTheme;
83
90
  portalRoot.dataset['darkTheme'] = darkTheme;
84
- // High z-index so overlays render above positioned UI (e.g. chat z-index 1001).
85
- portalRoot.style.position = 'relative';
91
+ /*
92
+ * Pinned to the origin of the document, never left in the flow of the body.
93
+ *
94
+ * Primer positions an anchored overlay — a menu, a dropdown — with
95
+ * `position: absolute` and coordinates taken from the VIEWPORT rectangle
96
+ * of its anchor. Those coordinates are only right when the containing
97
+ * block of the overlay starts at the origin of the document, which is why
98
+ * Primer's own default portal root is `absolute` at `0, 0`.
99
+ *
100
+ * Left `relative`, this root instead sits wherever the flow of the body
101
+ * ends and becomes the containing block of everything portaled into it:
102
+ * in an application whose markup is a full-height element — a React page
103
+ * hosting JupyterLab — that is the bottom of the screen, and every menu
104
+ * opened at the top of the page was drawn a screen further down, off the
105
+ * bottom edge. Which reads, to whoever clicked, as a menu that refuses to
106
+ * open. The high z-index is kept: it needs a positioned element, and
107
+ * `absolute` is one.
108
+ */
109
+ portalRoot.style.position = 'absolute';
110
+ portalRoot.style.top = '0';
111
+ portalRoot.style.left = '0';
112
+ portalRoot.style.width = '100%';
86
113
  portalRoot.style.zIndex = '9999';
87
114
  registerPortalRoot(portalRoot);
88
115
  };
116
+ /**
117
+ * The element Primer portals render under, when it has been set up.
118
+ *
119
+ * `setupPrimerPortals` creates it; before that call there is none, and this
120
+ * answers `null` rather than inventing one.
121
+ */
122
+ export const getPrimerPortalRoot = () => document.getElementById(PRIMER_PORTAL_ROOT_ID);
89
123
  /* ─── camelCase → kebab-case ─────────────────────────────────────────── */
90
124
  const camelToKebab = (s) => s.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
91
125
  /**
@@ -102,33 +136,54 @@ const camelToKebab = (s) => s.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
102
136
  * portals stay in sync whenever theme or color-mode changes.
103
137
  */
104
138
  export function syncPortalThemeStyles(styles) {
105
- const body = document.body;
106
- // 1. Remove properties set by the previous invocation.
107
- const prev = body[PORTAL_THEME_KEYS];
108
- if (prev) {
109
- for (const key of prev) {
110
- body.style.removeProperty(key);
111
- }
112
- }
113
- // 2. Apply the new properties.
114
- const tracked = [];
115
- for (const [key, value] of Object.entries(styles)) {
116
- if (value == null)
117
- continue;
118
- const strVal = String(value);
119
- if (key.startsWith('--')) {
120
- // CSS custom property — must use setProperty
121
- body.style.setProperty(key, strVal);
122
- tracked.push(key);
139
+ /*
140
+ * On the portal root as well as on the body, and that is the point.
141
+ *
142
+ * The body was enough for what portals INHERIT — a font, a line height —
143
+ * and never enough for the colours. The portal root carries Primer's own
144
+ * theme markers (`data-color-mode`, `data-light-theme`), and Primer's
145
+ * stylesheet declares `--bgColor-*`, `--fgColor-*` and the rest ON any
146
+ * element carrying them. A declaration on the element always beats a value
147
+ * inherited from an ancestor, so Primer's default palette won on the portal
148
+ * root and everything drawn inside it — the buttons of a dialog, the
149
+ * background of a menu — came out in the default theme while the same
150
+ * components in the page wore the chosen one.
151
+ *
152
+ * Written inline on that element, the theme wins in turn: an inline style
153
+ * outranks any selector in a stylesheet.
154
+ */
155
+ const targets = [
156
+ document.body,
157
+ document.getElementById(PRIMER_PORTAL_ROOT_ID)
158
+ ].filter(Boolean);
159
+ for (const target of targets) {
160
+ // 1. Remove properties set by the previous invocation.
161
+ const prev = target[PORTAL_THEME_KEYS];
162
+ if (prev) {
163
+ for (const key of prev) {
164
+ target.style.removeProperty(key);
165
+ }
123
166
  }
124
- else {
125
- // Standard CSS property (camelCase → kebab-case)
126
- const kebab = camelToKebab(key);
127
- body.style.setProperty(kebab, strVal);
128
- tracked.push(kebab);
167
+ // 2. Apply the new properties.
168
+ const tracked = [];
169
+ for (const [key, value] of Object.entries(styles)) {
170
+ if (value == null)
171
+ continue;
172
+ const strVal = String(value);
173
+ if (key.startsWith('--')) {
174
+ // CSS custom property — must use setProperty
175
+ target.style.setProperty(key, strVal);
176
+ tracked.push(key);
177
+ }
178
+ else {
179
+ // Standard CSS property (camelCase → kebab-case)
180
+ const kebab = camelToKebab(key);
181
+ target.style.setProperty(kebab, strVal);
182
+ tracked.push(kebab);
183
+ }
129
184
  }
185
+ // 3. Stash the list for the next cleanup.
186
+ target[PORTAL_THEME_KEYS] = tracked;
130
187
  }
131
- // 3. Stash the list for the next cleanup.
132
- body[PORTAL_THEME_KEYS] = tracked;
133
188
  }
134
189
  export default setupPrimerPortals;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/primer-addons",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "license": "BSD-3-Clause",
5
5
  "scripts": {
6
6
  "build": "npm run build:lib",