@umodeapporg/ui 0.35.0 → 0.35.1

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.
@@ -6,7 +6,8 @@ export interface IControlledViewToggleOption<V extends string = string> {
6
6
  icon?: SymbolCodepoints;
7
7
  /**
8
8
  * Option name. Rendered as visible text when the option has no icon or when
9
- * `showLabels` is on; otherwise shown as the option's tooltip.
9
+ * `showLabels` is on; otherwise shown as the option's tooltip and kept as
10
+ * screen-reader-only text, so the button is still named.
10
11
  */
11
12
  label: string;
12
13
  /**
@@ -141,7 +141,15 @@ const ControlledViewToggle = (props) => {
141
141
  ),
142
142
  children: [
143
143
  option.icon && /* @__PURE__ */ jsx(MaterialSymbol, { icon: option.icon, size: styles.icon }),
144
- showText && /* @__PURE__ */ jsx("span", { className: classNames("whitespace-nowrap font-medium", styles.textClass), children: option.label }),
144
+ /* @__PURE__ */ jsx(
145
+ "span",
146
+ {
147
+ className: classNames(
148
+ showText ? ["whitespace-nowrap font-medium", styles.textClass] : "sr-only"
149
+ ),
150
+ children: option.label
151
+ }
152
+ ),
145
153
  renderOptionCounter(option, isActive)
146
154
  ]
