@7shifts/sous-chef 3.24.0 → 3.26.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
@@ -4591,10 +4591,13 @@ var calculatePercentageOfProportion = function calculatePercentageOfProportion(p
4591
4591
  var ColumnSizes = function ColumnSizes(_ref) {
4592
4592
  var columns = _ref.columns,
4593
4593
  showActionMenu = _ref.showActionMenu;
4594
- var columnPercentageSizes = calculatePercentageOfProportion(columns.map(function (column) {
4594
+ var visibleColumns = columns.filter(function (column) {
4595
+ return !column.hidden;
4596
+ });
4597
+ var columnPercentageSizes = calculatePercentageOfProportion(visibleColumns.map(function (column) {
4595
4598
  return column.size || 1;
4596
4599
  }));
4597
- return React__default.createElement("colgroup", null, columns.map(function (column, index) {
4600
+ return React__default.createElement("colgroup", null, visibleColumns.map(function (column, index) {
4598
4601
  return React__default.createElement("col", {
4599
4602
  key: column.name,
4600
4603
  style: {
@@ -4661,7 +4664,9 @@ var DataTableHeader = function DataTableHeader(_ref) {
4661
4664
  showActionMenu: showActionMenu
4662
4665
  }), React__default.createElement("thead", null, React__default.createElement("tr", {
4663
4666
  className: styles$a['data-table-header']
4664
- }, columns.map(function (column) {
4667
+ }, columns.filter(function (column) {
4668
+ return !column.hidden;
4669
+ }).map(function (column) {
4665
4670
  var _classnames, _classnames2;
4666
4671
 
4667
4672
  var isSortable = column.isSortable;
@@ -7078,6 +7083,11 @@ var DataTableCellElement = function DataTableCellElement(_ref, ref) {
7078
7083
 
7079
7084
  var column = (_columns$columnIndex = columns === null || columns === void 0 ? void 0 : columns[columnIndex]) != null ? _columns$columnIndex : null;
7080
7085
  var isRightAligned = column ? column.isRightAligned : false;
7086
+
7087
+ if (column && column.hidden) {
7088
+ return null;
7089
+ }
7090
+
7081
7091
  var hasError = !!error;
7082
7092
  var errorMessage = error;
7083
7093
  var icon = hasError && React__default.createElement("div", {
@@ -7855,7 +7865,7 @@ function CustomMenu(_ref) {
7855
7865
  }, getLocalizedString('default.CREATE'))))));
7856
7866
  }
7857
7867
 
7858
- var useSelectField = function useSelectField(_ref, isMultiSelect) {
7868
+ var useSelectField = function useSelectField(_ref) {
7859
7869
  var _ref$asToolbarFilter = _ref.asToolbarFilter,
7860
7870
  asToolbarFilter = _ref$asToolbarFilter === void 0 ? false : _ref$asToolbarFilter,
7861
7871
  caption = _ref.caption,
@@ -7883,10 +7893,6 @@ var useSelectField = function useSelectField(_ref, isMultiSelect) {
7883
7893
  _ref$isSearchable = _ref.isSearchable,
7884
7894
  isSearchable = _ref$isSearchable === void 0 ? true : _ref$isSearchable;
7885
7895
 
7886
- if (isMultiSelect === void 0) {
7887
- isMultiSelect = false;
7888
- }
7889
-
7890
7896
  var _useState = React.useState(false),
7891
7897
  isMenuInputFocus = _useState[0],
7892
7898
  setIsMenuInputFocus = _useState[1];
@@ -7944,14 +7950,12 @@ var useSelectField = function useSelectField(_ref, isMultiSelect) {
7944
7950
  placeholder: placeholder,
7945
7951
  styles: getSelectStyles({
7946
7952
  isInvalid: hasError,
7947
- asToolbarFilter: asToolbarFilter,
7948
- wrapToNextLine: isMultiSelect ? true : undefined
7953
+ asToolbarFilter: asToolbarFilter
7949
7954
  }),
7950
7955
  value: controllers.value,
7951
7956
  defaultValue: defaultValue,
7952
7957
  menuIsOpen: isMenuInputFocus || undefined,
7953
- isSearchable: isSearchable,
7954
- isMulti: isMultiSelect
7958
+ isSearchable: isSearchable
7955
7959
  };
7956
7960
  var fieldProps = {
7957
7961
  caption: caption,
@@ -9046,20 +9050,82 @@ var PasswordField = function PasswordField(_ref) {
9046
9050
  }))));
9047
9051
  };
9048
9052
 
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;
9053
+ var MultiSelectField = function MultiSelectField(_ref) {
9054
+ var name = _ref.name,
9055
+ inputId = _ref.id,
9056
+ value = _ref.value,
9057
+ options = _ref.options,
9058
+ onChange = _ref.onChange,
9059
+ onBlur = _ref.onBlur,
9060
+ UserCustomOption = _ref.CustomOption,
9061
+ label = _ref.label,
9062
+ caption = _ref.caption,
9063
+ error = _ref.error,
9064
+ placeholder = _ref.placeholder,
9065
+ noOptionsMessage = _ref.noOptionsMessage,
9066
+ disabled = _ref.disabled,
9067
+ _ref$closeOnSelect = _ref.closeOnSelect,
9068
+ closeOnSelect = _ref$closeOnSelect === void 0 ? false : _ref$closeOnSelect,
9069
+ _ref$menuShouldScroll = _ref.menuShouldScrollIntoView,
9070
+ menuShouldScrollIntoView = _ref$menuShouldScroll === void 0 ? true : _ref$menuShouldScroll,
9071
+ testId = _ref.testId,
9072
+ _ref$isSearchable = _ref.isSearchable,
9073
+ isSearchable = _ref$isSearchable === void 0 ? true : _ref$isSearchable;
9074
+ var controllers = useMultiSelectFieldControllers({
9075
+ name: name,
9076
+ id: inputId,
9077
+ value: value,
9078
+ onChange: onChange,
9079
+ onBlur: onBlur,
9080
+ error: error
9081
+ });
9082
+ var hasError = !!controllers.error;
9083
+ var fieldProps = {
9084
+ name: name,
9085
+ id: controllers.id,
9086
+ label: label,
9087
+ caption: caption,
9088
+ error: controllers.error
9089
+ };
9090
+ var defaultNoOptionsMessage = noOptionsMessage && typeof noOptionsMessage === 'string' ? function () {
9091
+ return noOptionsMessage;
9092
+ } : undefined;
9093
+ return React__default.createElement(Field, Object.assign({}, fieldProps), React__default.createElement(Select__default, {
9094
+ inputId: controllers.id,
9095
+ options: options,
9096
+ isDisabled: disabled,
9097
+ value: controllers.value,
9098
+ placeholder: placeholder,
9099
+ noOptionsMessage: typeof noOptionsMessage === 'function' ? noOptionsMessage : defaultNoOptionsMessage,
9100
+ styles: getSelectStyles({
9101
+ isInvalid: hasError,
9102
+ wrapToNextLine: true
9103
+ }),
9104
+ menuPortalTarget: document.body,
9105
+ onChange: controllers.onChange,
9106
+ onBlur: controllers.onBlur,
9107
+ isMulti: true,
9108
+ closeMenuOnSelect: closeOnSelect,
9109
+ componentsProps: {
9110
+ testId: testId,
9111
+ UserCustomOption: UserCustomOption
9112
+ },
9113
+ components: {
9114
+ SelectContainer: CustomContainer,
9115
+ Option: UserCustomOption ? CustomOption : Select.components.Option
9116
+ },
9117
+ menuShouldScrollIntoView: menuShouldScrollIntoView,
9118
+ menuPlacement: menuShouldScrollIntoView ? 'bottom' : 'auto',
9119
+ menuPosition: menuShouldScrollIntoView ? 'absolute' : 'fixed',
9120
+ closeMenuOnScroll: function closeMenuOnScroll(e) {
9121
+ if (menuShouldScrollIntoView || !e.target) {
9122
+ return false;
9123
+ }
9059
9124
 
9060
- return React__default.createElement(Field, Object.assign({}, fieldProps), React__default.createElement(Select__default, Object.assign({
9061
- closeMenuOnSelect: closeOnSelect
9062
- }, selectProps)));
9125
+ return !isScrollingTheSelectMenu(e.target);
9126
+ },
9127
+ isSearchable: isSearchable
9128
+ }));
9063
9129
  };
9064
9130
 
9065
9131
  var styles$_ = {"custom-list":"_uC4zU"};