@glimstone/react 4.2.7 → 4.3.4

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,6 +1,6 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useLayoutEffect, useRef } from "react";
3
- import { keepReadmeFit, readmePartClass, readmeSoon, readmeUnitClass, } from "@glimstone/core";
3
+ import { keepReadmeFit, readmePartClass, readmePartLabel, readmeSoon, readmeUnitClass, } from "@glimstone/core";
4
4
  import { InfoBubble } from "./InfoBubble.js";
5
5
  export function ReadmeButton({ brand, parts, mark, markClass, art, hint, note, soonLabel, onLinkClick }) {
6
6
  const ref = useRef(null);
@@ -9,7 +9,7 @@ export function ReadmeButton({ brand, parts, mark, markClass, art, hint, note, s
9
9
  useLayoutEffect(() => (ref.current ? keepReadmeFit(ref.current) : undefined), [words]);
10
10
  return (_jsxs("div", { ref: ref, className: readmeUnitClass(brand, parts.length, !!note, soon), children: [parts.map((part, i) => {
11
11
  const sub = soon ? soonLabel : part.sub;
12
- const label = sub ? `${part.name} ${sub}` : part.name;
12
+ const label = readmePartLabel(part, sub);
13
13
  const className = readmePartClass(i, soon);
14
14
  const face = i === 0 && art ? (_jsx("span", { className: "glim-readme-btn-art", "aria-hidden": true, children: art })) : (_jsxs(_Fragment, { children: [i === 0 && mark && (_jsx("span", { className: `glim-readme-btn-mark ${markClass ?? ""}`, "aria-hidden": true, children: mark })), _jsxs("span", { className: "glim-readme-btn-text", children: [_jsx("span", { className: "glim-readme-btn-name", children: part.name }), sub && _jsx("span", { className: "glim-readme-btn-sub", children: sub })] })] }));
15
15
  if (soon) {
@@ -43,15 +43,18 @@ export interface SelectorProps<M extends SelectMode = "one", V extends string |
43
43
  * click, as a radio group; for a strip that saves a setting. */
44
44
  activation?: SelectorActivation;
45
45
  /** Pin every segment to the widest one's measured width, at least the shared
46
- * floor where the row has room; the page-level picker. */
46
+ * floor where the row has room; the page-level picker. Where the pinned
47
+ * widths do not fit the row, the segments share it by their labels. */
47
48
  equalWidth?: boolean;
48
49
  /** Hug the segments instead of spanning the box, for a strip that shares a
49
50
  * toolbar row, as it does inside a FieldRow. */
50
51
  inline?: boolean;
51
- /** Keep every segment on one row, for page tabs: once the labels do not fit
52
- * together every segment shows its glyph alone. */
52
+ /** Share the row evenly without a pinned width, for page tabs. Every strip
53
+ * keeps to one row; once its labels do not fit together it shows glyphs
54
+ * alone where every segment has one, a strip of one turns into a dropdown
55
+ * otherwise, and a `many` strip cuts its labels short. */
53
56
  fit?: boolean;
54
- /** Below 600px, two segments to a row with labels that wrap. */
57
+ /** Has no effect: every strip keeps to one row. */
55
58
  pairsOnPhone?: boolean;
56
59
  /** The button height for every segment, for a strip beside a Button. */
57
60
  buttonHeight?: boolean;
@@ -68,4 +71,4 @@ export interface SelectorProps<M extends SelectMode = "one", V extends string |
68
71
  panelId?: string;
69
72
  className?: string;
70
73
  }
71
- export declare function Selector<M extends SelectMode = "one", V extends string | number = string>({ items, label, select, value, onChange, onPress, orientation, size, variant, activation, equalWidth, inline: ownInline, fit, pairsOnPhone, buttonHeight, hue, hueOffset, disabled, panelId, className, }: SelectorProps<M, V>): import("react").JSX.Element;
74
+ export declare function Selector<M extends SelectMode = "one", V extends string | number = string>({ items, label, select, value, onChange, onPress, orientation, size, variant, activation, equalWidth, inline: ownInline, fit, buttonHeight, hue, hueOffset, disabled, panelId, className, }: SelectorProps<M, V>): import("react").JSX.Element;
package/dist/Selector.js CHANGED
@@ -1,14 +1,15 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useId, useLayoutEffect, useRef, useState, useSyncExternalStore, } from "react";
3
- import { countSelector, DESKTOP_QUERY, mediaMatches, roveSelector, rovedIndex, segmentView, selectorAxis, selectorFlex, selectorTabId, selectorView, subscribeMedia, toggleSelection, watchSelectorFit, watchSelectorRows, WIDE_QUERY, } from "@glimstone/core";
3
+ import { countSelector, mediaMatches, roveSelector, rovedIndex, segmentView, selectorAxis, selectorFlex, selectorTabId, selectorView, subscribeMedia, toggleSelection, watchSelectorFit, WIDE_QUERY, } from "@glimstone/core";
4
4
  import { useFieldName } from "./fieldName.js";
5
+ import { Select } from "./Select.js";
5
6
  import { useLabelMode } from "./useLabelMode.js";
6
7
  import { useTipBubble } from "./useTipBubble.js";
7
8
  export { selectorTabId } from "@glimstone/core";
8
9
  function useMedia(query) {
9
10
  return useSyncExternalStore((fn) => subscribeMedia(query, fn), () => mediaMatches(query), () => true);
10
11
  }
11
- export function Selector({ items, label, select, value, onChange, onPress, orientation = "horizontal", size = "md", variant = "well", activation = "auto", equalWidth = false, inline: ownInline = false, fit = false, pairsOnPhone = false, buttonHeight = false, hue = true, hueOffset, disabled = false, panelId, className = "", }) {
12
+ export function Selector({ items, label, select, value, onChange, onPress, orientation = "horizontal", size = "md", variant = "well", activation = "auto", equalWidth = false, inline: ownInline = false, fit = false, buttonHeight = false, hue = true, hueOffset, disabled = false, panelId, className = "", }) {
12
13
  const name = useFieldName(label);
13
14
  const inline = ownInline || (label === undefined && name !== undefined);
14
15
  const vertical = orientation === "vertical";
@@ -24,10 +25,8 @@ export function Selector({ items, label, select, value, onChange, onPress, orien
24
25
  equalWidth,
25
26
  inline,
26
27
  fit,
27
- pairsOnPhone,
28
28
  hue,
29
29
  hueOffset,
30
- desktop: useMedia(DESKTOP_QUERY),
31
30
  wide: useMedia(WIDE_QUERY),
32
31
  items: items.map((it) => ({ hasGlyph: !!it.glyph, iconOnly: !!it.iconOnly })),
33
32
  });
@@ -42,23 +41,17 @@ export function Selector({ items, label, select, value, onChange, onPress, orien
42
41
  // watch moves to it through disabledKey.
43
42
  const itemsKey = items.map((it) => it.label).join("\n");
44
43
  const disabledKey = items.map((it) => (disabled || it.disabled ? "1" : "0")).join("");
45
- const [rows, setRows] = useState(null);
44
+ const [layout, setLayout] = useState(null);
46
45
  useLayoutEffect(() => {
47
- if (!strip.pinWidth) {
48
- setRows(null);
46
+ if (vertical) {
47
+ setLayout(null);
49
48
  return;
50
49
  }
51
- return watchSelectorRows(track.current, { inline, equalWidth }, setRows);
52
- }, [strip.pinWidth, equalWidth, inline, itemsKey, disabledKey, size, strip.mode]);
53
- const [fitMode, setFitMode] = useState("even");
54
- useLayoutEffect(() => {
55
- if (!strip.canSqueeze) {
56
- setFitMode("even");
57
- return;
58
- }
59
- return watchSelectorFit(track.current, setFitMode);
60
- }, [strip.canSqueeze, itemsKey, disabledKey, size]);
61
- const layout = selectorFlex({ rows, pinWidth: strip.pinWidth, inline, fit, fitMode, pairsOnPhone });
50
+ const { pinWidth, canSqueeze, canList } = strip;
51
+ return watchSelectorFit(track.current, { pinWidth, fit, canSqueeze, canList }, setLayout);
52
+ }, [vertical, strip.pinWidth, fit, strip.canSqueeze, strip.canList, inline, itemsKey, disabledKey, size, strip.mode]);
53
+ const flex = selectorFlex({ layout, inline, fit });
54
+ const listed = layout?.fit === "list";
62
55
  const chosen = many ? value : null;
63
56
  const isOn = (id) => (chosen ? chosen.includes(id) : value === id);
64
57
  const disabledFlags = items.map((it) => disabled || !!it.disabled);
@@ -69,6 +62,9 @@ export function Selector({ items, label, select, value, onChange, onPress, orien
69
62
  change(chosen ? toggleSelection(chosen, id, items.map((it) => it.id)) : id);
70
63
  }
71
64
  function onKeyDown(e) {
65
+ // The dropdown's keys reach the track through the portal too.
66
+ if (listed)
67
+ return;
72
68
  // A tile is a link, and Space does not follow a link on its own.
73
69
  if (vertical && e.key === " " && e.target.dataset.selId) {
74
70
  e.preventDefault();
@@ -83,10 +79,14 @@ export function Selector({ items, label, select, value, onChange, onPress, orien
83
79
  if (strip.autoSelect && item)
84
80
  choose(item.id);
85
81
  }
86
- return (_jsx("div", { ref: track, role: strip.role, "aria-label": name, "aria-orientation": strip.role === "group" ? undefined : orientation, onKeyDown: onKeyDown, className: `${strip.className} ${className}`.trim(), style: layout.track, children: items.map((item, i) => (_jsx(Segment, { item: item, index: i, strip: strip, on: isOn(item.id), disabled: disabledFlags[i], roved: i === roved, share: vertical ? undefined : layout.segment, squeezed: strip.canSqueeze && fitMode === "squeezed", orientation: orientation, size: size, variant: variant, equalWidth: equalWidth, buttonHeight: buttonHeight, pairsOnPhone: pairsOnPhone, hue: hue, hueOffset: hueOffset, panelId: panelId, onSelect: () => choose(item.id) }, item.id))) }));
82
+ return (_jsxs("div", { ref: track, role: listed ? undefined : strip.role, "aria-label": listed ? undefined : name, "aria-orientation": listed || strip.role === "group" ? undefined : orientation, onKeyDown: onKeyDown, className: `${strip.className}${listed ? " glim-sel--listed" : ""} ${className}`.trim(), style: flex.track, children: [items.map((item, i) => (_jsx(Segment, { item: item, index: i, strip: strip, on: isOn(item.id), disabled: disabledFlags[i], roved: i === roved, listed: listed, share: vertical ? undefined : flex.segment, squeezed: layout?.fit === "squeezed", cut: !!layout?.cut[i], orientation: orientation, size: size, variant: variant, equalWidth: equalWidth, buttonHeight: buttonHeight, hue: hue, hueOffset: hueOffset, panelId: panelId, onSelect: () => choose(item.id) }, item.id))), listed && (_jsx("div", { className: "glim-sel-list", children: _jsx(Select, { label: name ?? "", hideLabel: true, wrap: true, width: "fill", size: size === "sm" ? "row" : "field", options: items.map((it, i) => ({ value: String(it.id), label: it.label, glyph: it.glyph, disabled: disabledFlags[i] })), value: value === null ? null : String(value), onChange: (next) => {
83
+ const item = items.find((it) => String(it.id) === next);
84
+ if (item)
85
+ choose(item.id);
86
+ }, disabled: disabledFlags.every(Boolean) }) }))] }));
87
87
  }
88
88
  // One segment or tile, a component of its own so each holds its own bubble.
89
- function Segment({ item, index, strip, on, disabled, roved, share, squeezed, orientation, size, variant, equalWidth, buttonHeight, pairsOnPhone, hue, hueOffset, panelId, onSelect, }) {
89
+ function Segment({ item, index, strip, on, disabled, roved, listed, share, squeezed, cut, orientation, size, variant, equalWidth, buttonHeight, hue, hueOffset, panelId, onSelect, }) {
90
90
  const view = segmentView({
91
91
  strip,
92
92
  orientation,
@@ -94,7 +94,6 @@ function Segment({ item, index, strip, on, disabled, roved, share, squeezed, ori
94
94
  variant,
95
95
  equalWidth,
96
96
  buttonHeight,
97
- pairsOnPhone,
98
97
  hue,
99
98
  hueOffset,
100
99
  index,
@@ -107,6 +106,7 @@ function Segment({ item, index, strip, on, disabled, roved, share, squeezed, ori
107
106
  disabled,
108
107
  dim: item.dim,
109
108
  squeezed,
109
+ cut,
110
110
  });
111
111
  const tooltip = useTipBubble(view.tip, disabled);
112
112
  // A disabled segment takes no hover or focus, so its reason is a
@@ -128,6 +128,6 @@ function Segment({ item, index, strip, on, disabled, roved, share, squeezed, ori
128
128
  };
129
129
  return (_jsxs(_Fragment, { children: [_jsx("a", { ...item.attrs, ref: tooltip.ref, href: item.href, "data-sel-id": item.id, role: "tab", "aria-selected": on, "aria-current": on ? "page" : undefined, "aria-describedby": described, tabIndex: roved ? 0 : -1, className: view.className, style: style, onClick: open, ...tooltip.handlers, children: content }), tooltip.bubble] }));
130
130
  }
131
- const button = (_jsx("button", { ...item.attrs, ref: tooltip.ref, type: "button", "data-sel-id": item.id, id: panelId && tab ? selectorTabId(panelId, item.id) : undefined, role: strip.kind === "toggle" ? undefined : strip.kind, "aria-selected": tab ? on : undefined, "aria-controls": panelId && tab && on ? panelId : undefined, "aria-checked": strip.kind === "radio" ? on : undefined, "aria-pressed": strip.kind === "toggle" ? on : undefined, "aria-label": view.ariaLabel, "aria-describedby": described, disabled: disabled, tabIndex: roved ? 0 : -1, className: view.className, style: style, onClick: onSelect, ...tooltip.handlers, children: content }));
131
+ const button = (_jsx("button", { ...item.attrs, ref: tooltip.ref, type: "button", "data-sel-id": item.id, id: panelId && tab ? selectorTabId(panelId, item.id) : undefined, role: strip.kind === "toggle" ? undefined : strip.kind, "aria-selected": tab ? on : undefined, "aria-controls": panelId && tab && on ? panelId : undefined, "aria-checked": strip.kind === "radio" ? on : undefined, "aria-pressed": strip.kind === "toggle" ? on : undefined, "aria-label": view.ariaLabel, "aria-describedby": described, "aria-hidden": listed || undefined, disabled: disabled, tabIndex: roved && !listed ? 0 : -1, className: view.className, style: style, onClick: onSelect, ...tooltip.handlers, children: content }));
132
132
  return (_jsxs(_Fragment, { children: [disabled && view.tip ? (_jsx("span", { className: "glim-tip-wrap", style: share, onMouseEnter: tooltip.show, onMouseLeave: tooltip.hide, children: button })) : (button), disabled && view.tip && (_jsx("span", { id: descId, hidden: true, children: view.tip })), tooltip.bubble] }));
133
133
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glimstone/react",
3
- "version": "4.2.7",
3
+ "version": "4.3.4",
4
4
  "description": "GlimStone's components for React",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": { "type": "git", "url": "git+https://github.com/junkerderprovinz/glimstone.git", "directory": "packages/react" },
@@ -16,7 +16,7 @@
16
16
  "build": "tsc -p tsconfig.build.json"
17
17
  },
18
18
  "dependencies": {
19
- "@glimstone/core": "4.2.7"
19
+ "@glimstone/core": "4.3.4"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "@zag-js/combobox": "^1.46.0",