@linzjs/lui 17.11.3 → 17.12.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/dist/lui.esm.js CHANGED
@@ -40367,7 +40367,7 @@ const LuiAccordicardStatic = (props) => {
40367
40367
  React__default.createElement(LuiIcon, { className: clsx('LuiAccordicardStatic-chevron', isOpen ? 'LuiAccordicardStatic-chevron--isOpen' : null), name: 'ic_expand_more', alt: "expand", title: "Expand and collapse panel", size: "md" }))));
40368
40368
  };
40369
40369
 
40370
- var css_248z$2 = "/**\n @deprecated\n */\n/**\n @deprecated\n */\n/**\n @deprecated\n */\n.LuiListBox {\n padding: 0;\n list-style: none;\n}\n.LuiListBox .LuiListBoxItem {\n font-family: \"Open Sans\", system-ui, sans-serif;\n font-style: normal;\n font-weight: normal;\n user-select: none;\n color: #2a292c;\n line-height: 24px;\n outline: none;\n padding: 0.5rem 0.75rem;\n border: 2px solid transparent;\n}\n.LuiListBox .LuiListBoxItem:focus-visible {\n border-color: #007198;\n}\n.LuiListBox .LuiListBoxItem.LuiListBoxItem-selected {\n background: #e2f3f7;\n}\n.LuiListBox .LuiListBoxItem:hover, .LuiListBox .LuiListBoxItem.LuiListBoxItem-selected:hover {\n background: #d6eef4;\n}\n.LuiListBox .LuiListBoxItem.LuiListBoxItem-disabled {\n background: #eaeaea;\n}\n.LuiListBox .LuiListBox-emptyIndicator, .LuiListBox .LuiListBox-loadingIndicator {\n padding: 0.5rem 0.75rem;\n}";
40370
+ var css_248z$2 = "/**\n @deprecated\n */\n/**\n @deprecated\n */\n/**\n @deprecated\n */\n.LuiListBox {\n padding: 0;\n list-style: none;\n}\n.LuiListBox .LuiListBoxItem {\n font-family: \"Open Sans\", system-ui, sans-serif;\n font-style: normal;\n font-weight: normal;\n user-select: none;\n color: #2a292c;\n line-height: 24px;\n outline: none;\n padding: 0.5rem 0.75rem;\n border: 2px solid transparent;\n}\n.LuiListBox .LuiListBoxItem:focus-visible {\n border-color: #007198;\n}\n.LuiListBox .LuiListBoxItem.LuiListBoxItem-selected {\n background: #e2f3f7;\n}\n.LuiListBox .LuiListBoxItem:hover, .LuiListBox .LuiListBoxItem.LuiListBoxItem-selected:hover {\n background: #d6eef4;\n}\n.LuiListBox .LuiListBoxItem.LuiListBoxItem-disabled {\n background: #eaeaea;\n}\n.LuiListBox .LuiListBox-emptyIndicator, .LuiListBox .LuiListBox-loadingIndicator {\n padding: 0.5rem 0.75rem;\n}\n.LuiListBox .LuiListBoxGroup .LuiListBoxGroup-heading {\n font-family: \"Open Sans\", system-ui, sans-serif;\n font-style: normal;\n font-weight: normal;\n font-size: 14px;\n user-select: none;\n color: #6b6966;\n line-height: 16px;\n padding: 0.5rem 0.5rem;\n}";
40371
40371
  styleInject(css_248z$2);
40372
40372
 
