@7shifts/sous-chef 3.68.0 → 3.69.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.
package/dist/index.js CHANGED
@@ -6070,6 +6070,9 @@ var SelectField$1 = {
6070
6070
  createOption: "Create option",
6071
6071
  createButton: "Create"
6072
6072
  };
6073
+ var PillSelectField$1 = {
6074
+ enterOption: "Enter an option"
6075
+ };
6073
6076
  var HintModal$1 = {
6074
6077
  dontShowAgainLabel: "Don't remind me again"
6075
6078
  };
@@ -6111,6 +6114,7 @@ var en = {
6111
6114
  PaginationControls: PaginationControls$1,
6112
6115
  AsyncSelectField: AsyncSelectField$1,
6113
6116
  SelectField: SelectField$1,
6117
+ PillSelectField: PillSelectField$1,
6114
6118
  HintModal: HintModal$1,
6115
6119
  Calendar: Calendar$1,
6116
6120
  Card: Card$1,
@@ -10931,7 +10935,7 @@ var TextFieldElement = function TextFieldElement(_ref, ref) {
10931
10935
  };
10932
10936
  var TextField = React.forwardRef(TextFieldElement);
10933
10937
 
10934
- var styles$j = {"pill-select-field":"_Yti6k","pill-select-field__custom-input":"_JXakU"};
10938
+ var styles$j = {"pill-select-field":"_Yti6k","pill-select-field__creating-input":"_dw-VP","pill-select-field__custom-input":"_JXakU","pill-select-field__add-new-input":"_MsKVV","pill-select-field__creating-custom-input":"_ZxEwG","pill-select-field__removable-icon":"_Odw1V"};
10935
10939
 
10936
10940
  var useMultiSelectFieldControllers = function useMultiSelectFieldControllers(_ref) {
10937
10941
  var name = _ref.name,
@@ -10979,6 +10983,72 @@ var useMultiSelectFieldControllers = function useMultiSelectFieldControllers(_re
10979
10983
  return controllers;
10980
10984
  };
10981
10985
 
10986
+ /** CreatableOption element for PillSelectField. */
10987
+ var CreatableOption = function CreatableOption(_ref) {
10988
+ var name = _ref.name,
10989
+ createOptionLabel = _ref.createOptionLabel,
10990
+ onCreate = _ref.onCreate,
10991
+ testId = _ref.testId;
10992
+ var __ = useTranslation('PillSelectField');
10993
+ var _useState = React.useState(false),
10994
+ isCreatingOption = _useState[0],
10995
+ setIsCreatingOption = _useState[1];
10996
+ var _useState2 = React.useState(''),
10997
+ newOptionLabel = _useState2[0],
10998
+ setNewOptionLabel = _useState2[1];
10999
+ var createOption = function createOption() {
11000
+ if (onCreate) {
11001
+ onCreate(newOptionLabel);
11002
+ }
11003
+ setNewOptionLabel('');
11004
+ setIsCreatingOption(false);
11005
+ };
11006
+ return React__default["default"].createElement(React__default["default"].Fragment, null, !isCreatingOption && React__default["default"].createElement("div", {
11007
+ key: 'pill-select-field-create-option',
11008
+ className: styles$j['pill-select-field']
11009
+ }, React__default["default"].createElement("button", {
11010
+ "data-testid": testId ? testId + "-create-option" : undefined,
11011
+ className: styles$j['pill-select-field__add-new-input'],
11012
+ onClick: function onClick() {
11013
+ setIsCreatingOption(true);
11014
+ setNewOptionLabel('');
11015
+ }
11016
+ }, React__default["default"].createElement(IconPlus, {
11017
+ size: "small"
11018
+ }), createOptionLabel)), isCreatingOption && React__default["default"].createElement("div", {
11019
+ key: 'pill-select-field-creating-option',
11020
+ className: styles$j['pill-select-field']
11021
+ }, React__default["default"].createElement("input", {
11022
+ className: styles$j['pill-select-field__creating-input'],
11023
+ name: name + "-pill-select-field-creating-option",
11024
+ id: 'pill-select-field-creating-option',
11025
+ type: "text",
11026
+ autoFocus: true,
11027
+ "data-testid": testId ? testId + "-creating-option" : undefined,
11028
+ value: newOptionLabel,
11029
+ onChange: function onChange(e) {
11030
+ return setNewOptionLabel(e.target.value);
11031
+ },
11032
+ onBlur: function onBlur() {
11033
+ createOption();
11034
+ },
11035
+ onClick: createOption,
11036
+ onKeyDown: function onKeyDown(e) {
11037
+ if (e.key === 'Enter') {
11038
+ createOption();
11039
+ } else if (e.key === 'Escape') {
11040
+ setIsCreatingOption(false);
11041
+ setNewOptionLabel('');
11042
+ }
11043
+ }
11044
+ }), React__default["default"].createElement("span", {
11045
+ className: styles$j['pill-select-field__creating-custom-input']
11046
+ }, !newOptionLabel && React__default["default"].createElement(Text, {
11047
+ as: "body",
11048
+ color: "grey-300"
11049
+ }, __('enterOption')), !!newOptionLabel && newOptionLabel)));
11050
+ };
11051
+
10982
11052
  /** PillSelectField form element. */
10983
11053
  var PillSelectField = function PillSelectField(_ref) {
10984
11054
  var name = _ref.name,
@@ -10990,7 +11060,10 @@ var PillSelectField = function PillSelectField(_ref) {
10990
11060
  caption = _ref.caption,
10991
11061
  error = _ref.error,
10992
11062
  disabled = _ref.disabled,
10993
- testId = _ref.testId;
11063
+ testId = _ref.testId,
11064
+ onCreate = _ref.onCreate,
11065
+ onRemoveOption = _ref.onRemoveOption,
11066
+ createOptionLabel = _ref.createOptionLabel;
10994
11067
  var controllers = useMultiSelectFieldControllers({
10995
11068
  name: name,
10996
11069
  id: inputId,
@@ -11006,9 +11079,31 @@ var PillSelectField = function PillSelectField(_ref) {
11006
11079
  caption: caption,
11007
11080
  error: controllers.error
11008
11081
  };
11082
+ var RemoveButton = function RemoveButton(_ref2) {
11083
+ var option = _ref2.option;
11084
+ var handleClick = function handleClick() {
11085
+ if (controllers.value) {
11086
+ var _controllers$value;
11087
+ controllers.onChange((_controllers$value = controllers.value) == null ? void 0 : _controllers$value.filter(function (o) {
11088
+ return o.value !== option.value;
11089
+ }));
11090
+ }
11091
+ if (option.isRemovable && onRemoveOption) {
11092
+ onRemoveOption(options.filter(function (x) {
11093
+ return x.value !== option.value;
11094
+ }));
11095
+ }
11096
+ };
11097
+ return React__default["default"].createElement("button", {
11098
+ className: styles$j['pill-select-field__removable-icon'],
11099
+ onClick: handleClick
11100
+ }, React__default["default"].createElement(IconTimes, {
11101
+ size: "small"
11102
+ }));
11103
+ };
11009
11104
  return React__default["default"].createElement(Field, _extends({}, fieldProps), React__default["default"].createElement(Inline, {
11010
11105
  flexWrap: "wrap",
11011
- space: 12
11106
+ space: 8
11012
11107
  }, options.map(function (option, key) {
11013
11108
  var selectedItemIndex = (controllers.value || []).findIndex(function (val) {
11014
11109
  return val.value === option.value;
@@ -11039,7 +11134,14 @@ var PillSelectField = function PillSelectField(_ref) {
11039
11134
  }
11040
11135
  }), React__default["default"].createElement("span", {
11041
11136
  className: styles$j['pill-select-field__custom-input']
11042
- }, option.label));
11137
+ }, option.label, option.isRemovable && React__default["default"].createElement(RemoveButton, {
11138
+ option: option
11139
+ })));
11140
+ }), createOptionLabel && React__default["default"].createElement(CreatableOption, {
11141
+ name: name,
11142
+ testId: testId,
11143
+ onCreate: onCreate,
11144
+ createOptionLabel: createOptionLabel
11043
11145
  })));
11044
11146
  };
11045
11147