@luscii-healthtech/web-ui 2.7.1 → 2.8.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.
@@ -0,0 +1,32 @@
1
+ /// <reference types="react" />
2
+ export interface Item {
3
+ id: string;
4
+ label: string;
5
+ isChecked: boolean;
6
+ group?: string;
7
+ isPinned?: boolean;
8
+ }
9
+ export interface Group {
10
+ title?: string;
11
+ items: Item[];
12
+ }
13
+ interface CheckboxListModalTexts {
14
+ title: string;
15
+ confirmLabel: string;
16
+ cancelLabel: string;
17
+ searchPlaceHolder?: string;
18
+ emptyState: string;
19
+ }
20
+ export interface CheckboxListModalProps {
21
+ texts: CheckboxListModalTexts;
22
+ initialItems: Array<Item>;
23
+ isLoadingInitialItems?: boolean;
24
+ isOpen: boolean;
25
+ onSave: (newItems: Item[]) => void;
26
+ onCloseClick: () => void;
27
+ filterItem: (item: Item, searchQuery: string) => boolean;
28
+ className?: string;
29
+ hasSearch: boolean;
30
+ }
31
+ export declare const CheckboxListModal: ({ texts, initialItems, isLoadingInitialItems, isOpen, onSave, onCloseClick, filterItem, className, hasSearch, }: CheckboxListModalProps) => JSX.Element;
32
+ export {};
package/dist/index.d.ts CHANGED
@@ -24,6 +24,7 @@ export { LoadingIndicator, LoadingIndicatorProps, } from "./components/LoadingIn
24
24
  export { default as Menu } from "./components/Menu/Menu";
25
25
  export { List, ListProps, ListItemProps, OnAssetLoadErrorPayload, } from "./components/List/List";
26
26
  export { CheckboxList, CheckboxListProps, } from "./components/CheckboxList/CheckboxList";
27
+ export { CheckboxListModal, CheckboxListModalProps, } from "./components/CheckBoxListModal/CheckboxListModal";
27
28
  export { MultiSelect } from "./components/MultiSelect/MultiSelect";
28
29
  export { NavLayout, NavMenuLayoutProps } from "./components/NavMenu/NavLayout";
29
30
  export { NavMenu, NavMenuElement } from "./components/NavMenu/NavMenu";
@@ -1613,6 +1613,10 @@ video {
1613
1613
  padding-left: 0.25rem;
1614
1614
  }
1615
1615
 
1616
+ .pr-4 {
1617
+ padding-right: 1rem;
1618
+ }
1619
+
1616
1620
  .pl-4 {
1617
1621
  padding-left: 1rem;
1618
1622
  }
@@ -2065,6 +2069,10 @@ video {
2065
2069
  width: 26rem;
2066
2070
  }
2067
2071
 
2072
+ .w-130 {
2073
+ width: 32.5rem;
2074
+ }
2075
+
2068
2076
  .w-auto {
2069
2077
  width: auto;
2070
2078
  }
@@ -18,6 +18,7 @@ var ClipboardJS = _interopDefault(require('clipboard'));
18
18
  var ReactSelect = require('react-select');
19
19
  var ReactSelect__default = _interopDefault(ReactSelect);
20
20
  var dragula = _interopDefault(require('react-dragula'));
21
+ var groupBy = _interopDefault(require('lodash/groupBy'));
21
22
  var debounce = _interopDefault(require('lodash.debounce'));
22
23
  var ReactQuill = _interopDefault(require('react-quill'));
23
24
  require('react-quill/dist/quill.snow.css');
@@ -3280,7 +3281,7 @@ var CheckboxGroup = function CheckboxGroup(_ref) {
3280
3281
  type: "strong",
3281
3282
  text: groupTitle || "",
3282
3283
  className: " ml-4"
3283
- }), " ", ":"), /*#__PURE__*/React__default.createElement(Checkbox, {
3284
+ }), " "), /*#__PURE__*/React__default.createElement(Checkbox, {
3284
3285
  onChange: handleGroupClick,
3285
3286
  className: "ml-auto",
3286
3287
  isChecked: groupCheckboxState === CheckboxState.CHECKED,
@@ -3327,6 +3328,170 @@ var CheckboxList = function CheckboxList(_ref) {
3327
3328
  }));
3328
3329
  };
3329
3330
 
