@7shifts/sous-chef 3.24.0 → 3.25.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,5 +1,5 @@
1
- import { SelectProps } from '../../forms/SelectField/types';
2
- declare type ToolbarSelectProps<T> = Omit<SelectProps<T>, 'asToolbarFilter' | 'caption' | 'error' | 'id' | 'isClearable' | 'label' | 'noOptionMessage' | 'CustomOption' | 'SelectedOptionPrefix' | 'creatableButton' | 'onCreate' | 'isSearchable'>;
1
+ import { Props } from '../../forms/SelectField/SelectField';
2
+ declare type ToolbarSelectProps<T> = Omit<Props<T>, 'asToolbarFilter' | 'caption' | 'error' | 'id' | 'isClearable' | 'label' | 'noOptionMessage' | 'CustomOption' | 'SelectedOptionPrefix' | 'creatableButton' | 'onCreate' | 'isSearchable'>;
3
3
  /** Toolbar component to make a possible selection from predefined options. */
4
- declare const ToolbarSelect: <T extends unknown>({ name, value, options, onChange, onBlur, placeholder, defaultValue, menuShouldScrollIntoView, disabled, prefix, testId }: Pick<SelectProps<T>, "disabled" | "onBlur" | "testId" | "name" | "onChange" | "menuShouldScrollIntoView" | "noOptionsMessage" | "options" | "placeholder" | "prefix" | "value" | "defaultValue">) => JSX.Element;
4
+ declare const ToolbarSelect: <T extends unknown>({ name, value, options, onChange, onBlur, placeholder, defaultValue, menuShouldScrollIntoView, disabled, prefix, testId }: Pick<Props<T>, "disabled" | "onBlur" | "testId" | "name" | "onChange" | "menuShouldScrollIntoView" | "noOptionsMessage" | "options" | "placeholder" | "prefix" | "value" | "defaultValue">) => JSX.Element;
5
5
  export default ToolbarSelect;
@@ -1,4 +1,4 @@
1
- import type { SelectProps } from '../SelectField/types';
1
+ import type { Props as SelectProps } from '../SelectField/SelectField';
2
2
  import { AsyncSelectOptions } from './types';
