@stokr/components-library 2.3.65-beta.6 → 2.3.65-beta.8

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.
@@ -7,9 +7,10 @@ exports.default = exports.Select = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _reactSelect = _interopRequireWildcard(require("react-select"));
10
+ var _creatable = _interopRequireDefault(require("react-select/creatable"));
10
11
  var _Input = require("./Input.styles");
11
12
  var _Select = require("./Select.styles");
12
- const _excluded = ["id", "name", "label", "options", "search", "error", "touched", "value", "disabled", "menuHeight"];
13
+ const _excluded = ["id", "name", "label", "options", "search", "error", "touched", "value", "disabled", "menuHeight", "creatable", "formatCreateLabel"];
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
15
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
15
16
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
@@ -59,7 +60,9 @@ const Select = props => {
59
60
  touched,
60
61
  value,
61
62
  disabled,
62
- menuHeight
63
+ menuHeight,
64
+ creatable,
65
+ formatCreateLabel
63
66
  } = props,
64
67
  otherProps = _objectWithoutProperties(props, _excluded);
65
68
  const [labelUp, setLabelUp] = (0, _react.useState)(!!value);
@@ -72,7 +75,7 @@ const Select = props => {
72
75
  name,
73
76
  value
74
77
  });
75
- if (search) {
78
+ if (search || creatable) {
76
79
  setHasFocus(true);
77
80
  }
78
81
  };
@@ -94,12 +97,46 @@ const Select = props => {
94
97
  setHasFocus(true);
95
98
  }, 1);
96
99
  };
100
+
101
+ // Choose component based on creatable prop
102
+ const SelectComponent = creatable ? _creatable.default : _reactSelect.default;
103
+
104
+ // Common styles for both components
105
+ const selectStyles = {
106
+ control: () => _Select.SelectControl,
107
+ menu: baseStyle => _objectSpread(_objectSpread({}, baseStyle), {}, {
108
+ marginTop: 0,
109
+ zIndex: 1000,
110
+ SelectMenu: _Select.SelectMenu
111
+ }),
112
+ option: (baseStyle, state) => _objectSpread({
113
+ fontWeight: state.isSelected || state.isFocused ? 'bold' : 'normal',
114
+ cursor: 'pointer'
115
+ }, _Select.SelectOption),
116
+ selectContainer: () => _Select.SelectContainer,
117
+ valueContainer: baseStyle => _objectSpread(_objectSpread({}, baseStyle), {}, {
118
+ padding: 0
119
+ })
120
+ };
121
+
122
+ // Common components for both
123
+ const selectComponents = {
124
+ DropdownIndicator,
125
+ IndicatorSeparator: null,
126
+ MenuList: SelectMenuListWithScroll
127
+ };
128
+
129
+ // Get current value - for creatable, also check if value exists even if not in options
130
+ const currentValue = creatable ? (options === null || options === void 0 ? void 0 : options.find(option => option.value === value)) || (value ? {
131
+ value,
132
+ label: value
133
+ } : null) : options === null || options === void 0 ? void 0 : options.find(option => option.value === value);
97
134
  return /*#__PURE__*/_react.default.createElement(_Input.Wrapper, null, label && /*#__PURE__*/_react.default.createElement(_Input.Label, {
98
135
  isUp: labelUp,
99
136
  active: hasFocus,
100
137
  error: error && touched,
101
138
  htmlFor: id
102
- }, label), /*#__PURE__*/_react.default.createElement(_reactSelect.default, _extends({}, otherProps, {
139
+ }, label), /*#__PURE__*/_react.default.createElement(SelectComponent, _extends({}, otherProps, {
103
140
  id: id,
104
141
  name: name,
105
142
  options: options,
@@ -107,32 +144,14 @@ const Select = props => {
107
144
  onChange: onChange,
108
145
  onBlur: onBlur,
109
146
  onFocus: onFocus,
110
- value: options === null || options === void 0 ? void 0 : options.find(option => option.value === value),
147
+ value: currentValue,
111
148
  placeholder: "",
112
- isSearchable: search,
149
+ isSearchable: creatable || search,
113
150
  maxMenuHeight: menuHeight,
114
- styles: {
115
- control: () => _Select.SelectControl,
116
- menu: (baseStyle, state) => _objectSpread(_objectSpread({}, baseStyle), {}, {
117
- marginTop: 0,
118
- zIndex: 1000,
119
- SelectMenu: _Select.SelectMenu
120
- }),
121
- option: (baseStyle, state) => _objectSpread({
122
- fontWeight: state.isSelected || state.isFocused ? 'bold' : 'normal',
123
- cursor: 'pointer'
124
- }, _Select.SelectOption),
125
- selectContainer: () => _Select.SelectContainer,
126
- valueContainer: baseStyle => _objectSpread(_objectSpread({}, baseStyle), {}, {
127
- padding: 0
128
- //marginLeft: '-2px',
129
- })
130
- },
131
- components: {
132
- DropdownIndicator,
133
- IndicatorSeparator: null,
134
- MenuList: SelectMenuListWithScroll
135
- }
151
+ styles: selectStyles,
152
+ components: selectComponents
153
+ }, creatable && {
154
+ formatCreateLabel: formatCreateLabel || (inputValue => "Create \"".concat(inputValue, "\""))
136
155
  })));
137
156
  };
138
157
  exports.Select = Select;
@@ -149,6 +168,8 @@ Select.propTypes = {
149
168
  label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node]).isRequired