147
155
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ControlledViewToggle.js","sources":["../../../src/components/Form/ControlledViewToggle.tsx"],"sourcesContent":["import { Fragment, useEffect, useMemo, useRef } from 'react';\nimport classNames from 'classnames';\n\nimport ControlledButton from '@/components/Form/ControlledButton';\nimport { useUiNavigation } from '@/components/Navigation/UiNavigationContext';\nimport ControlledTooltip from '@/components/UI/ControlledTooltip';\nimport LoadingSpinner from '@/components/UI/LoadingSpinner';\nimport { MaterialSymbol, SymbolCodepoints } from '@/components/UI/MaterialSymbol';\nimport { formatNumber } from '@/helpers/formatHelpers';\nimport { uiLogger } from '@/helpers/uiLogger';\nimport {\n claimUrlParam,\n ownsUrlParam,\n queueUrlParamUpdate,\n releaseUrlParam,\n TABS_URL_PARAM,\n URL_PARAM_PRIORITY,\n} from '@/helpers/urlParamSync';\n\nexport type TControlledViewToggleSize = 'sm' | 'md';\n\nexport interface IControlledViewToggleOption<V extends string = string> {\n value: V;\n /** Optional icon; options without one render their label as text instead. */\n icon?: SymbolCodepoints;\n /**\n * Option name. Rendered as visible text when the option has no icon or when\n * `showLabels` is on; otherwise shown as the option's tooltip.\n */\n label: string;\n /**\n * Replaces the label in the tooltip when the option needs to explain itself, not just be named.\n * The label stays the accessible name, so it must remain short.\n */\n tooltip?: string;\n /** Counter badge next to the label, as in ControlledTabs. Hidden when null/undefined. */\n count?: number | null;\n /** Replaces the counter badge with a spinner while this option's data loads. */\n loading?: boolean;\n}\n\ninterface IControlledViewToggleBaseProps<V extends string = string> {\n options: Array<IControlledViewToggleOption<V>>;\n /** Renders every option's label as visible text next to its icon. */\n showLabels?: boolean;\n /** `md` (default) pairs with page-level controls; `sm` matches compact filter bars. */\n size?: TControlledViewToggleSize;\n /** Disables every option, keeping the current selection visible. */\n disabled?: boolean;\n /**\n * Mirrors the selection in the URL, on by default like `ControlledTabs`. Turn it off for toggles\n * that hold form state (a weekday picker, an AND/OR combinator) or that live inside a drawer,\n * where the selection is not page state and should not reach the URL.\n */\n syncWithUrl?: boolean;\n /**\n * Query param used when `syncWithUrl` is on, defaults to `view`. A page holding more than one\n * synced toggle must give each a unique key: the first one mounted keeps the param and the others\n * stop writing (with a warning in development) instead of overwriting each other.\n *\n * Lifecycle mirrors `ControlledTabs`: on mount an existing valid param wins over `value` and is\n * pushed to the host through `onChange`; with no param (or an invalid one) the current value is\n * stamped into the URL right away. From there on the host selection is the authority and every\n * change rewrites the param, always preserving the other params and replacing the history entry.\n * In `multiple` mode values are comma separated and an empty selection removes the param.\n */\n urlParamKey?: string;\n className?: string;\n}\n\ninterface IControlledViewToggleSingleProps<V extends string = string> extends IControlledViewToggleBaseProps<V> {\n multiple?: false;\n value: V;\n onChange: (value: V) => void;\n}\n\ninterface IControlledViewToggleMultipleProps<V extends string = string> extends IControlledViewToggleBaseProps<V> {\n multiple: true;\n value: Array<V>;\n /** Receives the whole next selection, which may be empty. */\n onChange: (values: Array<V>) => void;\n}\n\nexport type TControlledViewToggleProps<V extends string = string> =\n IControlledViewToggleSingleProps<V> | IControlledViewToggleMultipleProps<V>;\n\nconst DEFAULT_URL_PARAM_KEY = 'view';\n\nconst SIZE_STYLES: Record<\n TControlledViewToggleSize,\n { container: string; button: string; textClass: string; inactive: string; icon: number }\n> = {\n sm: {\n // Inner radius mirrors the container radius minus its padding, so the active\n // segment stays concentric with the outer border.\n container: 'h-9 gap-1 rounded-xl',\n button: 'h-7 rounded-lg px-2.5',\n textClass: 'text-xs',\n // One step darker than md so the segments match the neighbouring controls\n // in the compact filter bars this size is used by.\n inactive: 'text-foreground-muted hover:bg-muted-hover hover:text-foreground',\n icon: 16,\n },\n // leading-[18px] matches the icon height so icon-only, text-only and\n // icon + text options all keep the same button height.\n md: {\n container: 'gap-1 rounded-lg shadow-sm',\n button: 'rounded-md px-2.5 py-1.5',\n textClass: 'text-sm leading-[18px]',\n inactive: 'text-foreground-subtle hover:bg-muted-hover hover:text-foreground-muted',\n icon: 18,\n },\n};\n\n/**\n * Segmented toggle for switching between visualization modes (e.g. cards /\n * list / grouped). Options can be icon-only, text-only or icon + text, and the\n * component is generic over the option value union so hosts keep their own mode\n * types. Clicking the already-active option fires `onChange` again, letting\n * hosts react to re-selection (e.g. reopening a configuration dialog).\n *\n * With `multiple`, it becomes a segmented multi-select: `value` is the selected\n * array, clicking an option adds or removes it, and `onChange` receives the\n * whole next selection, which may be empty.\n */\nconst ControlledViewToggle = <V extends string = string>(props: TControlledViewToggleProps<V>) => {\n const {\n options,\n showLabels = false,\n size = 'md',\n disabled = false,\n syncWithUrl = true,\n urlParamKey = DEFAULT_URL_PARAM_KEY,\n className,\n } = props;\n const styles = SIZE_STYLES[size];\n const { searchParams, setSearchParams } = useUiNavigation();\n\n const safeOptions = useMemo(() => (Array.isArray(options) ? options : []), [options]);\n const selectedValues = props.multiple ? (Array.isArray(props.value) ? props.value : []) : [props.value];\n const serializedValue = selectedValues.join(',');\n\n const hasReadUrlSelectionRef = useRef(false);\n const pendingUrlSelectionRef = useRef<string | null>(null);\n const ownerIdRef = useRef<object>({});\n\n const isUrlParamReserved = urlParamKey === TABS_URL_PARAM;\n const isUrlSyncEnabled = syncWithUrl && !isUrlParamReserved;\n\n useEffect(() => {\n if (!syncWithUrl) return;\n\n if (isUrlParamReserved) {\n uiLogger.warn(\n `[ControlledViewToggle] \"${TABS_URL_PARAM}\" belongs to ControlledTabs. ` +\n 'Give this toggle its own urlParamKey: it will not write to the URL.',\n );\n return;\n }\n\n const ownerId = ownerIdRef.current;\n\n if (!claimUrlParam(urlParamKey, ownerId, URL_PARAM_PRIORITY.viewToggle)) {\n uiLogger.warn(\n `[ControlledViewToggle] More than one control syncs \"${urlParamKey}\". ` +\n 'Give each one a unique urlParamKey: this instance will not write to the URL.',\n );\n }\n\n return () => releaseUrlParam(urlParamKey, ownerId);\n }, [syncWithUrl, isUrlParamReserved, urlParamKey]);\n\n // Um efeito só, em duas fases. Na montagem o parâmetro manda: existindo um valor válido ele é\n // aplicado no host, e a escrita fica suspensa até o host adotá-lo (senão o valor padrão seria\n // gravado por cima do que veio na URL). Não existindo, o valor atual é carimbado na hora. Depois\n // disso a seleção do host é a autoridade e a URL apenas a reflete.\n useEffect(() => {\n if (!isUrlSyncEnabled || !ownsUrlParam(urlParamKey, ownerIdRef.current)) return;\n\n const rawParam = searchParams.get(urlParamKey) ?? '';\n\n if (pendingUrlSelectionRef.current !== null) {\n if (serializedValue === pendingUrlSelectionRef.current) pendingUrlSelectionRef.current = null;\n return;\n }\n\n if (!hasReadUrlSelectionRef.current) {\n hasReadUrlSelectionRef.current = true;\n\n const optionValues = new Set(safeOptions.map((option) => option.value));\n const urlValues = rawParam\n .split(',')\n .map((rawValue) => rawValue.trim())\n .filter((rawValue): rawValue is V => optionValues.has(rawValue as V));\n\n if (urlValues.length) {\n const urlSelection = urlValues.join(',');\n if (urlSelection !== serializedValue) {\n pendingUrlSelectionRef.current = urlSelection;\n if (props.multiple) props.onChange(urlValues);\n else props.onChange(urlValues[0]);\n }\n return;\n }\n }\n\n if (rawParam === serializedValue) return;\n\n queueUrlParamUpdate(urlParamKey, serializedValue, setSearchParams);\n }, [isUrlSyncEnabled, urlParamKey, searchParams, safeOptions, serializedValue, setSearchParams, props]);\n\n const handleSelectOption = (optionValue: V) => {\n if (!props.multiple) {\n props.onChange(optionValue);\n return;\n }\n\n const currentValues = Array.isArray(props.value) ? props.value : [];\n props.onChange(\n currentValues.includes(optionValue)\n ? currentValues.filter((selectedValue) => selectedValue !== optionValue)\n : [...currentValues, optionValue],\n );\n };\n\n const renderOptionCounter = (option: IControlledViewToggleOption<V>, isActive: boolean) => {\n if (option.loading) return <LoadingSpinner size={3} />;\n if (option.count === undefined || option.count === null) return null;\n\n return (\n <span\n className={classNames(\n 'inline-flex min-w-[18px] items-center justify-center rounded-full px-1.5 py-px text-[11px] font-medium leading-none',\n isActive ? 'bg-glass/25 text-white' : 'bg-muted-hover text-foreground-subtle',\n )}\n >\n {formatNumber(option.count)}\n </span>\n );\n };\n\n return (\n <div\n className={classNames(\n 'inline-flex shrink-0 items-center border border-border bg-surface p-1',\n styles.container,\n className,\n )}\n >\n {safeOptions.map((option) => {\n const isActive = selectedValues.includes(option.value);\n const showText = showLabels || !option.icon;\n\n const button = (\n <ControlledButton\n defaultHtmlButton\n aria-pressed={isActive}\n disabled={disabled}\n onClick={() => handleSelectOption(option.value)}\n className={classNames(\n 'flex items-center justify-center gap-1.5 outline-none transition-colors focus-visible:ring-2 focus-visible:ring-brand-border disabled:cursor-not-allowed',\n styles.button,\n isActive ? 'bg-brand text-brand-fg shadow-sm' : styles.inactive,\n )}\n >\n {option.icon && <MaterialSymbol icon={option.icon} size={styles.icon} />}\n {showText && (\n <span className={classNames('whitespace-nowrap font-medium', styles.textClass)}>{option.label}</span>\n )}\n {renderOptionCounter(option, isActive)}\n </ControlledButton>\n );\n\n // The tooltip only adds value when the label is not already visible.\n return showText ? (\n <Fragment key={option.value}>{button}</Fragment>\n ) : (\n <ControlledTooltip key={option.value} content={option.tooltip ?? option.label}>\n {button}\n </ControlledTooltip>\n );\n })}\n </div>\n );\n};\n\nexport default ControlledViewToggle;\n"],"names":[],"mappings":";;;;;;;;;;;AAsFA,MAAM,wBAAwB;AAE9B,MAAM,cAGF;AAAA,EACF,IAAI;AAAA;AAAA;AAAA,IAGF,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,WAAW;AAAA;AAAA;AAAA,IAGX,UAAU;AAAA,IACV,MAAM;AAAA,EAAA;AAAA;AAAA;AAAA,EAIR,IAAI;AAAA,IACF,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,UAAU;AAAA,IACV,MAAM;AAAA,EAAA;AAEV;AAaA,MAAM,uBAAuB,CAA4B,UAAyC;AAChG,QAAM;AAAA,IACJ;AAAA,IACA,aAAa;AAAA,IACb,OAAO;AAAA,IACP,WAAW;AAAA,IACX,cAAc;AAAA,IACd,cAAc;AAAA,IACd;AAAA,EAAA,IACE;AACJ,QAAM,SAAS,YAAY,IAAI;AAC/B,QAAM,EAAE,cAAc,gBAAA,IAAoB,gBAAA;AAE1C,QAAM,cAAc,QAAQ,MAAO,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAA,GAAK,CAAC,OAAO,CAAC;AACpF,QAAM,iBAAiB,MAAM,WAAY,MAAM,QAAQ,MAAM,KAAK,IAAI,MAAM,QAAQ,CAAA,IAAM,CAAC,MAAM,KAAK;AACtG,QAAM,kBAAkB,eAAe,KAAK,GAAG;AAE/C,QAAM,yBAAyB,OAAO,KAAK;AAC3C,QAAM,yBAAyB,OAAsB,IAAI;AACzD,QAAM,aAAa,OAAe,EAAE;AAEpC,QAAM,qBAAqB,gBAAgB;AAC3C,QAAM,mBAAmB,eAAe,CAAC;AAEzC,YAAU,MAAM;AACd,QAAI,CAAC,YAAa;AAElB,QAAI,oBAAoB;AACtB,e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,oBAAoB,QAAQ,QAAQ;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAKzC,eAAO,WACL,oBAAC,UAAA,EAA6B,UAAA,UAAf,OAAO,KAAe,IAErC,oBAAC,mBAAA,EAAqC,SAAS,OAAO,WAAW,OAAO,OACrE,UAAA,OAAA,GADqB,OAAO,KAE/B;AAAA,MAEJ,CAAC;AAAA,IAAA;AAAA,EAAA;AAGP;"}
1
+ {"version":3,"file":"ControlledViewToggle.js","sources":["../../../src/components/Form/ControlledViewToggle.tsx"],"sourcesContent":["import { Fragment, useEffect, useMemo, useRef } from 'react';\nimport classNames from 'classnames';\n\nimport ControlledButton from '@/components/Form/ControlledButton';\nimport { useUiNavigation } from '@/components/Navigation/UiNavigationContext';\nimport ControlledTooltip from '@/components/UI/ControlledTooltip';\nimport LoadingSpinner from '@/components/UI/LoadingSpinner';\nimport { MaterialSymbol, SymbolCodepoints } from '@/components/UI/MaterialSymbol';\nimport { formatNumber } from '@/helpers/formatHelpers';\nimport { uiLogger } from '@/helpers/uiLogger';\nimport {\n claimUrlParam,\n ownsUrlParam,\n queueUrlParamUpdate,\n releaseUrlParam,\n TABS_URL_PARAM,\n URL_PARAM_PRIORITY,\n} from '@/helpers/urlParamSync';\n\nexport type TControlledViewToggleSize = 'sm' | 'md';\n\nexport interface IControlledViewToggleOption<V extends string = string> {\n value: V;\n /** Optional icon; options without one render their label as text instead. */\n icon?: SymbolCodepoints;\n /**\n * Option name. Rendered as visible text when the option has no icon or when\n * `showLabels` is on; otherwise shown as the option's tooltip and kept as\n * screen-reader-only text, so the button is still named.\n */\n label: string;\n /**\n * Replaces the label in the tooltip when the option needs to explain itself, not just be named.\n * The label stays the accessible name, so it must remain short.\n */\n tooltip?: string;\n /** Counter badge next to the label, as in ControlledTabs. Hidden when null/undefined. */\n count?: number | null;\n /** Replaces the counter badge with a spinner while this option's data loads. */\n loading?: boolean;\n}\n\ninterface IControlledViewToggleBaseProps<V extends string = string> {\n options: Array<IControlledViewToggleOption<V>>;\n /** Renders every option's label as visible text next to its icon. */\n showLabels?: boolean;\n /** `md` (default) pairs with page-level controls; `sm` matches compact filter bars. */\n size?: TControlledViewToggleSize;\n /** Disables every option, keeping the current selection visible. */\n disabled?: boolean;\n /**\n * Mirrors the selection in the URL, on by default like `ControlledTabs`. Turn it off for toggles\n * that hold form state (a weekday picker, an AND/OR combinator) or that live inside a drawer,\n * where the selection is not page state and should not reach the URL.\n */\n syncWithUrl?: boolean;\n /**\n * Query param used when `syncWithUrl` is on, defaults to `view`. A page holding more than one\n * synced toggle must give each a unique key: the first one mounted keeps the param and the others\n * stop writing (with a warning in development) instead of overwriting each other.\n *\n * Lifecycle mirrors `ControlledTabs`: on mount an existing valid param wins over `value` and is\n * pushed to the host through `onChange`; with no param (or an invalid one) the current value is\n * stamped into the URL right away. From there on the host selection is the authority and every\n * change rewrites the param, always preserving the other params and replacing the history entry.\n * In `multiple` mode values are comma separated and an empty selection removes the param.\n */\n urlParamKey?: string;\n className?: string;\n}\n\ninterface IControlledViewToggleSingleProps<V extends string = string> extends IControlledViewToggleBaseProps<V> {\n multiple?: false;\n value: V;\n onChange: (value: V) => void;\n}\n\ninterface IControlledViewToggleMultipleProps<V extends string = string> extends IControlledViewToggleBaseProps<V> {\n multiple: true;\n value: Array<V>;\n /** Receives the whole next selection, which may be empty. */\n onChange: (values: Array<V>) => void;\n}\n\nexport type TControlledViewToggleProps<V extends string = string> =\n IControlledViewToggleSingleProps<V> | IControlledViewToggleMultipleProps<V>;\n\nconst DEFAULT_URL_PARAM_KEY = 'view';\n\nconst SIZE_STYLES: Record<\n TControlledViewToggleSize,\n { container: string; button: string; textClass: string; inactive: string; icon: number }\n> = {\n sm: {\n // Inner radius mirrors the container radius minus its padding, so the active\n // segment stays concentric with the outer border.\n container: 'h-9 gap-1 rounded-xl',\n button: 'h-7 rounded-lg px-2.5',\n textClass: 'text-xs',\n // One step darker than md so the segments match the neighbouring controls\n // in the compact filter bars this size is used by.\n inactive: 'text-foreground-muted hover:bg-muted-hover hover:text-foreground',\n icon: 16,\n },\n // leading-[18px] matches the icon height so icon-only, text-only and\n // icon + text options all keep the same button height.\n md: {\n container: 'gap-1 rounded-lg shadow-sm',\n button: 'rounded-md px-2.5 py-1.5',\n textClass: 'text-sm leading-[18px]',\n inactive: 'text-foreground-subtle hover:bg-muted-hover hover:text-foreground-muted',\n icon: 18,\n },\n};\n\n/**\n * Segmented toggle for switching between visualization modes (e.g. cards /\n * list / grouped). Options can be icon-only, text-only or icon + text, and the\n * component is generic over the option value union so hosts keep their own mode\n * types. Clicking the already-active option fires `onChange` again, letting\n * hosts react to re-selection (e.g. reopening a configuration dialog).\n *\n * With `multiple`, it becomes a segmented multi-select: `value` is the selected\n * array, clicking an option adds or removes it, and `onChange` receives the\n * whole next selection, which may be empty.\n */\nconst ControlledViewToggle = <V extends string = string>(props: TControlledViewToggleProps<V>) => {\n const {\n options,\n showLabels = false,\n size = 'md',\n disabled = false,\n syncWithUrl = true,\n urlParamKey = DEFAULT_URL_PARAM_KEY,\n className,\n } = props;\n const styles = SIZE_STYLES[size];\n const { searchParams, setSearchParams } = useUiNavigation();\n\n const safeOptions = useMemo(() => (Array.isArray(options) ? options : []), [options]);\n const selectedValues = props.multiple ? (Array.isArray(props.value) ? props.value : []) : [props.value];\n const serializedValue = selectedValues.join(',');\n\n const hasReadUrlSelectionRef = useRef(false);\n const pendingUrlSelectionRef = useRef<string | null>(null);\n const ownerIdRef = useRef<object>({});\n\n const isUrlParamReserved = urlParamKey === TABS_URL_PARAM;\n const isUrlSyncEnabled = syncWithUrl && !isUrlParamReserved;\n\n useEffect(() => {\n if (!syncWithUrl) return;\n\n if (isUrlParamReserved) {\n uiLogger.warn(\n `[ControlledViewToggle] \"${TABS_URL_PARAM}\" belongs to ControlledTabs. ` +\n 'Give this toggle its own urlParamKey: it will not write to the URL.',\n );\n return;\n }\n\n const ownerId = ownerIdRef.current;\n\n if (!claimUrlParam(urlParamKey, ownerId, URL_PARAM_PRIORITY.viewToggle)) {\n uiLogger.warn(\n `[ControlledViewToggle] More than one control syncs \"${urlParamKey}\". ` +\n 'Give each one a unique urlParamKey: this instance will not write to the URL.',\n );\n }\n\n return () => releaseUrlParam(urlParamKey, ownerId);\n }, [syncWithUrl, isUrlParamReserved, urlParamKey]);\n\n // Um efeito só, em duas fases. Na montagem o parâmetro manda: existindo um valor válido ele é\n // aplicado no host, e a escrita fica suspensa até o host adotá-lo (senão o valor padrão seria\n // gravado por cima do que veio na URL). Não existindo, o valor atual é carimbado na hora. Depois\n // disso a seleção do host é a autoridade e a URL apenas a reflete.\n useEffect(() => {\n if (!isUrlSyncEnabled || !ownsUrlParam(urlParamKey, ownerIdRef.current)) return;\n\n const rawParam = searchParams.get(urlParamKey) ?? '';\n\n if (pendingUrlSelectionRef.current !== null) {\n if (serializedValue === pendingUrlSelectionRef.current) pendingUrlSelectionRef.current = null;\n return;\n }\n\n if (!hasReadUrlSelectionRef.current) {\n hasReadUrlSelectionRef.current = true;\n\n const optionValues = new Set(safeOptions.map((option) => option.value));\n const urlValues = rawParam\n .split(',')\n .map((rawValue) => rawValue.trim())\n .filter((rawValue): rawValue is V => optionValues.has(rawValue as V));\n\n if (urlValues.length) {\n const urlSelection = urlValues.join(',');\n if (urlSelection !== serializedValue) {\n pendingUrlSelectionRef.current = urlSelection;\n if (props.multiple) props.onChange(urlValues);\n else props.onChange(urlValues[0]);\n }\n return;\n }\n }\n\n if (rawParam === serializedValue) return;\n\n queueUrlParamUpdate(urlParamKey, serializedValue, setSearchParams);\n }, [isUrlSyncEnabled, urlParamKey, searchParams, safeOptions, serializedValue, setSearchParams, props]);\n\n const handleSelectOption = (optionValue: V) => {\n if (!props.multiple) {\n props.onChange(optionValue);\n return;\n }\n\n const currentValues = Array.isArray(props.value) ? props.value : [];\n props.onChange(\n currentValues.includes(optionValue)\n ? currentValues.filter((selectedValue) => selectedValue !== optionValue)\n : [...currentValues, optionValue],\n );\n };\n\n const renderOptionCounter = (option: IControlledViewToggleOption<V>, isActive: boolean) => {\n if (option.loading) return <LoadingSpinner size={3} />;\n if (option.count === undefined || option.count === null) return null;\n\n return (\n <span\n className={classNames(\n 'inline-flex min-w-[18px] items-center justify-center rounded-full px-1.5 py-px text-[11px] font-medium leading-none',\n isActive ? 'bg-glass/25 text-white' : 'bg-muted-hover text-foreground-subtle',\n )}\n >\n {formatNumber(option.count)}\n </span>\n );\n };\n\n return (\n <div\n className={classNames(\n 'inline-flex shrink-0 items-center border border-border bg-surface p-1',\n styles.container,\n className,\n )}\n >\n {safeOptions.map((option) => {\n const isActive = selectedValues.includes(option.value);\n const showText = showLabels || !option.icon;\n\n const button = (\n <ControlledButton\n defaultHtmlButton\n aria-pressed={isActive}\n disabled={disabled}\n onClick={() => handleSelectOption(option.value)}\n className={classNames(\n 'flex items-center justify-center gap-1.5 outline-none transition-colors focus-visible:ring-2 focus-visible:ring-brand-border disabled:cursor-not-allowed',\n styles.button,\n isActive ? 'bg-brand text-brand-fg shadow-sm' : styles.inactive,\n )}\n >\n {option.icon && <MaterialSymbol icon={option.icon} size={styles.icon} />}\n {/* Icon only: the label stays the button's name for assistive tech (the icon is decorative). */}\n <span\n className={classNames(\n showText ? ['whitespace-nowrap font-medium', styles.textClass] : 'sr-only',\n )}\n >\n {option.label}\n </span>\n {renderOptionCounter(option, isActive)}\n </ControlledButton>\n );\n\n // The tooltip only adds value when the label is not already visible.\n return showText ? (\n <Fragment key={option.value}>{button}</Fragment>\n ) : (\n <ControlledTooltip key={option.value} content={option.tooltip ?? option.label}>\n {button}\n </ControlledTooltip>\n );\n })}\n </div>\n );\n};\n\nexport default ControlledViewToggle;\n"],"names":[],"mappings":";;;;;;;;;;;AAuFA,MAAM,wBAAwB;AAE9B,MAAM,cAGF;AAAA,EACF,IAAI;AAAA;AAAA;AAAA,IAGF,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,WAAW;AAAA;AAAA;AAAA,IAGX,UAAU;AAAA,IACV,MAAM;AAAA,EAAA;AAAA;AAAA;AAAA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g/ui",
3
- "version": "0.35.0",
3
+ "version": "0.35.1",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "sideEffects": [