@agility/plenum-ui 1.1.2 → 1.1.5

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,18 +1,19 @@
1
- import { FC } from 'react';
2
- export declare type ComboboxItemProps = {
3
- value: string;
4
- };
5
- export interface ComboboxProps {
1
+ /// <reference types="react" />
2
+ export interface ComboboxProps<T extends Record<string, unknown>> {
6
3
  /** Label */
7
4
  label?: string;
8
5
  /** ID */
9
6
  id: string;
10
7
  /** Array of items to display */
11
- items: ComboboxItemProps[];
8
+ items: T[];
9
+ /** the item property to use as the key */
10
+ keyProperty: string;
11
+ /** the item property to use as the display */
12
+ displayProperty: string;
12
13
  /** Placeholder */
13
14
  placeholder?: string;
14
15
  /** Callback to trigger on change */
15
- onChange?(value: string): void;
16
+ onChange?(value: T): void;
16
17
  /** Select disabled state */
17
18
  isDisabled?: boolean;
18
19
  /** Select error state */
@@ -20,5 +21,4 @@ export interface ComboboxProps {
20
21
  /** Select required state */
21
22
  isRequired?: boolean;
22
23
  }
23
- /** Comment */
24
- export declare const Combobox: FC<ComboboxProps>;
24
+ export declare const Combobox: <T extends Record<string, unknown>>({ label, items, displayProperty, keyProperty, onChange, placeholder, isDisabled, isError, isRequired, id }: ComboboxProps<T>) => JSX.Element;
@@ -3,9 +3,12 @@ import { Story } from '@storybook/react';
3
3
  import { ComboboxProps } from './Combobox';
4
4
  declare const _default: Meta<import("@storybook/react").Args>;
5
5
  export default _default;
6
- export declare const AllVariations: Story<ComboboxProps>;
7
- export declare const Default: Story<ComboboxProps>;
8
- export declare const Label: Story<ComboboxProps>;
9
- export declare const Disabled: Story<ComboboxProps>;
10
- export declare const Required: Story<ComboboxProps>;
11
- export declare const Error: Story<ComboboxProps>;
6
+ interface ComboItem {
7
+ [value: string]: string;
8
+ }
9
+ export declare const AllVariations: Story<ComboboxProps<ComboItem>>;
10
+ export declare const Default: Story<ComboboxProps<ComboItem>>;
11
+ export declare const Label: Story<ComboboxProps<ComboItem>>;
12
+ export declare const Disabled: Story<ComboboxProps<ComboItem>>;
13
+ export declare const Required: Story<ComboboxProps<ComboItem>>;
14
+ export declare const Error: Story<ComboboxProps<ComboItem>>;
@@ -6,6 +6,8 @@ export interface CheckboxProps {
6
6
  id: string;
7
7
  /** Disabled state */
8
8
  isDisabled?: boolean;
9
+ /** value */
10
+ value?: string;
9
11
  /** Check state */
10
12
  isChecked?: boolean;
11
13
  /** If field is required */
@@ -15,7 +17,7 @@ export interface CheckboxProps {
15
17
  /** Message or description */
16
18
  message?: string;
17
19
  /** Callback on input change */
18
- onChange?(value: string): void;
20
+ onChange?(value: string, isChecked: boolean): void;
19
21
  }
20
22
  /** Comment */
21
23
  export declare const Checkbox: FC<CheckboxProps>;
@@ -10,3 +10,4 @@ export declare const Required: Story<CheckboxProps>;
10
10
  export declare const Checked: Story<CheckboxProps>;
11
11
  export declare const ErrorState: Story<CheckboxProps>;
12
12
  export declare const Disabled: Story<CheckboxProps>;
13
+ export declare const Events: Story<CheckboxProps>;
@@ -16,10 +16,12 @@ export interface RadioProps {
16
16
  isError?: boolean;
17
17
  /** Message or description */
18
18
  message?: string;
19
+ /** value */
20
+ value?: string;
19
21
  /** Callback on input change */
20
- onChange?(value: string): void;
22
+ onChange?(value: string, isChecked: boolean): void;
21
23
  /** Callback on click */
22
- onClick?(value: string): void;
24
+ onClick?(value: string, isChecked: boolean): void;
23
25
  }
24
26
  /** Comment */
25
27
  export declare const Radio: FC<RadioProps>;
package/lib/index.esm.js CHANGED
@@ -7089,9 +7089,9 @@ function classNames() {
7089
7089
  }
7090
7090
  return classes.filter(Boolean).join(' ');
7091
7091
  }
7092
- /** Comment */
7092
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
7093
7093
  var Combobox = function (_a) {
7094
- var label = _a.label, items = _a.items, onChange = _a.onChange, placeholder = _a.placeholder, isDisabled = _a.isDisabled, isError = _a.isError, isRequired = _a.isRequired, id = _a.id;
7094
+ var label = _a.label, items = _a.items, displayProperty = _a.displayProperty, keyProperty = _a.keyProperty, onChange = _a.onChange, placeholder = _a.placeholder, isDisabled = _a.isDisabled, isError = _a.isError, isRequired = _a.isRequired, id = _a.id;
7095
7095
  var _b = useState(''), query = _b[0], setQuery = _b[1];
7096
7096
  var _c = useState(), selectedItem = _c[0], setSelectedItem = _c[1];
7097
7097
  useEffect(function () {
@@ -7100,7 +7100,7 @@ var Combobox = function (_a) {
7100
7100
  var filteredItems = query === ''
7101
7101
  ? items
7102
7102
  : items.filter(function (item) {
7103
- return item.value.toLowerCase().includes(query.toLowerCase());
7103
+ return "".concat(item[displayProperty]).toLowerCase().includes(query.toLowerCase());
7104
7104
  });
7105
7105
  var inputStyles = cn$1('w-full rounded-md border bg-white py-2 pl-3 pr-10 shadow-sm sm:text-sm', 'focus:border-purple-500 focus:outline-none focus:ring-1 focus:ring-purple-500', { 'border-red-500': isError }, { 'border-gray-300': !isError });
7106
7106
  var labelStyles = cn$1('block text-sm font-medium text-gray-700');
@@ -7110,16 +7110,16 @@ var Combobox = function (_a) {
7110
7110
  label && (React__default.createElement(Na.Label, { className: labelStyles },
7111
7111
  React__default.createElement(InputLabel, { isPlaceholder: true, isActive: true, label: label, isRequired: isRequired, id: id, isError: isError, isDisabled: isDisabled }))),
7112
7112
  React__default.createElement("div", { className: "relative" },
7113
- React__default.createElement(Na.Input, { className: inputStyles, onChange: function (event) { return setQuery(event.target.value); }, displayValue: function (item) { return item.value; }, placeholder: placeholder }),
7113
+ React__default.createElement(Na.Input, { className: inputStyles, onChange: function (event) { return setQuery(event.target.value); }, displayValue: function (item) { return "".concat(item[displayProperty]); }, placeholder: placeholder }),
7114
7114
  React__default.createElement(Na.Button, { className: buttonStyles },
7115
7115
  React__default.createElement(DynamicIcons, { icon: "SelectorIcon", className: "h-5 w-5 text-gray-400", "aria-hidden": "true" })),
7116
- filteredItems.length > 0 && (React__default.createElement(Na.Options, { className: optionStyles }, filteredItems.map(function (item, index) { return (React__default.createElement(Na.Option, { key: index, value: item, className: function (_a) {
7116
+ filteredItems.length > 0 && (React__default.createElement(Na.Options, { className: optionStyles }, filteredItems.map(function (item, index) { return (React__default.createElement(Na.Option, { key: "".concat(item[keyProperty], "-").concat(index), value: item, className: function (_a) {
7117
7117
  var active = _a.active;
7118
7118
  return classNames('relative cursor-default select-none py-2 pl-3 pr-9', active ? 'bg-purple-600 text-white' : 'text-gray-900');
7119
7119
  } }, function (_a) {
7120
7120
  var active = _a.active, selected = _a.selected;
7121
7121
  return (React__default.createElement(React__default.Fragment, null,
7122
- React__default.createElement("span", { className: classNames('block truncate', selected ? 'font-semibold' : '') }, item.value),
7122
+ React__default.createElement("span", { className: classNames('block truncate', selected ? 'font-semibold' : '') }, "".concat(item[displayProperty])),
7123
7123
  selected && (React__default.createElement("span", { className: classNames('absolute inset-y-0 right-0 flex items-center pr-4', active ? 'text-white' : 'text-purple-600') },
7124
7124
  React__default.createElement(DynamicIcons, { icon: "CheckIcon", className: "h-5 w-5", "aria-hidden": "true" })))));
7125
7125
  })); }))))));
@@ -12433,22 +12433,24 @@ var TextInputSelect = function (_a) {
12433
12433
 
12434
12434
  /** Comment */
12435
12435
  var Radio = function (_a) {
12436
- var label = _a.label, id = _a.id, name = _a.name, _b = _a.isDisabled, isDisabled = _b === void 0 ? false : _b, _c = _a.isChecked, isChecked = _c === void 0 ? false : _c, _d = _a.isRequired, isRequired = _d === void 0 ? false : _d, _e = _a.isError, isError = _e === void 0 ? false : _e, message = _a.message, onChange = _a.onChange, onClick = _a.onClick;
12436
+ var label = _a.label, id = _a.id, name = _a.name, _b = _a.isDisabled, isDisabled = _b === void 0 ? false : _b, _c = _a.isChecked, isChecked = _c === void 0 ? false : _c, _d = _a.isRequired, isRequired = _d === void 0 ? false : _d, _e = _a.isError, isError = _e === void 0 ? false : _e, message = _a.message, onChange = _a.onChange, onClick = _a.onClick, value = _a.value;
12437
12437
  var checboxStyles = cn$1('focus:ring-purple-500 h-4 w-4 text-purple-600 border-gray-300', {
12438
12438
  'border-red-500 shadow-none': isError
12439
12439
  });
12440
12440
  var wrapperStyles = cn$1('relative flex items-start', { 'opacity-50': isDisabled });
12441
12441
  var handleChange = function (e) {
12442
12442
  var targetValue = e.currentTarget.value;
12443
- typeof onChange === 'function' && onChange(targetValue);
12443
+ var targetChecked = e.currentTarget.checked;
12444
+ typeof onChange === 'function' && onChange(targetValue, targetChecked);
12444
12445
  };
12445
12446
  var handleClick = function (e) {
12446
12447
  var targetValue = e.currentTarget.value;
12447
- typeof onClick === 'function' && onClick(targetValue);
12448
+ var targetChecked = e.currentTarget.checked;
12449
+ typeof onClick === 'function' && onClick(targetValue, targetChecked);
12448
12450
  };
12449
12451
  return (React__default.createElement("div", { className: wrapperStyles },
12450
12452
  React__default.createElement("div", { className: "flex items-center h-5" },
12451
- React__default.createElement("input", { id: id, "aria-describedby": "".concat(id, "-description"), name: name, type: "radio", className: checboxStyles, disabled: isDisabled, defaultChecked: isChecked, onChange: function (e) {
12453
+ React__default.createElement("input", { id: id, "aria-describedby": "".concat(id, "-description"), name: name, type: "radio", value: value, className: checboxStyles, disabled: isDisabled, defaultChecked: isChecked, onChange: function (e) {
12452
12454
  handleChange(e);
12453
12455
  }, onClick: function (e) {
12454
12456
  handleClick(e);
@@ -12501,16 +12503,17 @@ var Select = function (_a) {
12501
12503
 
12502
12504
  /** Comment */
12503
12505
  var Checkbox = function (_a) {
12504
- var label = _a.label, id = _a.id, isDisabled = _a.isDisabled, isChecked = _a.isChecked, isRequired = _a.isRequired, isError = _a.isError, message = _a.message, onChange = _a.onChange;
12506
+ var label = _a.label, id = _a.id, isDisabled = _a.isDisabled, isChecked = _a.isChecked, isRequired = _a.isRequired, isError = _a.isError, message = _a.message, value = _a.value, onChange = _a.onChange;
12505
12507
  var checboxStyles = cn$1('focus:ring-purple-500 h-4 w-4 text-purple-600 border-gray-300 rounded', { 'border-red-500 shadow-none': isError });
12506
12508
  var wrapperStyles = cn$1('relative flex items-start', { 'opacity-50': isDisabled });
12507
12509
  var handleChange = function (e) {
12508
12510
  var targetValue = e.currentTarget.value;
12509
- typeof onChange === 'function' && onChange(targetValue);
12511
+ var targetChecked = e.currentTarget.checked;
12512
+ typeof onChange === 'function' && onChange(targetValue, targetChecked);
12510
12513
  };
12511
12514
  return (React__default.createElement("div", { className: wrapperStyles },
12512
12515
  React__default.createElement("div", { className: "flex items-center h-5" },
12513
- React__default.createElement("input", { id: id, "aria-describedby": "".concat(id, "-description"), name: id, type: "checkbox", className: checboxStyles, disabled: isDisabled, defaultChecked: isChecked, onChange: function (e) {
12516
+ React__default.createElement("input", { id: id, "aria-describedby": "".concat(id, "-description"), name: id, value: value, type: "checkbox", className: checboxStyles, disabled: isDisabled, defaultChecked: isChecked, onChange: function (e) {
12514
12517
  handleChange(e);
12515
12518
  } })),
12516
12519
  React__default.createElement("div", { className: "ml-3 text-sm" },