150
169
  })).isRequired,
151
170
  search: _propTypes.default.bool,
171
+ creatable: _propTypes.default.bool,
172
+ formatCreateLabel: _propTypes.default.func,
152
173
  onChange: _propTypes.default.func,
153
174
  onBlur: _propTypes.default.func,
154
175
  onFocus: _propTypes.default.func
@@ -157,6 +178,8 @@ Select.defaultProps = {
157
178
  label: '',
158
179
  value: '',
159
180
  search: false,
181
+ creatable: false,
182
+ formatCreateLabel: null,
160
183
  error: false,
161
184
  touched: false,
162
185
  onChange: () => {},
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.SelectOptionStrings = exports.SelectOptionNodes = exports.SelectEmpty = void 0;
7
- var _react = _interopRequireDefault(require("react"));
6
+ exports.default = exports.SelectOptionStrings = exports.SelectOptionNodes = exports.SelectEmpty = exports.Searchable = exports.NotSearchable = exports.CreatableCustomLabel = exports.Creatable = exports.AllStates = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
8
  var _Select = require("./Select");
9
9
  var _ComponentWrapper = require("../ComponentWrapper/ComponentWrapper.styles");
10
10
  var _Medium = require("../icons/Medium");
@@ -12,9 +12,12 @@ var _Share = require("../icons/Share");
12
12
  var _Number = require("../Number/Number");
13
13
  var _global = _interopRequireDefault(require("../../styles/global"));
14
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
15
17
  var _default = exports.default = {
16
18
  title: 'Components Library/Inputs/Select',
17
19
  component: _Select.Select,
20
+ decorators: [Story => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_global.default, null), /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, null, /*#__PURE__*/_react.default.createElement(Story, null)))],
18
21
  argTypes: {
19
22
  id: {
20
23
  type: 'string',
@@ -55,7 +58,6 @@ var _default = exports.default = {
55
58
  }],
56
59
  required: true
57
60
  },
58
- // { required: true },
59
61
  search: {
60
62
  type: 'boolean',
61
63
  defaultValue: false
@@ -79,8 +81,21 @@ var _default = exports.default = {
79
81
  type: 'function'
80
82
  }
81
83
  }
84
+ }; // Controlled wrapper for interactive stories
85
+ const ControlledSelect = props => {
86
+ const [value, setValue] = (0, _react.useState)(props.value || '');
87
+ return /*#__PURE__*/_react.default.createElement(_Select.Select, _extends({}, props, {
88
+ value: value,
89
+ onChange: _ref => {
90
+ let {
91
+ value: newValue
92
+ } = _ref;
93
+ setValue(newValue);
94
+ console.log('Selected:', newValue);
95
+ }
96
+ }));
82
97
  };
