@stokr/components-library 2.3.65-beta.7 → 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.
- package/dist/components/Input/Input.js +33 -33
- package/dist/components/Input/Input.stories.js +83 -8
- package/dist/components/Input/Select.js +51 -28
- package/dist/components/Input/Select.stories.js +345 -6
- package/dist/components/ProfileBox/ProfileBox.js +2 -1
- package/dist/components/Snackbar/Snackbar.js +193 -0
- package/dist/components/Snackbar/Snackbar.stories.js +292 -0
- package/dist/components/Snackbar/Snackbar.styles.js +97 -0
- package/dist/components/Snackbar/SnackbarProvider.js +81 -0
- package/dist/components/Snackbar/index.js +32 -0
- package/dist/components/Snackbar/useSnackbar.js +43 -0
- package/dist/index.js +11 -0
- package/package.json +1 -1
|
@@ -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 =
|
|
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(
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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)))));
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.Snackbar = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _reactDom = require("react-dom");
|
|
9
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
|
+
var _Snackbar = require("./Snackbar.styles");
|
|
11
|
+
var _crossIcon = require("../../static/images/cross-icon.svg");
|
|
12
|
+
var _warningFilled = require("../../static/images/warning-filled.svg");
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
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
|
+
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); } // Import existing SVG icons
|
|
16
|
+
// Info icon - circled "i" (not available in library, matching design)
|
|
17
|
+
const InfoIcon = () => /*#__PURE__*/_react.default.createElement("svg", {
|
|
18
|
+
viewBox: "0 0 24 24",
|
|
19
|
+
fill: "none",
|
|
20
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
21
|
+
}, /*#__PURE__*/_react.default.createElement("circle", {
|
|
22
|
+
cx: "12",
|
|
23
|
+
cy: "12",
|
|
24
|
+
r: "10",
|
|
25
|
+
stroke: "currentColor",
|
|
26
|
+
strokeWidth: "2"
|
|
27
|
+
}), /*#__PURE__*/_react.default.createElement("line", {
|
|
28
|
+
x1: "12",
|
|
29
|
+
y1: "16",
|
|
30
|
+
x2: "12",
|
|
31
|
+
y2: "12",
|
|
32
|
+
stroke: "currentColor",
|
|
33
|
+
strokeWidth: "2",
|
|
34
|
+
strokeLinecap: "round"
|
|
35
|
+
}), /*#__PURE__*/_react.default.createElement("circle", {
|
|
36
|
+
cx: "12",
|
|
37
|
+
cy: "8",
|
|
38
|
+
r: "1",
|
|
39
|
+
fill: "currentColor"
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
// Error icon - circled "!" (not available in library, matching design)
|
|
43
|
+
const ErrorIcon = () => /*#__PURE__*/_react.default.createElement("svg", {
|
|
44
|
+
viewBox: "0 0 24 24",
|
|
45
|
+
fill: "none",
|
|
46
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
47
|
+
}, /*#__PURE__*/_react.default.createElement("circle", {
|
|
48
|
+
cx: "12",
|
|
49
|
+
cy: "12",
|
|
50
|
+
r: "10",
|
|
51
|
+
stroke: "currentColor",
|
|
52
|
+
strokeWidth: "2"
|
|
53
|
+
}), /*#__PURE__*/_react.default.createElement("line", {
|
|
54
|
+
x1: "12",
|
|
55
|
+
y1: "8",
|
|
56
|
+
x2: "12",
|
|
57
|
+
y2: "12",
|
|
58
|
+
stroke: "currentColor",
|
|
59
|
+
strokeWidth: "2",
|
|
60
|
+
strokeLinecap: "round"
|
|
61
|
+
}), /*#__PURE__*/_react.default.createElement("circle", {
|
|
62
|
+
cx: "12",
|
|
63
|
+
cy: "16",
|
|
64
|
+
r: "1",
|
|
65
|
+
fill: "currentColor"
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
// Success icon wrapper - adds circle around check icon
|
|
69
|
+
const SuccessIcon = () => /*#__PURE__*/_react.default.createElement("svg", {
|
|
70
|
+
viewBox: "0 0 24 24",
|
|
71
|
+
fill: "none",
|
|
72
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
73
|
+
}, /*#__PURE__*/_react.default.createElement("circle", {
|
|
74
|
+
cx: "12",
|
|
75
|
+
cy: "12",
|
|
76
|
+
r: "10",
|
|
77
|
+
stroke: "currentColor",
|
|
78
|
+
strokeWidth: "2"
|
|
79
|
+
}), /*#__PURE__*/_react.default.createElement("path", {
|
|
80
|
+
d: "M8 12L10.5 14.5L16 9",
|
|
81
|
+
stroke: "currentColor",
|
|
82
|
+
strokeWidth: "2",
|
|
83
|
+
strokeLinecap: "round",
|
|
84
|
+
strokeLinejoin: "round"
|
|
85
|
+
}));
|
|
86
|
+
const defaultIcons = {
|
|
87
|
+
info: /*#__PURE__*/_react.default.createElement(InfoIcon, null),
|
|
88
|
+
error: /*#__PURE__*/_react.default.createElement(ErrorIcon, null),
|
|
89
|
+
success: /*#__PURE__*/_react.default.createElement(SuccessIcon, null),
|
|
90
|
+
warning: /*#__PURE__*/_react.default.createElement(_warningFilled.ReactComponent, null)
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Individual Snackbar item component
|
|
95
|
+
*/
|
|
96
|
+
const SnackbarItem = _ref => {
|
|
97
|
+
let {
|
|
98
|
+
id,
|
|
99
|
+
message,
|
|
100
|
+
variant = 'info',
|
|
101
|
+
icon,
|
|
102
|
+
onClick,
|
|
103
|
+
onClose,
|
|
104
|
+
duration = 5000
|
|
105
|
+
} = _ref;
|
|
106
|
+
const [isExiting, setIsExiting] = (0, _react.useState)(false);
|
|
107
|
+
const handleClose = (0, _react.useCallback)(() => {
|
|
108
|
+
setIsExiting(true);
|
|
109
|
+
setTimeout(() => {
|
|
110
|
+
onClose(id);
|
|
111
|
+
}, 300); // Match animation duration
|
|
112
|
+
}, [id, onClose]);
|
|
113
|
+
(0, _react.useEffect)(() => {
|
|
114
|
+
if (duration === 'permanent' || duration === 0) return;
|
|
115
|
+
const timer = setTimeout(() => {
|
|
116
|
+
handleClose();
|
|
117
|
+
}, duration);
|
|
118
|
+
return () => clearTimeout(timer);
|
|
119
|
+
}, [duration, handleClose]);
|
|
120
|
+
const handleClick = () => {
|
|
121
|
+
if (onClick) {
|
|
122
|
+
onClick();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const displayIcon = icon !== undefined ? icon : defaultIcons[variant];
|
|
126
|
+
return /*#__PURE__*/_react.default.createElement(_Snackbar.SnackbarWrapper, {
|
|
127
|
+
$variant: variant,
|
|
128
|
+
$isExiting: isExiting,
|
|
129
|
+
$hasClick: !!onClick,
|
|
130
|
+
onClick: onClick ? handleClick : undefined
|
|
131
|
+
}, displayIcon && /*#__PURE__*/_react.default.createElement(_Snackbar.IconWrapper, {
|
|
132
|
+
$variant: variant
|
|
133
|
+
}, displayIcon), /*#__PURE__*/_react.default.createElement(_Snackbar.Message, null, message), /*#__PURE__*/_react.default.createElement(_Snackbar.CloseButton, {
|
|
134
|
+
onClick: e => {
|
|
135
|
+
e.stopPropagation();
|
|
136
|
+
handleClose();
|
|
137
|
+
},
|
|
138
|
+
"aria-label": "Close"
|
|
139
|
+
}, /*#__PURE__*/_react.default.createElement(_crossIcon.ReactComponent, null)));
|
|
140
|
+
};
|
|
141
|
+
SnackbarItem.propTypes = {
|
|
142
|
+
id: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]).isRequired,
|
|
143
|
+
message: _propTypes.default.node.isRequired,
|
|
144
|
+
variant: _propTypes.default.oneOf(['info', 'error', 'success', 'warning']),
|
|
145
|
+
icon: _propTypes.default.node,
|
|
146
|
+
onClick: _propTypes.default.func,
|
|
147
|
+
onClose: _propTypes.default.func.isRequired,
|
|
148
|
+
duration: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.oneOf(['permanent'])])
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Snackbar container component
|
|
153
|
+
* Can render to a specific container or to document.body
|
|
154
|
+
*/
|
|
155
|
+
const Snackbar = _ref2 => {
|
|
156
|
+
let {
|
|
157
|
+
snackbars = [],
|
|
158
|
+
onClose,
|
|
159
|
+
position = 'top-right',
|
|
160
|
+
container = null
|
|
161
|
+
} = _ref2;
|
|
162
|
+
if (snackbars.length === 0) return null;
|
|
163
|
+
const content = /*#__PURE__*/_react.default.createElement(_Snackbar.SnackbarContainer, {
|
|
164
|
+
$position: position,
|
|
165
|
+
$isContained: !!container
|
|
166
|
+
}, snackbars.map(snackbar => /*#__PURE__*/_react.default.createElement(SnackbarItem, _extends({
|
|
167
|
+
key: snackbar.id
|
|
168
|
+
}, snackbar, {
|
|
169
|
+
onClose: onClose
|
|
170
|
+
}))));
|
|
171
|
+
|
|
172
|
+
// If container is provided, render inside it (for contained snackbars)
|
|
173
|
+
// Otherwise, render to document.body via portal
|
|
174
|
+
if (container) {
|
|
175
|
+
return /*#__PURE__*/(0, _reactDom.createPortal)(content, container);
|
|
176
|
+
}
|
|
177
|
+
return /*#__PURE__*/(0, _reactDom.createPortal)(content, document.body);
|
|
178
|
+
};
|
|
179
|
+
exports.Snackbar = Snackbar;
|
|
180
|
+
Snackbar.propTypes = {
|
|
181
|
+
snackbars: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
182
|
+
id: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]).isRequired,
|
|
183
|
+
message: _propTypes.default.node.isRequired,
|
|
184
|
+
variant: _propTypes.default.oneOf(['info', 'error', 'success', 'warning']),
|
|
185
|
+
icon: _propTypes.default.node,
|
|
186
|
+
onClick: _propTypes.default.func,
|
|
187
|
+
duration: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.oneOf(['permanent'])])
|
|
188
|
+
})),
|
|
189
|
+
onClose: _propTypes.default.func.isRequired,
|
|
190
|
+
position: _propTypes.default.oneOf(['top-right', 'top-left', 'top-center', 'bottom-right', 'bottom-left', 'bottom-center']),
|
|
191
|
+
container: _propTypes.default.instanceOf(Element)
|
|
192
|
+
};
|
|
193
|
+
var _default = exports.default = Snackbar;
|