3331
+ var SearchIcon = function SearchIcon(props) {
3332
+ return /*#__PURE__*/React__default.createElement("svg", {
3333
+ className: props.className,
3334
+ onClick: props.onClick,
3335
+ role: props.onClick ? "button" : undefined,
3336
+ width: "24",
3337
+ height: "24",
3338
+ viewBox: "0 0 24 24",
3339
+ fill: "none",
3340
+ xmlns: "http://www.w3.org/2000/svg"
3341
+ }, /*#__PURE__*/React__default.createElement("path", {
3342
+ d: "M15.5 13.9996H14.71L14.43 13.7296C15.63 12.3296 16.25 10.4196 15.91 8.38965C15.44 5.60965 13.12 3.38965 10.32 3.04965C6.09001 2.52965 2.53002 6.08965 3.05002 10.3196C3.39002 13.1196 5.61002 15.4396 8.39002 15.9096C10.42 16.2496 12.33 15.6296 13.73 14.4296L14 14.7096V15.4996L18.25 19.7496C18.66 20.1596 19.33 20.1596 19.74 19.7496C20.15 19.3396 20.15 18.6696 19.74 18.2596L15.5 13.9996ZM9.50002 13.9996C7.01002 13.9996 5.00002 11.9896 5.00002 9.49965C5.00002 7.00965 7.01002 4.99965 9.50002 4.99965C11.99 4.99965 14 7.00965 14 9.49965C14 11.9896 11.99 13.9996 9.50002 13.9996Z",
3343
+ fill: "currentColor"
3344
+ }));
3345
+ };
3346
+
3347
+ var SearchInput = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
3348
+ return /*#__PURE__*/React__default.createElement(Input, Object.assign({}, props, {
3349
+ icon: SearchIcon,
3350
+ type: "text",
3351
+ clearable: true,
3352
+ ref: ref
3353
+ }));
3354
+ });
3355
+
3356
+ var transformToGroups = function transformToGroups(items) {
3357
+ var pinned = items.find(function (option) {
3358
+ return option.isPinned;
3359
+ });
3360
+ var itemsWithGroup = items.filter(function (option) {
3361
+ return option.group;
3362
+ });
3363
+ var groups = Object.entries(groupBy(itemsWithGroup, "group")).map(function (group) {
3364
+ return {
3365
+ title: group[0],
3366
+ items: group[1].sort(function (a, b) {
3367
+ return a.label > b.label ? 1 : b.label > a.label ? -1 : 0;
3368
+ })
3369
+ };
3370
+ });
3371
+ var itemsWithoutGroup = items.filter(function (option) {
3372
+ return !option.group;
3373
+ });
3374
+ var restGroup = {
3375
+ name: undefined,
3376
+ items: itemsWithoutGroup
3377
+ };
3378
+
3379
+ if (pinned) {
3380
+ var myGroup = {
3381
+ items: [pinned]
3382
+ };
3383
+ return [myGroup].concat(groups, [restGroup]);
3384
+ }
3385
+
3386
+ return [].concat(groups, [restGroup]);
3387
+ };
3388
+
3389
+ var CheckboxListModal = function CheckboxListModal(_ref) {
3390
+ var texts = _ref.texts,
3391
+ initialItems = _ref.initialItems,
3392
+ isLoadingInitialItems = _ref.isLoadingInitialItems,
3393
+ isOpen = _ref.isOpen,
3394
+ onSave = _ref.onSave,
3395
+ onCloseClick = _ref.onCloseClick,
3396
+ _ref$filterItem = _ref.filterItem,
3397
+ filterItem = _ref$filterItem === void 0 ? function () {
3398
+ return true;
3399
+ } : _ref$filterItem,
3400
+ className = _ref.className,
3401
+ _ref$hasSearch = _ref.hasSearch,
3402
+ hasSearch = _ref$hasSearch === void 0 ? false : _ref$hasSearch;
3403
+ var containerClassName = classNames(className);
3404
+
3405
+ var _useState = React.useState([]),
3406
+ items = _useState[0],
3407
+ setItems = _useState[1];
3408
+
3409
+ var _useState2 = React.useState([]),
3410
+ visibleItems = _useState2[0],
3411
+ setVisibleItems = _useState2[1];
3412
+
3413
+ var _useState3 = React.useState([]),
3414
+ groups = _useState3[0],
3415
+ setGroups = _useState3[1];
3416
+
3417
+ var _useState4 = React.useState(""),
3418
+ search = _useState4[0],
3419
+ setSearch = _useState4[1];
3420
+
3421
+ React.useEffect(function () {
3422
+ setItems(initialItems);
3423
+ }, [initialItems]);
3424
+ React.useEffect(function () {
3425
+ setVisibleItems(items.filter(function (item) {
3426
+ return filterItem(item, search);
3427
+ }));
3428
+ }, [items, search]);
3429
+ React.useEffect(function () {
3430
+ setGroups(transformToGroups(visibleItems));
3431
+ }, [visibleItems]);
3432
+
3433
+ var handleOnItemChange = function handleOnItemChange(event) {
3434
+ var updatedItems = [].concat(items);
3435
+ var index = updatedItems.findIndex(function (item) {
3436
+ return item.id === event.id;
3437
+ });
3438
+ updatedItems[index].isChecked = event.newCheckedValue;
3439
+ setItems(updatedItems);
3440
+ };
3441
+
3442
+ var handleOnCloseClick = function handleOnCloseClick(event) {
3443
+ event.stopPropagation();
3444
+ onCloseClick();
3445
+ };
3446
+
3447
+ var handleOnSaveClick = function handleOnSaveClick() {
3448
+ onSave(items.filter(function (item) {
3449
+ return item.isChecked;
3450
+ }));
3451
+ onCloseClick();
3452
+ };
3453
+
3454
+ var handleOnSearchChange = function handleOnSearchChange(event) {
3455
+ var _event$currentTarget$;
3456
+
3457
+ setSearch((_event$currentTarget$ = event.currentTarget.value) != null ? _event$currentTarget$ : "");
3458
+ };
3459
+
3460
+ var closeButton = /*#__PURE__*/React.createElement(SecondaryButton, {
3461
+ text: texts.cancelLabel,
3462
+ onClick: handleOnCloseClick,
3463
+ key: "close-checkbox-list-modal",
3464
+ className: "mr-2"
3465
+ });
3466
+ var saveButton = /*#__PURE__*/React.createElement(PrimaryButton, {
3467
+ text: texts.confirmLabel,
3468
+ onClick: handleOnSaveClick,
3469
+ key: "save-selected-checkbox-list-items"
3470
+ });
3471
+ return /*#__PURE__*/React.createElement(ModalWithButtons, {
3472
+ isOpen: isOpen,
3473
+ title: texts.title,
3474
+ onCloseClick: handleOnCloseClick,
3475
+ withPadding: true,
3476
+ shouldCloseOnOverlayClick: true,
3477
+ className: containerClassName,
3478
+ buttons: [closeButton, saveButton],
3479
+ buttonsAlignment: "justify-end"
3480
+ }, /*#__PURE__*/React.createElement("div", {
3481
+ className: "max-h-135 overflow-y-auto pr-4"
3482
+ }, isLoadingInitialItems && /*#__PURE__*/React.createElement(LoadingIndicator, null), hasSearch && !isLoadingInitialItems && /*#__PURE__*/React.createElement(SearchInput, {
3483
+ className: "w-130 mb-2",
3484
+ value: search,
3485
+ placeholder: texts.searchPlaceHolder,
3486
+ onChange: handleOnSearchChange
3487
+ }), !isLoadingInitialItems && (items == null ? void 0 : items.length) > 0 && /*#__PURE__*/React.createElement(CheckboxList, {
3488
+ groups: groups,
3489
+ onChange: handleOnItemChange
3490
+ }), !isLoadingInitialItems && (items == null ? void 0 : items.length) === 0 && /*#__PURE__*/React.createElement(Text, {
3491
+ text: texts.emptyState
3492
+ })));
3493
+ };
3494
+
3330
3495
  var TEXT_TYPE_OPTIONS = {
3331
3496
  DEFAULT: "default",
3332
3497
  STRONG: "strong",
@@ -5296,31 +5461,6 @@ function ViewItem(_ref) {
5296
5461
  })));
