@team-frieeren/components 1.0.0 → 1.0.1

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.
@@ -0,0 +1,5 @@
1
+ export { useFunnel } from "./components/Funnel";
2
+ export { safeLocalStorage, safeSessionStorage } from "./shared/storage";
3
+ export { RouterProvider, useRouter } from "./hooks/useRouter";
4
+ export { WindowRouter } from "./router/windowRouter";
5
+ export { useToast, ToastProvider } from "./components/Toast";
package/dist/client.js ADDED
@@ -0,0 +1,633 @@
1
+ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+ import { Children, isValidElement, useEffect, createContext, useContext, useMemo, useCallback, useState, Fragment as Fragment$1 } from 'react';
4
+ import cx from 'classnames';
5
+ import { createPortal } from 'react-dom';
6
+
7
+ var _assign = function __assign() {
8
+ _assign = Object.assign || function __assign(t) {
9
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
10
+ s = arguments[i];
11
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
12
+ }
13
+ return t;
14
+ };
15
+ return _assign.apply(this, arguments);
16
+ };
17
+ function __rest(s, e) {
18
+ var t = {};
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
20
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
21
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
22
+ }
23
+ return t;
24
+ }
25
+ function __spreadArray(to, from, pack) {
26
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
27
+ if (ar || !(i in from)) {
28
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
29
+ ar[i] = from[i];
30
+ }
31
+ }
32
+ return to.concat(ar || Array.prototype.slice.call(from));
33
+ }
34
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
35
+ var e = new Error(message);
36
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
37
+ };
38
+
39
+ var Funnel = function Funnel(_a) {
40
+ var steps = _a.steps,
41
+ step = _a.step,
42
+ children = _a.children;
43
+ var validChildren = Children.toArray(children).filter(isValidElement).filter(function (i) {
44
+ var _a;
45
+ return steps.includes((_a = i.props.name) !== null && _a !== void 0 ? _a : "");
46
+ });
47
+ var targetStep = validChildren.find(function (child) {
48
+ return child.props.name === step;
49
+ });
50
+ if (!targetStep) {
51
+ throw new Error("".concat(step, " Step Component\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4."));
52
+ }
53
+ return jsx(Fragment, {
54
+ children: targetStep
55
+ });
56
+ };
57
+ var Step = function Step(_a) {
58
+ var onMounted = _a.onMounted,
59
+ onUnMounted = _a.onUnMounted,
60
+ children = _a.children;
61
+ useEffect(function () {
62
+ onMounted === null || onMounted === void 0 ? void 0 : onMounted();
63
+ return function () {
64
+ onUnMounted === null || onUnMounted === void 0 ? void 0 : onUnMounted();
65
+ };
66
+ }, [onMounted, onUnMounted]);
67
+ return jsx(Fragment, {
68
+ children: children
69
+ });
70
+ };
71
+
72
+ var RouterContext = /*#__PURE__*/createContext(null);
73
+ var RouterProvider = RouterContext.Provider;
74
+ function useRouter() {
75
+ var router = useContext(RouterContext);
76
+ if (!router) {
77
+ throw new Error("RouterProvider를 설정해주세요");
78
+ }
79
+ return router;
80
+ }
81
+
82
+ function useQueryParam(name, options) {
83
+ var router = useRouter();
84
+ var value = router.getQuery(name);
85
+ return value;
86
+ }
87
+
88
+ var DEFAULT_STEP_QUERY_KEY = "funnel-step";
89
+ var useFunnel = function useFunnel(steps, options) {
90
+ var _a;
91
+ var router = useRouter();
92
+ var stepQueryKey = (_a = options === null || options === void 0 ? void 0 : options.stepQueryKey) !== null && _a !== void 0 ? _a : DEFAULT_STEP_QUERY_KEY;
93
+ if (steps.length === 0) {
94
+ throw new Error("steps가 비어있습니다.");
95
+ }
96
+ var FunnelComponent = useMemo(function () {
97
+ return Object.assign(function RouteFunnel(props) {
98
+ var _a;
99
+ var step = (_a = useQueryParam(stepQueryKey)) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.initialStep;
100
+ if (!step) {
101
+ throw new Error("\uD45C\uC2DC\uD560 \uC2A4\uD15D\uC744 ".concat(stepQueryKey, " \uCFFC\uB9AC \uD30C\uB77C\uBBF8\uD130\uC5D0 \uC9C0\uC815\uD574\uC8FC\uC138\uC694. \uCFFC\uB9AC \uD30C\uB77C\uBBF8\uD130\uAC00 \uC5C6\uC744 \uB54C \uCD08\uAE30 Step\uC744 \uB80C\uB354\uD558\uB824\uBA74 useFunnel\uC758 \uB450 \uBC88\uC9F8 \uD30C\uB77C\uBBF8\uD130 options\uC5D0 initialStep\uC744 \uC9C0\uC815\uD574\uC8FC\uC138\uC694."));
102
+ }
103
+ return jsx(Funnel, _assign({
104
+ steps: steps,
105
+ step: step
106
+ }, props));
107
+ }, {
108
+ Step: Step
109
+ });
110
+ }, []);
111
+ var setStep = useCallback(function (step) {
112
+ var _a;
113
+ router.setQuery((_a = {}, _a[stepQueryKey] = step, _a));
114
+ }, [stepQueryKey, router]);
115
+ return [FunnelComponent, setStep];
116
+ };
117
+
118
+ var generateRandomKey = function generateRandomKey() {
119
+ return Math.random().toString(36).substring(2, 11);
120
+ };
121
+
122
+ var MemoryStorage = /** @class */function () {
123
+ function MemoryStorage() {
124
+ this.map = new Map();
125
+ }
126
+ MemoryStorage.prototype.has = function (key) {
127
+ return this.map.get(key) !== null;
128
+ };
129
+ MemoryStorage.prototype.get = function (key) {
130
+ return this.map.get(key) || null;
131
+ };
132
+ MemoryStorage.prototype.set = function (key, value) {
133
+ this.map.set(key, value);
134
+ };
135
+ MemoryStorage.prototype.remove = function (key) {
136
+ this.map["delete"](key);
137
+ };
138
+ MemoryStorage.prototype.clear = function () {
139
+ this.map.clear();
140
+ };
141
+ MemoryStorage.prototype.setObject = function (key, value) {
142
+ this.map.set(key, JSON.stringify(value));
143
+ };
144
+ MemoryStorage.prototype.getObject = function (key) {
145
+ var value = this.map.get(key);
146
+ if (!value) return null;
147
+ return JSON.parse(value);
148
+ };
149
+ return MemoryStorage;
150
+ }();
151
+
152
+ var LocalStorage = /** @class */function () {
153
+ function LocalStorage() {}
154
+ LocalStorage.isEnabled = function () {
155
+ if (typeof window === "undefined" || !!window.localStorage) {
156
+ return false;
157
+ }
158
+ try {
159
+ var KEY = generateRandomKey();
160
+ localStorage.setItem(KEY, "test");
161
+ localStorage.removeItem(KEY);
162
+ return true;
163
+ } catch (_a) {
164
+ return false;
165
+ }
166
+ };
167
+ LocalStorage.prototype.has = function (key) {
168
+ return localStorage.getItem(key) !== null;
169
+ };
170
+ LocalStorage.prototype.get = function (key) {
171
+ return localStorage.getItem(key);
172
+ };
173
+ LocalStorage.prototype.set = function (key, value) {
174
+ localStorage.setItem(key, value);
175
+ };
176
+ LocalStorage.prototype.remove = function (key) {
177
+ localStorage.removeItem(key);
178
+ };
179
+ LocalStorage.prototype.clear = function () {
180
+ localStorage.clear();
181
+ };
182
+ LocalStorage.prototype.setObject = function (key, value) {
183
+ localStorage.setItem(key, JSON.stringify(value));
184
+ };
185
+ LocalStorage.prototype.getObject = function (key) {
186
+ var value = localStorage.getItem(key);
187
+ if (!value) return null;
188
+ return JSON.parse(value);
189
+ };
190
+ return LocalStorage;
191
+ }();
192
+ var safeLocalStorage = LocalStorage.isEnabled() ? new LocalStorage() : new MemoryStorage();
193
+
194
+ var SessionStorage = /** @class */function () {
195
+ function SessionStorage() {}
196
+ SessionStorage.isEnabled = function () {
197
+ if (typeof window === "undefined" || !!window.sessionStorage) {
198
+ return false;
199
+ }
200
+ try {
201
+ var KEY = generateRandomKey();
202
+ sessionStorage.setItem(KEY, "test");
203
+ sessionStorage.removeItem(KEY);
204
+ return true;
205
+ } catch (_a) {
206
+ return false;
207
+ }
208
+ };
209
+ SessionStorage.prototype.has = function (key) {
210
+ return sessionStorage.getItem(key) !== null;
211
+ };
212
+ SessionStorage.prototype.get = function (key) {
213
+ return sessionStorage.getItem(key);
214
+ };
215
+ SessionStorage.prototype.set = function (key, value) {
216
+ sessionStorage.setItem(key, value);
217
+ };
218
+ SessionStorage.prototype.remove = function (key) {
219
+ sessionStorage.removeItem(key);
220
+ };
221
+ SessionStorage.prototype.clear = function () {
222
+ sessionStorage.clear();
223
+ };
224
+ SessionStorage.prototype.setObject = function (key, value) {
225
+ sessionStorage.setItem(key, JSON.stringify(value));
226
+ };
227
+ SessionStorage.prototype.getObject = function (key) {
228
+ var value = sessionStorage.getItem(key);
229
+ if (!value) return null;
230
+ return JSON.parse(value);
231
+ };
232
+ return SessionStorage;
233
+ }();
234
+ var safeSessionStorage = SessionStorage.isEnabled() ? new SessionStorage() : new MemoryStorage();
235
+
236
+ var WindowRouter = /** @class */function () {
237
+ function WindowRouter() {}
238
+ Object.defineProperty(WindowRouter.prototype, "location", {
239
+ get: function get() {
240
+ return {
241
+ pathname: window.location.pathname,
242
+ search: window.location.search,
243
+ hash: window.location.hash,
244
+ state: window.history.state
245
+ };
246
+ },
247
+ enumerable: false,
248
+ configurable: true
249
+ });
250
+ WindowRouter.prototype.push = function (path, options) {
251
+ var _a;
252
+ window.history.pushState((_a = options === null || options === void 0 ? void 0 : options.state) !== null && _a !== void 0 ? _a : null, "", this.normalizePath(path));
253
+ };
254
+ WindowRouter.prototype.replace = function (path, options) {
255
+ var _a;
256
+ window.history.replaceState((_a = options === null || options === void 0 ? void 0 : options.state) !== null && _a !== void 0 ? _a : null, "", this.normalizePath(path));
257
+ };
258
+ WindowRouter.prototype.back = function () {
259
+ window.history.back();
260
+ };
261
+ WindowRouter.prototype.forward = function () {
262
+ window.history.forward();
263
+ };
264
+ WindowRouter.prototype.setQuery = function (query) {
265
+ var searchParams = new URLSearchParams(window.location.search);
266
+ Object.entries(query).forEach(function (_a) {
267
+ var key = _a[0],
268
+ value = _a[1];
269
+ if (Array.isArray(value)) {
270
+ searchParams["delete"](key);
271
+ value.forEach(function (v) {
272
+ return searchParams.append(key, v);
273
+ });
274
+ } else if (value !== undefined) {
275
+ searchParams.set(key, value);
276
+ } else {
277
+ searchParams["delete"](key);
278
+ }
279
+ });
280
+ this.replace("".concat(window.location.pathname, "?").concat(searchParams.toString()));
281
+ };
282
+ WindowRouter.prototype.getQuery = function (key) {
283
+ var searchParams = new URLSearchParams(window.location.search);
284
+ var values = searchParams.getAll(key);
285
+ if (values.length > 1) {
286
+ return values;
287
+ }
288
+ return searchParams.get(key);
289
+ };
290
+ WindowRouter.prototype.getAllQueries = function () {
291
+ var searchParams = new URLSearchParams(window.location.search);
292
+ var query = {};
293
+ searchParams.forEach(function (value, key) {
294
+ var existing = query[key];
295
+ if (existing !== undefined) {
296
+ query[key] = Array.isArray(existing) ? __spreadArray(__spreadArray([], existing, true), [value], false) : [existing, value];
297
+ } else {
298
+ query[key] = value;
299
+ }
300
+ });
301
+ return query;
302
+ };
303
+ WindowRouter.prototype.normalizePath = function (path) {
304
+ if (path.startsWith("http://") || path.startsWith("https://")) {
305
+ return path;
306
+ }
307
+ return path.startsWith("/") ? path : "/".concat(path);
308
+ };
309
+ return WindowRouter;
310
+ }();
311
+
312
+ function SwitchCase(_a) {
313
+ var _b;
314
+ var value = _a.value,
315
+ caseBy = _a.caseBy,
316
+ _c = _a.defaultComponent,
317
+ defaultComponent = _c === void 0 ? null : _c;
318
+ if (value == null) {
319
+ return defaultComponent;
320
+ }
321
+ return (_b = caseBy[value]) !== null && _b !== void 0 ? _b : defaultComponent;
322
+ }
323
+
324
+ function useIsMounted() {
325
+ var _a = useState(false),
326
+ mounted = _a[0],
327
+ setMounted = _a[1];
328
+ useEffect(function () {
329
+ setMounted(true);
330
+ }, []);
331
+ return mounted;
332
+ }
333
+
334
+ /** between the toasts spacing */
335
+ var GAP = 8;
336
+ var useToastStack = function useToastStack(toasts) {
337
+ var _a = useState({}),
338
+ heights = _a[0],
339
+ setHeights = _a[1];
340
+ var updateHeight = useCallback(function (id, height) {
341
+ setHeights(function (prev) {
342
+ var _a;
343
+ return _assign(_assign({}, prev), (_a = {}, _a[id] = height, _a));
344
+ });
345
+ }, []);
346
+ var groupedToasts = useMemo(function () {
347
+ var groups = {
348
+ "top-left": [],
349
+ "top-right": [],
350
+ "top-center": [],
351
+ "bottom-left": [],
352
+ "bottom-right": [],
353
+ "bottom-center": []
354
+ };
355
+ toasts.forEach(function (toast) {
356
+ var position = toast.position;
357
+ groups[position].push(toast);
358
+ });
359
+ return groups;
360
+ }, [toasts]);
361
+ var getToasterProps = useCallback(function (toast, index, position) {
362
+ var positionToasts = groupedToasts[position];
363
+ var offset = positionToasts.slice(0, index).reduce(function (total, t) {
364
+ return total + (heights[t.id] || 0) + GAP;
365
+ }, 0);
366
+ var translateY = "".concat(offset * (position.includes("top") ? 1 : -1), "px");
367
+ var translateX = position.includes("center") ? "-50%" : "0";
368
+ return {
369
+ ref: function ref(el) {
370
+ if (el) {
371
+ var height = el.getBoundingClientRect().height;
372
+ if (heights[toast.id] !== height) {
373
+ updateHeight(toast.id, height);
374
+ }
375
+ }
376
+ },
377
+ style: {
378
+ transform: "translate(".concat(translateX, ", ").concat(translateY, ")"),
379
+ transition: "transform 0.23s cubic-bezier(0.21, 1.02, 0.73, 1)"
380
+ },
381
+ className: cx("toast-wrapper", "toast-wrapper--".concat(position))
382
+ };
383
+ }, [heights, groupedToasts]);
384
+ return {
385
+ getToasterProps: getToasterProps,
386
+ groupedToasts: groupedToasts
387
+ };
388
+ };
389
+
390
+ var _path$2;
391
+ function _extends$2() { return _extends$2 = 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$2.apply(null, arguments); }
392
+ var SvgToastSuccess = function SvgToastSuccess(props) {
393
+ return /*#__PURE__*/React.createElement("svg", _extends$2({
394
+ xmlns: "http://www.w3.org/2000/svg",
395
+ width: "1em",
396
+ height: "1em",
397
+ fill: "none",
398
+ viewBox: "0 0 18 18"
399
+ }, props), _path$2 || (_path$2 = /*#__PURE__*/React.createElement("path", {
400
+ fill: "#50BF50",
401
+ fillRule: "evenodd",
402
+ d: "M9 18A9 9 0 1 0 9 0a9 9 0 0 0 0 18m4.768-11.36a1 1 0 1 0-1.536-1.28L8.634 9.677c-.347.416-.542.647-.697.788l-.006.006-.007-.005c-.168-.127-.383-.339-.766-.722l-1.45-1.451a1 1 0 0 0-1.415 1.414l1.451 1.451.041.041c.327.327.64.641.933.862.327.248.756.48 1.305.456.55-.025.956-.296 1.26-.572.27-.247.555-.588.85-.943l.037-.044z",
403
+ clipRule: "evenodd"
404
+ })));
405
+ };
406
+
407
+ var _path$1;
408
+ function _extends$1() { return _extends$1 = 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$1.apply(null, arguments); }
409
+ var SvgToastWarning = function SvgToastWarning(props) {
410
+ return /*#__PURE__*/React.createElement("svg", _extends$1({
411
+ xmlns: "http://www.w3.org/2000/svg",
412
+ width: "1em",
413
+ height: "1em",
414
+ fill: "none",
415
+ viewBox: "0 0 18 16"
416
+ }, props), _path$1 || (_path$1 = /*#__PURE__*/React.createElement("path", {
417
+ fill: "#FEF08A",
418
+ fillRule: "evenodd",
419
+ d: "M8.133.504a1 1 0 0 1 1.737 0l8 14A1 1 0 0 1 17 15.998h-16a1 1 0 0 1-.868-1.496zM7.981 5.16a1.02 1.02 0 1 1 2.042 0v4.146a1.02 1.02 0 0 1-2.042 0zm1.02 8.26c.565 0 1.022-.461 1.022-1.031s-.457-1.031-1.021-1.031-1.02.461-1.02 1.031.456 1.031 1.02 1.031",
420
+ clipRule: "evenodd"
421
+ })));
422
+ };
423
+
424
+ var _path;
425
+ 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); }
426
+ var SvgToastError = function SvgToastError(props) {
427
+ return /*#__PURE__*/React.createElement("svg", _extends({
428
+ xmlns: "http://www.w3.org/2000/svg",
429
+ width: "1em",
430
+ height: "1em",
431
+ fill: "none",
432
+ viewBox: "0 0 18 18"
433
+ }, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
434
+ fill: "#EF4444",
435
+ fillRule: "evenodd",
436
+ d: "M18 9A9 9 0 1 1 0 9a9 9 0 0 1 18 0M4.293 13.707a1 1 0 0 1 0-1.414L7.586 9 4.293 5.707a1 1 0 0 1 1.414-1.414L9 7.586l3.293-3.293a1 1 0 1 1 1.414 1.414L10.414 9l3.293 3.293a1 1 0 0 1-1.414 1.414L9 10.414l-3.293 3.293a1 1 0 0 1-1.414 0",
437
+ clipRule: "evenodd"
438
+ })));
439
+ };
440
+
441
+ var Toaster = function Toaster(_a) {
442
+ var toasts = _a.toasts;
443
+ var _b = useToastStack(toasts),
444
+ getToasterProps = _b.getToasterProps,
445
+ groupedToasts = _b.groupedToasts;
446
+ return jsx(Fragment$1, {
447
+ children: Object.entries(groupedToasts).map(function (_a) {
448
+ var position = _a[0],
449
+ positionToasts = _a[1];
450
+ return positionToasts.length > 0 && jsx("div", {
451
+ className: "toaster-content",
452
+ children: positionToasts.map(function (toast, idx) {
453
+ var toasterProps = getToasterProps(toast, idx, position);
454
+ return jsx("div", _assign({}, toasterProps, {
455
+ children: jsx(Toast, _assign({}, toast))
456
+ }), toast.id);
457
+ })
458
+ }, position);
459
+ })
460
+ });
461
+ };
462
+ var Toast = function Toast(_a) {
463
+ var toast = __rest(_a, []);
464
+ var width = toast.width,
465
+ type = toast.type,
466
+ action = toast.action,
467
+ position = toast.position,
468
+ offest = toast.offest,
469
+ duration = toast.duration,
470
+ style = toast.style,
471
+ message = toast.message,
472
+ buttonText = toast.buttonText,
473
+ onAction = toast.onAction;
474
+ var isMounted = useIsMounted();
475
+ var _b = useState(false),
476
+ visible = _b[0],
477
+ setVisible = _b[1];
478
+ var isTop = position === null || position === void 0 ? void 0 : position.includes("top");
479
+ var positionClass = isTop ? "top" : "bottom";
480
+ var offsetStyle = useMemo(function () {
481
+ var offsetValue = offest;
482
+ return isTop ? {
483
+ top: offsetValue + "px"
484
+ } : {
485
+ bottom: offsetValue + "px"
486
+ };
487
+ }, [isTop, offest]);
488
+ useEffect(function () {
489
+ if (isMounted) {
490
+ requestAnimationFrame(function () {
491
+ setVisible(true);
492
+ });
493
+ }
494
+ var timer = setTimeout(function () {
495
+ setVisible(false);
496
+ }, duration - 500);
497
+ return function () {
498
+ return clearTimeout(timer);
499
+ };
500
+ }, [isMounted]);
501
+ return jsxs("div", {
502
+ "data-frieeren-component": "Toast",
503
+ className: cx("toast--content", positionClass, {
504
+ visible: visible,
505
+ hidden: !visible
506
+ }),
507
+ style: _assign(_assign({
508
+ width: width,
509
+ visibility: visible ? "visible" : "hidden"
510
+ }, offsetStyle), style),
511
+ children: [jsxs("div", {
512
+ className: "toast--type-message",
513
+ children: [jsx("div", {
514
+ className: "toast--type-icon",
515
+ "data-toast-type": type,
516
+ children: jsx(SwitchCase, {
517
+ value: type || "default",
518
+ caseBy: {
519
+ success: jsx(SvgToastSuccess, {}),
520
+ warning: jsx(SvgToastWarning, {}),
521
+ error: jsx(SvgToastError, {})
522
+ },
523
+ defaultComponent: null
524
+ })
525
+ }), jsx("div", {
526
+ className: "toast--message",
527
+ children: message
528
+ })]
529
+ }), jsx(SwitchCase, {
530
+ value: action || "defualt",
531
+ caseBy: {
532
+ "icon-link": jsx("button", {
533
+ className: "toast--action-link",
534
+ onClick: onAction,
535
+ children: "\uB9C1\uD06C\u2192"
536
+ }),
537
+ "icon-button": jsx("button", {
538
+ className: "toast--action-button",
539
+ onClick: onAction,
540
+ children: buttonText
541
+ })
542
+ },
543
+ defaultComponent: null
544
+ })]
545
+ });
546
+ };
547
+
548
+ var defaultToastValue = {
549
+ type: "default",
550
+ action: "defualt",
551
+ style: {},
552
+ offest: 0,
553
+ message: "",
554
+ duration: 3000,
555
+ position: "top-right"
556
+ };
557
+ var ToastContext = /*#__PURE__*/createContext({
558
+ toasts: [],
559
+ add: function add() {
560
+ return "";
561
+ },
562
+ remove: function remove() {}
563
+ });
564
+ var ToastPortal = function ToastPortal(_a) {
565
+ var children = _a.children;
566
+ var isMounted = useIsMounted();
567
+ var node = document.getElementById("toast-portal");
568
+ if (!isMounted) return null;
569
+ return /*#__PURE__*/createPortal(children, node);
570
+ };
571
+ var ToastProvider = function ToastProvider(_a) {
572
+ var options = _a.options,
573
+ children = _a.children;
574
+ var _b = useState([]),
575
+ toasts = _b[0],
576
+ setToasts = _b[1];
577
+ var add = useCallback(function (toast) {
578
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
579
+ var id = Math.random().toString(36).substring(2, 9);
580
+ var newToast = _assign(_assign({}, toast), {
581
+ id: id,
582
+ type: (_b = (_a = toast.type) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.type) !== null && _b !== void 0 ? _b : defaultToastValue.type,
583
+ action: (_d = (_c = toast.action) !== null && _c !== void 0 ? _c : options === null || options === void 0 ? void 0 : options.action) !== null && _d !== void 0 ? _d : defaultToastValue.action,
584
+ style: (_f = (_e = toast.style) !== null && _e !== void 0 ? _e : options === null || options === void 0 ? void 0 : options.style) !== null && _f !== void 0 ? _f : defaultToastValue.style,
585
+ offest: (_h = (_g = toast.offest) !== null && _g !== void 0 ? _g : options === null || options === void 0 ? void 0 : options.offest) !== null && _h !== void 0 ? _h : defaultToastValue.offest,
586
+ radius: (_k = (_j = toast.radius) !== null && _j !== void 0 ? _j : options === null || options === void 0 ? void 0 : options.radius) !== null && _k !== void 0 ? _k : defaultToastValue.radius,
587
+ message: (_m = (_l = toast.message) !== null && _l !== void 0 ? _l : options === null || options === void 0 ? void 0 : options.message) !== null && _m !== void 0 ? _m : defaultToastValue.message,
588
+ duration: (_p = (_o = toast.duration) !== null && _o !== void 0 ? _o : options === null || options === void 0 ? void 0 : options.duration) !== null && _p !== void 0 ? _p : defaultToastValue.duration,
589
+ position: (_r = (_q = toast.position) !== null && _q !== void 0 ? _q : options === null || options === void 0 ? void 0 : options.position) !== null && _r !== void 0 ? _r : defaultToastValue.position
590
+ });
591
+ setToasts(function (prev) {
592
+ return __spreadArray([newToast], prev, true);
593
+ });
594
+ if (newToast.duration > 0) {
595
+ setTimeout(function () {
596
+ return remove(id);
597
+ }, newToast.duration);
598
+ }
599
+ return id;
600
+ }, [options]);
601
+ var remove = useCallback(function (id) {
602
+ setToasts(function (prev) {
603
+ return prev.filter(function (toast) {
604
+ return toast.id !== id;
605
+ });
606
+ });
607
+ }, []);
608
+ var value = useMemo(function () {
609
+ return {
610
+ toasts: toasts,
611
+ add: add,
612
+ remove: remove
613
+ };
614
+ }, [toasts, add, remove]);
615
+ return jsxs(ToastContext.Provider, {
616
+ value: value,
617
+ children: [children, jsx(ToastPortal, {
618
+ children: toasts.length && jsx(Toaster, {
619
+ toasts: toasts
620
+ })
621
+ })]
622
+ });
623
+ };
624
+
625
+ var useToast = function useToast() {
626
+ var context = useContext(ToastContext);
627
+ if (!context) {
628
+ throw new Error("useToast must be used within a ToastProvider");
629
+ }
630
+ return context;
631
+ };
632
+
633
+ export { RouterProvider, ToastProvider, WindowRouter, safeLocalStorage, safeSessionStorage, useFunnel, useRouter, useToast };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import "./style/index.scss";
2
- export { useFunnel } from "./components/Funnel";
3
2
  export { Box } from "./components/layout/Box";