3
3
  declare type Props<T> = {
4
4
  /** It is a function that takes the input search as parameter and returns a Promise with all the options and if there are more options to load. If it brings all the options on the first load, it won't call the `loadOptions` to perform the search. */
@@ -1,30 +1,30 @@
1
1
  import React from 'react';
2
- import type { SelectOption, SelectOptions, NoOptionsMessageFunction } from '../SelectField/types';
2
+ import type { SelectOption, SelectOptions } from '../SelectField/types';
3
+ declare type NoOptionsMessageFunction = (input: {
4
+ inputValue: string;
5
+ }) => string | null;
3
6
  declare type Props<T> = {
4
- caption?: React.ReactNode;
5
- disabled?: boolean;
6
- error?: React.ReactNode;
7
- /** If not provided it will generate a random id so the l¡abel links properly with the text input */
8
- id?: string;
9
- label?: React.ReactNode;
10
- /** When the user opens the menu, if this prop is `true`, it will scroll the page into to the menu view (if its content falls under a scroll). It is recommended to disable this behaviour when using the `SelectField` inside a modal. */
11
- menuShouldScrollIntoView?: boolean;
12
7
  name: string;
13
- noOptionsMessage?: string | NoOptionsMessageFunction;
14
- onChange?: (e: SelectOption<T> | SelectOption<T>[]) => void;
15
- onBlur?: (e: SelectOption<T> | SelectOption<T>[]) => void;
8
+ /** If not provided it will generate a random id so the label links properly with the text input */
9
+ id?: string;
10
+ value?: SelectOption<T>[];
16
11
  options: SelectOptions<T>;
17
- placeholder?: string;
18
- value?: SelectOption<T> | SelectOption<T>[];
19
- defaultValue?: SelectOption<T> | SelectOption<T>[];
12
+ onChange?: (e: SelectOption<T>[]) => void;
13
+ onBlur?: (e: SelectOption<T>[]) => void;
20
14
  CustomOption?: React.ElementType;
21
- /** This is used for setting the data-testid */
15
+ label?: React.ReactNode;
16
+ caption?: React.ReactNode;
17
+ error?: React.ReactNode;
18
+ placeholder?: string;
19
+ noOptionsMessage?: string | NoOptionsMessageFunction;
20
+ disabled?: boolean;
21
+ closeOnSelect?: boolean;
22
+ /** When the user opens the menu, if this prop is `true`, it will scroll the page into to the menu view (if its content falls under a scroll). It is recomended to disable this behaviour when using the `MultiSelectField` inside a modal. */
23
+ menuShouldScrollIntoView?: boolean;
22
24
  testId?: string;
23
- creatableButton?: React.ReactNode;
24
- onCreate?: (option: string) => void;
25
25
  /** This is to allow disable the seach functionality. Use it just in some edge-cases, for example in touch devices when the user clicks on the field it opens a virtual keyboard to search, sometimes that virtual keyboard taks much space then passing `isSearchable={false}` prevents opening it. */
26
26
  isSearchable?: boolean;
27
- closeOnSelect?: boolean;
28
27
  };
29
- declare const MultiSelectField: <T extends unknown>(props: Props<T>) => JSX.Element;
28
+ /** Component to make possible choose from a predefined options. */
29
+ declare const MultiSelectField: <T extends unknown>({ name, id: inputId, value, options, onChange, onBlur, CustomOption: UserCustomOption, label, caption, error, placeholder, noOptionsMessage, disabled, closeOnSelect, menuShouldScrollIntoView, testId, isSearchable }: Props<T>) => JSX.Element;
30
30
  export default MultiSelectField;
@@ -1,4 +1,41 @@
1
- import type { SelectProps } from './types';
1
+ import React from 'react';
2
+ import type { SelectOption, SelectOptions } from './types';
3
+ declare type NoOptionsMessageFunction = (input: {
4
+ inputValue: string;
5
+ }) => string | null;
6
+ export declare type Props<T> = {
7
+ /**
8
+ * @deprecated `asToolbarFilter` prop has been replaced with the `ToolbarSelect` component.
9
+ */
10
+ asToolbarFilter?: boolean;
11
+ caption?: React.ReactNode;
12
+ disabled?: boolean;
13
+ error?: React.ReactNode;
14
+ /** If not provided it will generate a random id so the l¡abel links properly with the text input */
15
+ id?: string;
16
+ isClearable?: boolean;
17
+ label?: React.ReactNode;
18
+ /** When the user opens the menu, if this prop is `true`, it will scroll the page into to the menu view (if its content falls under a scroll). It is recommended to disable this behaviour when using the `SelectField` inside a modal. */
19
+ menuShouldScrollIntoView?: boolean;
20
+ name: string;
21
+ noOptionsMessage?: string | NoOptionsMessageFunction;
22
+ onChange?: (e: SelectOption<T>) => void;
23
+ onBlur?: (e: SelectOption<T>) => void;
24
+ options: SelectOptions<T>;
25
+ placeholder?: string;
26
+ /** Use a prefix for things like currency symbols (“$”, “¥”, “£”) or icons. */
27
+ prefix?: React.ReactNode;
28
+ value?: SelectOption<T>;
29
+ defaultValue?: SelectOption<T>;
30
+ CustomOption?: React.ElementType;
31
+ SelectedOptionPrefix?: React.ElementType;
32
+ /** This is used for setting the data-testid */
33
+ testId?: string;
34
+ creatableButton?: React.ReactNode;
35
+ onCreate?: (option: string) => void;
36
+ /** This is to allow disable the seach functionality. Use it just in some edge-cases, for example in touch devices when the user clicks on the field it opens a virtual keyboard to search, sometimes that virtual keyboard taks much space then passing `isSearchable={false}` prevents opening it. */
37
+ isSearchable?: boolean;
38
+ };
2
39
  /** Component to make possible choose from a predefined options. */
3
- declare const SelectField: <T extends unknown>(props: SelectProps<T>) => JSX.Element;
40
+ declare const SelectField: <T extends unknown>(props: Props<T>) => JSX.Element;
4
41
  export default SelectField;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { ControlProps } from 'react-select';
3
2
  export declare type GroupOption<T> = {
4
3
  label: string;
@@ -20,39 +19,3 @@ export declare type CustomOptionProps<T> = {
20
19
  export interface SelectedOptionPrefixProps<T> extends ControlProps<T, false> {
21
20
  selectedOption: SelectOption<T>;
22
21
  }
23
- export declare type NoOptionsMessageFunction = (input: {
24
- inputValue: string;
25
- }) => string | null;
26
- export declare type SelectProps<T> = {
27
- /**
28
- * @deprecated `asToolbarFilter` prop has been replaced with the `ToolbarSelect` component.
29
- */
30
- asToolbarFilter?: boolean;
31
- caption?: React.ReactNode;
32
- disabled?: boolean;
33
- error?: React.ReactNode;
34
- /** If not provided it will generate a random id so the l¡abel links properly with the text input */
35
- id?: string;
36
- isClearable?: boolean;
37
- label?: React.ReactNode;
38
- /** When the user opens the menu, if this prop is `true`, it will scroll the page into to the menu view (if its content falls under a scroll). It is recommended to disable this behaviour when using the `SelectField` inside a modal. */
39
- menuShouldScrollIntoView?: boolean;
40
- name: string;
41
- noOptionsMessage?: string | NoOptionsMessageFunction;
42
- onChange?: (e: SelectOption<T> | SelectOption<T>[]) => void;
43
- onBlur?: (e: SelectOption<T> | SelectOption<T>[]) => void;
44
- options: SelectOptions<T>;
45
- placeholder?: string;
46
- /** Use a prefix for things like currency symbols (“$”, “¥”, “£”) or icons. */
47
- prefix?: React.ReactNode;
48
- value?: SelectOption<T> | SelectOption<T>[];
49
- defaultValue?: SelectOption<T> | SelectOption<T>[];
50
- CustomOption?: React.ElementType;
51
- SelectedOptionPrefix?: React.ElementType;
52
- /** This is used for setting the data-testid */
53
- testId?: string;
54
- creatableButton?: React.ReactNode;
55
- onCreate?: (option: string) => void;
56
- /** This is to allow disable the seach functionality. Use it just in some edge-cases, for example in touch devices when the user clicks on the field it opens a virtual keyboard to search, sometimes that virtual keyboard taks much space then passing `isSearchable={false}` prevents opening it. */
57
- isSearchable?: boolean;
58
- };
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { SelectProps } from './types';
3
- export declare const useSelectField: <T extends unknown>({ asToolbarFilter, caption, disabled, error, id, isClearable, label, menuShouldScrollIntoView, name, noOptionsMessage, options, onBlur, onChange, placeholder, value, defaultValue, CustomOption: UserCustomOption, SelectedOptionPrefix, testId, creatableButton, onCreate, isSearchable, }: SelectProps<T>, isMultiSelect?: boolean) => {
2
+ import type { Props } from './SelectField';
3
+ export declare const useSelectField: <T extends unknown>({ asToolbarFilter, caption, disabled, error, id, isClearable, label, menuShouldScrollIntoView, name, noOptionsMessage, options, onBlur, onChange, placeholder, value, defaultValue, CustomOption: UserCustomOption, SelectedOptionPrefix, testId, creatableButton, onCreate, isSearchable }: Props<T>) => {
4
4
  selectProps: Pick<import("react-select").Props<import("react-select").OptionTypeBase, boolean, import("react-select").GroupTypeBase<any>>, import("react").ReactText> & import("react-select/src/stateManager").Props<import("react-select").OptionTypeBase, boolean, import("react-select").GroupTypeBase<any>> & import("react-select").Props<import("react-select").OptionTypeBase, boolean, import("react-select").GroupTypeBase<any>>;
5
5
  fieldProps: {
6
6
  caption: import("react").ReactNode;
@@ -3,16 +3,16 @@ import type { SelectOption } from '../SelectField/types';
3
3
  declare type FieldControls<T> = {
4
4
  id: string;
5
5
  error?: React.ReactNode;
6
- value?: SelectOption<T> | SelectOption<T>[];
7
- onChange: (e: SelectOption<T> | SelectOption<T>[]) => void;
8
- onBlur: (e: SelectOption<T> | SelectOption<T>[]) => void;
6
+ value?: SelectOption<T>;
7
+ onChange: (e: SelectOption<T>) => void;
8
+ onBlur: (e: SelectOption<T>) => void;
9
9
  };
10
10
  declare type Props<T> = {
11
11
  name: string;
12
12
  id?: string;
13
- value?: SelectOption<T> | SelectOption<T>[];
14
- onChange?: (e: SelectOption<T> | SelectOption<T>[]) => void;
15
- onBlur?: (e: SelectOption<T> | SelectOption<T>[]) => void;
13
+ value?: SelectOption<T>;
14
+ onChange?: (e: SelectOption<T>) => void;
15
+ onBlur?: (e: SelectOption<T>) => void;
16
16
  error?: React.ReactNode;
17
17
  onMenuInputFocus?: (isFocused: boolean) => void;
18
18
  };
package/dist/index.js CHANGED
@@ -7855,7 +7855,7 @@ function CustomMenu(_ref) {
7855
7855
  }, getLocalizedString('default.CREATE'))))));
7856
7856
  }
