@wickermoney/ui-kit 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -34,7 +34,9 @@ export function Summary({ net }: { net: string }) {
34
34
 
35
35
  The package entry imports its stylesheets (`tokens.css` and `components.css`)
36
36
  as a side effect, so your bundler must handle CSS imports. Vite and most modern
37
- bundlers do by default.
37
+ bundlers do by default. `package.json` declares `./dist/index.js` and `./dist/*.css` as the
38
+ only files with side effects (`sideEffects`), so a bundler can still drop the
39
+ components you never import.
38
40
 
39
41
  **Inside a Wicker Money plugin:** the host already loads these styles, so
40
42
  components in your widgets are styled with no extra setup. For your plugin's
@@ -48,9 +50,11 @@ A federated remote's emitted stylesheet is never requested.
48
50
  |---|---|
49
51
  | `Surface` | Card/panel with an optional title and header action |
50
52
  | `Button` | `variant`: `default`, `primary` or `danger` |
53
+ | `IconButton` | Square icon-only button for table rows. `icon` is one of `edit`, `delete`, `disable`, `enable`, `archive`, `history`, `end` or `balance`; `label` is required and is both the accessible name and the hover tooltip; `variant`: `default` or `danger`. Takes any other native `<button>` attribute |
54
+ | `Dialog` | Modal built on the native `<dialog>` (`showModal()`): a side drawer on a desktop window, a full-screen sheet on a phone. `title` is the heading and the accessible name; `onClose` is called on Escape, the close button or a click on the backdrop. The page behind is inert, Tab stays inside, the first input in the body gets focus, and focus returns to what opened it when it unmounts. Render it only while it is wanted |
51
55
  | `Field`, `SelectField` | Labelled form inputs; optional `hint` and `error` (wires `aria-invalid` and `aria-describedby`) |
52
56
  | `FormError` | A form-level error, shown beside the form's submit button |
53
- | `Table` | Typed table: `columns`, `rows`, `rowKey`; `numeric` columns right-align |
57
+ | `Table` | Typed table: `columns`, `rows`, `rowKey`; `numeric` columns right-align. `empty` is rendered instead of the table when `rows` is empty; `className` adds a class to the table's scroller. Optional `caption` names the table: it is rendered as a visually hidden `<caption>` that a screen reader announces. Header cells carry `scope="col"`, and a column whose `header` is an empty string (a column of row buttons) gets a visually hidden "Actions" label in its header cell, so no header cell is empty |
54
58
  | `Stat` | Label + value; `tone="auto"` colours by sign |
55
59
  | `CategoryOptions`, `orderByParent` | Category `<option>` list grouped under parents |
56
60
  | `Alert` | Inline error or notice (`role="alert"`) |
@@ -67,7 +71,44 @@ names and returns anything left over as one form-level message;
67
71
  and `hasFormErrors` cover the empty case.
68
72
 
69
73
  Every component's props type is exported alongside it (`SurfaceProps`,
70
- `TableProps<T>`, ...).
74
+ `TableProps<T>`, ...). The other exported types are `Column<T>` (a `Table` column),
75
+ `IconName`, `FieldCommon`, `GroupableCategory`, and the form-error types
76
+ `FormErrors`, `FormErrorState`, `FieldMatcher` and `ValidationIssue`.
77
+
78
+ ### Focus trap
79
+
80
+ `useFocusTrap(ref, active, options?)` keeps Tab and Shift+Tab inside the element
81
+ `ref` points at while `active` is true: Tab from the last tabbable element wraps
82
+ to the first, Shift+Tab from the first wraps to the last, and if focus is outside
83
+ the container the next Tab pulls it in. Disabled, `inert`, hidden and
84
+ `tabindex="-1"` elements are skipped. It does not move focus when it turns on
85
+ (you know what should be focused first) and it does not handle Escape. The
86
+ container must be mounted whenever `active` is true.
87
+
88
+ By default, when the trap turns off, focus goes back to whatever had it when the
89
+ trap turned on. Pass `{ restoreFocus: false }` (the `restoreFocus` field of
90
+ `FocusTrapOptions`, default `true`) when you return focus somewhere more specific
91
+ yourself.
92
+
93
+ ```tsx
94
+ import { useRef } from 'react'
95
+ import { useFocusTrap } from '@wickermoney/ui-kit'
96
+
97
+ export function Menu({ onClose }: { onClose: () => void }) {
98
+ const ref = useRef<HTMLDivElement>(null)
99
+ useFocusTrap(ref, true)
100
+ return (
101
+ <div ref={ref} role="dialog" aria-modal="true" aria-label="Menu" tabIndex={-1}
102
+ onKeyDown={(e) => { if (e.key === 'Escape') onClose() }}>
103
+ <button type="button" onClick={onClose}>Close</button>
104
+ </div>
105
+ )
106
+ }
107
+ ```
108
+
109
+ It is for hand-rolled modals that are not a native `<dialog>`. A native `<dialog>`
110
+ opened with `showModal()` already keeps focus inside, and the kit's own `Dialog`
111
+ is one.
71
112
 
