@stackone/malachite 2.105.1 → 2.106.0
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/COMPONENTS.md +1 -1
- package/dist/components/FilterSearch.js +392 -355
- package/dist/components/FilterSearch.js.map +1 -1
- package/dist/components/FilterSearchPanel.js +167 -0
- package/dist/components/FilterSearchPanel.js.map +1 -0
- package/dist/components/SegmentedControl.js +25 -23
- package/dist/components/SegmentedControl.js.map +1 -1
- package/dist/components/filterSearchModel.js +32 -31
- package/dist/components/filterSearchModel.js.map +1 -1
- package/dist/index.d.ts +12 -5
- package/dist/tailwind.css.js +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { jsx as m, jsxs as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { FOCUS_RING as
|
|
4
|
-
import { rovingTabStop as
|
|
5
|
-
const
|
|
1
|
+
import { jsx as m, jsxs as $ } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as w } from "react";
|
|
3
|
+
import { FOCUS_RING as I } from "./focusRing.js";
|
|
4
|
+
import { rovingTabStop as D, nextRovingIndex as N } from "./rovingKeys.js";
|
|
5
|
+
const j = {
|
|
6
6
|
small: {
|
|
7
7
|
text: "text-[length:var(--malachite-font-size-small,13px)]",
|
|
8
8
|
track: "h-[var(--malachite-control-height-small,28px)]",
|
|
@@ -18,44 +18,46 @@ const N = {
|
|
|
18
18
|
track: "h-[var(--malachite-control-height-large,42px)]",
|
|
19
19
|
item: "h-full px-4"
|
|
20
20
|
}
|
|
21
|
-
},
|
|
22
|
-
options:
|
|
21
|
+
}, z = "inline-flex items-center justify-center gap-1.5 rounded-[var(--malachite-radius-10,10px)] border-0 font-medium tracking-[0.13px] whitespace-nowrap transition-colors duration-150 ease-in-out", _ = ({
|
|
22
|
+
options: r,
|
|
23
23
|
value: s,
|
|
24
24
|
onChange: u,
|
|
25
25
|
size: g = "medium",
|
|
26
26
|
fullWidth: x = !1,
|
|
27
|
-
disabled:
|
|
27
|
+
disabled: l = !1,
|
|
28
28
|
"aria-label": b,
|
|
29
29
|
"aria-labelledby": v,
|
|
30
|
-
|
|
30
|
+
"aria-describedby": p,
|
|
31
|
+
className: k = ""
|
|
31
32
|
}) => {
|
|
32
|
-
const o =
|
|
33
|
+
const o = w([]), d = j[g], y = r.findIndex((e) => e.value === s), h = r.map((e) => !e.disabled), f = D(y, h);
|
|
33
34
|
return /* @__PURE__ */ m(
|
|
34
35
|
"div",
|
|
35
36
|
{
|
|
36
37
|
role: "radiogroup",
|
|
37
38
|
"aria-label": b,
|
|
38
39
|
"aria-labelledby": v,
|
|
39
|
-
"aria-
|
|
40
|
+
"aria-describedby": p,
|
|
41
|
+
"aria-disabled": l || void 0,
|
|
40
42
|
onKeyDown: (e) => {
|
|
41
43
|
var a;
|
|
42
|
-
if (
|
|
44
|
+
if (l)
|
|
43
45
|
return;
|
|
44
|
-
const n = o.current.findIndex((c) => c === e.target), t =
|
|
45
|
-
t !== void 0 && (e.preventDefault(),
|
|
46
|
+
const n = o.current.findIndex((c) => c === e.target), t = N(e, n >= 0 ? n : f, h);
|
|
47
|
+
t !== void 0 && (e.preventDefault(), r[t].value !== s && u(r[t].value), (a = o.current[t]) == null || a.focus());
|
|
46
48
|
},
|
|
47
49
|
className: `${// One display utility, not two: `flex` and `inline-flex` are both plain
|
|
48
50
|
// `display` utilities, so emitting both would resolve by stylesheet order
|
|
49
51
|
// (same hazard as the background above).
|
|
50
|
-
x ? "flex w-full" : "inline-flex"} ${d.track} items-center gap-1 p-0.5 rounded-xl bg-[var(--malachite-segmented-control-track-background)] ${
|
|
51
|
-
children:
|
|
52
|
-
const t = e.value === s, a =
|
|
52
|
+
x ? "flex w-full" : "inline-flex"} ${d.track} items-center gap-1 p-0.5 rounded-xl bg-[var(--malachite-segmented-control-track-background)] ${l ? "opacity-50" : ""} ${k}`,
|
|
53
|
+
children: r.map((e, n) => {
|
|
54
|
+
const t = e.value === s, a = l || e.disabled, c = e.badge !== void 0 && e.badge !== null && e.badge !== !1;
|
|
53
55
|
let i;
|
|
54
|
-
return t ? i = "bg-[var(--malachite-segmented-control-selected-background)] text-[var(--malachite-segmented-control-selected-foreground)]" : a ? i = "bg-transparent text-[var(--malachite-segmented-control-item-foreground)]" : i = "bg-transparent text-[var(--malachite-segmented-control-item-foreground)] hover:text-[var(--malachite-segmented-control-item-hover-foreground)] cursor-pointer", /* @__PURE__ */
|
|
56
|
+
return t ? i = "bg-[var(--malachite-segmented-control-selected-background)] text-[var(--malachite-segmented-control-selected-foreground)]" : a ? i = "bg-transparent text-[var(--malachite-segmented-control-item-foreground)]" : i = "bg-transparent text-[var(--malachite-segmented-control-item-foreground)] hover:text-[var(--malachite-segmented-control-item-hover-foreground)] cursor-pointer", /* @__PURE__ */ $(
|
|
55
57
|
"button",
|
|
56
58
|
{
|
|
57
|
-
ref: (
|
|
58
|
-
o.current[n] =
|
|
59
|
+
ref: (S) => {
|
|
60
|
+
o.current[n] = S;
|
|
59
61
|
},
|
|
60
62
|
type: "button",
|
|
61
63
|
role: "radio",
|
|
@@ -65,7 +67,7 @@ const N = {
|
|
|
65
67
|
onClick: () => {
|
|
66
68
|
!a && !t && u(e.value);
|
|
67
69
|
},
|
|
68
|
-
className: `${
|
|
70
|
+
className: `${I} ${z} ${d.text} ${d.item} ${i} ${x ? "flex-1" : ""} ${e.disabled && !l ? "opacity-50 cursor-not-allowed" : ""}`,
|
|
69
71
|
style: {
|
|
70
72
|
// Inline rather than a Tailwind shadow class: Tailwind's shadow
|
|
71
73
|
// utilities compose `--tw-shadow-*` custom properties that rely on
|
|
@@ -87,7 +89,7 @@ const N = {
|
|
|
87
89
|
);
|
|
88
90
|
};
|
|
89
91
|
export {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
_ as SegmentedControl,
|
|
93
|
+
_ as default
|
|
92
94
|
};
|
|
93
95
|
//# sourceMappingURL=SegmentedControl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedControl.js","sources":["../../src/components/SegmentedControl.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport { FOCUS_RING } from './focusRing';\nimport { nextRovingIndex, rovingTabStop } from './rovingKeys';\n\ntype SegmentedControlSize = 'small' | 'medium' | 'large';\n\ninterface SegmentedControlOption<T extends string = string> {\n value: T;\n label: string;\n icon?: React.ReactNode;\n /**\n * Small mark after the label, e.g. a compact `Tag` naming a saving. It renders inside\n * the segment's `<button>`, so it must not be interactive — no `onClick` or `onRemove`.\n */\n badge?: React.ReactNode;\n disabled?: boolean;\n}\n\ninterface SegmentedControlProps<T extends string = string> {\n options: SegmentedControlOption<T>[];\n /** The selected option's value. A value not present in `options` renders nothing selected. */\n value: T;\n onChange: (value: T) => void;\n size?: SegmentedControlSize;\n /** Stretch the track to its container and split it into equal segments. */\n fullWidth?: boolean;\n /** Disables every segment. Individual segments can also be disabled via `options`. */\n disabled?: boolean;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n className?: string;\n}\n\n// The ladder governs a control's outer box. The height therefore sits on the track and\n// the items fill whatever the 4px inset leaves — putting it on the item instead makes a\n// `medium` segmented control 40px tall beside a 32px Dropdown.\nconst SIZE_CLASSES: Record<SegmentedControlSize, { text: string; track: string; item: string }> = {\n small: {\n text: 'text-[length:var(--malachite-font-size-small,13px)]',\n track: 'h-[var(--malachite-control-height-small,28px)]',\n item: 'h-full px-2.5',\n },\n medium: {\n text: 'text-[length:var(--malachite-font-size-small,13px)]',\n track: 'h-[var(--malachite-control-height-medium,32px)]',\n item: 'h-full px-2.5',\n },\n large: {\n text: 'text-[length:var(--malachite-font-size-15,15px)]',\n track: 'h-[var(--malachite-control-height-large,42px)]',\n item: 'h-full px-4',\n },\n};\n\n// Deliberately no `bg-*` here: each state branch below supplies exactly one\n// background-color utility. Both `bg-transparent` and an arbitrary-value `bg-` are plain\n// single-class utilities in the same `@layer utilities`, so an element carrying both\n// resolves by stylesheet order — and the arbitrary value loses, silently rendering the\n// selected thumb transparent.\nconst ITEM_BASE =\n 'inline-flex items-center justify-center gap-1.5 rounded-[var(--malachite-radius-10,10px)] border-0 font-medium tracking-[0.13px] whitespace-nowrap transition-colors duration-150 ease-in-out';\n\n/**\n * A rounded track of mutually-exclusive options — the segmented \"one of these\" control.\n *\n * Owns the track background, the selected-thumb chrome and the radiogroup semantics in\n * one place, so consumers never hand-roll a track around `PillButton` (whose `default`\n * variant tokens are tuned for standalone filter pills, not for a sunken track).\n *\n * Selection is conveyed non-visually via `role=\"radio\"` + `aria-checked`, and by a\n * foreground-colour change as well as the thumb, so it does not rest on background\n * colour alone.\n */\nconst SegmentedControl = <T extends string = string>({\n options,\n value,\n onChange,\n size = 'medium',\n fullWidth = false,\n disabled = false,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n}: SegmentedControlProps<T>) => {\n const itemRefs = useRef<(HTMLButtonElement | null)[]>([]);\n const sizeBlock = SIZE_CLASSES[size];\n\n const selectedIndex = options.findIndex((option) => option.value === value);\n const enabled = options.map((option) => !option.disabled);\n // Roving tabindex: the group is a single tab stop. When the selected option is\n // missing or disabled, the first enabled option takes the stop so the control is\n // still reachable by keyboard.\n const tabStopIndex = rovingTabStop(selectedIndex, enabled);\n\n // Arrow keys move AND select, per the WAI-ARIA radiogroup pattern, from the focused option.\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (disabled) {\n return;\n }\n const focused = itemRefs.current.findIndex((item) => item === event.target);\n const next = nextRovingIndex(event, focused >= 0 ? focused : tabStopIndex, enabled);\n if (next === undefined) {\n return;\n }\n\n // Only once we know we'll act — otherwise Home/End etc. should still scroll.\n event.preventDefault();\n if (options[next].value !== value) {\n onChange(options[next].value);\n }\n itemRefs.current[next]?.focus();\n };\n\n return (\n <div\n role=\"radiogroup\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-disabled={disabled || undefined}\n onKeyDown={handleKeyDown}\n className={`${\n // One display utility, not two: `flex` and `inline-flex` are both plain\n // `display` utilities, so emitting both would resolve by stylesheet order\n // (same hazard as the background above).\n fullWidth ? 'flex w-full' : 'inline-flex'\n } ${sizeBlock.track} items-center gap-1 p-0.5 rounded-xl bg-[var(--malachite-segmented-control-track-background)] ${\n disabled ? 'opacity-50' : ''\n } ${className}`}\n >\n {options.map((option, index) => {\n const isSelected = option.value === value;\n const isDisabled = disabled || option.disabled;\n const hasBadge =\n option.badge !== undefined && option.badge !== null && option.badge !== false;\n\n let colorClasses: string;\n if (isSelected) {\n colorClasses =\n 'bg-[var(--malachite-segmented-control-selected-background)] text-[var(--malachite-segmented-control-selected-foreground)]';\n } else if (isDisabled) {\n colorClasses =\n 'bg-transparent text-[var(--malachite-segmented-control-item-foreground)]';\n } else {\n colorClasses =\n 'bg-transparent text-[var(--malachite-segmented-control-item-foreground)] hover:text-[var(--malachite-segmented-control-item-hover-foreground)] cursor-pointer';\n }\n\n return (\n <button\n key={option.value}\n ref={(element) => {\n itemRefs.current[index] = element;\n }}\n type=\"button\"\n role=\"radio\"\n aria-checked={isSelected}\n disabled={isDisabled}\n tabIndex={index === tabStopIndex ? 0 : -1}\n onClick={() => {\n // Radios don't toggle off on re-click.\n if (!isDisabled && !isSelected) {\n onChange(option.value);\n }\n }}\n className={`${FOCUS_RING} ${ITEM_BASE} ${sizeBlock.text} ${sizeBlock.item} ${colorClasses} ${\n fullWidth ? 'flex-1' : ''\n } ${option.disabled && !disabled ? 'opacity-50 cursor-not-allowed' : ''}`}\n style={{\n // Inline rather than a Tailwind shadow class: Tailwind's shadow\n // utilities compose `--tw-shadow-*` custom properties that rely on\n // document-level @property registration and silently don't paint\n // inside a shadow root (same caveat as `ring-*`).\n boxShadow: isSelected\n ? 'var(--malachite-segmented-control-selected-shadow, 0px 1px 5px 0px rgba(0, 0, 0, 0.1))'\n : undefined,\n }}\n >\n {option.icon ? (\n <span className=\"inline-flex items-center justify-center w-4 h-4 shrink-0\">\n {option.icon}\n </span>\n ) : null}\n {option.label}\n {/* The space keeps the name \"Annual Save\" rather than \"AnnualSave\";\n the flex gap already spaces the two visually. */}\n {hasBadge ? ' ' : null}\n {hasBadge ? (\n <span className=\"inline-flex items-center shrink-0\">\n {option.badge}\n </span>\n ) : null}\n </button>\n );\n })}\n </div>\n );\n};\n\nexport default SegmentedControl;\nexport { SegmentedControl };\nexport type { SegmentedControlProps, SegmentedControlOption, SegmentedControlSize };\n"],"names":["SIZE_CLASSES","ITEM_BASE","SegmentedControl","options","value","onChange","size","fullWidth","disabled","ariaLabel","ariaLabelledBy","className","itemRefs","useRef","sizeBlock","selectedIndex","option","enabled","tabStopIndex","rovingTabStop","jsx","event","focused","item","next","nextRovingIndex","_a","index","isSelected","isDisabled","hasBadge","colorClasses","jsxs","element","FOCUS_RING"],"mappings":";;;;AAoCA,MAAMA,IAA4F;AAAA,EAC9F,OAAO;AAAA,IACH,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EAAA;AAAA,EAEV,QAAQ;AAAA,IACJ,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EAAA;AAAA,EAEV,OAAO;AAAA,IACH,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EAAA;AAEd,GAOMC,IACF,iMAaEC,IAAmB,CAA4B;AAAA,EACjD,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,WAAAC,IAAY;AAAA,EACZ,UAAAC,IAAW;AAAA,EACX,cAAcC;AAAA,EACd,mBAAmBC;AAAA,EACnB,WAAAC,IAAY;AAChB,MAAgC;AAC5B,QAAMC,IAAWC,EAAqC,EAAE,GAClDC,IAAYd,EAAaM,CAAI,GAE7BS,IAAgBZ,EAAQ,UAAU,CAACa,MAAWA,EAAO,UAAUZ,CAAK,GACpEa,IAAUd,EAAQ,IAAI,CAACa,MAAW,CAACA,EAAO,QAAQ,GAIlDE,IAAeC,EAAcJ,GAAeE,CAAO;AAqBzD,SACI,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CAAS,IAAIa,EAAU,IAAI,IAAIA,EAAU,IAAI,IAAIiB,CAAY,IACrFxB,IAAY,WAAW,EAC3B,IAAIS,EAAO,YAAY,CAACR,IAAW,kCAAkC,EAAE;AAAA,YACvE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,cAKH,WAAWoB,IACL,2FACA;AAAA,YAAA;AAAA,YAGT,UAAA;AAAA,cAAAZ,EAAO,OACJ,gBAAAI,EAAC,QAAA,EAAK,WAAU,4DACX,UAAAJ,EAAO,MACZ,IACA;AAAA,cACHA,EAAO;AAAA,cAGPc,IAAW,MAAM;AAAA,cACjBA,IACG,gBAAAV,EAAC,QAAA,EAAK,WAAU,qCACX,UAAAJ,EAAO,OACZ,IACA;AAAA,YAAA;AAAA,UAAA;AAAA,UAzCCA,EAAO;AAAA,QAAA;AAAA,MA4CxB,CAAC;AAAA,IAAA;AAAA,EAAA;AAGb;"}
|
|
1
|
+
{"version":3,"file":"SegmentedControl.js","sources":["../../src/components/SegmentedControl.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport { FOCUS_RING } from './focusRing';\nimport { nextRovingIndex, rovingTabStop } from './rovingKeys';\n\ntype SegmentedControlSize = 'small' | 'medium' | 'large';\n\ninterface SegmentedControlOption<T extends string = string> {\n value: T;\n label: string;\n icon?: React.ReactNode;\n /**\n * Small mark after the label, e.g. a compact `Tag` naming a saving. It renders inside\n * the segment's `<button>`, so it must not be interactive — no `onClick` or `onRemove`.\n */\n badge?: React.ReactNode;\n disabled?: boolean;\n}\n\ninterface SegmentedControlProps<T extends string = string> {\n options: SegmentedControlOption<T>[];\n /** The selected option's value. A value not present in `options` renders nothing selected. */\n value: T;\n onChange: (value: T) => void;\n size?: SegmentedControlSize;\n /** Stretch the track to its container and split it into equal segments. */\n fullWidth?: boolean;\n /** Disables every segment. Individual segments can also be disabled via `options`. */\n disabled?: boolean;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n 'aria-describedby'?: string;\n className?: string;\n}\n\n// The ladder governs a control's outer box. The height therefore sits on the track and\n// the items fill whatever the 4px inset leaves — putting it on the item instead makes a\n// `medium` segmented control 40px tall beside a 32px Dropdown.\nconst SIZE_CLASSES: Record<SegmentedControlSize, { text: string; track: string; item: string }> = {\n small: {\n text: 'text-[length:var(--malachite-font-size-small,13px)]',\n track: 'h-[var(--malachite-control-height-small,28px)]',\n item: 'h-full px-2.5',\n },\n medium: {\n text: 'text-[length:var(--malachite-font-size-small,13px)]',\n track: 'h-[var(--malachite-control-height-medium,32px)]',\n item: 'h-full px-2.5',\n },\n large: {\n text: 'text-[length:var(--malachite-font-size-15,15px)]',\n track: 'h-[var(--malachite-control-height-large,42px)]',\n item: 'h-full px-4',\n },\n};\n\n// Deliberately no `bg-*` here: each state branch below supplies exactly one\n// background-color utility. Both `bg-transparent` and an arbitrary-value `bg-` are plain\n// single-class utilities in the same `@layer utilities`, so an element carrying both\n// resolves by stylesheet order — and the arbitrary value loses, silently rendering the\n// selected thumb transparent.\nconst ITEM_BASE =\n 'inline-flex items-center justify-center gap-1.5 rounded-[var(--malachite-radius-10,10px)] border-0 font-medium tracking-[0.13px] whitespace-nowrap transition-colors duration-150 ease-in-out';\n\n/**\n * A rounded track of mutually-exclusive options — the segmented \"one of these\" control.\n *\n * Owns the track background, the selected-thumb chrome and the radiogroup semantics in\n * one place, so consumers never hand-roll a track around `PillButton` (whose `default`\n * variant tokens are tuned for standalone filter pills, not for a sunken track).\n *\n * Selection is conveyed non-visually via `role=\"radio\"` + `aria-checked`, and by a\n * foreground-colour change as well as the thumb, so it does not rest on background\n * colour alone.\n */\nconst SegmentedControl = <T extends string = string>({\n options,\n value,\n onChange,\n size = 'medium',\n fullWidth = false,\n disabled = false,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n className = '',\n}: SegmentedControlProps<T>) => {\n const itemRefs = useRef<(HTMLButtonElement | null)[]>([]);\n const sizeBlock = SIZE_CLASSES[size];\n\n const selectedIndex = options.findIndex((option) => option.value === value);\n const enabled = options.map((option) => !option.disabled);\n // Roving tabindex: the group is a single tab stop. When the selected option is\n // missing or disabled, the first enabled option takes the stop so the control is\n // still reachable by keyboard.\n const tabStopIndex = rovingTabStop(selectedIndex, enabled);\n\n // Arrow keys move AND select, per the WAI-ARIA radiogroup pattern, from the focused option.\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (disabled) {\n return;\n }\n const focused = itemRefs.current.findIndex((item) => item === event.target);\n const next = nextRovingIndex(event, focused >= 0 ? focused : tabStopIndex, enabled);\n if (next === undefined) {\n return;\n }\n\n // Only once we know we'll act — otherwise Home/End etc. should still scroll.\n event.preventDefault();\n if (options[next].value !== value) {\n onChange(options[next].value);\n }\n itemRefs.current[next]?.focus();\n };\n\n return (\n <div\n role=\"radiogroup\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n aria-disabled={disabled || undefined}\n onKeyDown={handleKeyDown}\n className={`${\n // One display utility, not two: `flex` and `inline-flex` are both plain\n // `display` utilities, so emitting both would resolve by stylesheet order\n // (same hazard as the background above).\n fullWidth ? 'flex w-full' : 'inline-flex'\n } ${sizeBlock.track} items-center gap-1 p-0.5 rounded-xl bg-[var(--malachite-segmented-control-track-background)] ${\n disabled ? 'opacity-50' : ''\n } ${className}`}\n >\n {options.map((option, index) => {\n const isSelected = option.value === value;\n const isDisabled = disabled || option.disabled;\n const hasBadge =\n option.badge !== undefined && option.badge !== null && option.badge !== false;\n\n let colorClasses: string;\n if (isSelected) {\n colorClasses =\n 'bg-[var(--malachite-segmented-control-selected-background)] text-[var(--malachite-segmented-control-selected-foreground)]';\n } else if (isDisabled) {\n colorClasses =\n 'bg-transparent text-[var(--malachite-segmented-control-item-foreground)]';\n } else {\n colorClasses =\n 'bg-transparent text-[var(--malachite-segmented-control-item-foreground)] hover:text-[var(--malachite-segmented-control-item-hover-foreground)] cursor-pointer';\n }\n\n return (\n <button\n key={option.value}\n ref={(element) => {\n itemRefs.current[index] = element;\n }}\n type=\"button\"\n role=\"radio\"\n aria-checked={isSelected}\n disabled={isDisabled}\n tabIndex={index === tabStopIndex ? 0 : -1}\n onClick={() => {\n // Radios don't toggle off on re-click.\n if (!isDisabled && !isSelected) {\n onChange(option.value);\n }\n }}\n className={`${FOCUS_RING} ${ITEM_BASE} ${sizeBlock.text} ${sizeBlock.item} ${colorClasses} ${\n fullWidth ? 'flex-1' : ''\n } ${option.disabled && !disabled ? 'opacity-50 cursor-not-allowed' : ''}`}\n style={{\n // Inline rather than a Tailwind shadow class: Tailwind's shadow\n // utilities compose `--tw-shadow-*` custom properties that rely on\n // document-level @property registration and silently don't paint\n // inside a shadow root (same caveat as `ring-*`).\n boxShadow: isSelected\n ? 'var(--malachite-segmented-control-selected-shadow, 0px 1px 5px 0px rgba(0, 0, 0, 0.1))'\n : undefined,\n }}\n >\n {option.icon ? (\n <span className=\"inline-flex items-center justify-center w-4 h-4 shrink-0\">\n {option.icon}\n </span>\n ) : null}\n {option.label}\n {/* The space keeps the name \"Annual Save\" rather than \"AnnualSave\";\n the flex gap already spaces the two visually. */}\n {hasBadge ? ' ' : null}\n {hasBadge ? (\n <span className=\"inline-flex items-center shrink-0\">\n {option.badge}\n </span>\n ) : null}\n </button>\n );\n })}\n </div>\n );\n};\n\nexport default SegmentedControl;\nexport { SegmentedControl };\nexport type { SegmentedControlProps, SegmentedControlOption, SegmentedControlSize };\n"],"names":["SIZE_CLASSES","ITEM_BASE","SegmentedControl","options","value","onChange","size","fullWidth","disabled","ariaLabel","ariaLabelledBy","ariaDescribedBy","className","itemRefs","useRef","sizeBlock","selectedIndex","option","enabled","tabStopIndex","rovingTabStop","jsx","event","focused","item","next","nextRovingIndex","_a","index","isSelected","isDisabled","hasBadge","colorClasses","jsxs","element","FOCUS_RING"],"mappings":";;;;AAqCA,MAAMA,IAA4F;AAAA,EAC9F,OAAO;AAAA,IACH,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,E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AAAA,EAAA;AAGb;"}
|
|
@@ -3,74 +3,74 @@ const w = (e, t) => e !== null ? "items" : t.trim().length > 0 ? "search" : "fil
|
|
|
3
3
|
return e.label.toLowerCase().includes(s) || e.value.toLowerCase().includes(s);
|
|
4
4
|
}, d = (e, t) => {
|
|
5
5
|
var s;
|
|
6
|
-
return new Set(((s = e.find((
|
|
6
|
+
return new Set(((s = e.find((r) => r.filter === t)) == null ? void 0 : s.items) ?? []);
|
|
7
7
|
}, p = (e, t) => e.flatMap((s) => {
|
|
8
|
-
const
|
|
9
|
-
return s.items.map((o) => ({ item: o, filter: s, selected:
|
|
8
|
+
const r = d(t, s.value);
|
|
9
|
+
return s.items.map((o) => ({ item: o, filter: s, selected: r.has(o.value) }));
|
|
10
10
|
}), g = (e, t) => {
|
|
11
11
|
const s = e.filter((n) => m(n.item, t));
|
|
12
12
|
if (!s.some((n) => !n.item.disabled)) return null;
|
|
13
|
-
const
|
|
14
|
-
return
|
|
13
|
+
const r = e.every((n) => n.item.disabled || n.selected), o = t.trim().length > 0 && s.filter((n) => !n.item.disabled).every((n) => n.selected);
|
|
14
|
+
return r || o ? "deselect" : "select";
|
|
15
15
|
}, v = (e, t) => ({
|
|
16
16
|
toggle: g(e, t),
|
|
17
17
|
items: e.filter((s) => m(s.item, t))
|
|
18
|
-
}), S = (e, t, s,
|
|
18
|
+
}), S = (e, t, s, r) => {
|
|
19
19
|
var f;
|
|
20
20
|
if (e === null) return;
|
|
21
21
|
const o = t.find((i) => i.value === e), n = s == null ? void 0 : s.find((i) => i.value === e);
|
|
22
22
|
if (!o || !n) return o ?? n;
|
|
23
|
-
const
|
|
23
|
+
const l = new Set((f = r.find((i) => i.filter === e)) == null ? void 0 : f.items), u = new Set(o.items.map((i) => i.value)), a = n.items.filter((i) => l.has(i.value) && !u.has(i.value));
|
|
24
24
|
return a.length ? { ...o, items: [...o.items, ...a] } : o;
|
|
25
25
|
}, y = (e, t, s) => e ? v(p([e], t), s) : { toggle: null, items: [] }, x = (e, t, s) => v(p(e, t), s), h = (e, t) => {
|
|
26
26
|
const s = new Set(t);
|
|
27
|
-
return e.length === s.size && e.every((
|
|
27
|
+
return e.length === s.size && e.every((r) => s.has(r));
|
|
28
28
|
}, c = (e, t) => {
|
|
29
29
|
const s = t.filter(
|
|
30
|
-
(
|
|
31
|
-
),
|
|
32
|
-
filter:
|
|
33
|
-
items:
|
|
34
|
-
})).filter((
|
|
35
|
-
(
|
|
30
|
+
(l) => !h(l.items, [...d(e, l.filter)])
|
|
31
|
+
), r = new Map(s.map((l) => [l.filter, l.items])), o = e.map((l) => ({
|
|
32
|
+
filter: l.filter,
|
|
33
|
+
items: r.get(l.filter) ?? l.items
|
|
34
|
+
})).filter((l) => l.items.length > 0), n = s.filter(
|
|
35
|
+
(l) => l.items.length > 0 && !e.some((u) => u.filter === l.filter)
|
|
36
36
|
);
|
|
37
37
|
return { next: [...o, ...n], changes: s };
|
|
38
38
|
}, C = (e, t, s) => {
|
|
39
|
-
const
|
|
39
|
+
const r = [...d(e, t)], o = r.includes(s) ? r.filter((n) => n !== s) : [...r, s];
|
|
40
40
|
return c(e, [{ filter: t, items: o }]);
|
|
41
41
|
}, M = (e, t, s) => c(
|
|
42
42
|
t,
|
|
43
|
-
e.map((
|
|
44
|
-
const o = d(t,
|
|
45
|
-
(
|
|
46
|
-
).map((
|
|
47
|
-
return { filter:
|
|
43
|
+
e.map((r) => {
|
|
44
|
+
const o = d(t, r.value), n = r.items.filter(
|
|
45
|
+
(l) => !o.has(l.value) && !l.disabled && m(l, s)
|
|
46
|
+
).map((l) => l.value);
|
|
47
|
+
return { filter: r.value, items: [...o, ...n] };
|
|
48
48
|
})
|
|
49
49
|
), $ = (e, t, s) => c(
|
|
50
50
|
t,
|
|
51
|
-
e.map((
|
|
52
|
-
const o = d(t,
|
|
53
|
-
|
|
51
|
+
e.map((r) => {
|
|
52
|
+
const o = d(t, r.value), n = new Set(
|
|
53
|
+
r.items.filter((l) => !l.disabled && m(l, s)).map((l) => l.value)
|
|
54
54
|
);
|
|
55
55
|
return {
|
|
56
|
-
filter:
|
|
57
|
-
items: [...o].filter((
|
|
56
|
+
filter: r.value,
|
|
57
|
+
items: [...o].filter((l) => !n.has(l))
|
|
58
58
|
};
|
|
59
59
|
})
|
|
60
|
-
), b = (e, t) => c(e, [{ filter: t, items: [] }]), k = (e) => c(
|
|
60
|
+
), b = (e, t) => c(e, [{ filter: t, items: [] }]), k = (e, t = null) => c(
|
|
61
61
|
e,
|
|
62
|
-
e.
|
|
63
|
-
), A = (e, t, s) => c(e, [{ filter: t, items: [s] }]),
|
|
64
|
-
const
|
|
62
|
+
e.filter((s) => s.filter !== t).map((s) => ({ filter: s.filter, items: [] }))
|
|
63
|
+
), A = (e, t, s) => c(e, [{ filter: t, items: s }]), R = (e, t, s) => c(e, [{ filter: t, items: [s] }]), V = (e, t) => t.length === 0 ? e : t.length === 1 ? `${e}: ${t[0]}` : `${e}: (${t.join(", ")})`, T = (e, t, s = null) => {
|
|
64
|
+
const r = new Set(e.map((n) => n.filter)), o = t.filter((n) => r.has(n) || n === s);
|
|
65
65
|
return [
|
|
66
66
|
...o,
|
|
67
67
|
...e.map((n) => n.filter).filter((n) => !o.includes(n))
|
|
68
68
|
];
|
|
69
69
|
};
|
|
70
70
|
export {
|
|
71
|
-
|
|
71
|
+
V as chipText,
|
|
72
72
|
k as clearAll,
|
|
73
|
-
|
|
73
|
+
R as commitText,
|
|
74
74
|
$ as deselectAll,
|
|
75
75
|
y as filterRows,
|
|
76
76
|
m as matchesQuery,
|
|
@@ -80,6 +80,7 @@ export {
|
|
|
80
80
|
w as resolveMode,
|
|
81
81
|
x as searchRows,
|
|
82
82
|
M as selectAll,
|
|
83
|
+
A as setValues,
|
|
83
84
|
C as toggleValue
|
|
84
85
|
};
|
|
85
86
|
//# sourceMappingURL=filterSearchModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterSearchModel.js","sources":["../../src/components/filterSearchModel.ts"],"sourcesContent":["import type { ReactNode } from 'react';\n\nexport interface FilterSearchItem {\n value: string;\n label: string;\n disabled?: boolean;\n /** Drawn before the label in the menu and in the applied chip: a logo, a status dot. Keep it 12px. */\n icon?: ReactNode;\n}\n\nexport interface FilterSearchFilter {\n value: string;\n label: string;\n /** Shown beside the filter's name in the menu, and beside its values in a cross-filter search. */\n info?: string;\n /** Right-aligned hint on the filter's row, e.g. `e.g. Attio, Ashby`. */\n example?: string;\n /** `false` drops the filter's name from its chip, for a value that reads alone: `Configured only`. */\n chipLabel?: boolean;\n items: FilterSearchItem[];\n}\n\nexport interface FilterSearchSelection {\n filter: string;\n items: string[];\n}\n\n/** One filter's new values. An empty `items` means the filter was removed. */\nexport interface FilterSearchChange {\n filter: string;\n items: string[];\n}\n\nexport interface FilterSearchUpdate {\n next: FilterSearchSelection[];\n changes: FilterSearchChange[];\n}\n\nexport type FilterSearchMode = 'filters' | 'items' | 'search';\n\nexport type FilterSearchToggle = 'select' | 'deselect';\n\nexport interface FilterSearchItemRow {\n item: FilterSearchItem;\n filter: FilterSearchFilter;\n selected: boolean;\n}\n\nexport interface FilterSearchRows {\n /** The Select All / Deselect All row, absent when no enabled value matches. */\n toggle: FilterSearchToggle | null;\n items: FilterSearchItemRow[];\n}\n\nexport const resolveMode = (activeFilter: string | null, query: string): FilterSearchMode => {\n if (activeFilter !== null) return 'items';\n return query.trim().length > 0 ? 'search' : 'filters';\n};\n\nexport const matchesQuery = (item: FilterSearchItem, query: string): boolean => {\n const needle = query.trim().toLowerCase();\n return item.label.toLowerCase().includes(needle) || item.value.toLowerCase().includes(needle);\n};\n\nconst selectedValues = (selections: FilterSearchSelection[], filter: string): Set<string> =>\n new Set(selections.find((selection) => selection.filter === filter)?.items ?? []);\n\nconst toRows = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n): FilterSearchItemRow[] =>\n filters.flatMap((filter) => {\n const selected = selectedValues(selections, filter.value);\n return filter.items.map((item) => ({ item, filter, selected: selected.has(item.value) }));\n });\n\n/**\n * \"Deselect All\" replaces \"Select All\" once every enabled value is chosen, or once every value\n * the query matches is.\n */\nconst toggleFor = (all: FilterSearchItemRow[], query: string): FilterSearchToggle | null => {\n const matched = all.filter((row) => matchesQuery(row.item, query));\n if (!matched.some((row) => !row.item.disabled)) return null;\n\n const everyEnabledSelected = all.every((row) => row.item.disabled || row.selected);\n const everyMatchSelected =\n query.trim().length > 0 &&\n matched.filter((row) => !row.item.disabled).every((row) => row.selected);\n\n return everyEnabledSelected || everyMatchSelected ? 'deselect' : 'select';\n};\n\nconst rowsFor = (all: FilterSearchItemRow[], query: string): FilterSearchRows => ({\n toggle: toggleFor(all, query),\n items: all.filter((row) => matchesQuery(row.item, query)),\n});\n\n/** The values of one filter, as the menu lists them once that filter is picked. */\n/**\n * The open filter as its menu lists it: `filters`' entry, with any picked value only\n * `searchFilters` holds added back, so a value picked through search can be unticked from its\n * own chip. A filter only `searchFilters` holds is listed from there.\n */\nexport const openFilterOf = (\n active: string | null,\n filters: FilterSearchFilter[],\n searchFilters: FilterSearchFilter[] | undefined,\n selections: FilterSearchSelection[],\n): FilterSearchFilter | undefined => {\n if (active === null) return undefined;\n const narrowed = filters.find((filter) => filter.value === active);\n const wide = searchFilters?.find((filter) => filter.value === active);\n if (!narrowed || !wide) return narrowed ?? wide;\n const picked = new Set(selections.find((selection) => selection.filter === active)?.items);\n const listed = new Set(narrowed.items.map((item) => item.value));\n const missing = wide.items.filter((item) => picked.has(item.value) && !listed.has(item.value));\n return missing.length ? { ...narrowed, items: [...narrowed.items, ...missing] } : narrowed;\n};\n\nexport const filterRows = (\n filter: FilterSearchFilter | undefined,\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchRows =>\n filter ? rowsFor(toRows([filter], selections), query) : { toggle: null, items: [] };\n\n/** The values of every filter that match a query typed before any filter was picked. */\nexport const searchRows = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchRows => rowsFor(toRows(filters, selections), query);\n\n// As sets: a Select All that adds nothing returns the values in item order, not the order chosen.\nconst sameItems = (a: string[], b: string[]) => {\n const set = new Set(b);\n return a.length === set.size && a.every((value) => set.has(value));\n};\n\n/** Applies per-filter changes, keeping each filter where it already was and dropping the emptied. */\nconst applyChanges = (\n selections: FilterSearchSelection[],\n proposed: FilterSearchChange[],\n): FilterSearchUpdate => {\n const changes = proposed.filter(\n (change) => !sameItems(change.items, [...selectedValues(selections, change.filter)]),\n );\n const byFilter = new Map(changes.map((change) => [change.filter, change.items]));\n const kept = selections\n .map((selection) => ({\n filter: selection.filter,\n items: byFilter.get(selection.filter) ?? selection.items,\n }))\n .filter((selection) => selection.items.length > 0);\n const added = changes.filter(\n (change) =>\n change.items.length > 0 &&\n !selections.some((selection) => selection.filter === change.filter),\n );\n\n return { next: [...kept, ...added], changes };\n};\n\nexport const toggleValue = (\n selections: FilterSearchSelection[],\n filter: string,\n value: string,\n): FilterSearchUpdate => {\n const current = [...selectedValues(selections, filter)];\n const items = current.includes(value)\n ? current.filter((item) => item !== value)\n : [...current, value];\n\n return applyChanges(selections, [{ filter, items }]);\n};\n\n/** Select All keeps what is already chosen and adds every enabled value the query matches. */\nexport const selectAll = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchUpdate =>\n applyChanges(\n selections,\n filters.map((filter) => {\n const selected = selectedValues(selections, filter.value);\n const added = filter.items\n .filter(\n (item) =>\n !selected.has(item.value) && !item.disabled && matchesQuery(item, query),\n )\n .map((item) => item.value);\n // Chosen values stay even when `items` no longer lists them (a stale or lazy list).\n return { filter: filter.value, items: [...selected, ...added] };\n }),\n );\n\n/** Deselect All drops every enabled value the query matches and keeps the rest. */\nexport const deselectAll = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchUpdate =>\n applyChanges(\n selections,\n filters.map((filter) => {\n const selected = selectedValues(selections, filter.value);\n const dropped = new Set(\n filter.items\n .filter((item) => !item.disabled && matchesQuery(item, query))\n .map((item) => item.value),\n );\n return {\n filter: filter.value,\n items: [...selected].filter((value) => !dropped.has(value)),\n };\n }),\n );\n\nexport const removeFilter = (\n selections: FilterSearchSelection[],\n filter: string,\n): FilterSearchUpdate => applyChanges(selections, [{ filter, items: [] }]);\n\nexport const clearAll = (selections: FilterSearchSelection[]): FilterSearchUpdate =>\n applyChanges(\n selections,\n selections.map((selection) => ({ filter: selection.filter, items: [] })),\n );\n\nexport const commitText = (\n selections: FilterSearchSelection[],\n filter: string,\n text: string,\n): FilterSearchUpdate => applyChanges(selections, [{ filter, items: [text] }]);\n\n/** `Connector: Notion`, or `Connector: (Notion, Attio)` once there is more than one value. */\nexport const chipText = (filterLabel: string, itemLabels: string[]): string => {\n if (itemLabels.length === 0) return filterLabel;\n if (itemLabels.length === 1) return `${filterLabel}: ${itemLabels[0]}`;\n return `${filterLabel}: (${itemLabels.join(', ')})`;\n};\n\n/**\n * The order chips show filters in: when each was first added. A consumer reading its selection back\n * from the URL gets it in a fixed key order, which would reshuffle the chips on every change.\n */\nexport const orderSelections = (\n selections: FilterSearchSelection[],\n order: string[],\n /** A filter to hold its place in `order` while it has no values, e.g. the one being edited. */\n keep: string | null = null,\n): string[] => {\n const present = new Set(selections.map((selection) => selection.filter));\n const kept = order.filter((filter) => present.has(filter) || filter === keep);\n return [\n ...kept,\n ...selections.map((selection) => selection.filter).filter((f) => !kept.includes(f)),\n ];\n};\n"],"names":["resolveMode","activeFilter","query","matchesQuery","item","needle","selectedValues","selections","filter","_a","selection","toRows","filters","selected","toggleFor","all","matched","row","everyEnabledSelected","everyMatchSelected","rowsFor","openFilterOf","active","searchFilters","narrowed","wide","picked","listed","missing","filterRows","searchRows","sameItems","a","b","set","value","applyChanges","proposed","changes","change","byFilter","kept","added","toggleValue","current","items","selectAll","deselectAll","dropped","removeFilter","clearAll","commitText","text","chipText","filterLabel","itemLabels","orderSelections","order","keep","present","f"],"mappings":"AAsDO,MAAMA,IAAc,CAACC,GAA6BC,MACjDD,MAAiB,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,IAAInD,CAAM,KAAKA,MAAWkD,CAAI;AAC5E,SAAO;AAAA,IACH,GAAGjB;AAAA,IACH,GAAGlC,EAAW,IAAI,CAACG,MAAcA,EAAU,MAAM,EAAE,OAAO,CAACkD,MAAM,CAACnB,EAAK,SAASmB,CAAC,CAAC;AAAA,EAAA;AAE1F;"}
|
|
1
|
+
{"version":3,"file":"filterSearchModel.js","sources":["../../src/components/filterSearchModel.ts"],"sourcesContent":["import type { ReactNode } from 'react';\n\nexport interface FilterSearchItem {\n value: string;\n label: string;\n disabled?: boolean;\n /** Drawn before the label in the menu and in the applied chip: a logo, a status dot. Keep it 12px. */\n icon?: ReactNode;\n /** Drawn at the end of the value's row in the Filters panel: how many results it matches. */\n count?: number;\n}\n\nexport type FilterSearchControl = 'list' | 'toggle' | 'segmented';\n\nexport interface FilterSearchFilter {\n value: string;\n label: string;\n /** Shown beside the filter's name in the menu, and beside its values in a cross-filter search. */\n info?: string;\n /** Right-aligned hint on the filter's row, e.g. `e.g. Attio, Ashby`. */\n example?: string;\n /** `false` drops the filter's name from its chip, for a value that reads alone: `Configured only`. */\n chipLabel?: boolean;\n /** Filters panel control: `list` (default) ticks values, `toggle` switches its first item's value, `segmented` picks one or All. */\n control?: FilterSearchControl;\n items: FilterSearchItem[];\n}\n\nexport interface FilterSearchSelection {\n filter: string;\n items: string[];\n}\n\n/** One filter's new values. An empty `items` means the filter was removed. */\nexport interface FilterSearchChange {\n filter: string;\n items: string[];\n}\n\nexport interface FilterSearchUpdate {\n next: FilterSearchSelection[];\n changes: FilterSearchChange[];\n}\n\nexport type FilterSearchMode = 'filters' | 'items' | 'search';\n\nexport type FilterSearchToggle = 'select' | 'deselect';\n\nexport interface FilterSearchItemRow {\n item: FilterSearchItem;\n filter: FilterSearchFilter;\n selected: boolean;\n}\n\nexport interface FilterSearchRows {\n /** The Select All / Deselect All row, absent when no enabled value matches. */\n toggle: FilterSearchToggle | null;\n items: FilterSearchItemRow[];\n}\n\nexport const resolveMode = (activeFilter: string | null, query: string): FilterSearchMode => {\n if (activeFilter !== null) return 'items';\n return query.trim().length > 0 ? 'search' : 'filters';\n};\n\nexport const matchesQuery = (item: FilterSearchItem, query: string): boolean => {\n const needle = query.trim().toLowerCase();\n return item.label.toLowerCase().includes(needle) || item.value.toLowerCase().includes(needle);\n};\n\nconst selectedValues = (selections: FilterSearchSelection[], filter: string): Set<string> =>\n new Set(selections.find((selection) => selection.filter === filter)?.items ?? []);\n\nconst toRows = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n): FilterSearchItemRow[] =>\n filters.flatMap((filter) => {\n const selected = selectedValues(selections, filter.value);\n return filter.items.map((item) => ({ item, filter, selected: selected.has(item.value) }));\n });\n\n/**\n * \"Deselect All\" replaces \"Select All\" once every enabled value is chosen, or once every value\n * the query matches is.\n */\nconst toggleFor = (all: FilterSearchItemRow[], query: string): FilterSearchToggle | null => {\n const matched = all.filter((row) => matchesQuery(row.item, query));\n if (!matched.some((row) => !row.item.disabled)) return null;\n\n const everyEnabledSelected = all.every((row) => row.item.disabled || row.selected);\n const everyMatchSelected =\n query.trim().length > 0 &&\n matched.filter((row) => !row.item.disabled).every((row) => row.selected);\n\n return everyEnabledSelected || everyMatchSelected ? 'deselect' : 'select';\n};\n\nconst rowsFor = (all: FilterSearchItemRow[], query: string): FilterSearchRows => ({\n toggle: toggleFor(all, query),\n items: all.filter((row) => matchesQuery(row.item, query)),\n});\n\n/**\n * The open filter as its menu lists it: `filters`' entry, with any picked value only\n * `searchFilters` holds added back, so a value picked through search can be unticked from its\n * own chip. A filter only `searchFilters` holds is listed from there.\n */\nexport const openFilterOf = (\n active: string | null,\n filters: FilterSearchFilter[],\n searchFilters: FilterSearchFilter[] | undefined,\n selections: FilterSearchSelection[],\n): FilterSearchFilter | undefined => {\n if (active === null) return undefined;\n const narrowed = filters.find((filter) => filter.value === active);\n const wide = searchFilters?.find((filter) => filter.value === active);\n if (!narrowed || !wide) return narrowed ?? wide;\n const picked = new Set(selections.find((selection) => selection.filter === active)?.items);\n const listed = new Set(narrowed.items.map((item) => item.value));\n const missing = wide.items.filter((item) => picked.has(item.value) && !listed.has(item.value));\n return missing.length ? { ...narrowed, items: [...narrowed.items, ...missing] } : narrowed;\n};\n\nexport const filterRows = (\n filter: FilterSearchFilter | undefined,\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchRows =>\n filter ? rowsFor(toRows([filter], selections), query) : { toggle: null, items: [] };\n\n/** The values of every filter that match a query typed before any filter was picked. */\nexport const searchRows = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchRows => rowsFor(toRows(filters, selections), query);\n\n// As sets: a Select All that adds nothing returns the values in item order, not the order chosen.\nconst sameItems = (a: string[], b: string[]) => {\n const set = new Set(b);\n return a.length === set.size && a.every((value) => set.has(value));\n};\n\n/** Applies per-filter changes, keeping each filter where it already was and dropping the emptied. */\nconst applyChanges = (\n selections: FilterSearchSelection[],\n proposed: FilterSearchChange[],\n): FilterSearchUpdate => {\n const changes = proposed.filter(\n (change) => !sameItems(change.items, [...selectedValues(selections, change.filter)]),\n );\n const byFilter = new Map(changes.map((change) => [change.filter, change.items]));\n const kept = selections\n .map((selection) => ({\n filter: selection.filter,\n items: byFilter.get(selection.filter) ?? selection.items,\n }))\n .filter((selection) => selection.items.length > 0);\n const added = changes.filter(\n (change) =>\n change.items.length > 0 &&\n !selections.some((selection) => selection.filter === change.filter),\n );\n\n return { next: [...kept, ...added], changes };\n};\n\nexport const toggleValue = (\n selections: FilterSearchSelection[],\n filter: string,\n value: string,\n): FilterSearchUpdate => {\n const current = [...selectedValues(selections, filter)];\n const items = current.includes(value)\n ? current.filter((item) => item !== value)\n : [...current, value];\n\n return applyChanges(selections, [{ filter, items }]);\n};\n\n/** Select All keeps what is already chosen and adds every enabled value the query matches. */\nexport const selectAll = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchUpdate =>\n applyChanges(\n selections,\n filters.map((filter) => {\n const selected = selectedValues(selections, filter.value);\n const added = filter.items\n .filter(\n (item) =>\n !selected.has(item.value) && !item.disabled && matchesQuery(item, query),\n )\n .map((item) => item.value);\n // Chosen values stay even when `items` no longer lists them (a stale or lazy list).\n return { filter: filter.value, items: [...selected, ...added] };\n }),\n );\n\n/** Deselect All drops every enabled value the query matches and keeps the rest. */\nexport const deselectAll = (\n filters: FilterSearchFilter[],\n selections: FilterSearchSelection[],\n query: string,\n): FilterSearchUpdate =>\n applyChanges(\n selections,\n filters.map((filter) => {\n const selected = selectedValues(selections, filter.value);\n const dropped = new Set(\n filter.items\n .filter((item) => !item.disabled && matchesQuery(item, query))\n .map((item) => item.value),\n );\n return {\n filter: filter.value,\n items: [...selected].filter((value) => !dropped.has(value)),\n };\n }),\n );\n\nexport const removeFilter = (\n selections: FilterSearchSelection[],\n filter: string,\n): FilterSearchUpdate => applyChanges(selections, [{ filter, items: [] }]);\n\n/** Removes every filter but `keep`, e.g. the typed text's pill. */\nexport const clearAll = (\n selections: FilterSearchSelection[],\n keep: string | null = null,\n): FilterSearchUpdate =>\n applyChanges(\n selections,\n selections\n .filter((selection) => selection.filter !== keep)\n .map((selection) => ({ filter: selection.filter, items: [] })),\n );\n\nexport const setValues = (\n selections: FilterSearchSelection[],\n filter: string,\n items: string[],\n): FilterSearchUpdate => applyChanges(selections, [{ filter, items }]);\n\nexport const commitText = (\n selections: FilterSearchSelection[],\n filter: string,\n text: string,\n): FilterSearchUpdate => applyChanges(selections, [{ filter, items: [text] }]);\n\n/** `Connector: Notion`, or `Connector: (Notion, Attio)` once there is more than one value. */\nexport const chipText = (filterLabel: string, itemLabels: string[]): string => {\n if (itemLabels.length === 0) return filterLabel;\n if (itemLabels.length === 1) return `${filterLabel}: ${itemLabels[0]}`;\n return `${filterLabel}: (${itemLabels.join(', ')})`;\n};\n\n/**\n * The order chips show filters in: when each was first added. A consumer reading its selection back\n * from the URL gets it in a fixed key order, which would reshuffle the chips on every change.\n */\nexport const orderSelections = (\n selections: FilterSearchSelection[],\n order: string[],\n /** A filter to hold its place in `order` while it has no values, e.g. the one being edited. */\n keep: string | null = null,\n): string[] => {\n const present = new Set(selections.map((selection) => selection.filter));\n const kept = order.filter((filter) => present.has(filter) || filter === keep);\n return [\n ...kept,\n ...selections.map((selection) => selection.filter).filter((f) => !kept.includes(f)),\n ];\n};\n"],"names":["resolveMode","activeFilter","query","matchesQuery","item","needle","selectedValues","selections","filter","_a","selection","toRows","filters","selected","toggleFor","all","matched","row","everyEnabledSelected","everyMatchSelected","rowsFor","openFilterOf","active","searchFilters","narrowed","wide","picked","listed","missing","filterRows","searchRows","sameItems","a","b","set","value","applyChanges","proposed","changes","change","byFilter","kept","added","toggleValue","current","items","selectAll","deselectAll","dropped","removeFilter","clearAll","keep","setValues","commitText","text","chipText","filterLabel","itemLabels","orderSelections","order","present","f"],"mappings":"AA4DO,MAAMA,IAAc,CAACC,GAA6BC,MACjDD,MAAiB,OAAa,UAC3BC,EAAM,KAAA,EAAO,SAAS,IAAI,WAAW,WAGnCC,IAAe,CAACC,GAAwBF,MAA2B;AAC5E,QAAMG,IAASH,EAAM,KAAA,EAAO,YAAA;AAC5B,SAAOE,EAAK,MAAM,YAAA,EAAc,SAASC,CAAM,KAAKD,EAAK,MAAM,cAAc,SAASC,CAAM;AAChG,GAEMC,IAAiB,CAACC,GAAqCC,MAAA;AAVtD,MAAAC;AAWH,aAAI,MAAIA,IAAAF,EAAW,KAAK,CAACG,MAAcA,EAAU,WAAWF,CAAM,MAA1D,gBAAAC,EAA6D,UAAS,CAAA,CAAE;AAAA,GAE9EE,IAAS,CACXC,GACAL,MAEAK,EAAQ,QAAQ,CAACJ,MAAW;AACxB,QAAMK,IAAWP,EAAeC,GAAYC,EAAO,KAAK;AACxD,SAAOA,EAAO,MAAM,IAAI,CAACJ,OAAU,EAAE,MAAAA,GAAM,QAAAI,GAAQ,UAAUK,EAAS,IAAIT,EAAK,KAAK,IAAI;AAC5F,CAAC,GAMCU,IAAY,CAACC,GAA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4C,IAAsB,SAEtBf;AAAA,EACI7B;AAAA,EACAA,EACK,OAAO,CAACG,MAAcA,EAAU,WAAWyC,CAAI,EAC/C,IAAI,CAACzC,OAAe,EAAE,QAAQA,EAAU,QAAQ,OAAO,CAAA,IAAK;AACrE,GAES0C,IAAY,CACrB7C,GACAC,GACAqC,MACqBT,EAAa7B,GAAY,CAAC,EAAE,QAAAC,GAAQ,OAAAqC,GAAO,CAAC,GAExDQ,IAAa,CACtB9C,GACAC,GACA8C,MACqBlB,EAAa7B,GAAY,CAAC,EAAE,QAAAC,GAAQ,OAAO,CAAC8C,CAAI,EAAA,CAAG,CAAC,GAGhEC,IAAW,CAACC,GAAqBC,MACtCA,EAAW,WAAW,IAAUD,IAChCC,EAAW,WAAW,IAAU,GAAGD,CAAW,KAAKC,EAAW,CAAC,CAAC,KAC7D,GAAGD,CAAW,MAAMC,EAAW,KAAK,IAAI,CAAC,KAOvCC,IAAkB,CAC3BnD,GACAoD,GAEAR,IAAsB,SACX;AACX,QAAMS,IAAU,IAAI,IAAIrD,EAAW,IAAI,CAACG,MAAcA,EAAU,MAAM,CAAC,GACjE+B,IAAOkB,EAAM,OAAO,CAACnD,MAAWoD,EAAQ,IAAIpD,CAAM,KAAKA,MAAW2C,CAAI;AAC5E,SAAO;AAAA,IACH,GAAGV;AAAA,IACH,GAAGlC,EAAW,IAAI,CAACG,MAAcA,EAAU,MAAM,EAAE,OAAO,CAACmD,MAAM,CAACpB,EAAK,SAASoB,CAAC,CAAC;AAAA,EAAA;AAE1F;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2034,6 +2034,8 @@ export declare interface FilterSearchChange {
|
|
|
2034
2034
|
items: string[];
|
|
2035
2035
|
}
|
|
2036
2036
|
|
|
2037
|
+
export declare type FilterSearchControl = 'list' | 'toggle' | 'segmented';
|
|
2038
|
+
|
|
2037
2039
|
export declare interface FilterSearchFilter {
|
|
2038
2040
|
value: string;
|
|
2039
2041
|
label: string;
|
|
@@ -2043,6 +2045,8 @@ export declare interface FilterSearchFilter {
|
|
|
2043
2045
|
example?: string;
|
|
2044
2046
|
/** `false` drops the filter's name from its chip, for a value that reads alone: `Configured only`. */
|
|
2045
2047
|
chipLabel?: boolean;
|
|
2048
|
+
/** Filters panel control: `list` (default) ticks values, `toggle` switches its first item's value, `segmented` picks one or All. */
|
|
2049
|
+
control?: FilterSearchControl;
|
|
2046
2050
|
items: FilterSearchItem[];
|
|
2047
2051
|
}
|
|
2048
2052
|
|
|
@@ -2052,6 +2056,8 @@ export declare interface FilterSearchItem {
|
|
|
2052
2056
|
disabled?: boolean;
|
|
2053
2057
|
/** Drawn before the label in the menu and in the applied chip: a logo, a status dot. Keep it 12px. */
|
|
2054
2058
|
icon?: ReactNode;
|
|
2059
|
+
/** Drawn at the end of the value's row in the Filters panel: how many results it matches. */
|
|
2060
|
+
count?: number;
|
|
2055
2061
|
}
|
|
2056
2062
|
|
|
2057
2063
|
export declare interface FilterSearchProps {
|
|
@@ -2068,9 +2074,9 @@ export declare interface FilterSearchProps {
|
|
|
2068
2074
|
onChange: (next: FilterSearchSelection[], changes: FilterSearchChange[]) => void;
|
|
2069
2075
|
/** Called when the clear control empties the bar, after `onChange`. */
|
|
2070
2076
|
onClear?: () => void;
|
|
2071
|
-
/** The filter whose values are open, or `null` on the filter list — for loading values lazily. */
|
|
2077
|
+
/** The filter whose values are open, or `null` on the filter list — for loading values lazily. Never called with `filtersButton`, whose panel draws every filter's `items` at once. */
|
|
2072
2078
|
onActiveFilterChange?: (filter: string | null) => void;
|
|
2073
|
-
/** The text in the field on every change: typed, put back by clicking the text pill, or reset to `''` when a value is picked or the menu closes. */
|
|
2079
|
+
/** The text in the field on every change: typed, put back by clicking the text pill, or reset to `''` when a value is picked or the menu closes (with `filtersButton`, only by Enter or Escape). */
|
|
2074
2080
|
onQueryChange?: (query: string) => void;
|
|
2075
2081
|
/** Lets typed text be committed as its own pill, under a `value` no filter uses. Its selection is `{ filter: textFilter.value, items: [text] }`. */
|
|
2076
2082
|
textFilter?: {
|
|
@@ -2086,8 +2092,8 @@ export declare interface FilterSearchProps {
|
|
|
2086
2092
|
/** Chips past this count collapse into `+N`. */
|
|
2087
2093
|
maxVisibleChips?: number;
|
|
2088
2094
|
/**
|
|
2089
|
-
* Puts a Filters button, with the applied filter count, at the bar's right end
|
|
2090
|
-
*
|
|
2095
|
+
* Puts a Filters button, with the applied filter count, at the bar's right end, and makes it the
|
|
2096
|
+
* only way to filters: the field becomes a plain search box whose Enter pins the text as a `textFilter` pill.
|
|
2091
2097
|
*/
|
|
2092
2098
|
filtersButton?: boolean;
|
|
2093
2099
|
className?: string;
|
|
@@ -4896,7 +4902,7 @@ export declare const SecurityIcon: React.FC<IconProps_99>;
|
|
|
4896
4902
|
* foreground-colour change as well as the thumb, so it does not rest on background
|
|
4897
4903
|
* colour alone.
|
|
4898
4904
|
*/
|
|
4899
|
-
export declare const SegmentedControl: <T extends string = string>({ options, value, onChange, size, fullWidth, disabled, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, className, }: SegmentedControlProps<T>) => JSX_2.Element;
|
|
4905
|
+
export declare const SegmentedControl: <T extends string = string>({ options, value, onChange, size, fullWidth, disabled, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, className, }: SegmentedControlProps<T>) => JSX_2.Element;
|
|
4900
4906
|
|
|
4901
4907
|
export declare interface SegmentedControlOption<T extends string = string> {
|
|
4902
4908
|
value: T;
|
|
@@ -4922,6 +4928,7 @@ export declare interface SegmentedControlProps<T extends string = string> {
|
|
|
4922
4928
|
disabled?: boolean;
|
|
4923
4929
|
'aria-label'?: string;
|
|
4924
4930
|
'aria-labelledby'?: string;
|
|
4931
|
+
'aria-describedby'?: string;
|
|
4925
4932
|
className?: string;
|
|
4926
4933
|
}
|
|
4927
4934
|
|