esewa-ui-library 1.0.8 → 1.0.9

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/README.md CHANGED
@@ -478,6 +478,7 @@ The `ESewaChipGroup` component is a customizable chip group component built with
478
478
  | `required` | `boolean?` | `false` | If true, ensures that at least one chip is selected when the selection mode is `'multiple'`. |
479
479
  | `chips` | `ChipProps[]` | Required | An array of chips to display. Each chip includes a text label, an optional icon, and an ID. |
480
480
  | `className` | `string?` | `''` | Optional custom class name for styling the chip container. |
481
+ | `onChange` | `(selected: number[] | number) => void?` | `undefined` | Callback function to handle chip state change. |
481
482
 
482
483
  # ESewaDatePicker
483
484
 
@@ -4,6 +4,7 @@ interface ChipGroupProps {
4
4
  required?: boolean;
5
5
  chips: ChipProps[];
6
6
  className?: string;
7
+ onChange?: (selected: number[] | number) => void;
7
8
  }
8
9
  interface ChipProps {
9
10
  showIcon?: boolean;
package/dist/index.js CHANGED
@@ -7005,18 +7005,31 @@ var ESewaChipGroup = function ESewaChipGroup(_ref3) {
7005
7005
  var selection = _ref3.selection,
7006
7006
  required = _ref3.required,
7007
7007
  chips = _ref3.chips,
7008
- className = _ref3.className;
7008
+ className = _ref3.className,
7009
+ onChange = _ref3.onChange;
7009
7010
  var _useState = React.useState([]),
7010
7011
  selectedChips = _useState[0],
7011
7012
  setSelectedChips = _useState[1];
7012
7013
  var handleSelectChip = function handleSelectChip(id) {
7013
7014
  if (selection === 'single') {
7014
7015
  setSelectedChips([id]);
7016
+ onChange === null || onChange === void 0 ? void 0 : onChange(id);
7015
7017
  } else {
7016
7018
  setSelectedChips(function (prev) {
7017
- return prev.includes(id) ? required && prev.length === 1 ? prev : prev.filter(function (chipId) {
7018
- return chipId !== id;
7019
- }) : [].concat(prev, [id]);
7019
+ var updated;
7020
+ if (prev.includes(id)) {
7021
+ if (required && prev.length === 1) {
7022
+ updated = prev;
7023
+ } else {
7024
+ updated = prev.filter(function (chipId) {
7025
+ return chipId !== id;
7026
+ });
7027
+ }
7028
+ } else {
7029
+ updated = [].concat(prev, [id]);
7030
+ }
7031
+ onChange === null || onChange === void 0 ? void 0 : onChange(updated);
7032
+ return updated;
7020
7033
  });
7021
7034
  }
7022
7035
  };