4
3
  export { Container } from "./components/layout/Container";
5
4
  export { Flex } from "./components/layout/Flex";
@@ -14,8 +13,3 @@ export { Popup } from "./components/Popup";
14
13
  export { BottomSheet } from "./components/BottomSheet";
15
14
  export { Input } from "./components/Input";
16
15
  export { Tabs } from "./components/Tabs";
17
- export { ToastProvider } from "./components/Toast";
18
- export { safeLocalStorage, safeSessionStorage } from "./shared/storage";
19
- export { RouterProvider, useRouter } from "./hooks/useRouter";
20
- export { WindowRouter } from "./router/windowRouter";
21
- export { useToast } from "./components/Toast";
package/dist/index.js CHANGED
@@ -1,14 +1,13 @@
1
- import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
- import * as React from 'react';
3
- import { Children, isValidElement, useEffect, createContext, useContext, useMemo, useCallback, forwardRef, useState, useRef, Fragment as Fragment$1 } from 'react';
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
4
2
  import cx from 'classnames';
3
+ import * as React from 'react';
4
+ import { forwardRef, useState, useCallback, useEffect, useRef } from 'react';
5
5
  import * as RadioGroupBase from '@radix-ui/react-radio-group';
6
6
  import * as CheckboxBase from '@radix-ui/react-checkbox';
