@datalayer/primer-addons 1.0.56 → 1.0.57

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 CHANGED
@@ -43,8 +43,9 @@ This project has been [shared in a discussion](https://github.com/primer/react/d
43
43
  - [x] Timeline
44
44
  - [x] Toast Panel and its queue (`toastQueue`)
45
45
  - [x] Toolbar and Floating Toolbar
46
+ - [x] Route Tabs (tabs that are routes, navigated by the host)
46
47
  - [x] Truncate
47
- - [x] View Tabs
48
+ - [x] View Tabs and `useTabParam` (the open tab in the address)
48
49
 
49
50
  The action buttons, Animated Text, the display helpers, Fluent Emoji, the
50
51
  progress components, Sparklines, the labels, Timeline, the toasts, Truncate
@@ -53,6 +54,13 @@ until 29 November 2026; they are imported from `@datalayer/primer-addons`
53
54
  now, with no alias left in core. Fluent Emoji's drawings are regenerated by
54
55
  `scripts/generate-fluent-emoji.py`.
55
56
 
57
+ `useTabParam` (core's until then) and Route Tabs (the Datalayer landing's
58
+ `Tabs`) followed the same day. Neither carries a router: `useTabParam` is
59
+ handed the search pair React Router's `useSearchParams()` returns,
60
+ `useTabParam(ids, useSearchParams(), 'part')`, and Route Tabs a `navigate`
61
+ called with the chosen tab's `to`. The gallery's *Tabs* page shows both
62
+ beside View Tabs.
63
+
56
64
  The components use the active theme's semantic tokens rather than fixed
57
65
  visual values. For example, toolbar icon buttons and dropdown triggers read
58
66
  `--theme-radius-control`: they retain the regular Primer corner in the default
@@ -0,0 +1,38 @@
1
+ /**
2
+ * A row of tabs that are routes: the selected one is in the address, so a
3
+ * link opens a page on its tab and the back button returns to the last one.
4
+ * Underlined, the open tab in the accent; a row too long for its width
5
+ * scrolls rather than wrapping.
6
+ *
7
+ * The component has no router of its own: `navigate` is the host's, called
8
+ * with the chosen tab's `to`.
9
+ *
10
+ * @module components/tabs/RouteTabs
11
+ */
12
+ import type { JSX } from 'react';
13
+ import type { Icon } from '@primer/octicons-react';
14
+ export type RouteTab = {
15
+ key: string;
16
+ label: string;
17
+ /** Where the tab lives. */
18
+ to: string;
19
+ /** A count shown after the label, when there is one. */
20
+ count?: number | null;
21
+ /**
22
+ * A mark before the label, when the tab has one. It is the same mark the
23
+ * destination wears elsewhere in the application, so a row of tabs and the
24
+ * sidebar name the same thing the same way.
25
+ */
26
+ icon?: Icon;
27
+ };
28
+ export type RouteTabsProps = {
29
+ /** What the tabs are of, said to assistive technology. */
30
+ label: string;
31
+ items: ReadonlyArray<RouteTab>;
32
+ /** The key of the open tab. */
33
+ current: string;
34
+ /** The host's navigation, called with the chosen tab's `to`. */
35
+ navigate: (to: string) => void;
36
+ };
37
+ export declare const RouteTabs: ({ label, items, current, navigate, }: RouteTabsProps) => JSX.Element;
38
+ export default RouteTabs;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CounterLabel } from '@primer/react';
3
+ import { Box } from '../box/Box';
4
+ export const RouteTabs = ({ label, items, current, navigate, }) => (_jsx(Box, { role: "tablist", "aria-label": label, display: "flex", gap: 1, borderBottom: "1px solid", borderColor: "border.default", mb: 3, overflowX: "auto", children: items.map(item => {
5
+ const selected = item.key === current;
6
+ return (_jsxs(Box, { as: "button", type: "button", role: "tab", "aria-selected": selected, "data-tab": item.key, onClick: () => navigate(item.to), appearance: "none", background: "none", border: "none", borderBottom: "2px solid", borderBottomColor: selected ? 'accent.fg' : 'transparent', color: selected ? 'fg.default' : 'fg.muted', fontWeight: selected ? 'semibold' : 'normal', fontSize: 1, px: 2, py: 2, cursor: "pointer", whiteSpace: "nowrap", display: "inline-flex", alignItems: "center", gap: 2, hover: { color: 'fg.default' }, children: [item.icon ? (_jsx(Box, { as: "span", "aria-hidden": "true", display: "inline-flex", color: selected ? 'accent.fg' : 'fg.muted', children: _jsx(item.icon, { size: 16 }) })) : null, item.label, typeof item.count === 'number' ? (_jsx(CounterLabel, { children: item.count })) : null] }, item.key));
7
+ }) }));
8
+ export default RouteTabs;
@@ -0,0 +1,12 @@
1
+ import type { StoryObj } from '@storybook/react';
2
+ declare const meta: {
3
+ title: string;
4
+ component: ({ label, items, current, navigate, }: import("./RouteTabs").RouteTabsProps) => import("react").JSX.Element;
5
+ tags: string[];
6
+ parameters: {
7
+ layout: string;
8
+ };
9
+ };
10
+ export default meta;
11
+ type Story = StoryObj<typeof meta>;
12
+ export declare const Default: Story;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } 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 { useState } from 'react';
7
+ import { GearIcon, GraphIcon, PlayIcon } from '@primer/octicons-react';
8
+ import { Box } from '../box/Box';
9
+ import { RouteTabs } from './RouteTabs';
10
+ const meta = {
11
+ title: 'Components/RouteTabs',
12
+ component: RouteTabs,
13
+ tags: ['autodocs'],
14
+ parameters: { layout: 'fullscreen' },
15
+ };
16
+ export default meta;
17
+ const ITEMS = [
18
+ { key: 'overview', label: 'Overview', to: '/benchmarks/swe' },
19
+ { key: 'runs', label: 'Runs', to: '/benchmarks/swe/runs', count: 12, icon: PlayIcon },
20
+ { key: 'reports', label: 'Reports', to: '/benchmarks/swe/reports', count: 0, icon: GraphIcon },
21
+ { key: 'settings', label: 'Settings', to: '/benchmarks/swe/settings', icon: GearIcon },
22
+ ];
23
+ const Routed = (props) => {
24
+ const [path, setPath] = useState(props.items[0].to);
25
+ const current = props.items.find(item => item.to === path)?.key ?? props.items[0].key;
26
+ return (_jsxs(Box, { p: 3, bg: "canvas.default", children: [_jsx(RouteTabs, { label: "Benchmark", items: props.items, current: current, navigate: setPath }), _jsx(Box, { as: "code", color: "fg.muted", fontSize: 1, children: path })] }));
27
+ };
28
+ export const Default = {
29
+ args: { label: 'Benchmark', items: ITEMS, current: 'overview', navigate: () => undefined },
30
+ render: args => _jsx(Routed, { items: args.items }),
31
+ };
@@ -9,7 +9,8 @@
9
9
  * - A tab may be `disabled`, its `title` saying why; it may carry a `count`.
