@trafilea/afrodita-components 4.0.2-beta.11 → 4.0.2-beta.12

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/build/index.d.ts CHANGED
@@ -452,23 +452,27 @@ declare const ButtonSecondary: ({ text, onClick, disabled, wide, size, className
452
452
 
453
453
  declare const ButtonSecondaryOutline: ({ text, onClick, disabled, wide, size, className, }: CTAProps) => _emotion_react_jsx_runtime.JSX.Element;
454
454
 
455
+ declare type Value<T> = DropdownOption<T>;
456
+ declare type OnChange<T> = (option: Value<T>) => void;
455
457
  declare type CommonProps<T> = {
456
- options: DropdownOption<T>[];
458
+ options: Value<T>[];
457
459
  disabled?: boolean;
458
460
  wide?: boolean;
459
- onChange: (option: DropdownOption<T>) => void;
460
461
  label?: string;
461
462
  sort?: boolean;
462
- };
463
- declare type ConditionalProps<T> = {
464
- initialValue: DropdownOption<T>;
465
- placeHolder?: string;
466
- } | {
467
- initialValue?: undefined;
463
+ initialValue?: Value<T>;
468
464
  placeHolder: string;
469
465
  };
470
- declare type SimpleDropdownProps<T> = CommonProps<T> & ConditionalProps<T>;
471
- declare function SimpleDropdown<T>({ options, disabled, initialValue, placeHolder, label, wide, sort, onChange, }: SimpleDropdownProps<T>): JSX.Element;
466
+ declare type ControlledProps<T> = {
467
+ value: Value<T>;
468
+ onChange: OnChange<T>;
469
+ } & CommonProps<T>;
470
+ declare type UncontrolledProps<T> = {
471
+ value?: never;
472
+ onChange?: OnChange<T>;
473
+ } & CommonProps<T>;
474
+ declare type SimpleDropdownProps<T> = UncontrolledProps<T> | ControlledProps<T>;
475
+ declare function SimpleDropdown<T>({ options, disabled, initialValue, placeHolder, label, wide, sort, onChange, value, }: SimpleDropdownProps<T>): JSX.Element;
472
476
 
473
477
  interface SizeSelectorProps {
474
478
  label: string;
@@ -6243,20 +6243,28 @@ var BaseDropdown$1 = Object.assign(BaseDropdown, {
6243
6243
  });
6244
6244
 
6245
6245
  function SimpleDropdown(_a) {
6246
- var options = _a.options, _b = _a.disabled, disabled = _b === void 0 ? false : _b, initialValue = _a.initialValue, placeHolder = _a.placeHolder, label = _a.label, _c = _a.wide, wide = _c === void 0 ? false : _c, _d = _a.sort, sort = _d === void 0 ? false : _d, onChange = _a.onChange;
6247
- var _e = useState(initialValue), selectedValue = _e[0], setSelectedValue = _e[1];
6248
- var selectedOptionLabel = function () {
6249
- if (selectedValue)
6246
+ var options = _a.options, _b = _a.disabled, disabled = _b === void 0 ? false : _b, initialValue = _a.initialValue, placeHolder = _a.placeHolder, label = _a.label, _c = _a.wide, wide = _c === void 0 ? false : _c, _d = _a.sort, sort = _d === void 0 ? false : _d, onChange = _a.onChange, value = _a.value;
6247
+ var _e = useState(value || initialValue), selectedValue = _e[0], setSelectedValue = _e[1];
6248
+ var selectedOptionLabel = useMemo(function () {
6249
+ if (selectedValue) {
6250
6250
  return selectedValue.label;
6251
- else
6252
- return placeHolder;
6253
- };
6251
+ }
6252
+ return placeHolder;
6253
+ }, [selectedValue, placeHolder]);
6254
6254
  var onChangeHandler = function (value) {
6255
- onChange(value);
6255
+ if (onChange) {
6256
+ onChange(value);
6257
+ }
6256
6258
  setSelectedValue(value);
6257
6259
  };
6260
+ useEffect(function () {
6261
+ if (value == null) {
6262
+ return;
6263
+ }
6264
+ setSelectedValue(value);
6265
+ }, [value]);
6258
6266
  var Button = label ? withLabel(BaseDropdown$1.Button, label) : BaseDropdown$1.Button;
6259
- return (jsxs$1(BaseDropdown$1, __assign({ value: selectedValue, onChange: onChangeHandler, disabled: disabled, wide: wide }, { children: [jsx$1(Button, __assign({ OpenIcon: Icon.Arrows.ChevronDown, CloseIcon: Icon.Arrows.ChevronUp, wide: wide, isSortOrFilter: sort }, { children: selectedOptionLabel() }), void 0), jsx$1(BaseDropdown$1.Options, { children: options.map(function (item) { return (jsx$1(BaseDropdown$1.Option, __assign({ value: item, disabled: false }, { children: item.label }), item.key)); }) }, void 0)] }), void 0));
6267
+ return (jsxs$1(BaseDropdown$1, __assign({ value: selectedValue, onChange: onChangeHandler, disabled: disabled, wide: wide }, { children: [jsx$1(Button, __assign({ OpenIcon: Icon.Arrows.ChevronDown, CloseIcon: Icon.Arrows.ChevronUp, wide: wide, isSortOrFilter: sort }, { children: selectedOptionLabel }), void 0), jsx$1(BaseDropdown$1.Options, { children: options.map(function (item) { return (jsx$1(BaseDropdown$1.Option, __assign({ value: item, disabled: false }, { children: item.label }), item.key)); }) }, void 0)] }), void 0));
6260
6268
  }
6261
6269
 
6262
6270
  var getStylesBySize$8 = function (size, theme) {