7
7
  import { Switch, Dialog } from 'radix-ui';
8
8
  import * as SelectBase from '@radix-ui/react-select';
9
9
  import { Drawer } from 'vaul';
10
10
  import * as TabsBase from '@radix-ui/react-tabs';
11
- import { createPortal } from 'react-dom';
12
11
 
13
12
  var _assign = function __assign() {
14
13
  _assign = Object.assign || function __assign(t) {
@@ -28,99 +27,11 @@ function __rest(s, e) {
28
27
  }
29
28
  return t;
30
29
  }
31
- function __spreadArray(to, from, pack) {
32
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
33
- if (ar || !(i in from)) {
34
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
35
- ar[i] = from[i];
36
- }
37
- }
38
- return to.concat(ar || Array.prototype.slice.call(from));
39
- }
40
30
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
41
31
  var e = new Error(message);
42
32
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
43
33
  };
44
34
 
45
- var Funnel = function Funnel(_a) {
46
- var steps = _a.steps,
47
- step = _a.step,
48
- children = _a.children;
49
- var validChildren = Children.toArray(children).filter(isValidElement).filter(function (i) {
50
- var _a;
51
- return steps.includes((_a = i.props.name) !== null && _a !== void 0 ? _a : "");
52
- });
53
- var targetStep = validChildren.find(function (child) {
54
- return child.props.name === step;
55
- });
56
- if (!targetStep) {
57
- throw new Error("".concat(step, " Step Component\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4."));
58
- }
59
- return jsx(Fragment, {
60
- children: targetStep
61
- });
62
- };
63
- var Step = function Step(_a) {
64
- var onMounted = _a.onMounted,
65
- onUnMounted = _a.onUnMounted,
66
- children = _a.children;
67
- useEffect(function () {
68
- onMounted === null || onMounted === void 0 ? void 0 : onMounted();
69
- return function () {
70
- onUnMounted === null || onUnMounted === void 0 ? void 0 : onUnMounted();
71
- };
72
- }, [onMounted, onUnMounted]);
73
- return jsx(Fragment, {
74
- children: children
75
- });
76
- };
77
-
78
- var RouterContext = /*#__PURE__*/createContext(null);
79
- var RouterProvider = RouterContext.Provider;
80
- function useRouter() {
81
- var router = useContext(RouterContext);
82
- if (!router) {
83
- throw new Error("RouterProvider를 설정해주세요");
84
- }
85
- return router;
86
- }
87
-
88
- function useQueryParam(name, options) {
89
- var router = useRouter();
90
- var value = router.getQuery(name);
91
- return value;
92
- }
93
-
94
- var DEFAULT_STEP_QUERY_KEY = "funnel-step";
95
- var useFunnel = function useFunnel(steps, options) {
96
- var _a;
97
- var router = useRouter();
98
- var stepQueryKey = (_a = options === null || options === void 0 ? void 0 : options.stepQueryKey) !== null && _a !== void 0 ? _a : DEFAULT_STEP_QUERY_KEY;
99
- if (steps.length === 0) {
100
- throw new Error("steps가 비어있습니다.");
101
- }
102
- var FunnelComponent = useMemo(function () {
103
- return Object.assign(function RouteFunnel(props) {
104
- var _a;
105
- var step = (_a = useQueryParam(stepQueryKey)) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.initialStep;
106
- if (!step) {
107
- throw new Error("\uD45C\uC2DC\uD560 \uC2A4\uD15D\uC744 ".concat(stepQueryKey, " \uCFFC\uB9AC \uD30C\uB77C\uBBF8\uD130\uC5D0 \uC9C0\uC815\uD574\uC8FC\uC138\uC694. \uCFFC\uB9AC \uD30C\uB77C\uBBF8\uD130\uAC00 \uC5C6\uC744 \uB54C \uCD08\uAE30 Step\uC744 \uB80C\uB354\uD558\uB824\uBA74 useFunnel\uC758 \uB450 \uBC88\uC9F8 \uD30C\uB77C\uBBF8\uD130 options\uC5D0 initialStep\uC744 \uC9C0\uC815\uD574\uC8FC\uC138\uC694."));
108
- }
109
- return jsx(Funnel, _assign({
110
- steps: steps,
111
- step: step
112
- }, props));
113
- }, {
114
- Step: Step
115
- });
116
- }, []);
117
- var setStep = useCallback(function (step) {
118
- var _a;
119
- router.setQuery((_a = {}, _a[stepQueryKey] = step, _a));
120
- }, [stepQueryKey, router]);
121
- return [FunnelComponent, setStep];
122
- };
123
-
124
35
  var SpacingMap = {
125
36
  m: ["margin"],
126
37
  mx: ["marginLeft", "marginRight"],
@@ -640,10 +551,10 @@ var BottomSheet = function BottomSheet(_a) {
640
551
  });