72
113
  ## Design tokens
73
114
 
package/dist/Table.d.ts CHANGED
@@ -30,12 +30,22 @@ export interface TableProps<T> {
30
30
  * is text, so that CSS can place them and label them.
31
31
  */
32
32
  readonly className?: string;
33
+ /**
34
+ * A name for the table, announced by screen readers (a visually hidden
35
+ * `<caption>`). Give one whenever a page has more than one table or the
36
+ * heading above it does not say what the rows are.
37
+ */
38
+ readonly caption?: string;
33
39
  }
34
40
  /**
35
41
  * A data table.
36
42
  *
37
43
  * Wrapped in its own horizontal scroller so that a wide table does not force the
38
- * whole page to scroll sideways on a narrow screen.
44
+ * whole page to scroll sideways on a narrow screen. Header cells carry
45
+ * `scope="col"`, and a column with an empty string header (a column of row
46
+ * buttons) gets a visually hidden "Actions" label so no header cell is empty.
47
+ * That label is in the `<th>` only; `data-label` stays unset for it, so the
48
+ * phone card layouts do not print it.
39
49
  */
40
- export declare function Table<T>({ columns, rows, rowKey, empty, className }: TableProps<T>): import("react").JSX.Element;
50
+ export declare function Table<T>({ columns, rows, rowKey, empty, className, caption }: TableProps<T>): import("react").JSX.Element;
41
51
  //# sourceMappingURL=Table.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../src/Table.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,+CAA+C;AAC/C,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB,wCAAwC;IACxC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;IAC1B,8EAA8E;IAC9E,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,SAAS,CAAA;CAC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AAI,EAAE,SAAS,CAAC,EAAE,CAAA;IAC3B,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,MAAM,CAAA;IACnC,0DAA0D;IAC1D,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAA;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,+BAkC3F"}
package/dist/Table.js CHANGED
@@ -3,11 +3,15 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
3
3
  * A data table.
4
4
  *
5
5
  * Wrapped in its own horizontal scroller so that a wide table does not force the
6
- * whole page to scroll sideways on a narrow screen.
6
+ * whole page to scroll sideways on a narrow screen. Header cells carry
7
+ * `scope="col"`, and a column with an empty string header (a column of row
8
+ * buttons) gets a visually hidden "Actions" label so no header cell is empty.
9
+ * That label is in the `<th>` only; `data-label` stays unset for it, so the
10
+ * phone card layouts do not print it.
7
11
  */