83
- const Template = args => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_global.default, null), /*#__PURE__*/_react.default.createElement(_ComponentWrapper.ComponentWrapper, null, /*#__PURE__*/_react.default.createElement(_Select.Select, args)));
98
+ const Template = args => /*#__PURE__*/_react.default.createElement(ControlledSelect, args);
84
99
  const SelectOptionStrings = exports.SelectOptionStrings = Template.bind({});
85
100
  SelectOptionStrings.args = {
86
101
  label: 'click LABEL here for options',
@@ -134,6 +149,330 @@ SelectOptionNodes.args = {
134
149
  const SelectEmpty = exports.SelectEmpty = Template.bind({});
135
150
  SelectEmpty.args = {};
136
151
 
137
- //doublecheck:
152
+ // Searchable Select - type to filter options
153
+ const Searchable = () => {
154
+ const [value, setValue] = (0, _react.useState)('');
155
+ const countryOptions = [{
156
+ key: 'us',
157
+ value: 'us',
158
+ label: 'United States'
159
+ }, {
160
+ key: 'uk',
161
+ value: 'uk',
162
+ label: 'United Kingdom'
163
+ }, {
164
+ key: 'de',
165
+ value: 'de',
166
+ label: 'Germany'
167
+ }, {
168
+ key: 'fr',
169
+ value: 'fr',
170
+ label: 'France'
171
+ }, {
172
+ key: 'es',
173
+ value: 'es',
174
+ label: 'Spain'
175
+ }, {
176
+ key: 'it',
177
+ value: 'it',
178
+ label: 'Italy'
179
+ }, {
180
+ key: 'nl',
181
+ value: 'nl',
182
+ label: 'Netherlands'
183
+ }, {
184
+ key: 'ch',
185
+ value: 'ch',
186
+ label: 'Switzerland'
187
+ }, {
188
+ key: 'at',
189
+ value: 'at',
190
+ label: 'Austria'
191
+ }, {
192
+ key: 'be',
193
+ value: 'be',
194
+ label: 'Belgium'
195
+ }];
196
+ return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h4", {
197
+ style: {
198
+ marginBottom: '16px',
199
+ fontSize: '14px'
200
+ }
201
+ }, "Type to filter options (try typing \"United\" or \"Ger\")"), /*#__PURE__*/_react.default.createElement(_Select.Select, {
202
+ id: "country",
203
+ name: "country",
204
+ label: "Select Country",
205
+ options: countryOptions,
206
+ value: value,
207
+ search: true,
208
+ onChange: _ref2 => {
209
+ let {
210
+ value: newValue
211
+ } = _ref2;
212
+ return setValue(newValue);
213
+ }
214
+ }), /*#__PURE__*/_react.default.createElement("p", {
215
+ style: {
216
+ marginTop: '12px',
217
+ fontSize: '12px',
218
+ color: '#666'
219
+ }
220
+ }, "Selected: ", /*#__PURE__*/_react.default.createElement("strong", null, value || '(none)')));
221
+ };
222
+
223
+ // Not Searchable (default)
224
+ exports.Searchable = Searchable;
225
+ const NotSearchable = () => {
226
+ const [value, setValue] = (0, _react.useState)('');
227
+ const options = [{
228
+ key: 'opt1',
229
+ value: 'option1',
230
+ label: 'Option 1'
231
+ }, {
232
+ key: 'opt2',
233
+ value: 'option2',
234
+ label: 'Option 2'
235
+ }, {
236
+ key: 'opt3',
237
+ value: 'option3',
238
+ label: 'Option 3'
239
+ }];
240
+ return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h4", {
241
+ style: {
242
+ marginBottom: '16px',
243
+ fontSize: '14px'
244
+ }
245
+ }, "Click to open, no typing (search=false)"), /*#__PURE__*/_react.default.createElement(_Select.Select, {
246
+ id: "basic",
247
+ name: "basic",
248
+ label: "Select Option",
249
+ options: options,
250
+ value: value,
251
+ search: false,
252
+ onChange: _ref3 => {
253
+ let {
254
+ value: newValue
255
+ } = _ref3;
256
+ return setValue(newValue);
257
+ }
258
+ }), /*#__PURE__*/_react.default.createElement("p", {
259
+ style: {
260
+ marginTop: '12px',
261
+ fontSize: '12px',
262
+ color: '#666'
263
+ }
264
+ }, "Selected: ", /*#__PURE__*/_react.default.createElement("strong", null, value || '(none)')));
265
+ };
138
266
 
