@luscii-healthtech/web-ui 27.6.1 → 27.7.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.
@@ -1,3 +1,7 @@
1
- /// <reference types="react" />
2
- import { CheckboxGroupProps } from "./CheckboxList.types";
3
- export declare const CheckboxGroup: ({ title, items, onChange, className, isCollapsed, collapsible, }: CheckboxGroupProps) => JSX.Element;
1
+ import React from "react";
2
+ import { CheckboxGroupProps, CheckboxListItem } from "./CheckboxList.types";
3
+ type Props = CheckboxGroupProps & {
4
+ onStateChange?: (state: CheckboxListItem[]) => void;
5
+ };
6
+ export declare const CheckboxGroup: React.FC<Props>;
7
+ export {};
@@ -1,4 +1,10 @@
1
- /// <reference types="react" />
1
+ import React from "react";
2
2
  import { CheckboxListProps } from "./CheckboxList.types";
3
- export { type CheckboxListProps };
4
- export declare const CheckboxList: ({ groups, onChange, className, }: CheckboxListProps) => JSX.Element;
3
+ type Props = {
4
+ groups: CheckboxListProps["groups"];
5
+ onChange?: CheckboxListProps["onChange"];
6
+ onStateChange?: (state: CheckboxListProps["groups"]) => void;
7
+ className?: string;
8
+ };
9
+ export { type Props as CheckboxListProps };
10
+ export declare const CheckboxList: React.FC<Props>;
@@ -40,7 +40,7 @@ type WithCollapsible = {
40
40
  collapsible?: boolean;
41
41
  };
42
42
  export type CheckboxGroupProps = CheckboxGroup & {
43
- onChange: (event: CheckboxChangeEvent) => void;
43
+ onChange?: (event: CheckboxChangeEvent) => void;
44
44
  className?: string;
45
45
  } & WithCollapsible;
46
46
  export interface CheckboxGroupItemProps extends CheckboxListItem {
@@ -3773,7 +3773,7 @@ var CheckboxState;
3773
3773
  CheckboxState2["UNCHECKED"] = "unchecked";
3774
3774
  })(CheckboxState || (CheckboxState = {}));
3775
3775
 
