@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.
@@ -6215,6 +6215,9 @@ var SelectField$1 = {
6215
6215
  createOption: "Create option",
6216
6216
  createButton: "Create"
6217
6217
  };
6218
+ var PillSelectField$1 = {
6219
+ enterOption: "Enter an option"
6220
+ };
6218
6221
  var HintModal$1 = {
6219
6222
  dontShowAgainLabel: "Don't remind me again"
6220
6223
  };
@@ -6256,6 +6259,7 @@ var en = {
6256
6259
  PaginationControls: PaginationControls$1,
6257
6260
  AsyncSelectField: AsyncSelectField$1,
6258
6261
  SelectField: SelectField$1,
6262
+ PillSelectField: PillSelectField$1,
6259
6263
  HintModal: HintModal$1,
6260
6264
  Calendar: Calendar$1,
6261
6265
  Card: Card$1,
@@ -11097,7 +11101,7 @@ const TextFieldElement = (_ref, ref) => {
11097
11101
  };
11098
11102
  const TextField = forwardRef(TextFieldElement);
11099
11103
 
11100
- var styles$j = {"pill-select-field":"_Yti6k","pill-select-field__custom-input":"_JXakU"};
11104
+ 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"};
11101
11105
 
11102
11106
  const useMultiSelectFieldControllers = ({
11103
11107
  name,
@@ -11143,6 +11147,67 @@ const useMultiSelectFieldControllers = ({
11143
11147
  return controllers;
11144
11148
  };
11145
11149
 
11150
+ /** CreatableOption element for PillSelectField. */
11151
+ const CreatableOption = ({
11152
+ name,
11153
+ createOptionLabel,
11154
+ onCreate,
11155
+ testId
11156
+ }) => {
11157
+ const __ = useTranslation('PillSelectField');
11158
+ const [isCreatingOption, setIsCreatingOption] = useState(false);
11159
+ const [newOptionLabel, setNewOptionLabel] = useState('');
11160
+ const createOption = () => {
11161
+ if (onCreate) {
11162
+ onCreate(newOptionLabel);
11163
+ }
11164
+ setNewOptionLabel('');
11165
+ setIsCreatingOption(false);
11166
+ };
11167
+ return React__default.createElement(React__default.Fragment, null, !isCreatingOption && React__default.createElement("div", {
11168
+ key: 'pill-select-field-create-option',
11169
+ className: styles$j['pill-select-field']
11170
+ }, React__default.createElement("button", {
11171
+ "data-testid": testId ? `${testId}-create-option` : undefined,
11172
+ className: styles$j['pill-select-field__add-new-input'],
11173
+ onClick: () => {
11174
+ setIsCreatingOption(true);
11175
+ setNewOptionLabel('');
11176
+ }
11177
+ }, React__default.createElement(IconPlus, {
11178
+ size: "small"
11179
+ }), createOptionLabel)), isCreatingOption && React__default.createElement("div", {
11180
+ key: 'pill-select-field-creating-option',
11181
+ className: styles$j['pill-select-field']
11182
+ }, React__default.createElement("input", {
11183
+ className: styles$j['pill-select-field__creating-input'],
11184
+ name: `${name}-pill-select-field-creating-option`,
11185
+ id: 'pill-select-field-creating-option',
11186
+ type: "text",
11187
+ autoFocus: true,
11188
+ "data-testid": testId ? `${testId}-creating-option` : undefined,
11189
+ value: newOptionLabel,
11190
+ onChange: e => setNewOptionLabel(e.target.value),
11191
+ onBlur: () => {
11192
+ createOption();
11193
+ },
11194
+ onClick: createOption,
11195
+ onKeyDown: e => {
11196
+ if (e.key === 'Enter') {
11197
+ createOption();
11198
+ } else if (e.key === 'Escape') {
11199
+ setIsCreatingOption(false);
11200
+ setNewOptionLabel('');
11201
+ }
11202
+ }
11203
+ }), React__default.createElement("span", {
11204
+ className: styles$j['pill-select-field__creating-custom-input']
11205
+ }, !newOptionLabel && React__default.createElement(Text, {
11206
+ as: "body",
11207
+ color: "grey-300"
11208
+ }, __('enterOption')), !!newOptionLabel && newOptionLabel)));
11209
+ };
11210
+
11146
11211
  /** PillSelectField form element. */
11147
11212
  const PillSelectField = ({
11148
11213
  name,
@@ -11154,7 +11219,10 @@ const PillSelectField = ({
11154
11219
  caption,
11155
11220
  error,
11156
11221
  disabled,
11157
- testId
11222
+ testId,
11223
+ onCreate,
11224
+ onRemoveOption,
11225
+ createOptionLabel
11158
11226
  }) => {
11159
11227
  const controllers = useMultiSelectFieldControllers({
11160
11228
  name,
@@ -11171,9 +11239,28 @@ const PillSelectField = ({
11171
11239
  caption,
11172
11240
  error: controllers.error
11173
11241
  };
11242
+ const RemoveButton = ({
11243
+ option
11244
+ }) => {
11245
+ const handleClick = () => {
11246
+ if (controllers.value) {
11247
+ var _controllers$value;
11248
+ controllers.onChange((_controllers$value = controllers.value) == null ? void 0 : _controllers$value.filter(o => o.value !== option.value));
11249
+ }
11250
+ if (option.isRemovable && onRemoveOption) {
11251
+ onRemoveOption(options.filter(x => x.value !== option.value));
11252
+ }
11253
+ };
11254
+ return React__default.createElement("button", {
11255
+ className: styles$j['pill-select-field__removable-icon'],
11256
+ onClick: handleClick
11257
+ }, React__default.createElement(IconTimes, {
11258
+ size: "small"
11259
+ }));
11260
+ };
11174
11261
  return React__default.createElement(Field, _extends({}, fieldProps), React__default.createElement(Inline, {
11175
11262
  flexWrap: "wrap",
11176
- space: 12
11263
+ space: 8
11177
11264
  }, options.map((option, key) => {
11178
11265
  const selectedItemIndex = (controllers.value || []).findIndex(val => val.value === option.value);
11179
11266
  const isChecked = selectedItemIndex >= 0;
@@ -11202,7 +11289,14 @@ const PillSelectField = ({
11202
11289
  }
11203
11290
  }), React__default.createElement("span", {
11204
11291
  className: styles$j['pill-select-field__custom-input']
11205
- }, option.label));
11292
+ }, option.label, option.isRemovable && React__default.createElement(RemoveButton, {
11293
+ option: option
11294
+ })));
11295
+ }), createOptionLabel && React__default.createElement(CreatableOption, {
11296
+ name: name,
11297
+ testId: testId,
11298
+ onCreate: onCreate,
11299
+ createOptionLabel: createOptionLabel
11206
11300
  })));
11207
11301
  };
11208
11302