@linzjs/lui 18.3.0 → 18.3.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.
- package/CHANGELOG.md +7 -0
- package/dist/components/LuiMultiSwitch/LuiMultiSwitch.d.ts +3 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +90 -0
- package/dist/index.js.map +1 -1
- package/dist/lui.css +58 -0
- package/dist/lui.css.map +1 -1
- package/dist/lui.esm.js +89 -1
- package/dist/lui.esm.js.map +1 -1
- package/dist/scss/Components/LuiMultiSwitch/LuiMultiSwitch.scss +59 -0
- package/dist/scss/base.scss +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [18.3.1](https://github.com/linz/lui/compare/v18.3.0...v18.3.1) (2023-07-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Fix scss location and exports ([#971](https://github.com/linz/lui/issues/971)) ([9f7773b](https://github.com/linz/lui/commit/9f7773b87e7846b3cdcd0bcd2c7adf0479d8a781))
|
|
7
|
+
|
|
1
8
|
# [18.3.0](https://github.com/linz/lui/compare/v18.2.0...v18.3.0) (2023-07-27)
|
|
2
9
|
|
|
3
10
|
# [18.2.0](https://github.com/linz/lui/compare/v18.1.0...v18.2.0) (2023-07-26)
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import './LuiMultiSwitch.scss';
|
|
2
1
|
import { ReactElement } from 'react';
|
|
3
|
-
export interface
|
|
2
|
+
export interface LuiMultiSwitchOption<ValueType> {
|
|
4
3
|
text: ReactElement | string;
|
|
5
4
|
value: ValueType;
|
|
6
5
|
shortcutKey?: string;
|
|
7
6
|
className?: string;
|
|
8
7
|
}
|
|
9
|
-
export declare const LuiMultiSwitchYesNo:
|
|
8
|
+
export declare const LuiMultiSwitchYesNo: LuiMultiSwitchOption<boolean>[];
|
|
10
9
|
export interface LuiMultiSwitchProps<ValueType> {
|
|
11
10
|
'data-testid'?: string;
|
|
12
11
|
className?: string;
|
|
@@ -14,7 +13,7 @@ export interface LuiMultiSwitchProps<ValueType> {
|
|
|
14
13
|
value?: ValueType | null;
|
|
15
14
|
disabled?: boolean;
|
|
16
15
|
autoFocus?: boolean;
|
|
17
|
-
options:
|
|
16
|
+
options: LuiMultiSwitchOption<ValueType>[];
|
|
18
17
|
onChange: (value: ValueType) => Promise<boolean> | any;
|
|
19
18
|
}
|
|
20
19
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ export { LuiSwitchButton } from './components/LuiSwitchButton/LuiSwitchButton';
|
|
|
58
58
|
export { LuiAccordicard } from './components/LuiAccordicard/LuiAccordicard';
|
|
59
59
|
export { LuiAccordicardStatic } from './components/LuiAccordicardStatic/LuiAccordicardStatic';
|
|
60
60
|
export { LuiAccordion } from './components/LuiAccordion/LuiAccordion';
|
|
61
|
+
export * from './components/LuiMultiSwitch/LuiMultiSwitch';
|
|
61
62
|
export { LuiListBox, ILuiListBoxItem, ILuiListBoxProps, IItemRendererProps, } from './components/LuiListBox/LuiListBox';
|
|
62
63
|
export { RadioItemRenderer } from './components/LuiListBox/Renderers/RadioItemRenderer';
|
|
63
64
|
export { CheckboxItemRenderer } from './components/LuiListBox/Renderers/CheckboxItemRenderer';
|
package/dist/index.js
CHANGED
|
@@ -67682,6 +67682,94 @@ var LuiAccordion = function (props) {
|
|
|
67682
67682
|
children));
|
|
67683
67683
|
};
|
|
67684
67684
|
|
|
67685
|
+
var LuiMultiSwitchYesNo = [
|
|
67686
|
+
{ text: 'Yes', value: true, shortcutKey: 'y' },
|
|
67687
|
+
{ text: 'No', value: false, shortcutKey: 'n' },
|
|
67688
|
+
];
|
|
67689
|
+
/**
|
|
67690
|
+
* Uncontrolled grouped button style component where component has single focus and associated keyboard events.
|
|
67691
|
+
*/
|
|
67692
|
+
var LuiMultiSwitch = function (_a) {
|
|
67693
|
+
var className = _a.className, defaultValue = _a.defaultValue, value = _a.value, onChange = _a.onChange, disabled = _a.disabled, autoFocus = _a.autoFocus, options = _a.options, props = __rest(_a, ["className", "defaultValue", "value", "onChange", "disabled", "autoFocus", "options"]);
|
|
67694
|
+
var id = React.useRef(v4());
|
|
67695
|
+
var inputRef = React.useRef(null);
|
|
67696
|
+
var updating = React.useRef(false);
|
|
67697
|
+
var _b = React.useState(function () {
|
|
67698
|
+
if (defaultValue === undefined && value === undefined) {
|
|
67699
|
+
console.error('LuiMultiSwitch is missing either a defaultValue(uncontrolled) or a value(controlled) parameter');
|
|
67700
|
+
}
|
|
67701
|
+
// eslint-disable-next-line eqeqeq
|
|
67702
|
+
return options === null || options === void 0 ? void 0 : options.findIndex(function (option) { return option.value == defaultValue; });
|
|
67703
|
+
}), selectedIndex = _b[0], setSelectedIndex = _b[1];
|
|
67704
|
+
var isUncontrolled = defaultValue !== undefined;
|
|
67705
|
+
React.useEffect(function () {
|
|
67706
|
+
// Controlled input
|
|
67707
|
+
if (!isUncontrolled) {
|
|
67708
|
+
// eslint-disable-next-line eqeqeq
|
|
67709
|
+
setSelectedIndex(options === null || options === void 0 ? void 0 : options.findIndex(function (option) { return option.value == value; }));
|
|
67710
|
+
}
|
|
67711
|
+
}, [value]);
|
|
67712
|
+
/**
|
|
67713
|
+
* Calls and awaits onChange callback, blocking further updates until callback has finished.
|
|
67714
|
+
* If callback returns false or there is an exception it reverts the change.
|
|
67715
|
+
*
|
|
67716
|
+
* @param newSelectedIndex option index to select.
|
|
67717
|
+
*/
|
|
67718
|
+
var select = function (newSelectedIndex) { return __awaiter(void 0, void 0, void 0, function () {
|
|
67719
|
+
var preSelectedIndex, result;
|
|
67720
|
+
var _a;
|
|
67721
|
+
return __generator(this, function (_b) {
|
|
67722
|
+
switch (_b.label) {
|
|
67723
|
+
case 0:
|
|
67724
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
67725
|
+
if (disabled || updating.current || newSelectedIndex === selectedIndex) {
|
|
67726
|
+
return [2 /*return*/];
|
|
67727
|
+
}
|
|
67728
|
+
if (isUncontrolled) {
|
|
67729
|
+
setSelectedIndex(newSelectedIndex);
|
|
67730
|
+
}
|
|
67731
|
+
updating.current = true;
|
|
67732
|
+
preSelectedIndex = selectedIndex;
|
|
67733
|
+
result = false;
|
|
67734
|
+
_b.label = 1;
|
|
67735
|
+
case 1:
|
|
67736
|
+
_b.trys.push([1, , 3, 4]);
|
|
67737
|
+
return [4 /*yield*/, onChange(options[newSelectedIndex].value)];
|
|
67738
|
+
case 2:
|
|
67739
|
+
result = _b.sent();
|
|
67740
|
+
return [3 /*break*/, 4];
|
|
67741
|
+
case 3:
|
|
67742
|
+
updating.current = false;
|
|
67743
|
+
return [7 /*endfinally*/];
|
|
67744
|
+
case 4:
|
|
67745
|
+
if (result === false && isUncontrolled) {
|
|
67746
|
+
setSelectedIndex(preSelectedIndex);
|
|
67747
|
+
}
|
|
67748
|
+
return [2 /*return*/];
|
|
67749
|
+
}
|
|
67750
|
+
});
|
|
67751
|
+
}); };
|
|
67752
|
+
var selectOffset = function (offset, wrap) {
|
|
67753
|
+
if (wrap === void 0) { wrap = false; }
|
|
67754
|
+
var newSelectedIndex = selectedIndex + offset;
|
|
67755
|
+
if (newSelectedIndex < 0)
|
|
67756
|
+
newSelectedIndex = wrap ? options.length - 1 : 0;
|
|
67757
|
+
if (newSelectedIndex >= options.length)
|
|
67758
|
+
newSelectedIndex = wrap ? 0 : options.length - 1;
|
|
67759
|
+
select(newSelectedIndex).then();
|
|
67760
|
+
};
|
|
67761
|
+
return (React__default["default"].createElement("div", { className: clsx('LuiMultiSwitch', className), role: 'radiogroup', "data-testid": props['data-testid'] },
|
|
67762
|
+
React__default["default"].createElement("input", { ref: inputRef, name: id.current, type: 'text', value: selectedIndex, autoFocus: autoFocus, onKeyUp: function (e) {
|
|
67763
|
+
e.key === 'ArrowLeft' && selectOffset(-1);
|
|
67764
|
+
e.key === 'ArrowRight' && selectOffset(1);
|
|
67765
|
+
e.key === ' ' && selectOffset(1, true);
|
|
67766
|
+
options.forEach(function (option, i) {
|
|
67767
|
+
return e.key && e.key === option.shortcutKey && select(i).then();
|
|
67768
|
+
});
|
|
67769
|
+
} }),
|
|
67770
|
+
React__default["default"].createElement("div", { className: clsx('LuiMultiSwitch-labels', disabled && 'LuiMultiSwitch-disabled') }, options === null || options === void 0 ? void 0 : options.map(function (option, i) { return (React__default["default"].createElement("label", { role: 'radio', key: i, htmlFor: id.current, "aria-disabled": disabled, "aria-checked": selectedIndex === i, className: option.className, onClick: function () { return select(i); }, onTouchStart: function () { return select(i); } }, option.text)); }))));
|
|
67771
|
+
};
|
|
67772
|
+
|
|
67685
67773
|
var css_248z$5 = "/**\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}";
|
|
67686
67774
|
styleInject(css_248z$5);
|
|
67687
67775
|
|
|
@@ -71400,6 +71488,8 @@ exports.LuiMessagingContextProvider = LuiMessagingContextProvider;
|
|
|
71400
71488
|
exports.LuiMiniSpinner = LuiMiniSpinner;
|
|
71401
71489
|
exports.LuiModal = LuiModal;
|
|
71402
71490
|
exports.LuiMoneyInput = LuiMoneyInput;
|
|
71491
|
+
exports.LuiMultiSwitch = LuiMultiSwitch;
|
|
71492
|
+
exports.LuiMultiSwitchYesNo = LuiMultiSwitchYesNo;
|
|
71403
71493
|
exports.LuiProgressBar = LuiProgressBar;
|
|
71404
71494
|
exports.LuiRadioInput = LuiRadioInput;
|
|
71405
71495
|
exports.LuiResizableLayout = LuiResizableLayout;
|