10
10
  * - A tab may carry a `leadingVisual`, an icon before its label (the user,
11
11
  * 21 November 2026: the application page's Build, Try, Validate and Ship).
12
- * - `useTabParam` (./useTabParam) keeps the open tab in the address (`?tab=`).
12
+ * - `useTabParam` (./useTabParam) keeps the open tab in the address (`?tab=`),
13
+ * given the host's search pair (React Router's `useSearchParams()`).
13
14
  *
14
15
  * @module components/tabs/ViewTabs
15
16
  */
@@ -11,3 +11,4 @@ declare const meta: {
11
11
  export default meta;
12
12
  type Story = StoryObj<typeof meta>;
13
13
  export declare const Default: Story;
14
+ export declare const InTheAddress: Story;
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /*
3
3
  * Copyright (c) 2021-2026 Datalayer, Inc.
4
4
  * Distributed under the terms of the Modified BSD License.
@@ -7,6 +7,7 @@ import { useState } from 'react';
7
7
  import { PlayIcon, ToolsIcon } from '@primer/octicons-react';
8
8
  import { Box } from '../box/Box';
9
9
  import { ViewTabs } from './ViewTabs';
10
+ import { useTabParam } from './useTabParam';
10
11
  const meta = {
11
12
  title: 'Components/ViewTabs',
12
13
  component: ViewTabs,
@@ -28,3 +29,14 @@ export const Default = {
28
29
  args: { label: 'Sections', tabs: TABS, value: 'all', onChange: () => undefined },
29
30
  render: args => _jsx(Stateful, { tabs: args.tabs }),
30
31
  };
32
+ /** The open tab in the address: the search pair held in state, as a router would hand it. */
33
+ const InTheAddressStory = (props) => {
34
+ const [search, setSearch] = useState(() => new URLSearchParams());
35
+ const pair = [search, next => setSearch(next)];
36
+ const [open, setOpen] = useTabParam(props.tabs.map(tab => tab.id), pair);
37
+ return (_jsxs(Box, { p: 3, bg: "canvas.default", children: [_jsx(ViewTabs, { label: "Sections", tabs: props.tabs, value: open, onChange: setOpen }), _jsxs(Box, { as: "code", color: "fg.muted", fontSize: 1, children: ["?", search.toString()] })] }));
38
+ };
39
+ export const InTheAddress = {
40
+ args: { label: 'Sections', tabs: TABS, value: 'all', onChange: () => undefined },
41
+ render: args => _jsx(InTheAddressStory, { tabs: args.tabs }),
42
+ };
@@ -1 +1,3 @@
1
1
  export * from './ViewTabs';
2
+ export * from './RouteTabs';
3
+ export * from './useTabParam';
@@ -3,3 +3,5 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  export * from './ViewTabs';
6
+ export * from './RouteTabs';
7
+ export * from './useTabParam';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The address's search parameters and how to replace them: the pair React
3
+ * Router's `useSearchParams()` returns, or any state shaped the same way.
4
+ */
5
+ export type TabSearch = readonly [
6
+ URLSearchParams,
7
+ (next: URLSearchParams, options: {
8
+ replace: boolean;
9
+ }) => void
10
+ ];
11
+ /**
12
+ * The open tab kept in the address under `param` (`tab` by default): the
13
+ * first of `ids` when absent or unknown, and dropped from the address when it
14
+ * is the first, so the view's own address opens it. Choosing a tab replaces
15
+ * the address rather than pushing one, and keeps its other parameters.
16
+ */
17
+ export declare function useTabParam<T extends string>(ids: ReadonlyArray<T>, [search, setSearch]: TabSearch, param?: string): [T, (id: T) => void];
18
+ export default useTabParam;
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright (c) 2023-2026 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * The open tab kept in the address, with no router of its own: the host hands
7
+ * in its search parameters and their setter, as React Router's
8
+ * `useSearchParams()` returns them, so `useTabParam(ids, useSearchParams())`
9
+ * is the whole binding.
10
+ *
11
+ * @module components/tabs/useTabParam
12
+ */
13
+ import { useCallback } from 'react';
14
+ /**
15
+ * The open tab kept in the address under `param` (`tab` by default): the
16
+ * first of `ids` when absent or unknown, and dropped from the address when it
17
+ * is the first, so the view's own address opens it. Choosing a tab replaces
18
+ * the address rather than pushing one, and keeps its other parameters.
19
+ */
20
+ export function useTabParam(ids, [search, setSearch], param = 'tab') {
21
+ const asked = search.get(param);
22
+ const open = ids.includes(asked ?? '')
23
+ ? asked
24
+ : ids[0];
25
+ const choose = useCallback((id) => {
26
+ const next = new URLSearchParams(search);
27
+ if (id === ids[0]) {
28
+ next.delete(param);
29
+ }
30
+ else {
31
+ next.set(param, id);
32
+ }
33
+ setSearch(next, { replace: true });
34
+ }, [search, setSearch, ids, param]);
35
+ return [open, choose];
36
+ }
37
+ export default useTabParam;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/primer-addons",
3
- "version": "1.0.56",
3
+ "version": "1.0.57",
4
4
  "license": "BSD-3-Clause",
5
5
  "scripts": {
6
6
  "build": "npm run build:lib",