139
- //why is value not showing? (it does move the label up) (label down on blur, even if field is filled)
267
+ // All States
268
+ exports.NotSearchable = NotSearchable;
269
+ const AllStates = () => {
270
+ const [value1, setValue1] = (0, _react.useState)('');
271
+ const [value2, setValue2] = (0, _react.useState)('de');
272
+ const [value3, setValue3] = (0, _react.useState)('');
273
+ const options = [{
274
+ key: 'us',
275
+ value: 'us',
276
+ label: 'United States'
277
+ }, {
278
+ key: 'uk',
279
+ value: 'uk',
280
+ label: 'United Kingdom'
281
+ }, {
282
+ key: 'de',
283
+ value: 'de',
284
+ label: 'Germany'
285
+ }, {
286
+ key: 'fr',
287
+ value: 'fr',
288
+ label: 'France'
289
+ }];
290
+ return /*#__PURE__*/_react.default.createElement("div", {
291
+ style: {
292
+ display: 'flex',
293
+ flexDirection: 'column',
294
+ gap: '32px'
295
+ }
296
+ }, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h4", {
297
+ style: {
298
+ marginBottom: '8px',
299
+ fontSize: '12px',
300
+ color: '#666'
301
+ }
302
+ }, "Empty with search"), /*#__PURE__*/_react.default.createElement(_Select.Select, {
303
+ id: "empty",
304
+ name: "empty",
305
+ label: "Country",
306
+ options: options,
307
+ value: value1,
308
+ search: true,
309
+ onChange: _ref4 => {
310
+ let {
311
+ value
312
+ } = _ref4;
313
+ return setValue1(value);
314
+ }
315
+ })), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h4", {
316
+ style: {
317
+ marginBottom: '8px',
318
+ fontSize: '12px',
319
+ color: '#666'
320
+ }
321
+ }, "Pre-selected value"), /*#__PURE__*/_react.default.createElement(_Select.Select, {
322
+ id: "preselected",
323
+ name: "preselected",
324
+ label: "Country",
325
+ options: options,
326
+ value: value2,
327
+ search: true,
328
+ onChange: _ref5 => {
329
+ let {
330
+ value
331
+ } = _ref5;
332
+ return setValue2(value);
333
+ }
334
+ })), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h4", {
335
+ style: {
336
+ marginBottom: '8px',
337
+ fontSize: '12px',
338
+ color: '#666'
339
+ }
340
+ }, "Disabled"), /*#__PURE__*/_react.default.createElement(_Select.Select, {
341
+ id: "disabled",
342
+ name: "disabled",
343
+ label: "Country",
344
+ options: options,
345
+ value: "uk",
346
+ disabled: true,
347
+ onChange: () => {}
348
+ })), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h4", {
349
+ style: {
350
+ marginBottom: '8px',
351
+ fontSize: '12px',
352
+ color: '#666'
353
+ }
354
+ }, "Error state"), /*#__PURE__*/_react.default.createElement(_Select.Select, {
355
+ id: "error",
356
+ name: "error",
357
+ label: "Country",
358
+ options: options,
359
+ value: value3,
360
+ error: true,
361
+ touched: true,
362
+ onChange: _ref6 => {
363
+ let {
364
+ value
365
+ } = _ref6;
366
+ return setValue3(value);
367
+ }
368
+ })));
369
+ };
370
+
371
+ // Creatable - type to add custom options
372
+ exports.AllStates = AllStates;
373
+ const Creatable = () => {
374
+ const [value, setValue] = (0, _react.useState)('');
375
+ const [options, setOptions] = (0, _react.useState)([{
376
+ key: 'react',
377
+ value: 'react',
378
+ label: 'React'
379
+ }, {
380
+ key: 'vue',
381
+ value: 'vue',
382
+ label: 'Vue'
383
+ }, {
384
+ key: 'angular',
385
+ value: 'angular',
386
+ label: 'Angular'
387
+ }, {
388
+ key: 'svelte',
389
+ value: 'svelte',
390
+ label: 'Svelte'
391
+ }]);
392
+ const handleChange = _ref7 => {
393
+ let {
394
+ value: newValue
395
+ } = _ref7;
396
+ setValue(newValue);
397
+ // Add new option to the list if it doesn't exist
398
+ if (!options.find(opt => opt.value === newValue)) {
399
+ setOptions([...options, {
400
+ key: newValue,
401
+ value: newValue,
402
+ label: newValue
403
+ }]);
404
+ }
405
+ };
406
+ return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h4", {
407
+ style: {
408
+ marginBottom: '16px',
409
+ fontSize: '14px'
410
+ }
411
+ }, "Type to search or create a new option (try typing \"Next.js\")"), /*#__PURE__*/_react.default.createElement(_Select.Select, {
412
+ id: "framework",
413
+ name: "framework",
414
+ label: "Framework",
415
+ options: options,
416
+ value: value,
417
+ creatable: true,
418
+ onChange: handleChange
419
+ }), /*#__PURE__*/_react.default.createElement("p", {
420
+ style: {
421
+ marginTop: '12px',
422
+ fontSize: '12px',
423
+ color: '#666'
424
+ }
425
+ }, "Selected: ", /*#__PURE__*/_react.default.createElement("strong", null, value || '(none)')), /*#__PURE__*/_react.default.createElement("p", {
426
+ style: {
427
+ marginTop: '8px',
428
+ fontSize: '12px',
429
+ color: '#666'
430
+ }
431
+ }, "Options: ", options.map(o => o.label).join(', ')));
432
+ };
433
+
434
+ // Creatable with custom label
435
+ exports.Creatable = Creatable;
436
+ const CreatableCustomLabel = () => {
437
+ const [value, setValue] = (0, _react.useState)('');
438
+ const tagOptions = [{
439
+ key: 'bug',
440
+ value: 'bug',
441
+ label: 'Bug'
442
+ }, {
443
+ key: 'feature',
444
+ value: 'feature',
445
+ label: 'Feature'
446
+ }, {
447
+ key: 'docs',
448
+ value: 'docs',
449
+ label: 'Documentation'
450
+ }];
451
+ return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h4", {
452
+ style: {
453
+ marginBottom: '16px',
454
+ fontSize: '14px'
455
+ }
456
+ }, "Custom \"create\" label format"), /*#__PURE__*/_react.default.createElement(_Select.Select, {
457
+ id: "tag",
458
+ name: "tag",
459
+ label: "Add Tag",
460
+ options: tagOptions,
461
+ value: value,
462
+ creatable: true,
463
+ formatCreateLabel: inputValue => "+ Add new tag: ".concat(inputValue),
464
+ onChange: _ref8 => {
465
+ let {
466
+ value: newValue
467
+ } = _ref8;
468
+ return setValue(newValue);
469
+ }
470
+ }), /*#__PURE__*/_react.default.createElement("p", {
471
+ style: {
472
+ marginTop: '12px',
473
+ fontSize: '12px',
474
+ color: '#666'
475
+ }
476
+ }, "Selected: ", /*#__PURE__*/_react.default.createElement("strong", null, value || '(none)')));
477
+ };
478
+ exports.CreatableCustomLabel = CreatableCustomLabel;
@@ -29,7 +29,8 @@ const ProfileBox = _ref => {
29
29
  return /*#__PURE__*/_react.default.createElement(_ProfileBox.Container, null, /*#__PURE__*/_react.default.createElement(_ProfileBox.ImageWrapper, null, /*#__PURE__*/_react.default.createElement(_Background.default, {
30
30
  src: pictureSrc
31
31
  })), /*#__PURE__*/_react.default.createElement(_ProfileBox.EditButton, {
32
- onClick: handleEdit
32
+ onClick: handleEdit,
33
+ "data-cy": "edit-button-profile-box"
33
34
  }, /*#__PURE__*/_react.default.createElement(_ComponentWrapper.default, null, /*#__PURE__*/_react.default.createElement(_ProfileBox.Name, {
34
35
  style: _objectSpread(_objectSpread({}, lineBreaker), nameStyle)
35
36
  }, name, withEditButton && /*#__PURE__*/_react.default.createElement(_ProfileBox.EditIcon, null)))));