641
552
  };
642
553
 
643
- var _rect, _path$4;
644
- function _extends$4() { return _extends$4 = 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$4.apply(null, arguments); }
554
+ var _rect, _path$1;
555
+ function _extends$1() { return _extends$1 = 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$1.apply(null, arguments); }
645
556
  var SvgClose = function SvgClose(props) {
646
- return /*#__PURE__*/React.createElement("svg", _extends$4({
557
+ return /*#__PURE__*/React.createElement("svg", _extends$1({
647
558
  xmlns: "http://www.w3.org/2000/svg",
648
559
  width: "1em",
649
560
  height: "1em",
@@ -654,7 +565,7 @@ var SvgClose = function SvgClose(props) {
654
565
  height: 16,
655
566
  fill: "#F6F7F9",
656
567
  rx: 8
657
- })), _path$4 || (_path$4 = /*#__PURE__*/React.createElement("path", {
568
+ })), _path$1 || (_path$1 = /*#__PURE__*/React.createElement("path", {
658
569
  fill: "#A6ABAF",
659
570
  fillRule: "evenodd",
660
571
  d: "M5.997 5.29a.5.5 0 0 0-.707.707L7.293 8 5.29 10.004a.5.5 0 1 0 .707.707L8 8.708l2.004 2.003a.5.5 0 0 0 .707-.707L8.707 8l2.004-2.003a.5.5 0 0 0-.707-.707L8 7.293z",
@@ -662,16 +573,16 @@ var SvgClose = function SvgClose(props) {
662
573
  })));
663
574
  };
664
575
 
665
- var _path$3, _path2;
666
- function _extends$3() { return _extends$3 = 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$3.apply(null, arguments); }
576
+ var _path, _path2;
577
+ 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); }
667
578
  var SvgLink = function SvgLink(props) {
668
- return /*#__PURE__*/React.createElement("svg", _extends$3({
579
+ return /*#__PURE__*/React.createElement("svg", _extends({
669
580
  xmlns: "http://www.w3.org/2000/svg",
670
581
  width: "1em",
671
582
  height: "1em",
672
583
  fill: "none",
673
584
  viewBox: "0 0 24 24"
674
- }, props), _path$3 || (_path$3 = /*#__PURE__*/React.createElement("path", {
585
+ }, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
675
586
  stroke: "#A6ABAF",
676
587
  strokeLinecap: "round",
677
588
  strokeLinejoin: "round",
@@ -872,507 +783,4 @@ var Tabs = function Tabs(props) {
872
783
  }));
873
784
  };
874
785
 
875
- function useIsMounted() {
876
- var _a = useState(false),
877
- mounted = _a[0],
878
- setMounted = _a[1];
879
- useEffect(function () {
880
- setMounted(true);
881
- }, []);
882
- return mounted;
883
- }
884
-
885
- /** between the toasts spacing */
886
- var GAP = 8;
887
- var useToastStack = function useToastStack(toasts) {
888
- var _a = useState({}),
889
- heights = _a[0],
890
- setHeights = _a[1];
891
- var updateHeight = useCallback(function (id, height) {
892
- setHeights(function (prev) {
893
- var _a;
894
- return _assign(_assign({}, prev), (_a = {}, _a[id] = height, _a));
895
- });
896
- }, []);
897
- var groupedToasts = useMemo(function () {
898
- var groups = {
899
- "top-left": [],
900
- "top-right": [],
901
- "top-center": [],
902
- "bottom-left": [],
903
- "bottom-right": [],
904
- "bottom-center": []
905
- };
906
- toasts.forEach(function (toast) {
907
- var position = toast.position;
908
- groups[position].push(toast);
909
- });
910
- return groups;
911
- }, [toasts]);
912
- var getToasterProps = useCallback(function (toast, index, position) {
913
- var positionToasts = groupedToasts[position];
914
- var offset = positionToasts.slice(0, index).reduce(function (total, t) {
915
- return total + (heights[t.id] || 0) + GAP;
916
- }, 0);
917
- var translateY = "".concat(offset * (position.includes("top") ? 1 : -1), "px");
918
- var translateX = position.includes("center") ? "-50%" : "0";
919
- return {
920
- ref: function ref(el) {
921
- if (el) {
922
- var height = el.getBoundingClientRect().height;
923
- if (heights[toast.id] !== height) {
924
- updateHeight(toast.id, height);
925
- }
926
- }
927
- },
928
- style: {
929
- transform: "translate(".concat(translateX, ", ").concat(translateY, ")"),
930
- transition: "transform 0.23s cubic-bezier(0.21, 1.02, 0.73, 1)"
931
- },
932
- className: cx("toast-wrapper", "toast-wrapper--".concat(position))
933
- };
934
- }, [heights, groupedToasts]);
935
- return {
936
- getToasterProps: getToasterProps,
937
- groupedToasts: groupedToasts
938
- };
939
- };
940
-
941
- var _path$2;
942
- function _extends$2() { return _extends$2 = 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$2.apply(null, arguments); }
943
- var SvgToastSuccess = function SvgToastSuccess(props) {
944
- return /*#__PURE__*/React.createElement("svg", _extends$2({
945
- xmlns: "http://www.w3.org/2000/svg",
946
- width: "1em",
947
- height: "1em",
948
- fill: "none",
949
- viewBox: "0 0 18 18"
950
- }, props), _path$2 || (_path$2 = /*#__PURE__*/React.createElement("path", {
951
- fill: "#50BF50",
952
- fillRule: "evenodd",
953
- d: "M9 18A9 9 0 1 0 9 0a9 9 0 0 0 0 18m4.768-11.36a1 1 0 1 0-1.536-1.28L8.634 9.677c-.347.416-.542.647-.697.788l-.006.006-.007-.005c-.168-.127-.383-.339-.766-.722l-1.45-1.451a1 1 0 0 0-1.415 1.414l1.451 1.451.041.041c.327.327.64.641.933.862.327.248.756.48 1.305.456.55-.025.956-.296 1.26-.572.27-.247.555-.588.85-.943l.037-.044z",
954
- clipRule: "evenodd"
955
- })));
956
- };
957
-
958
- var _path$1;
959
- function _extends$1() { return _extends$1 = 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$1.apply(null, arguments); }
960
- var SvgToastWarning = function SvgToastWarning(props) {
961
- return /*#__PURE__*/React.createElement("svg", _extends$1({
962
- xmlns: "http://www.w3.org/2000/svg",
963
- width: "1em",
964
- height: "1em",
965
- fill: "none",
966
- viewBox: "0 0 18 16"
967
- }, props), _path$1 || (_path$1 = /*#__PURE__*/React.createElement("path", {
968
- fill: "#FEF08A",
969
- fillRule: "evenodd",
970
- d: "M8.133.504a1 1 0 0 1 1.737 0l8 14A1 1 0 0 1 17 15.998h-16a1 1 0 0 1-.868-1.496zM7.981 5.16a1.02 1.02 0 1 1 2.042 0v4.146a1.02 1.02 0 0 1-2.042 0zm1.02 8.26c.565 0 1.022-.461 1.022-1.031s-.457-1.031-1.021-1.031-1.02.461-1.02 1.031.456 1.031 1.02 1.031",
971
- clipRule: "evenodd"
972
- })));
973
- };
974
-
975
- var _path;
976
- 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); }
977
- var SvgToastError = function SvgToastError(props) {
978
- return /*#__PURE__*/React.createElement("svg", _extends({
979
- xmlns: "http://www.w3.org/2000/svg",
980
- width: "1em",
981
- height: "1em",
982
- fill: "none",
983
- viewBox: "0 0 18 18"
984
- }, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
985
- fill: "#EF4444",
986
- fillRule: "evenodd",
987
- d: "M18 9A9 9 0 1 1 0 9a9 9 0 0 1 18 0M4.293 13.707a1 1 0 0 1 0-1.414L7.586 9 4.293 5.707a1 1 0 0 1 1.414-1.414L9 7.586l3.293-3.293a1 1 0 1 1 1.414 1.414L10.414 9l3.293 3.293a1 1 0 0 1-1.414 1.414L9 10.414l-3.293 3.293a1 1 0 0 1-1.414 0",
988
- clipRule: "evenodd"
989
- })));
990
- };
991
-
992
- var Toaster = function Toaster(_a) {
993
- var toasts = _a.toasts;
994
- var _b = useToastStack(toasts),
995
- getToasterProps = _b.getToasterProps,
996
- groupedToasts = _b.groupedToasts;
997
- return jsx(Fragment$1, {
998
- children: Object.entries(groupedToasts).map(function (_a) {
999
- var position = _a[0],
1000
- positionToasts = _a[1];
1001
- return positionToasts.length > 0 && jsx("div", {
1002
- className: "toaster-content",
1003
- children: positionToasts.map(function (toast, idx) {
1004
- var toasterProps = getToasterProps(toast, idx, position);
1005
- return jsx("div", _assign({}, toasterProps, {
1006
- children: jsx(Toast, _assign({}, toast))
1007
- }), toast.id);
1008
- })
1009
- }, position);
1010
- })
1011
- });
1012
- };
1013
- var Toast = function Toast(_a) {
1014
- var toast = __rest(_a, []);
1015
- var width = toast.width,
1016
- type = toast.type,
1017
- action = toast.action,
1018
- position = toast.position,
1019
- offest = toast.offest,
1020
- duration = toast.duration,
1021
- style = toast.style,
1022
- message = toast.message,
1023
- buttonText = toast.buttonText,
1024
- onAction = toast.onAction;
1025
- var isMounted = useIsMounted();
1026
- var _b = useState(false),
1027
- visible = _b[0],
1028
- setVisible = _b[1];
1029
- var isTop = position === null || position === void 0 ? void 0 : position.includes("top");
1030
- var positionClass = isTop ? "top" : "bottom";
1031
- var offsetStyle = useMemo(function () {
1032
- var offsetValue = offest;
1033
- return isTop ? {
1034
- top: offsetValue + "px"
1035
- } : {
1036
- bottom: offsetValue + "px"
1037
- };
1038
- }, [isTop, offest]);
1039
- useEffect(function () {
1040
- if (isMounted) {
1041
- requestAnimationFrame(function () {
1042
- setVisible(true);
1043
- });
1044
- }
1045
- var timer = setTimeout(function () {
1046
- setVisible(false);
1047
- }, duration - 500);
1048
- return function () {
1049
- return clearTimeout(timer);
1050
- };
1051
- }, [isMounted]);
1052
- return jsxs("div", {
1053
- "data-frieeren-component": "Toast",
1054
- className: cx("toast--content", positionClass, {
1055
- visible: visible,
1056
- hidden: !visible
1057
- }),
1058
- style: _assign(_assign({
1059
- width: width,
1060
- visibility: visible ? "visible" : "hidden"
1061
- }, offsetStyle), style),
1062
- children: [jsxs("div", {
1063
- className: "toast--type-message",
1064
- children: [jsx("div", {
1065
- className: "toast--type-icon",
1066
- "data-toast-type": type,
1067
- children: jsx(SwitchCase, {
1068
- value: type || "default",
1069
- caseBy: {
1070
- success: jsx(SvgToastSuccess, {}),
1071
- warning: jsx(SvgToastWarning, {}),
1072
- error: jsx(SvgToastError, {})
1073
- },
1074
- defaultComponent: null
1075
- })
1076
- }), jsx("div", {
1077
- className: "toast--message",
1078
- children: message
1079
- })]
1080
- }), jsx(SwitchCase, {
1081
- value: action || "defualt",
1082
- caseBy: {
1083
- "icon-link": jsx("button", {
1084
- className: "toast--action-link",
1085
- onClick: onAction,
1086
- children: "\uB9C1\uD06C\u2192"
1087
- }),
1088
- "icon-button": jsx("button", {
1089
- className: "toast--action-button",
1090
- onClick: onAction,
1091
- children: buttonText
1092
- })
1093
- },
1094
- defaultComponent: null
1095
- })]
1096
- });
1097
- };
1098
-
1099
- var defaultToastValue = {
1100
- type: "default",
1101
- action: "defualt",
1102
- style: {},
1103
- offest: 0,
1104
- message: "",
1105
- duration: 3000,
1106
- position: "top-right"
1107
- };
1108
- var ToastContext = /*#__PURE__*/createContext({
1109
- toasts: [],
1110
- add: function add() {
1111
- return "";
1112
- },
1113
- remove: function remove() {}
1114
- });
1115
- var ToastPortal = function ToastPortal(_a) {
1116
- var children = _a.children;
1117
- var isMounted = useIsMounted();
1118
- var node = document.getElementById("toast-portal");
1119
- if (!isMounted) return null;
1120
- return /*#__PURE__*/createPortal(children, node);
1121
- };
1122
- var ToastProvider = function ToastProvider(_a) {
1123
- var options = _a.options,
1124
- children = _a.children;
1125
- var _b = useState([]),
1126
- toasts = _b[0],
1127
- setToasts = _b[1];
1128
- var add = useCallback(function (toast) {
1129
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
1130
- var id = Math.random().toString(36).substring(2, 9);
1131
- var newToast = _assign(_assign({}, toast), {
1132
- id: id,
1133
- type: (_b = (_a = toast.type) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.type) !== null && _b !== void 0 ? _b : defaultToastValue.type,
1134
- action: (_d = (_c = toast.action) !== null && _c !== void 0 ? _c : options === null || options === void 0 ? void 0 : options.action) !== null && _d !== void 0 ? _d : defaultToastValue.action,
1135
- style: (_f = (_e = toast.style) !== null && _e !== void 0 ? _e : options === null || options === void 0 ? void 0 : options.style) !== null && _f !== void 0 ? _f : defaultToastValue.style,
1136
- offest: (_h = (_g = toast.offest) !== null && _g !== void 0 ? _g : options === null || options === void 0 ? void 0 : options.offest) !== null && _h !== void 0 ? _h : defaultToastValue.offest,
1137
- radius: (_k = (_j = toast.radius) !== null && _j !== void 0 ? _j : options === null || options === void 0 ? void 0 : options.radius) !== null && _k !== void 0 ? _k : defaultToastValue.radius,
1138
- message: (_m = (_l = toast.message) !== null && _l !== void 0 ? _l : options === null || options === void 0 ? void 0 : options.message) !== null && _m !== void 0 ? _m : defaultToastValue.message,
1139
- duration: (_p = (_o = toast.duration) !== null && _o !== void 0 ? _o : options === null || options === void 0 ? void 0 : options.duration) !== null && _p !== void 0 ? _p : defaultToastValue.duration,
1140
- position: (_r = (_q = toast.position) !== null && _q !== void 0 ? _q : options === null || options === void 0 ? void 0 : options.position) !== null && _r !== void 0 ? _r : defaultToastValue.position
1141
- });
1142
- setToasts(function (prev) {
1143
- return __spreadArray([newToast], prev, true);
1144
- });
1145
- if (newToast.duration > 0) {
1146
- setTimeout(function () {
1147
- return remove(id);
1148
- }, newToast.duration);
1149
- }
1150
- return id;
1151
- }, [options]);
1152
- var remove = useCallback(function (id) {
1153
- setToasts(function (prev) {
1154
- return prev.filter(function (toast) {
1155
- return toast.id !== id;
1156
- });
1157
- });
1158
- }, []);
1159
- var value = useMemo(function () {
1160
- return {
1161
- toasts: toasts,
1162
- add: add,
1163
- remove: remove
1164
- };
1165
- }, [toasts, add, remove]);
1166
- return jsxs(ToastContext.Provider, {
1167
- value: value,
1168
- children: [children, jsx(ToastPortal, {
1169
- children: toasts.length && jsx(Toaster, {
1170
- toasts: toasts
1171
- })
1172
- })]
1173
- });
1174
- };
1175
-
1176
- var useToast = function useToast() {
1177
- var context = useContext(ToastContext);
1178
- if (!context) {
1179
- throw new Error("useToast must be used within a ToastProvider");
1180
- }
1181
- return context;
1182
- };
1183
-
1184
- var generateRandomKey = function generateRandomKey() {
1185
- return Math.random().toString(36).substring(2, 11);
1186
- };
1187
-
1188
- var MemoryStorage = /** @class */function () {
1189
- function MemoryStorage() {
1190
- this.map = new Map();
1191
- }
1192
- MemoryStorage.prototype.has = function (key) {
1193
- return this.map.get(key) !== null;
1194
- };
1195
- MemoryStorage.prototype.get = function (key) {
1196
- return this.map.get(key) || null;
1197
- };
1198
- MemoryStorage.prototype.set = function (key, value) {
1199
- this.map.set(key, value);
1200
- };
1201
- MemoryStorage.prototype.remove = function (key) {
1202
- this.map["delete"](key);
1203
- };
1204
- MemoryStorage.prototype.clear = function () {
1205
- this.map.clear();
1206
- };
1207
- MemoryStorage.prototype.setObject = function (key, value) {
1208
- this.map.set(key, JSON.stringify(value));
1209
- };
1210
- MemoryStorage.prototype.getObject = function (key) {
1211
- var value = this.map.get(key);
1212
- if (!value) return null;
1213
- return JSON.parse(value);
1214
- };
1215
- return MemoryStorage;
1216
- }();
1217
-
1218
- var LocalStorage = /** @class */function () {
1219
- function LocalStorage() {}
1220
- LocalStorage.isEnabled = function () {
1221
- if (typeof window === "undefined" || !!window.localStorage) {
1222
- return false;
1223
- }
1224
- try {
1225
- var KEY = generateRandomKey();
1226
- localStorage.setItem(KEY, "test");
1227
- localStorage.removeItem(KEY);
1228
- return true;
1229
- } catch (_a) {
1230
- return false;
1231
- }
1232
- };
1233
- LocalStorage.prototype.has = function (key) {
1234
- return localStorage.getItem(key) !== null;
1235
- };
1236
- LocalStorage.prototype.get = function (key) {
1237
- return localStorage.getItem(key);
1238
- };
1239
- LocalStorage.prototype.set = function (key, value) {
1240
- localStorage.setItem(key, value);
1241
- };
1242
- LocalStorage.prototype.remove = function (key) {
1243
- localStorage.removeItem(key);
1244
- };
1245
- LocalStorage.prototype.clear = function () {
1246
- localStorage.clear();
1247
- };
1248
- LocalStorage.prototype.setObject = function (key, value) {
1249
- localStorage.setItem(key, JSON.stringify(value));
1250
- };
1251
- LocalStorage.prototype.getObject = function (key) {
1252
- var value = localStorage.getItem(key);
1253
- if (!value) return null;
1254
- return JSON.parse(value);
1255
- };
1256
- return LocalStorage;
1257
- }();
1258
- var safeLocalStorage = LocalStorage.isEnabled() ? new LocalStorage() : new MemoryStorage();
1259
-
1260
- var SessionStorage = /** @class */function () {
1261
- function SessionStorage() {}
1262
- SessionStorage.isEnabled = function () {
1263
- if (typeof window === "undefined" || !!window.sessionStorage) {
1264
- return false;
1265
- }
1266
- try {
1267
- var KEY = generateRandomKey();
1268
- sessionStorage.setItem(KEY, "test");
1269
- sessionStorage.removeItem(KEY);
1270
- return true;
1271
- } catch (_a) {
1272
- return false;
1273
- }
1274
- };
1275
- SessionStorage.prototype.has = function (key) {
1276
- return sessionStorage.getItem(key) !== null;
1277
- };
1278
- SessionStorage.prototype.get = function (key) {
1279
- return sessionStorage.getItem(key);
1280
- };
1281
- SessionStorage.prototype.set = function (key, value) {
1282
- sessionStorage.setItem(key, value);
1283
- };
1284
- SessionStorage.prototype.remove = function (key) {
1285
- sessionStorage.removeItem(key);
1286
- };
1287
- SessionStorage.prototype.clear = function () {
1288
- sessionStorage.clear();
1289
- };
1290
- SessionStorage.prototype.setObject = function (key, value) {
1291
- sessionStorage.setItem(key, JSON.stringify(value));
1292
- };
1293
- SessionStorage.prototype.getObject = function (key) {
1294
- var value = sessionStorage.getItem(key);
1295
- if (!value) return null;
1296
- return JSON.parse(value);
1297
- };
1298
- return SessionStorage;
1299
- }();
1300
- var safeSessionStorage = SessionStorage.isEnabled() ? new SessionStorage() : new MemoryStorage();
1301
-
1302
- var WindowRouter = /** @class */function () {
1303
- function WindowRouter() {}
1304
- Object.defineProperty(WindowRouter.prototype, "location", {
1305
- get: function get() {
1306
- return {
1307
- pathname: window.location.pathname,
1308
- search: window.location.search,
1309
- hash: window.location.hash,
1310
- state: window.history.state
1311
- };
1312
- },
1313
- enumerable: false,
1314
- configurable: true
1315
- });
1316
- WindowRouter.prototype.push = function (path, options) {
1317
- var _a;
1318
- window.history.pushState((_a = options === null || options === void 0 ? void 0 : options.state) !== null && _a !== void 0 ? _a : null, "", this.normalizePath(path));
1319
- };
1320
- WindowRouter.prototype.replace = function (path, options) {
1321
- var _a;
1322
- window.history.replaceState((_a = options === null || options === void 0 ? void 0 : options.state) !== null && _a !== void 0 ? _a : null, "", this.normalizePath(path));
1323
- };
1324
- WindowRouter.prototype.back = function () {
1325
- window.history.back();
1326
- };
1327
- WindowRouter.prototype.forward = function () {
1328
- window.history.forward();
1329
- };
1330
- WindowRouter.prototype.setQuery = function (query) {
1331
- var searchParams = new URLSearchParams(window.location.search);
1332
- Object.entries(query).forEach(function (_a) {
1333
- var key = _a[0],
1334
- value = _a[1];
1335
- if (Array.isArray(value)) {
1336
- searchParams["delete"](key);
1337
- value.forEach(function (v) {
1338
- return searchParams.append(key, v);
1339
- });
1340
- } else if (value !== undefined) {
1341
- searchParams.set(key, value);
1342
- } else {
1343
- searchParams["delete"](key);
1344
- }
1345
- });
1346
- this.replace("".concat(window.location.pathname, "?").concat(searchParams.toString()));
1347
- };
1348
- WindowRouter.prototype.getQuery = function (key) {
1349
- var searchParams = new URLSearchParams(window.location.search);
1350
- var values = searchParams.getAll(key);
1351
- if (values.length > 1) {
1352
- return values;
1353
- }
1354
- return searchParams.get(key);
1355
- };
1356
- WindowRouter.prototype.getAllQueries = function () {
1357
- var searchParams = new URLSearchParams(window.location.search);
1358
- var query = {};
1359
- searchParams.forEach(function (value, key) {
1360
- var existing = query[key];
1361
- if (existing !== undefined) {
1362
- query[key] = Array.isArray(existing) ? __spreadArray(__spreadArray([], existing, true), [value], false) : [existing, value];
1363
- } else {
1364
- query[key] = value;
1365
- }
1366
- });
1367
- return query;
1368
- };
1369
- WindowRouter.prototype.normalizePath = function (path) {
1370
- if (path.startsWith("http://") || path.startsWith("https://")) {
1371
- return path;
1372
- }
1373
- return path.startsWith("/") ? path : "/".concat(path);
1374
- };
1375
- return WindowRouter;
1376
- }();
1377
-
1378
- export { BottomSheet, Box, Button, Checkbox, Container, Flex, Grid, Input, Popup, RadioGroup, RouterProvider, Select, Tabs, Text, ToastProvider, Toggle, WindowRouter, safeLocalStorage, safeSessionStorage, useFunnel, useRouter, useToast };
786
+ export { BottomSheet, Box, Button, Checkbox, Container, Flex, Grid, Input, Popup, RadioGroup, Select, Tabs, Text, Toggle };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-frieeren/components",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -75,6 +75,10 @@
75
75
  "import": "./dist/index.js",
76
76
  "types": "./dist/index.d.ts"
77
77
  },
78
+ "./client": {
79
+ "import": "./dist/client.js",
80
+ "types": "./dist/client.d.ts"
81
+ },
78
82
  "./styles": "./dist/index.css"
79
83
  },
80
84
  "scripts": {