@linzjs/lui 24.2.0 → 24.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 CHANGED
@@ -5,6 +5,22 @@
5
5
 
6
6
  * **LuiComboSelect:** restore interface to support styling of the input element. ([#1270](https://github.com/linz/lui/issues/1270)) ([7ce6a13](https://github.com/linz/lui/commit/7ce6a137c7f16ffa3acbe4357569a6eb59ef47db))
7
7
 
8
+ ## [24.3.1](https://github.com/linz/Lui/compare/lui-v24.3.0...lui-v24.3.1) (2025-11-24)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **LuiModal:** add tabindex prop for modal controller ([45d8a36](https://github.com/linz/Lui/commit/45d8a36a4cc723559de1caaa89a9a38de7a10045))
14
+ * **LuiModal:** add tabindex prop for modal controller ([45d8a36](https://github.com/linz/Lui/commit/45d8a36a4cc723559de1caaa89a9a38de7a10045))
15
+ * **LuiModal:** SEARCH-7756 add tabindex prop for modal controller ([#1290](https://github.com/linz/Lui/issues/1290)) ([45d8a36](https://github.com/linz/Lui/commit/45d8a36a4cc723559de1caaa89a9a38de7a10045))
16
+
17
+ ## [24.3.0](https://github.com/linz/Lui/compare/lui-v24.2.0...lui-v24.3.0) (2025-11-20)
18
+
19
+
20
+ ### Features
21
+
22
+ * CS-8474 - filter characters in LuiInput ([#1272](https://github.com/linz/Lui/issues/1272)) ([2b58207](https://github.com/linz/Lui/commit/2b58207f2844eb769d9c274f55a5b1b8e2336dcf))
23
+
8
24
  ## [24.2.0](https://github.com/linz/Lui/compare/lui-v24.1.2...lui-v24.2.0) (2025-11-19)
9
25
 
10
26
 
package/README.md CHANGED
@@ -50,4 +50,4 @@ There are lots of things to do in this project, often things will be left until
50
50
 
51
51
  Storybook is the main source of documentation.
52
52
 
53
- - [Lui Storybook](https://linz.github.io/Lui/)
53
+ - [Lui Storybook](https://linz.github.io/Lui/)
@@ -3,7 +3,7 @@ import { Splitter } from '../Splitter/Splitter';
3
3
  import './Drawer.scss';
4
4
  import { UseDisableParentScroll } from './utils';
5
5
  type Position = 'top' | 'bottom' | 'left' | 'right';
6
- export type DrawerProps = PropsWithChildren<{
6
+ type BaseDrawerProps = {
7
7
  /** It's not recommended to make this prop dynamic during runtime as it might affect the opening animation. See the `Positions` story for more info. */
8
8
  position?: Position;
9
9
  /** Drawer open state is fully handled by the parent */
@@ -39,6 +39,7 @@ export type DrawerProps = PropsWithChildren<{
39
39
  mountChildrenOn?: 'mount' | 'first-open';
40
40
  /** Called when the drawer is resized either manually or programmatically. */
41
41
  onResized?: ComponentProps<typeof Splitter>['onResized'];
42
- }> & Omit<ComponentProps<typeof Splitter>, 'ratio' | 'orientation' | 'onResized' | 'startAt' | 'min' | 'max'>;
42
+ };
43
+ export type DrawerProps = PropsWithChildren<BaseDrawerProps> & Omit<ComponentProps<typeof Splitter>, 'ratio' | 'orientation' | 'onResized' | 'startAt' | 'min' | 'max'>;
43
44
  export declare const Drawer: React.ForwardRefExoticComponent<Omit<DrawerProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
44
45
  export {};
@@ -21,6 +21,8 @@ export type LuiModalV2Props = {
21
21
  preventAutoFocus?: boolean;
22
22
  /** By default, the modal portal will be appended to the document's body, but we might need to append it to another element. This is passed the React Modal `parentSelector` prop. */
23
23
  appendToElement?: () => HTMLElement;
24
+ /** Sets the tab index of the modal container */
25
+ tabIndex?: number | null;
24
26
  };
25
27
  /** Implements the [updated modal design system](https://www.figma.com/design/E7g3n5ziI7bR8MisISayia/FigLUI?node-id=9924-54717&t=q2r6Gct1cKGP9Q5B-0), keeping the same api as `LuiModal` as much as possible. */
26
28
  export declare const LuiModalV2: {
@@ -0,0 +1,11 @@
1
+ import React, { ChangeEvent, PropsWithChildren } from 'react';
2
+ export interface LuiFilterCharactersContext {
3
+ filterCharacters: (input: string | undefined) => string | undefined;
4
+ filterInputEvent: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
5
+ }
6
+ export declare const LuiFilterCharactersContext: React.Context<LuiFilterCharactersContext>;
7
+ export declare function useFilterCharacters(): LuiFilterCharactersContext;
8
+ export type LuiFilterCharactersProviderProps = {
9
+ filterFunction?: (input: string) => string;
10
+ };
11
+ export declare const LuiFilterCharactersProvider: ({ children, filterFunction, }: PropsWithChildren<LuiFilterCharactersProviderProps>) => React.JSX.Element;
@@ -0,0 +1,14 @@
1
+ export type LinzFreeTextFilterType = (value?: string | null) => string;
2
+ /**
3
+ * Default LINZ free text filter function.
4
+ * Silently converts some invalid characters with supported alternatives.
5
+ * Removes all other invalid characters.
6
+ */
7
+ export declare const LinzFreeTextFilter: LinzFreeTextFilterType;
8
+ /**
9
+ * LINZ free text filter function that leaves invalid characters intact.
10
+ * Silently converts some invalid characters with supported alternatives.
11
+ * Leaves all other invalid characters as is.
12
+ * Should be paired with LinzFreeTextValidator to warn users about invalid characters.
13
+ */
14
+ export declare const LinzFreeTextFilterConvertOnly: LinzFreeTextFilterType;
@@ -0,0 +1,2 @@
1
+ export declare const LinzInvalidCharMatcher: RegExp;
2
+ export declare const LinzFreeTextValidator: (value?: string | null, invalidCharMatcher?: RegExp, maxReportedChars?: number) => string | undefined;
package/dist/index.d.ts CHANGED
@@ -83,5 +83,10 @@ export { useToast } from './components/Toast';
83
83
  export { LuiMessagingContextProvider, useShowLUIMessage, LuiToastMessage, } from './components/Toast/Upgrade';
84
84
  export { LuiErrorPanel } from './components/LuiErrorPanel/LuiErrorPanel';
85
85
  export { DrawerGlobalProvider, useDrawerGlobalContext, DrawerGlobalContext, } from './components/Drawer/DrawerGlobalContext';
86
- export { Drawer, DrawerProps } from './components/Drawer/Drawer';
87
- export { DrawerGlobal, DrawerGlobalProps, } from './components/Drawer/DrawerGlobal';
86
+ export { Drawer } from './components/Drawer/Drawer';
87
+ export type { DrawerProps } from './components/Drawer/Drawer';
88
+ export { DrawerGlobal } from './components/Drawer/DrawerGlobal';
89
+ export type { DrawerGlobalProps } from './components/Drawer/DrawerGlobal';
90
+ export { LuiFilterCharactersProvider, useFilterCharacters, } from './contexts/LuiFilterCharactersProvider';
91
+ export { LinzFreeTextValidator } from './functions/LinzFreeTextValidator';
92
+ export { LinzFreeTextFilter, LinzFreeTextFilterConvertOnly, } from './functions/LinzFreeTextFilter';
package/dist/index.js CHANGED
@@ -7018,6 +7018,113 @@ var DateInput = React.forwardRef(function (props, ref) {
7018
7018
  } })));
7019
7019
  });
7020
7020
 
7021
+ // eslint-disable-next-line no-control-regex
7022
+ var LinzInvalidCharMatcher = /([^\u0000-\u017f])/gu;
7023
+ var LinzFreeTextValidator = function (value, invalidCharMatcher, maxReportedChars) {
7024
+ if (invalidCharMatcher === void 0) { invalidCharMatcher = LinzInvalidCharMatcher; }
7025
+ if (maxReportedChars === void 0) { maxReportedChars = 10; }
7026
+ if (!value) {
7027
+ return undefined;
7028
+ }
7029
+ var matchedItems = value.match(invalidCharMatcher);
7030
+ if (matchedItems === null) {
7031
+ return undefined;
7032
+ }
7033
+ var invalidCharacters = Array.from(new Set(matchedItems)).slice(0, maxReportedChars);
7034
+ return "Invalid character".concat(invalidCharacters.length === 1 ? '' : 's', " ").concat(invalidCharacters.join(', '));
7035
+ };
7036
+
7037
+ function CreateLinzFreeTextFilter(removeInvalidChars) {
7038
+ if (removeInvalidChars === void 0) { removeInvalidChars = true; }
7039
+ return function (value) {
7040
+ if (!value) {
7041
+ return '';
7042
+ }
7043
+ var strLength = value.length;
7044
+ if (!strLength) {
7045
+ return '';
7046
+ }
7047
+ return Array.prototype.flatMap
7048
+ .call(value, function (char) {
7049
+ // Supported character range
7050
+ if (char.match(LinzInvalidCharMatcher) === null) {
7051
+ return char;
7052
+ }
7053
+ var charCode = char.charCodeAt(0);
7054
+ // Silent conversion characters
7055
+ // why: https://toitutewhenua.atlassian.net/wiki/spaces/STEP/pages/124322198/Minimum+Text+Validation#Silent-conversion-characters
7056
+ switch (charCode) {
7057
+ case 0x2018:
7058
+ case 0x2019:
7059
+ return "'";
7060
+ case 0x201c:
7061
+ case 0x201d:
7062
+ return '"';
7063
+ case 0x2022:
7064
+ return '*';
7065
+ case 0x2013:
7066
+ case 0x2014:
7067
+ return '-';
7068
+ }
7069
+ return removeInvalidChars ? '' : char;
7070
+ })
7071
+ .join('');
7072
+ };
7073
+ }
7074
+ /**
7075
+ * Default LINZ free text filter function.
7076
+ * Silently converts some invalid characters with supported alternatives.
7077
+ * Removes all other invalid characters.
7078
+ */
7079
+ var LinzFreeTextFilter = CreateLinzFreeTextFilter(true);
7080
+ /**
7081
+ * LINZ free text filter function that leaves invalid characters intact.
7082
+ * Silently converts some invalid characters with supported alternatives.
7083
+ * Leaves all other invalid characters as is.
7084
+ * Should be paired with LinzFreeTextValidator to warn users about invalid characters.
7085
+ */
7086
+ var LinzFreeTextFilterConvertOnly = CreateLinzFreeTextFilter(false);
7087
+
7088
+ var LuiFilterCharactersContext = React.createContext({
7089
+ filterCharacters: function (input) {
7090
+ // Default implementation: return input as is.
7091
+ return input;
7092
+ },
7093
+ filterInputEvent: function () {
7094
+ // Default implementation: do nothing.
7095
+ return;
7096
+ }
7097
+ });
7098
+ function useFilterCharacters() {
7099
+ return React.useContext(LuiFilterCharactersContext);
7100
+ }
7101
+ var LuiFilterCharactersProvider = function (_a) {
7102
+ var children = _a.children, filterFunction = _a.filterFunction;
7103
+ var filterCharacters = React.useCallback(function (input) {
7104
+ if (input === undefined) {
7105
+ return input;
7106
+ }
7107
+ var filter = typeof filterFunction === 'function'
7108
+ ? filterFunction
7109
+ : LinzFreeTextFilter;
7110
+ return filter(input);
7111
+ }, [filterFunction]);
7112
+ var filterInputEvent = React.useCallback(function (event) {
7113
+ var value = event.target.value;
7114
+ var filteredValue = filterCharacters(value);
7115
+ if (filteredValue !== value) {
7116
+ var caretPosition = event.target.selectionStart;
7117
+ event.target.value = filteredValue;
7118
+ if (caretPosition !== null) {
7119
+ var positionOffset = value.length - filteredValue.length;
7120
+ var newCaretPosition = Math.max(caretPosition - positionOffset, 0);
7121
+ event.target.setSelectionRange(newCaretPosition, newCaretPosition);
7122
+ }
7123
+ }
7124
+ }, [filterFunction]);
7125
+ return (React__default["default"].createElement(LuiFilterCharactersContext.Provider, { value: { filterCharacters: filterCharacters, filterInputEvent: filterInputEvent } }, children));
7126
+ };
7127
+
7021
7128
  function useGenerateOrDefaultId(idFromProps) {
7022
7129
  var id = React.useState(idFromProps ? idFromProps : v4())[0];
7023
7130
  return id;
@@ -7026,6 +7133,7 @@ var BareInput = React.forwardRef(function (props, ref) { return React__default["
7026
7133
  var LuiTextInput = React.forwardRef(function (props, ref) {
7027
7134
  var _a, _b, _c;
7028
7135
  var id = useGenerateOrDefaultId((_a = props.inputProps) === null || _a === void 0 ? void 0 : _a.id);
7136
+ var filterInputEvent = useFilterCharacters().filterInputEvent;
7029
7137
  var LuiInput = ((_b = props.inputProps) === null || _b === void 0 ? void 0 : _b.type) === 'date' ? DateInput : BareInput;
7030
7138
  return (React__default["default"].createElement("div", { className: clsx$1('LuiTextInput', props.error && 'hasError', props.warning && 'hasWarning', props.className) },
7031
7139
  React__default["default"].createElement("label", { className: 'LuiTextInput-label', htmlFor: id },
@@ -7033,7 +7141,15 @@ var LuiTextInput = React.forwardRef(function (props, ref) {
7033
7141
  React__default["default"].createElement("span", { className: 'LuiTextInput-label-text ' +
7034
7142
  clsx$1(props.hideLabel ? 'LuiScreenReadersOnly' : '') }, props.label),
7035
7143
  React__default["default"].createElement("span", { className: "LuiTextInput-inputWrapper" },
7036
- React__default["default"].createElement(LuiInput, __assign({ ref: ref, className: clsx$1('LuiTextInput-input', props.showPadlockIcon ? 'LuiTextInput-padlock-icon ' : '', props.size ? "LuiTextInput-".concat(props.size) : ''), min: ((_c = props.inputProps) === null || _c === void 0 ? void 0 : _c.type) === 'date' ? undefined : '0', value: props.value, onChange: props.onChange }, props.inputProps, { id: id })),
7144
+ React__default["default"].createElement(LuiInput, __assign({ ref: ref, className: clsx$1('LuiTextInput-input', props.showPadlockIcon ? 'LuiTextInput-padlock-icon ' : '', props.size ? "LuiTextInput-".concat(props.size) : ''), min: ((_c = props.inputProps) === null || _c === void 0 ? void 0 : _c.type) === 'date' ? undefined : '0', value: props.value, onChange: function (event) {
7145
+ var _a;
7146
+ if (((_a = props.inputProps) === null || _a === void 0 ? void 0 : _a.type) !== 'date') {
7147
+ filterInputEvent(event);
7148
+ }
7149
+ if (props.onChange) {
7150
+ props.onChange(event);
7151
+ }
7152
+ } }, props.inputProps, { id: id })),
7037
7153
  props.icon),
7038
7154
  props.error && (React__default["default"].createElement("span", { className: "LuiTextInput-error" },
7039
7155
  React__default["default"].createElement(LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextInput-error-icon", size: "sm", status: "error" }),
@@ -7178,13 +7294,22 @@ var LuiSelectInput = function (props) {
7178
7294
  var LuiTextAreaInput = React__default["default"].forwardRef(function (props, ref) {
7179
7295
  var _a, _b;
7180
7296
  var id = useGenerateOrDefaultId((_a = props.inputProps) === null || _a === void 0 ? void 0 : _a.id);
7297
+ var filterInputEvent = useFilterCharacters().filterInputEvent;
7181
7298
  var rows = props.rows !== undefined ? props.rows : 5;
7182
7299
  return (React__default["default"].createElement("div", { className: clsx$1('LuiTextAreaInput', ((_b = props.inputProps) === null || _b === void 0 ? void 0 : _b.disabled) ? 'isDisabled' : '', props.error ? 'hasError' : '', props.warning ? 'hasWarning' : '') },
7183
7300
  React__default["default"].createElement("label", { htmlFor: id },
7184
7301
  props.mandatory && (React__default["default"].createElement("span", { className: "LuiTextAreaInput-mandatory" }, "*")),
7185
7302
  React__default["default"].createElement("span", { className: "LuiTextAreaInput-label" }, props.label),
7186
7303
  React__default["default"].createElement("div", { className: "LuiTextAreaInput-wrapper" },
7187
- React__default["default"].createElement("textarea", __assign({ id: id, value: props.value, onChange: props.onChange, ref: ref, rows: rows }, props.inputProps)))),
7304
+ React__default["default"].createElement("textarea", __assign({ id: id, value: props.value, onChange: function (event) {
7305
+ var _a;
7306
+ if (((_a = props.inputProps) === null || _a === void 0 ? void 0 : _a.type) !== 'date') {
7307
+ filterInputEvent(event);
7308
+ }
7309
+ if (props.onChange) {
7310
+ props.onChange(event);
7311
+ }
7312
+ }, ref: ref, rows: rows }, props.inputProps)))),
7188
7313
  props.error && (React__default["default"].createElement("span", { className: "LuiTextAreaInput-error" },
7189
7314
  React__default["default"].createElement(LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextAreaInput-error-icon", size: "sm", status: "error" }),
7190
7315
  props.error)),
@@ -18266,7 +18391,23 @@ var LuiModalV2 = function (props) {
18266
18391
  showButtons && (React__default["default"].createElement("div", { className: "lui-modal-v2-header-buttons" },
18267
18392
  showHelpButton && React__default["default"].createElement(HelpButton, { helpLink: props.helpLink }),
18268
18393
  showCloseButton && React__default["default"].createElement(CloseButton, { onClose: props.onClose })))),
18269
- React__default["default"].createElement("div", { className: "lui-modal-v2-contents" }, props.children))));
18394
+ React__default["default"].createElement(ModalContents, { children: props.children, tabIndex: props.tabIndex }))));
18395
+ };
18396
+ var ModalContents = function (props) {
18397
+ React.useEffect(function () {
18398
+ var modalContent = document.querySelector('.ReactModal__Content');
18399
+ if (props.tabIndex === undefined || !modalContent)
18400
+ return;
18401
+ switch (props.tabIndex) {
18402
+ case null:
18403
+ modalContent === null || modalContent === void 0 ? void 0 : modalContent.removeAttribute('tabindex');
18404
+ break;
18405
+ default:
18406
+ modalContent === null || modalContent === void 0 ? void 0 : modalContent.setAttribute('tabindex', props.tabIndex.toString());
18407
+ break;
18408
+ }
18409
+ }, []);
18410
+ return React__default["default"].createElement("div", { className: "lui-modal-v2-contents" }, props.children);
18270
18411
  };
18271
18412
  var ButtonRow = function (props) { return (React__default["default"].createElement("div", { className: clsx$1('lui-modal-v2-btn-row', props.className) }, props.children)); };
18272
18413
  LuiModalV2.Buttons = ButtonRow;
@@ -41344,6 +41485,9 @@ exports.Drawer = Drawer;
41344
41485
  exports.DrawerGlobal = DrawerGlobal;
41345
41486
  exports.DrawerGlobalContext = DrawerGlobalContext;
41346
41487
  exports.DrawerGlobalProvider = DrawerGlobalProvider;
41488
+ exports.LinzFreeTextFilter = LinzFreeTextFilter;
41489
+ exports.LinzFreeTextFilterConvertOnly = LinzFreeTextFilterConvertOnly;
41490
+ exports.LinzFreeTextValidator = LinzFreeTextValidator;
41347
41491
  exports.LuiAccordicard = LuiAccordicard;
41348
41492
  exports.LuiAccordicardStatic = LuiAccordicardStatic;
41349
41493
  exports.LuiAccordion = LuiAccordion;
@@ -41386,6 +41530,7 @@ exports.LuiErrorPage = LuiErrorPage;
41386
41530
  exports.LuiErrorPanel = LuiErrorPanel;
41387
41531
  exports.LuiExpandableBanner = LuiExpandableBanner;
41388
41532
  exports.LuiFileInputBox = LuiFileInputBox;
41533
+ exports.LuiFilterCharactersProvider = LuiFilterCharactersProvider;
41389
41534
  exports.LuiFilterContainer = LuiFilterContainer;
41390
41535
  exports.LuiFilterMenu = LuiFilterMenu;
41391
41536
  exports.LuiFooter = LuiFooter;
@@ -41456,6 +41601,7 @@ exports.isChromatic = isChromatic;
41456
41601
  exports.useClickedOutsideElement = useClickedOutsideElement;
41457
41602
  exports.useDrawerGlobalContext = useDrawerGlobalContext;
41458
41603
  exports.useEscapeFunction = useEscapeFunction;
41604
+ exports.useFilterCharacters = useFilterCharacters;
41459
41605
  exports.useLuiCloseableHeaderMenuContextV2 = useLuiCloseableHeaderMenuContextV2;
41460
41606
  exports.useMediaQuery = useMediaQuery;
41461
41607
  exports.usePageClickFunction = usePageClickFunction;