@linzjs/lui 17.13.3 → 17.14.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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [17.14.0](https://github.com/linz/lui/compare/v17.13.3...v17.14.0) (2022-09-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **LuiListBox:** Adding aria-label support to listbox items ([#756](https://github.com/linz/lui/issues/756)) ([4702258](https://github.com/linz/lui/commit/4702258110d1642b5b6db010cf355b8f44114bb1))
|
|
7
|
+
|
|
1
8
|
## [17.13.3](https://github.com/linz/lui/compare/v17.13.2...v17.13.3) (2022-09-13)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -4,6 +4,7 @@ import { SelectionBehavior, SelectionMode } from '@react-types/shared';
|
|
|
4
4
|
import { AriaListBoxOptions } from '@react-aria/listbox';
|
|
5
5
|
export declare type KeyGetter<T> = (item: T) => Key;
|
|
6
6
|
export declare type GroupGetter<T> = (item: T) => string | null;
|
|
7
|
+
export declare type LabelGetter<T> = (item: T) => string;
|
|
7
8
|
export interface ILuiListItemNode<T> {
|
|
8
9
|
key: Key;
|
|
9
10
|
textValue: string;
|
|
@@ -38,7 +39,8 @@ export interface ILuiListBoxProps<T = ILuiListBoxItem> extends Omit<HTMLAttribut
|
|
|
38
39
|
groupHeadingRenderer?: (props: IGroupHeadingRendererProps) => ReactNode;
|
|
39
40
|
getKey?: KeyGetter<T>;
|
|
40
41
|
getGroup?: GroupGetter<T>;
|
|
42
|
+
getLabel?: LabelGetter<T>;
|
|
41
43
|
loadingIndicator?: () => ReactNode;
|
|
42
44
|
emptyIndicator?: () => ReactNode;
|
|
43
45
|
}
|
|
44
|
-
export declare function LuiListBox<T extends object = ILuiListBoxItem>({ ariaLabel, ariaLabelledBy, itemRenderer, groupHeadingRenderer, loadingIndicator, emptyIndicator, selectionMode, selectionBehavior, disabled, items, value, onChange, getKey, getGroup, ariaProps, className, ...ulProps }: ILuiListBoxProps<T>): JSX.Element;
|
|
46
|
+
export declare function LuiListBox<T extends object = ILuiListBoxItem>({ ariaLabel, ariaLabelledBy, itemRenderer, groupHeadingRenderer, loadingIndicator, emptyIndicator, selectionMode, selectionBehavior, disabled, items, value, onChange, getKey, getGroup, getLabel, ariaProps, className, ...ulProps }: ILuiListBoxProps<T>): JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ListProps } from '@react-stately/list';
|
|
2
2
|
import { ILuiListBoxProps, ILuiListItemNode } from './LuiListBox';
|
|
3
|
-
export declare function useLuiListBox<T extends object>({ selectionMode, selectionBehavior, items, value, onChange, ariaProps, getGroup, getKey, }: ILuiListBoxProps<T>): ListProps<ILuiListItemNode<T>>;
|
|
3
|
+
export declare function useLuiListBox<T extends object>({ selectionMode, selectionBehavior, items, value, onChange, ariaProps, getGroup, getKey, getLabel, }: ILuiListBoxProps<T>): ListProps<ILuiListItemNode<T>>;
|
package/dist/index.js
CHANGED
|
@@ -40826,7 +40826,7 @@ function $453cc9f0df89c0a5$export$77d5aafae4e095b2(collection) {
|
|
|
40826
40826
|
}
|
|
40827
40827
|
|
|
40828
40828
|
function useLuiListBox(_a) {
|
|
40829
|
-
var selectionMode = _a.selectionMode, selectionBehavior = _a.selectionBehavior, _b = _a.items, items = _b === void 0 ? [] : _b, value = _a.value, onChange = _a.onChange, ariaProps = _a.ariaProps, _c = _a.getGroup, getGroup = _c === void 0 ? defaultGroupGetter : _c, _d = _a.getKey, getKey = _d === void 0 ? defaultKeyGetter : _d;
|
|
40829
|
+
var selectionMode = _a.selectionMode, selectionBehavior = _a.selectionBehavior, _b = _a.items, items = _b === void 0 ? [] : _b, value = _a.value, onChange = _a.onChange, ariaProps = _a.ariaProps, _c = _a.getGroup, getGroup = _c === void 0 ? defaultGroupGetter : _c, _d = _a.getKey, getKey = _d === void 0 ? defaultKeyGetter : _d, _e = _a.getLabel, getLabel = _e === void 0 ? defaultLabelGetter : _e;
|
|
40830
40830
|
var children = React.useCallback(function (item) {
|
|
40831
40831
|
return item.childNodes ? (React__default["default"].createElement($9fc4852771d079eb$export$6e2c8f0811a474ce, { key: item.key, items: item.childNodes, title: item.textValue }, function (item) { return React__default["default"].createElement($c1d7fb2ec91bae71$export$6d08773d2e66f8f2, null, String(item.key)); })) : (React__default["default"].createElement($c1d7fb2ec91bae71$export$6d08773d2e66f8f2, null, String(item.key)));
|
|
40832
40832
|
}, []);
|
|
@@ -40836,26 +40836,20 @@ function useLuiListBox(_a) {
|
|
|
40836
40836
|
}
|
|
40837
40837
|
onChange(keys === 'all' ? items.map(function (item) { return getKey(item); }) : Array.from(keys), keys === 'all' ? items : items.filter(function (item) { return keys.has(getKey(item)); }));
|
|
40838
40838
|
}, [items, onChange, getKey]);
|
|
40839
|
-
var nodes = React.useMemo(function () { return mapItemsToNodes(items, getKey, getGroup); }, [
|
|
40840
|
-
items,
|
|
40841
|
-
getKey,
|
|
40842
|
-
getGroup,
|
|
40843
|
-
]);
|
|
40839
|
+
var nodes = React.useMemo(function () { return mapItemsToNodes(items, getKey, getGroup, getLabel); }, [items, getKey, getGroup, getLabel]);
|
|
40844
40840
|
return __assign(__assign({}, ariaProps), { items: nodes, selectionMode: selectionMode, selectionBehavior: selectionBehavior, selectedKeys: (Array.isArray(value) ? value : [value]).filter(Boolean), children: children, onSelectionChange: onSelectionChange });
|
|
40845
40841
|
}
|
|
40846
|
-
function mapItemsToNodes(items, getKey, getGroup) {
|
|
40842
|
+
function mapItemsToNodes(items, getKey, getGroup, getLabel) {
|
|
40847
40843
|
var rootNodes = new Map();
|
|
40848
40844
|
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
40849
40845
|
var item = items_1[_i];
|
|
40850
40846
|
var groupName = getGroup(item);
|
|
40851
40847
|
var key = getKey(item);
|
|
40848
|
+
var textValue = getLabel(item);
|
|
40849
|
+
var node = { key: key, textValue: textValue, value: item };
|
|
40852
40850
|
// Is an item without a group
|
|
40853
40851
|
if (!groupName) {
|
|
40854
|
-
rootNodes.set(key,
|
|
40855
|
-
key: key,
|
|
40856
|
-
textValue: String(key),
|
|
40857
|
-
value: item
|
|
40858
|
-
});
|
|
40852
|
+
rootNodes.set(key, node);
|
|
40859
40853
|
}
|
|
40860
40854
|
// is an item with a group that has not been encountered yet.
|
|
40861
40855
|
if (groupName && !rootNodes.get(groupName)) {
|
|
@@ -40866,11 +40860,7 @@ function mapItemsToNodes(items, getKey, getGroup) {
|
|
|
40866
40860
|
});
|
|
40867
40861
|
}
|
|
40868
40862
|
if (groupName) {
|
|
40869
|
-
rootNodes.get(groupName).childNodes.push(
|
|
40870
|
-
key: key,
|
|
40871
|
-
textValue: String(key),
|
|
40872
|
-
value: item
|
|
40873
|
-
});
|
|
40863
|
+
rootNodes.get(groupName).childNodes.push(node);
|
|
40874
40864
|
}
|
|
40875
40865
|
}
|
|
40876
40866
|
return Array.from(rootNodes.values());
|
|
@@ -40883,6 +40873,12 @@ function defaultKeyGetter(item) {
|
|
|
40883
40873
|
}
|
|
40884
40874
|
function defaultGroupGetter(item) {
|
|
40885
40875
|
return item.group || null;
|
|
40876
|
+
}
|
|
40877
|
+
function defaultLabelGetter(item) {
|
|
40878
|
+
if (!item.hasOwnProperty('key')) {
|
|
40879
|
+
throw Error('Could not find `label` property on item, please provide a custom `getLabel` function');
|
|
40880
|
+
}
|
|
40881
|
+
return item.label;
|
|
40886
40882
|
}
|
|
40887
40883
|
|
|
40888
40884
|
function $458b0a5536c1a7cf$export$40bfa8c7b0832715(value1, defaultValue, onChange) {
|
|
@@ -43501,7 +43497,7 @@ function $af383d3bef1cfdc9$export$c3f9f39876e4bc7(props) {
|
|
|
43501
43497
|
function LuiListBoxItem(_a) {
|
|
43502
43498
|
var node = _a.node, state = _a.state, renderer = _a.renderer;
|
|
43503
43499
|
var ref = React.useRef(null);
|
|
43504
|
-
var _b = $293f70390ea03370$export$497855f14858aa34({ key: node.key }, state, ref), optionProps = _b.optionProps, isSelected = _b.isSelected, isDisabled = _b.isDisabled;
|
|
43500
|
+
var _b = $293f70390ea03370$export$497855f14858aa34({ key: node.key, 'aria-label': node.textValue }, state, ref), optionProps = _b.optionProps, isSelected = _b.isSelected, isDisabled = _b.isDisabled;
|
|
43505
43501
|
var _c = $f7dceffc5ad7768b$export$4e328f61c538687f(), isFocusVisible = _c.isFocusVisible, focusProps = _c.focusProps;
|
|
43506
43502
|
return (React__default["default"].createElement("li", __assign({ ref: ref }, $3ef42575df84b30b$export$9d1611c77c2fe928(optionProps, focusProps), { className: clsx('LuiListBoxItem', isSelected && 'LuiListBoxItem-selected', isDisabled && 'LuiListBoxItem-disabled') }), renderer({
|
|
43507
43503
|
item: node.value,
|
|
@@ -43992,7 +43988,7 @@ function LuiListBoxGroup(_a) {
|
|
|
43992
43988
|
}
|
|
43993
43989
|
|
|
43994
43990
|
function LuiListBox(_a) {
|
|
43995
|
-
var ariaLabel = _a.ariaLabel, ariaLabelledBy = _a.ariaLabelledBy, _b = _a.itemRenderer, itemRenderer = _b === void 0 ? DefaultItemRenderer : _b, _c = _a.groupHeadingRenderer, groupHeadingRenderer = _c === void 0 ? DefaultGroupHeadingRenderer : _c, _d = _a.loadingIndicator, loadingIndicator = _d === void 0 ? DefaultLoadingIndicator : _d, _e = _a.emptyIndicator, emptyIndicator = _e === void 0 ? DefaultEmptyIndicator : _e, _f = _a.selectionMode, selectionMode = _f === void 0 ? 'single' : _f, _g = _a.selectionBehavior, selectionBehavior = _g === void 0 ? 'toggle' : _g, _h = _a.disabled, disabled = _h === void 0 ? false : _h, items = _a.items, value = _a.value, onChange = _a.onChange, getKey = _a.getKey, getGroup = _a.getGroup, ariaProps = _a.ariaProps, className = _a.className, ulProps = __rest(_a, ["ariaLabel", "ariaLabelledBy", "itemRenderer", "groupHeadingRenderer", "loadingIndicator", "emptyIndicator", "selectionMode", "selectionBehavior", "disabled", "items", "value", "onChange", "getKey", "getGroup", "ariaProps", "className"]);
|
|
43991
|
+
var ariaLabel = _a.ariaLabel, ariaLabelledBy = _a.ariaLabelledBy, _b = _a.itemRenderer, itemRenderer = _b === void 0 ? DefaultItemRenderer : _b, _c = _a.groupHeadingRenderer, groupHeadingRenderer = _c === void 0 ? DefaultGroupHeadingRenderer : _c, _d = _a.loadingIndicator, loadingIndicator = _d === void 0 ? DefaultLoadingIndicator : _d, _e = _a.emptyIndicator, emptyIndicator = _e === void 0 ? DefaultEmptyIndicator : _e, _f = _a.selectionMode, selectionMode = _f === void 0 ? 'single' : _f, _g = _a.selectionBehavior, selectionBehavior = _g === void 0 ? 'toggle' : _g, _h = _a.disabled, disabled = _h === void 0 ? false : _h, items = _a.items, value = _a.value, onChange = _a.onChange, getKey = _a.getKey, getGroup = _a.getGroup, getLabel = _a.getLabel, ariaProps = _a.ariaProps, className = _a.className, ulProps = __rest(_a, ["ariaLabel", "ariaLabelledBy", "itemRenderer", "groupHeadingRenderer", "loadingIndicator", "emptyIndicator", "selectionMode", "selectionBehavior", "disabled", "items", "value", "onChange", "getKey", "getGroup", "getLabel", "ariaProps", "className"]);
|
|
43996
43992
|
var listProps = useLuiListBox({
|
|
43997
43993
|
selectionMode: selectionMode,
|
|
43998
43994
|
selectionBehavior: selectionBehavior,
|
|
@@ -44001,6 +43997,7 @@ function LuiListBox(_a) {
|
|
|
44001
43997
|
onChange: onChange,
|
|
44002
43998
|
getKey: getKey,
|
|
44003
43999
|
getGroup: getGroup,
|
|
44000
|
+
getLabel: getLabel,
|
|
44004
44001
|
ariaProps: ariaProps,
|
|
44005
44002
|
disabled: disabled
|
|
44006
44003
|
});
|
|
@@ -44052,7 +44049,7 @@ styleInject(css_248z);
|
|
|
44052
44049
|
|
|
44053
44050
|
function CheckboxItemRenderer(_a) {
|
|
44054
44051
|
var item = _a.item, isSelected = _a.isSelected;
|
|
44055
|
-
return (React__default["default"].createElement("div", { className: "CheckboxRenderer ".concat(isSelected ? 'LuiCheckboxInput--isChecked' : '')
|
|
44052
|
+
return (React__default["default"].createElement("div", { className: "CheckboxRenderer ".concat(isSelected ? 'LuiCheckboxInput--isChecked' : '') },
|
|
44056
44053
|
React__default["default"].createElement(LuiIcon, { size: "md", name: isSelected ? 'ic_check' : 'ic_zoom_out', alt: isSelected ? 'Checked' : 'Indeterminate Check', className: "LuiCheckboxInput-labelCheck ".concat(isSelected ? 'LuiCheckboxInput--isChecked' : '') }),
|
|
44057
44054
|
item.label));
|
|
44058
44055
|
}
|