7857
7857
 
7858
- var useSelectField = function useSelectField(_ref, isMultiSelect) {
7858
+ var useSelectField = function useSelectField(_ref) {
7859
7859
  var _ref$asToolbarFilter = _ref.asToolbarFilter,
7860
7860
  asToolbarFilter = _ref$asToolbarFilter === void 0 ? false : _ref$asToolbarFilter,
7861
7861
  caption = _ref.caption,
@@ -7883,10 +7883,6 @@ var useSelectField = function useSelectField(_ref, isMultiSelect) {
7883
7883
  _ref$isSearchable = _ref.isSearchable,
7884
7884
  isSearchable = _ref$isSearchable === void 0 ? true : _ref$isSearchable;
7885
7885
 
7886
- if (isMultiSelect === void 0) {
7887
- isMultiSelect = false;
7888
- }
7889
-
7890
7886
  var _useState = React.useState(false),
7891
7887
  isMenuInputFocus = _useState[0],
7892
7888
  setIsMenuInputFocus = _useState[1];
@@ -7944,14 +7940,12 @@ var useSelectField = function useSelectField(_ref, isMultiSelect) {
7944
7940
  placeholder: placeholder,
7945
7941
  styles: getSelectStyles({
7946
7942
  isInvalid: hasError,
7947
- asToolbarFilter: asToolbarFilter,
7948
- wrapToNextLine: isMultiSelect ? true : undefined
7943
+ asToolbarFilter: asToolbarFilter
7949
7944
  }),
7950
7945
  value: controllers.value,
7951
7946
  defaultValue: defaultValue,
7952
7947
  menuIsOpen: isMenuInputFocus || undefined,
7953
- isSearchable: isSearchable,
7954
- isMulti: isMultiSelect
7948
+ isSearchable: isSearchable
7955
7949
  };
7956
7950
  var fieldProps = {
7957
7951
  caption: caption,
@@ -9046,20 +9040,82 @@ var PasswordField = function PasswordField(_ref) {
9046
9040
  }))));