3776
- const CheckboxGroup = ({ title, items, onChange, className, isCollapsed = true, collapsible = true }) => {
3776
+ const CheckboxGroup = ({ title, items, onChange, onStateChange, className, isCollapsed = true, collapsible = true }) => {
3777
3777
  const [groupCheckboxState, setGroupCheckboxState] = React.useState(CheckboxState.UNCHECKED);
3778
3778
  const [collapsed, setCollapsed] = React.useState(collapsible ? isCollapsed : false);
3779
3779
  const [isDisabled, setIsDisabled] = React.useState(false);
@@ -3802,12 +3802,19 @@ const CheckboxGroup = ({ title, items, onChange, className, isCollapsed = true,
3802
3802
  }, [items]);
3803
3803
  const handleGroupClick = (event) => {
3804
3804
  event.stopPropagation();
3805
- if (!onChange) {
3806
- return;
3807
- }
3808
- const enabledItems = items.filter((item) => !item.isDisabled);
3805
+ const enabledItems = [];
3806
+ const newState = [];
3807
+ items.forEach((item) => {
3808
+ if (item.isDisabled) {
3809
+ newState.push(item);
3810
+ return;
3811
+ }
3812
+ enabledItems.push(item);
3813
+ newState.push(Object.assign(Object.assign({}, item), { isChecked: event.currentTarget.checked }));
3814
+ });
3809
3815
  const newCheckedValue = event.currentTarget.checked;
3810
- enabledItems.forEach((item) => onChange({ id: item.id, newCheckedValue }));
3816
+ enabledItems.forEach((item) => onChange === null || onChange === void 0 ? void 0 : onChange({ id: item.id, newCheckedValue }));
3817
+ onStateChange === null || onStateChange === void 0 ? void 0 : onStateChange(newState);
3811
3818
  };
3812
3819
  const handleGroupCollapse = (event) => {
3813
3820
  event.stopPropagation();
@@ -3816,10 +3823,16 @@ const CheckboxGroup = ({ title, items, onChange, className, isCollapsed = true,
3816
3823
  }
3817
3824
  };
3818
3825
  const handleCheckboxChange = (e) => {
3819
- onChange({
3826
+ onChange === null || onChange === void 0 ? void 0 : onChange({
3820
3827
  id: e.target.id,
3821
3828
  newCheckedValue: e.target.checked
3822
3829
  });
3830
+ onStateChange === null || onStateChange === void 0 ? void 0 : onStateChange(items.map((item) => {
3831
+ if (item.id !== e.target.id) {
3832
+ return item;
3833
+ }
3834
+ return Object.assign(Object.assign({}, item), { isChecked: e.target.checked });
3835
+ }));
3823
3836
  };
3824
3837
  const checkedItemsCount = items === null || items === void 0 ? void 0 : items.filter((item) => item === null || item === void 0 ? void 0 : item.isChecked).length;
3825
3838
  const groupTitle = checkedItemsCount > 0 ? `${title} (${checkedItemsCount})` : title;
@@ -3870,16 +3883,35 @@ function GroupCollapseButton(props) {
3870
3883
  );
3871
3884
  }
3872
3885
 
3873
- const CheckboxList = ({ groups, onChange, className }) => {
3886
+ const CheckboxList = ({ groups, onChange, onStateChange, className }) => {
3874
3887
  const handleCheckboxChange = (e) => {
3875
- onChange({
3888
+ onChange === null || onChange === void 0 ? void 0 : onChange({
3876
3889
  id: e.target.id,
3877
3890
  newCheckedValue: e.target.checked
3878
3891
  });
3892
+ const totalState = [...groups];
3893
+ for (const group of groups) {
3894
+ for (const item of group.items) {
3895
+ if (item.id === e.target.id) {
3896
+ item.isChecked = e.target.checked;
3897
+ }
3898
+ }
3899
+ }
3900
+ onStateChange === null || onStateChange === void 0 ? void 0 : onStateChange(totalState);
3901
+ };
3902
+ const handleGroupChange = ({ groupTitle, items }) => {
3903
+ const newState = groups.map((group) => {
3904
+ if (group.title === groupTitle) {
3905
+ return Object.assign(Object.assign({}, group), { items });
3906
+ }
3907
+ return group;
3908
+ });
3909
+ onStateChange === null || onStateChange === void 0 ? void 0 : onStateChange(newState);
3879
3910
  };
3880
3911
  return React__namespace.default.createElement("div", { className: classNames__default.default("ui-flex ui-flex-col", className) }, groups.map((group) => {
3881
3912
  if (group.title) {
3882
- return React__namespace.default.createElement(CheckboxGroup, { key: group.title, items: group.items, title: group.title, isCollapsed: group.isCollapsed, collapsible: group.collapsible, onChange });
3913
+ const groupTitle = group.title;
3914
+ return React__namespace.default.createElement(CheckboxGroup, { key: group.title, items: group.items, title: group.title, isCollapsed: group.isCollapsed, collapsible: group.collapsible, onChange, onStateChange: (items) => handleGroupChange({ groupTitle, items }) });
3883
3915
  } else {
3884
3916
  return group.items.map((item) => React__namespace.default.createElement(Checkbox, Object.assign({}, item, { key: item.id, text: item.label, onChange: handleCheckboxChange, classNameCheckboxLabel: "ui-py-3" })));
3885
3917
  }
@@ -4358,7 +4390,7 @@ const TabbarItem = ({ title, index, isSelected, onSelect, className, badgeCount
4358
4390
  });
4359
4391
  return React__namespace.default.createElement(
4360
4392
  "button",
4361
- { className: itemClassName, onClick: handleTabClick, "data-test-id": dataTestId },
4393
+ { className: itemClassName, onClick: handleTabClick, "data-test-id": dataTestId, role: "tab", "aria-selected": isSelected },
4362
4394
  typeof title === "string" ? React__namespace.default.createElement(Text, { variant: "strong", color: "current", inline: true, className: "ui-leading-inherit" }, title) : title,
4363
4395
  badgeCount > 0 && React__namespace.default.createElement(Badge, { className: "ui-ml-1", badgeCount }),
4364
4396
  isLoading && React__namespace.default.createElement(LoadingIndicator, { asSpinner: true, spinnerColor: "gray", className: "ui-w-6" })
@@ -4374,7 +4406,7 @@ const Tabbar = ({ tabs = [], selectedIndex, onSelect, className }) => {
4374
4406
  setInnerSelectedIndex(index);
4375
4407
  onSelect === null || onSelect === void 0 ? void 0 : onSelect({ index, selectedTab: tabs[index] });
4376
4408
  };
4377
- return React__namespace.default.createElement("div", { className: classNames__default.default("ui-flex ui-w-full ui-gap-xl", className) }, tabs === null || tabs === void 0 ? void 0 : tabs.map((tabItemProps, index) => {
4409
+ return React__namespace.default.createElement("div", { className: classNames__default.default("ui-flex ui-w-full ui-gap-xl", className), role: "tablist" }, tabs === null || tabs === void 0 ? void 0 : tabs.map((tabItemProps, index) => {
4378
4410
  var _a;
4379
4411
  const itemProps = Object.assign({ index, onSelect: handleOnTabSelect, isSelected: innerSelectedIndex === index }, tabItemProps);
4380
4412
  return React__namespace.default.createElement(TabbarItem, Object.assign({ key: (_a = tabItemProps.dataTestId) !== null && _a !== void 0 ? _a : index }, itemProps));