@dbcdk/react-components 0.0.186 → 0.0.187

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.
@@ -14,8 +14,7 @@ function ButtonSelect(props) {
14
14
  const selectedValues = Array.isArray(props.value) ? props.value : [props.value];
15
15
  function handleSelect(optionValue) {
16
16
  if (props.multiple) {
17
- const currentValues = Array.isArray(props.value) ? props.value : [props.value];
18
- const nextValue = currentValues.includes(optionValue) ? currentValues.filter((current) => current !== optionValue) : [...currentValues, optionValue];
17
+ const nextValue = props.value.includes(optionValue) ? props.value.filter((current) => current !== optionValue) : [...props.value, optionValue];
19
18
  props.onChange(nextValue);
20
19
  return;
21
20
  }
@@ -11,10 +11,16 @@ interface ButtonSelectBaseProps<T extends string = string> {
11
11
  size?: ButtonSize;
12
12
  disabled?: boolean;
13
13
  }
14
- export interface ButtonSelectProps<T extends string = string> extends ButtonSelectBaseProps<T> {
15
- value: T | T[];
16
- onChange: (value: T | T[]) => void;
17
- multiple?: boolean;
14
+ export interface ButtonSelectSingleProps<T extends string = string> extends ButtonSelectBaseProps<T> {
15
+ value: T;
16
+ onChange: (value: T) => void;
17
+ multiple?: false;
18
+ }
19
+ export interface ButtonSelectMultipleProps<T extends string = string> extends ButtonSelectBaseProps<T> {
20
+ value: T[];
21
+ onChange: (value: T[]) => void;
22
+ multiple: true;
18
23
  }
24
+ export type ButtonSelectProps<T extends string = string> = ButtonSelectSingleProps<T> | ButtonSelectMultipleProps<T>;
19
25
  export declare function ButtonSelect<T extends string>(props: ButtonSelectProps<T>): JSX.Element;
20
26
  export {};
@@ -8,8 +8,7 @@ function ButtonSelect(props) {
8
8
  const selectedValues = Array.isArray(props.value) ? props.value : [props.value];
9
9
  function handleSelect(optionValue) {
10
10
  if (props.multiple) {
11
- const currentValues = Array.isArray(props.value) ? props.value : [props.value];
12
- const nextValue = currentValues.includes(optionValue) ? currentValues.filter((current) => current !== optionValue) : [...currentValues, optionValue];
11
+ const nextValue = props.value.includes(optionValue) ? props.value.filter((current) => current !== optionValue) : [...props.value, optionValue];
13
12
  props.onChange(nextValue);
14
13
  return;
15
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbcdk/react-components",
3
- "version": "0.0.186",
3
+ "version": "0.0.187",
4
4
  "description": "Reusable React components for DBC projects",
5
5
  "license": "ISC",
6
6
  "author": "",