9047
9041
  };
9048
9042
 
9049
- var MultiSelectField = function MultiSelectField(props) {
9050
- var _props$closeOnSelect;
9051
-
9052
- var closeOnSelect = (_props$closeOnSelect = props.closeOnSelect) != null ? _props$closeOnSelect : false;
9053
-
9054
- var _useSelectField = useSelectField(_extends({}, props, {
9055
- isClearable: true
9056
- }), true),
9057
- fieldProps = _useSelectField.fieldProps,
9058
- selectProps = _useSelectField.selectProps;
9043
+ var MultiSelectField = function MultiSelectField(_ref) {
9044
+ var name = _ref.name,
9045
+ inputId = _ref.id,
9046
+ value = _ref.value,
9047
+ options = _ref.options,
9048
+ onChange = _ref.onChange,
9049
+ onBlur = _ref.onBlur,
9050
+ UserCustomOption = _ref.CustomOption,
9051
+ label = _ref.label,
9052
+ caption = _ref.caption,
9053
+ error = _ref.error,
9054
+ placeholder = _ref.placeholder,
9055
+ noOptionsMessage = _ref.noOptionsMessage,
9056
+ disabled = _ref.disabled,
9057
+ _ref$closeOnSelect = _ref.closeOnSelect,
9058
+ closeOnSelect = _ref$closeOnSelect === void 0 ? false : _ref$closeOnSelect,
9059
+ _ref$menuShouldScroll = _ref.menuShouldScrollIntoView,
9060
+ menuShouldScrollIntoView = _ref$menuShouldScroll === void 0 ? true : _ref$menuShouldScroll,
9061
+ testId = _ref.testId,
9062
+ _ref$isSearchable = _ref.isSearchable,
9063
+ isSearchable = _ref$isSearchable === void 0 ? true : _ref$isSearchable;
9064
+ var controllers = useMultiSelectFieldControllers({
9065
+ name: name,
9066
+ id: inputId,
9067
+ value: value,
9068
+ onChange: onChange,
9069
+ onBlur: onBlur,
9070
+ error: error
9071
+ });
9072
+ var hasError = !!controllers.error;
9073
+ var fieldProps = {
9074
+ name: name,
9075
+ id: controllers.id,
9076
+ label: label,
9077
+ caption: caption,
9078
+ error: controllers.error
9079
+ };
9080
+ var defaultNoOptionsMessage = noOptionsMessage && typeof noOptionsMessage === 'string' ? function () {
9081
+ return noOptionsMessage;
9082
+ } : undefined;
9083
+ return React__default.createElement(Field, Object.assign({}, fieldProps), React__default.createElement(Select__default, {
9084
+ inputId: controllers.id,
9085
+ options: options,
9086
+ isDisabled: disabled,
9087
+ value: controllers.value,
9088
+ placeholder: placeholder,
9089
+ noOptionsMessage: typeof noOptionsMessage === 'function' ? noOptionsMessage : defaultNoOptionsMessage,
9090
+ styles: getSelectStyles({
9091
+ isInvalid: hasError,
9092
+ wrapToNextLine: true
9093
+ }),
9094
+ menuPortalTarget: document.body,
9095
+ onChange: controllers.onChange,
9096
+ onBlur: controllers.onBlur,
9097
+ isMulti: true,
9098
+ closeMenuOnSelect: closeOnSelect,
9099
+ componentsProps: {
9100
+ testId: testId,
9101
+ UserCustomOption: UserCustomOption
9102
+ },
9103
+ components: {
9104
+ SelectContainer: CustomContainer,
9105
+ Option: UserCustomOption ? CustomOption : Select.components.Option
9106
+ },
9107
+ menuShouldScrollIntoView: menuShouldScrollIntoView,
9108
+ menuPlacement: menuShouldScrollIntoView ? 'bottom' : 'auto',
9109
+ menuPosition: menuShouldScrollIntoView ? 'absolute' : 'fixed',
9110
+ closeMenuOnScroll: function closeMenuOnScroll(e) {
9111
+ if (menuShouldScrollIntoView || !e.target) {
9112
+ return false;
9113
+ }
9059
9114
 
9060
- return React__default.createElement(Field, Object.assign({}, fieldProps), React__default.createElement(Select__default, Object.assign({
9061
- closeMenuOnSelect: closeOnSelect
9062
- }, selectProps)));
9115
+ return !isScrollingTheSelectMenu(e.target);
9116
+ },
9117
+ isSearchable: isSearchable
9118
+ }));
9063
9119
  };
9064
9120
 
9065
9121
  var styles$_ = {"custom-list":"_uC4zU"};