5297
5462
  }
5298
5463
 
5299
- var SearchIcon = function SearchIcon(props) {
5300
- return /*#__PURE__*/React__default.createElement("svg", {
5301
- className: props.className,
5302
- onClick: props.onClick,
5303
- role: props.onClick ? "button" : undefined,
5304
- width: "24",
5305
- height: "24",
5306
- viewBox: "0 0 24 24",
5307
- fill: "none",
5308
- xmlns: "http://www.w3.org/2000/svg"
5309
- }, /*#__PURE__*/React__default.createElement("path", {
5310
- d: "M15.5 13.9996H14.71L14.43 13.7296C15.63 12.3296 16.25 10.4196 15.91 8.38965C15.44 5.60965 13.12 3.38965 10.32 3.04965C6.09001 2.52965 2.53002 6.08965 3.05002 10.3196C3.39002 13.1196 5.61002 15.4396 8.39002 15.9096C10.42 16.2496 12.33 15.6296 13.73 14.4296L14 14.7096V15.4996L18.25 19.7496C18.66 20.1596 19.33 20.1596 19.74 19.7496C20.15 19.3396 20.15 18.6696 19.74 18.2596L15.5 13.9996ZM9.50002 13.9996C7.01002 13.9996 5.00002 11.9896 5.00002 9.49965C5.00002 7.00965 7.01002 4.99965 9.50002 4.99965C11.99 4.99965 14 7.00965 14 9.49965C14 11.9896 11.99 13.9996 9.50002 13.9996Z",
5311
- fill: "currentColor"
5312
- }));
5313
- };
5314
-
5315
- var SearchInput = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
5316
- return /*#__PURE__*/React__default.createElement(Input, Object.assign({}, props, {
5317
- icon: SearchIcon,
5318
- type: "text",
5319
- clearable: true,
5320
- ref: ref
5321
- }));
5322
- });
5323
-
5324
5464
  /**
5325
5465
  * Decorator for any input component. Adds a label and additional information to be shown.
5326
5466
  *
@@ -6357,6 +6497,7 @@ exports.ChatBoxIcon = ChatBoxIcon;
6357
6497
  exports.CheckIcon = CheckIcon;
6358
6498
  exports.Checkbox = Checkbox;
6359
6499
  exports.CheckboxList = CheckboxList;
6500
+ exports.CheckboxListModal = CheckboxListModal;
6360
6501
  exports.ChevronDoubleIcon = ChevronDoubleIcon;
6361
6502
  exports.ConfirmationDialog = ConfirmationDialog;
6362
6503
  exports.CrossIcon = CrossIcon;