40373
40373
  function $c1d7fb2ec91bae71$var$Item(props) {
@@ -40415,6 +40415,42 @@ let $c1d7fb2ec91bae71$export$6d08773d2e66f8f2 = $c1d7fb2ec91bae71$var$Item;
40415
40415
 
40416
40416
 
40417
40417
 
40418
+ function $9fc4852771d079eb$var$Section(props) {
40419
+ return null;
40420
+ }
40421
+ $9fc4852771d079eb$var$Section.getCollectionNode = function* getCollectionNode(props) {
40422
+ let { children: children , title: title , items: items1 } = props;
40423
+ yield {
40424
+ type: 'section',
40425
+ hasChildNodes: true,
40426
+ rendered: title,
40427
+ 'aria-label': props['aria-label'],
40428
+ *childNodes () {
40429
+ if (typeof children === 'function') {
40430
+ if (!items1) throw new Error('props.children was a function but props.items is missing');
40431
+ for (let item of items1)yield {
40432
+ type: 'item',
40433
+ value: item,
40434
+ renderer: children
40435
+ };
40436
+ } else {
40437
+ let items = [];
40438
+ React__default.Children.forEach(children, (child)=>{
40439
+ items.push({
40440
+ type: 'item',
40441
+ element: child
40442
+ });
40443
+ });
40444
+ yield* items;
40445
+ }
40446
+ }
40447
+ };
40448
+ };
40449
+ // We don't want getCollectionNode to show up in the type definition
40450
+ let $9fc4852771d079eb$export$6e2c8f0811a474ce = $9fc4852771d079eb$var$Section;
40451
+
40452
+
40453
+
40418
40454
  class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
40419
40455
  build(props, context) {
40420
40456
  this.context = context;
@@ -40620,38 +40656,68 @@ function $453cc9f0df89c0a5$export$77d5aafae4e095b2(collection) {
40620
40656
  return count;
40621
40657
  }
40622
40658
 
40623
- function mapToAriaListBoxProps({ selectionMode, selectionBehavior, items = [], value, onChange, ariaProps, getKey = (item) => {
40624
- if (!item.hasOwnProperty('key')) {
40625
- throw Error('Could not find `key` property on item, please provide a custom `getKey` function');
40626
- }
40627
- return item.key;
40628
- }, }) {
40659
+ function useLuiListBox({ selectionMode, selectionBehavior, items = [], value, onChange, ariaProps, getGroup = defaultGroupGetter, getKey = defaultKeyGetter, }) {
40660
+ const children = useCallback((item) => item.childNodes ? (React__default.createElement($9fc4852771d079eb$export$6e2c8f0811a474ce, { key: item.key, items: item.childNodes, title: item.textValue }, (item) => React__default.createElement($c1d7fb2ec91bae71$export$6d08773d2e66f8f2, null, String(item.key)))) : (React__default.createElement($c1d7fb2ec91bae71$export$6d08773d2e66f8f2, null, String(item.key))), []);
40661
+ const onSelectionChange = useCallback((keys) => {
40662
+ if (!onChange) {
40663
+ return;
40664
+ }
40665
+ onChange(keys === 'all' ? items.map((item) => getKey(item)) : Array.from(keys), keys === 'all' ? items : items.filter((item) => keys.has(getKey(item))));
40666
+ }, [items, onChange, getKey]);
40667
+ const nodes = useMemo(() => mapItemsToNodes(items, getKey, getGroup), [
40668
+ items,
40669
+ getKey,
40670
+ getGroup,
40671
+ ]);
40629
40672
  return {
40630
40673
  ...ariaProps,
40631
- items: items?.map((item) => {
40632
- if (item.hasOwnProperty('key')) {
40633
- return item;
40634
- }
40635
- return { ...item, key: getKey(item) };
40636
- }),
40674
+ items: nodes,
40637
40675
  selectionMode,
40638
40676
  selectionBehavior,
40639
40677
  selectedKeys: (Array.isArray(value) ? value : [value]).filter(Boolean),
40640
- children: (item) => React__default.createElement($c1d7fb2ec91bae71$export$6d08773d2e66f8f2, null, String(item.key)),
40641
- ...(onChange
40642
- ? {
40643
- onSelectionChange: (keys) => {
40644
- const selectedItems = keys === 'all'
40645
- ? items
40646
- : items.filter((item) => keys.has(getKey(item)));
40647
- const selectedKeys = keys === 'all'
40648
- ? items.map((item) => getKey(item))
40649
- : Array.from(keys);
40650
- onChange(selectedKeys, selectedItems);
40651
- },
40652
- }
40653
- : {}),
40678
+ children,
40679
+ onSelectionChange,
40654
40680
  };
40681
+ }
40682
+ function mapItemsToNodes(items, getKey, getGroup) {
40683
+ const rootNodes = new Map();
40684
+ for (const item of items) {
40685
+ const groupName = getGroup(item);
40686
+ const key = getKey(item);
40687
+ // Is an item without a group
40688
+ if (!groupName) {
40689
+ rootNodes.set(key, {
40690
+ key,
40691
+ textValue: String(key),
40692
+ value: item,
40693
+ });
40694
+ }
40695
+ // is an item with a group that has not been encountered yet.
40696
+ if (groupName && !rootNodes.get(groupName)) {
40697
+ rootNodes.set(groupName, {
40698
+ key: groupName,
40699
+ textValue: groupName,
40700
+ childNodes: [],
40701
+ });
40702
+ }
40703
+ if (groupName) {
40704
+ rootNodes.get(groupName).childNodes.push({
40705
+ key,
40706
+ textValue: String(key),
40707
+ value: item,
40708
+ });
40709
+ }
40710
+ }
40711
+ return Array.from(rootNodes.values());
40712
+ }
40713
+ function defaultKeyGetter(item) {
40714
+ if (!item.hasOwnProperty('key')) {
40715
+ throw Error('Could not find `key` property on item, please provide a custom `getKey` function');
40716
+ }
40717
+ return item.key;
40718
+ }
40719
+ function defaultGroupGetter(item) {
40720
+ return item.group || null;
40655
40721
  }
40656
40722
 
40657
40723
  function $458b0a5536c1a7cf$export$40bfa8c7b0832715(value1, defaultValue, onChange) {
@@ -43242,20 +43308,41 @@ function $293f70390ea03370$export$497855f14858aa34(props, state, ref) {
43242
43308
  };
43243
43309
  }
43244
43310
 
43311
+
43312
+
43313
+ function $af383d3bef1cfdc9$export$c3f9f39876e4bc7(props) {
43314
+ let { heading: heading , 'aria-label': ariaLabel } = props;
43315
+ let headingId = $bdb11010cef70236$export$f680877a34711e37();
43316
+ return {
43317
+ itemProps: {
43318
+ role: 'presentation'
43319
+ },
43320
+ headingProps: heading ? {
43321
+ // Techincally, listbox cannot contain headings according to ARIA.
43322
+ // We hide the heading from assistive technology, and only use it
43323
+ // as a label for the nested group.
43324
+ id: headingId,
43325
+ 'aria-hidden': true
43326
+ } : {
43327
+ },
43328
+ groupProps: {
43329
+ role: 'group',
43330
+ 'aria-label': ariaLabel,
43331
+ 'aria-labelledby': heading ? headingId : undefined
43332
+ }
43333
+ };
43334
+ }
43335
+
43245
43336
  function LuiListBoxItem({ node, state, renderer, }) {
43246
43337
  const ref = useRef(null);
43247
43338
  const { optionProps, isSelected, isDisabled } = $293f70390ea03370$export$497855f14858aa34({ key: node.key }, state, ref);
43248
43339
  const { isFocusVisible, focusProps } = $f7dceffc5ad7768b$export$4e328f61c538687f();
43249
- return (React__default.createElement("li", { ref: ref, ...$3ef42575df84b30b$export$9d1611c77c2fe928(optionProps, focusProps), className: clsx('LuiListBoxItem', isSelected && 'LuiListBoxItem-selected', isDisabled && 'LuiListBoxItem-disabled') }, renderer
43250
- ? renderer({ item: node.value, isDisabled, isSelected, isFocusVisible })
43251
- : node.rendered));
43252
- }
43253
-
43254
- function DefaultItemRenderer({ item, }) {
43255
- if (!item.hasOwnProperty('label')) {
43256
- throw Error('Could not find `label` property on item, please provide a custom `itemRenderer`');
43257
- }
43258
- return React__default.createElement(React__default.Fragment, null, item.label);
43340
+ return (React__default.createElement("li", { ref: ref, ...$3ef42575df84b30b$export$9d1611c77c2fe928(optionProps, focusProps), className: clsx('LuiListBoxItem', isSelected && 'LuiListBoxItem-selected', isDisabled && 'LuiListBoxItem-disabled') }, renderer({
43341
+ item: node.value,
43342
+ isDisabled,
43343
+ isSelected,
43344
+ isFocusVisible,
43345
+ })));
43259
43346
  }
43260
43347
 
43261
43348
  class $e40ea825a81a3709$export$52baac22726c72bf extends Set {
@@ -43727,27 +43814,28 @@ function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
43727
43814
  };
43728
43815
  }
43729
43816
 
43730
- function LuiListBox({ ariaLabel, ariaLabelledBy, itemRenderer = DefaultItemRenderer, loadingIndicator = DefaultLoadingIndicator, emptyIndicator = DefaultEmptyIndicator, selectionMode = 'single', selectionBehavior = 'toggle', disabled = false, items, value, onChange = () => {
43731
- /* noop */
43732
- }, getKey, ariaProps, className, ...ulProps }) {
43733
- const listProps = useMemo(() => mapToAriaListBoxProps({
43817
+ function LuiListBoxGroup({ group, state, headingRenderer, itemRenderer, }) {
43818
+ let { itemProps, headingProps, groupProps } = $af383d3bef1cfdc9$export$c3f9f39876e4bc7({
43819
+ heading: group.textValue,
43820
+ 'aria-label': group.textValue,
43821
+ });
43822
+ return (React__default.createElement("li", { className: "LuiListBoxGroup", ...itemProps },
43823
+ React__default.createElement("span", { className: "LuiListBoxGroup-heading", ...headingProps }, headingRenderer({ text: group.textValue })),
43824
+ React__default.createElement("ul", { className: "LuiListBoxGroup-items", ...groupProps }, (group.childNodes || []).map((node) => (React__default.createElement(LuiListBoxItem, { key: node.key, node: node, state: state, renderer: itemRenderer }))))));
43825
+ }
43826
+
43827
+ function LuiListBox({ ariaLabel, ariaLabelledBy, itemRenderer = DefaultItemRenderer, groupHeadingRenderer = DefaultGroupHeadingRenderer, loadingIndicator = DefaultLoadingIndicator, emptyIndicator = DefaultEmptyIndicator, selectionMode = 'single', selectionBehavior = 'toggle', disabled = false, items, value, onChange, getKey, getGroup, ariaProps, className, ...ulProps }) {
43828
+ const listProps = useLuiListBox({
43734
43829
  selectionMode,
43735
43830
  selectionBehavior,
43736
43831
  items,
43737
43832
  value,
43738
43833
  onChange,
43739
43834
  getKey,
43835
+ getGroup,
43740
43836
  ariaProps,
43741
43837
  disabled,
43742
- }), [
43743
- selectionMode,
43744
- selectionBehavior,
43745
- items,
43746
- value,
43747
- onChange,
43748
- getKey,
43749
- ariaProps,
43750
- ]);
43838
+ });
43751
43839
  const ariaListBoxProps = useMemo(() => ({
43752
43840
  'aria-label': ariaLabel,
43753
43841
  'aria-labelledby': ariaLabelledBy,
@@ -43759,7 +43847,16 @@ function LuiListBox({ ariaLabel, ariaLabelledBy, itemRenderer = DefaultItemRende
43759
43847
  return (React__default.createElement("ul", { ...ulProps, ...listBoxProps, ref: ref, className: clsx('LuiListBox', className) },
43760
43848
  !items && loadingIndicator(),
43761
43849
  items?.length === 0 && emptyIndicator(),
43762
- [...state.collection].map((node) => (React__default.createElement(LuiListBoxItem, { key: node.key, node: node, state: state, renderer: itemRenderer })))));
43850
+ [...state.collection].map((node) => node.type === 'section' ? (React__default.createElement(LuiListBoxGroup, { key: node.key, group: node.value, state: state, headingRenderer: groupHeadingRenderer, itemRenderer: itemRenderer })) : (React__default.createElement(LuiListBoxItem, { key: node.key, node: node.value, state: state, renderer: itemRenderer })))));
43851
+ }
43852
+ function DefaultItemRenderer({ item, }) {
43853
+ if (!item.hasOwnProperty('label')) {
43854
+ throw Error('Could not find `label` property on item, please provide a custom `itemRenderer`');
43855
+ }
43856
+ return React__default.createElement(React__default.Fragment, null, item.label);
43857
+ }
43858
+ function DefaultGroupHeadingRenderer({ text, }) {
43859
+ return text;
43763
43860
  }
43764
43861
  function DefaultLoadingIndicator() {
43765
43862
  return (React__default.createElement(React__default.Fragment, null,