8
- export function Table({ columns, rows, rowKey, empty, className }) {
12
+ export function Table({ columns, rows, rowKey, empty, className, caption }) {
9
13
  if (rows.length === 0 && empty !== undefined)
10
14
  return _jsx(_Fragment, { children: empty });
11
- return (_jsx("div", { className: className === undefined ? 'wm-table__scroll' : `wm-table__scroll ${className}`, children: _jsxs("table", { className: "wm-table", children: [_jsx("thead", { children: _jsx("tr", { children: columns.map((c) => (_jsx("th", { "data-col": c.key, className: c.numeric === true ? 'wm-num' : undefined, children: c.header }, c.key))) }) }), _jsx("tbody", { children: rows.map((row) => (_jsx("tr", { children: columns.map((c) => (_jsx("td", { "data-col": c.key, "data-label": typeof c.header === 'string' && c.header !== '' ? c.header : undefined, className: c.numeric === true ? 'wm-num' : undefined, children: c.render(row) }, c.key))) }, rowKey(row)))) })] }) }));
15
+ return (_jsx("div", { className: className === undefined ? 'wm-table__scroll' : `wm-table__scroll ${className}`, children: _jsxs("table", { className: "wm-table", children: [caption === undefined ? null : _jsx("caption", { className: "wm-visually-hidden", children: caption }), _jsx("thead", { children: _jsx("tr", { children: columns.map((c) => (_jsx("th", { scope: "col", "data-col": c.key, className: c.numeric === true ? 'wm-num' : undefined, children: c.header === '' ? _jsx("span", { className: "wm-visually-hidden", children: "Actions" }) : c.header }, c.key))) }) }), _jsx("tbody", { children: rows.map((row) => (_jsx("tr", { children: columns.map((c) => (_jsx("td", { "data-col": c.key, "data-label": typeof c.header === 'string' && c.header !== '' ? c.header : undefined, className: c.numeric === true ? 'wm-num' : undefined, children: c.render(row) }, c.key))) }, rowKey(row)))) })] }) }));
12
16
  }
13
17
  //# sourceMappingURL=Table.js.map
package/dist/Table.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Table.js","sourceRoot":"","sources":["../src/Table.tsx"],"names":[],"mappings":";AAoCA;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAiB;IACjF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,4BAAG,KAAK,GAAI,CAAA;IACjE,OAAO,CACL,cAAK,SAAS,EAAE,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,oBAAoB,SAAS,EAAE,YAC5F,iBAAO,SAAS,EAAC,UAAU,aACzB,0BACE,uBACG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAClB,yBAA0B,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,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BAAS,SAAS,EAAC,oBAAoB,YAAE,OAAO,GAAW,EAC3F,0BACE,uBACG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAClB,aAAgB,KAAK,EAAC,KAAK,cAAW,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,YAC9F,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,eAAM,SAAS,EAAC,oBAAoB,wBAAe,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAD1E,CAAC,CAAC,GAAG,CAET,CACN,CAAC,GACC,GACC,EACR,0BACG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CACjB,uBACG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAClB,yBAEY,CAAC,CAAC,GAAG,gBACH,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EAClF,SAAS,EAAE,CAAC,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,YAEnD,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IALT,CAAC,CAAC,GAAG,CAMP,CACN,CAAC,IAVK,MAAM,CAAC,GAAG,CAAC,CAWf,CACN,CAAC,GACI,IACF,GACJ,CACP,CAAA;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -37,4 +37,6 @@ export { EmptyState } from './EmptyState.js';
37
37
  export type { EmptyStateProps } from './EmptyState.js';
38
38
  export { Spinner } from './Spinner.js';
39
39
  export type { SpinnerProps } from './Spinner.js';
40
+ export { useFocusTrap } from './useFocusTrap.js';
41
+ export type { FocusTrapOptions } from './useFocusTr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B,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA"}
package/dist/index.js CHANGED
@@ -18,4 +18,5 @@ export { orderByParent } from './orderByParent.js';
18
18
  export { Alert } from './Alert.js';
19
19
  export { EmptyState } from './EmptyState.js';
20
20
  export { Spinner } from './Spinner.js';
21
+ export { useFocusTrap } from './useFocusTrap.js';
21
22
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAA;AACrB,OAAO,kBAAkB,CAAA;AAEzB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAq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MAAM,YAAY,CAAA;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAGtD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA"}
package/dist/tokens.css CHANGED
@@ -14,7 +14,7 @@
14
14
  --wm-text-muted: #5b6472;
15
15
  --wm-accent: #2e500d;
16
16
  --wm-accent-text: #ffffff;
17
- --wm-positive: #0c7e65;
17
+ --wm-positive: #0a7660;
18
18
  --wm-negative: #c0392b;
19
19
  --wm-warning: #8a5a0a;
20
20
 
@@ -0,0 +1,26 @@
1
+ import { type RefObject } from 'react';
2
+ /** Options for {@link useFocusTrap}. */
3
+ export interface FocusTrapOptions {
4
+ /**
5
+ * Put focus back on whatever had it when the trap turned on, once it turns
6
+ * off. Default `true`. Turn it off when the caller returns focus somewhere
7
+ * more specific itself.
8
+ */
9
+ readonly restoreFocus?: boolean;
10
+ }
11
+ /**
12
+ * Keeps Tab and Shift+Tab inside a container while it is `active`.
13
+ *
14
+ * Tab from the last tabbable element wraps to the first and Shift+Tab from the
15
+ * first wraps to the last; if focus is somewhere outside the container (or on
16
+ * the container itself) the next Tab pulls it in. It does not move focus on
17
+ * activation (the caller knows what should be focused first) and does not
18
+ * handle Escape. Elements that are disabled, `inert`, hidden or `tabindex="-1"`
19
+ * are skipped. For a hand-rolled modal that is not a native `<dialog>`.
20
+ *
21
+ * @param ref - The container to trap focus in; must be attached when `active` is true.
22
+ * @param active - Whether the trap is on.
23
+ * @param options - See {@link FocusTrapOptions}.
24
+ */
25
+ export declare function useFocusTrap<T extends HTMLElement>(ref: RefObject<T | null>, active: boolean, { restoreFocus }?: FocusTrapOptions): void;
26
+ //# sourceMappingURL=useFocusTrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFocusTrap.d.ts","sourceRoot":"","sources":["../src/useFocusTrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAezD,wCAAwC;AACxC,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAChC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,WAAW,EAChD,GAAG,EAAE,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,EACxB,MAAM,EAAE,OAAO,EACf,EAAE,YAAmB,EAAE,GAAE,gBAAqB,GAC7C,IAAI,CA0BN"}
@@ -0,0 +1,61 @@
1
+ import { useEffect, useRef } from 'react';
2
+ const TABBABLE = 'a[href], button, input, select, textarea, summary, [tabindex], [contenteditable=""], [contenteditable="true"]';
3
+ function tabbablesIn(root) {
4
+ return Array.from(root.querySelectorAll(TABBABLE)).filter((el) => el.tabIndex >= 0 &&
5
+ !el.hasAttribute('disabled') &&
6
+ el.closest('[inert], [hidden]') === null &&
7
+ el.getAttribute('type') !== 'hidden');
8
+ }
9
+ /**
10
+ * Keeps Tab and Shift+Tab inside a container while it is `active`.
11
+ *
12
+ * Tab from the last tabbable element wraps to the first and Shift+Tab from the
13
+ * first wraps to the last; if focus is somewhere outside the container (or on
14
+ * the container itself) the next Tab pulls it in. It does not move focus on
15
+ * activation (the caller knows what should be focused first) and does not
16
+ * handle Escape. Elements that are disabled, `inert`, hidden or `tabindex="-1"`
17
+ * are skipped. For a hand-rolled modal that is not a native `<dialog>`.
18
+ *
19
+ * @param ref - The container to trap focus in; must be attached when `active` is true.
20
+ * @param active - Whether the trap is on.
21
+ * @param options - See {@link FocusTrapOptions}.
22
+ */
23
+ export function useFocusTrap(ref, active, { restoreFocus = true } = {}) {
24
+ const restore = useRef(restoreFocus);
25
+ restore.current = restoreFocus;
26
+ useEffect(() => {
27
+ if (!active)
28
+ return;
29
+ const opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
30
+ const onKey = (e) => {
31
+ const root = ref.current;
32
+ if (e.key !== 'Tab' || root === null)
33
+ return;
34
+ const items = tabbablesIn(root);
35
+ if (items.length === 0) {
36
+ e.preventDefault();
37
+ root.focus();
38
+ return;
39
+ }
40
+ const first = items[0];
41
+ const last = items[items.length - 1];
42
+ const current = document.activeElement;
43
+ const inside = current instanceof Node && root.contains(current) && current !== root;
44
+ if (e.shiftKey && (!inside || current === first)) {
45
+ e.preventDefault();
46
+ last.focus();
47
+ }
48
+ else if (!e.shiftKey && (!inside || current === last)) {
49
+ e.preventDefault();
50
+ first.focus();
51
+ }
52
+ };
53
+ document.addEventListener('keydown', onKey);
54
+ return () => {
55
+ document.removeEventListener('keydown', onKey);
56
+ if (restore.current && opener?.isConnected === true)
57
+ opener.focus();
58
+ };
59
+ }, [ref, active]);
60
+ }
61
+ //# sourceMappingURL=useFocusTrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFocusTrap.js","sourceRoot":"","sources":["../src/useFocusTrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAkB,MAAM,OAAO,CAAA;AAEzD,MAAM,QAAQ,GACZ,+GAA+G,CAAA;AAEjH,SAAS,WAAW,CAAC,IAAiB;IACpC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAc,QAAQ,CAAC,CAAC,CAAC,MAAM,CACpE,CAAC,EAAE,EAAE,EAAE,CACL,EAAE,CAAC,QAAQ,IAAI,CAAC;QAChB,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC;QAC5B,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAK,IAAI;QACxC,EAAE,CAAC,YAAY,CAAC,MAA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gBAAC,CAAC,CAAC,cAAc,EAAE,CAAC;gBAAC,IAAI,CAAC,KAAK,EAAE,CAAA;YAAC,CAAC;iBACjF,IAAI,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,MAAM,IAAI,OAAO,KAAK,IAAI,CAAC,EAAE,CAAC;gBAAC,CAAC,CAAC,cAAc,EAAE,CAAC;gBAAC,KAAK,CAAC,KAAK,EAAE,CAAA;YAAC,CAAC;QAC9F,CAAC,CAAA;QACD,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;QAC3C,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;YAC9C,IAAI,OAAO,CAAC,OAAO,IAAI,MAAM,EAAE,WAAW,KAAK,IAAI;gBAAE,MAAM,CAAC,KAAK,EAAE,CAAA;QACrE,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;AACnB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wickermoney/ui-kit",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,6 +21,10 @@
21
21
  },
22
22
  "./styles.css": "./dist/tokens.css"
23
23
  },
24
+ "sideEffects": [
25
+ "./dist/index.js",
26
+ "./dist/*.css"
27
+ ],
24
28
  "files": [
25
29
  "dist"
26
30
  ],
@@ -36,7 +40,7 @@
36
40
  "devDependencies": {
37
41
  "@testing-library/react": "^16.3.3",
38
42
  "@types/react": "^19.3.0",
39
- "jsdom": "30.1.1",
43
+ "jsdom": "30.1.2",
40
44
  "react": "^19.3.0",
41
45
  "react-dom": "^19.3.0",
42
46
  "typescript": "^6.0.3",