@tokyo3rdhq/magi-design-system 0.2.0 → 0.3.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.
package/dist/index.js CHANGED
@@ -1,289 +1,316 @@
1
- import { jsx as r, jsxs as f, Fragment as h } from "react/jsx-runtime";
2
- import { forwardRef as b, useId as N } from "react";
3
- function o(...n) {
1
+ import { jsx as o, jsxs as p, Fragment as y } from "react/jsx-runtime";
2
+ import { forwardRef as v, useId as N, isValidElement as P, cloneElement as $, useMemo as x, useInsertionEffect as C, createContext as k } from "react";
3
+ function l(...n) {
4
4
  return n.filter(Boolean).join(" ");
5
5
  }
6
- function x({
6
+ function E({
7
7
  size: n = "xl",
8
- as: a,
9
- className: e,
10
- children: t,
11
- ...i
12
- }) {
13
- const c = a ?? "div", s = o("magi-container", `magi-container--${n}`, e);
14
- return /* @__PURE__ */ r(c, { className: s, ...i, children: t });
15
- }
16
- function C({
17
- spacing: n = "lg",
18
- surface: a = "default",
19
- fullWidth: e = !1,
20
8
  as: t,
21
- className: i,
9
+ className: a,
22
10
  children: c,
23
11
  ...s
24
12
  }) {
25
- const m = t ?? "section", g = o(
13
+ const e = t ?? "div", i = l("magi-container", `magi-container--${n}`, a);
14
+ return /* @__PURE__ */ o(e, { className: i, ...s, children: c });
15
+ }
16
+ function j({
17
+ spacing: n = "lg",
18
+ surface: t = "default",
19
+ fullWidth: a = !1,
20
+ as: c,
21
+ className: s,
22
+ children: e,
23
+ ...i
24
+ }) {
25
+ const r = c ?? "section", m = l(
26
26
  "magi-section",
27
27
  `magi-section--${n}`,
28
- `magi-section--${a}`,
29
- e && "magi-section--fullWidth",
30
- i
28
+ `magi-section--${t}`,
29
+ a && "magi-section--fullWidth",
30
+ s
31
31
  );
32
- return /* @__PURE__ */ r(m, { className: g, ...s, children: c });
32
+ return /* @__PURE__ */ o(r, { className: m, ...i, children: e });
33
33
  }
34
- function w({
34
+ function T({
35
35
  direction: n = "column",
36
- gap: a = "4",
37
- align: e = "stretch",
38
- wrap: t = !0,
39
- as: i,
40
- className: c,
41
- style: s,
42
- children: m,
43
- ...g
36
+ gap: t = "4",
37
+ align: a = "stretch",
38
+ wrap: c = !0,
39
+ as: s,
40
+ className: e,
41
+ style: i,
42
+ children: r,
43
+ ...m
44
44
  }) {
45
- const d = i ?? "div", l = n === "row" && !t ? { flexWrap: "nowrap" } : void 0, u = o(
45
+ const g = s ?? "div", d = n === "row" && !c ? { flexWrap: "nowrap" } : void 0, u = l(
46
46
  "magi-stack",
47
47
  n === "row" && "magi-stack--row",
48
- `magi-stack--gap-${a}`,
49
- `magi-stack--align-${e}`,
50
- c
48
+ `magi-stack--gap-${t}`,
49
+ `magi-stack--align-${a}`,
50
+ e
51
51
  );
52
- return /* @__PURE__ */ r(d, { className: u, style: { ...l, ...s }, ...g, children: m });
52
+ return /* @__PURE__ */ o(g, { className: u, style: { ...d, ...i }, ...m, children: r });
53
53
  }
54
- const B = b(
54
+ const V = v(
55
55
  function({
56
- variant: a = "primary",
57
- size: e = "md",
58
- loading: t = !1,
59
- disabled: i,
60
- className: c,
61
- children: s,
62
- type: m,
63
- ...g
64
- }, d) {
65
- const l = o(
56
+ variant: t = "primary",
57
+ size: a = "md",
58
+ loading: c = !1,
59
+ disabled: s,
60
+ className: e,
61
+ children: i,
62
+ type: r,
63
+ ...m
64
+ }, g) {
65
+ const d = l(
66
66
  "magi-button",
67
+ `magi-button--${t}`,
67
68
  `magi-button--${a}`,
68
- `magi-button--${e}`,
69
- t && "magi-button--loading",
70
- c
69
+ c && "magi-button--loading",
70
+ e
71
71
  );
72
- return /* @__PURE__ */ r(
72
+ return /* @__PURE__ */ o(
73
73
  "button",
74
74
  {
75
- ref: d,
76
- className: l,
77
- type: m ?? "button",
78
- disabled: i || t,
79
- "aria-busy": t || void 0,
80
- ...g,
81
- children: s
75
+ ref: g,
76
+ className: d,
77
+ type: r ?? "button",
78
+ disabled: s || c,
79
+ "aria-busy": c || void 0,
80
+ ...m,
81
+ children: i
82
82
  }
83
83
  );
84
84
  }
85
- ), S = b(function({ variant: a = "default", padding: e = "md", className: t, children: i, ...c }, s) {
86
- const m = o(
85
+ ), F = v(function({ variant: t = "default", padding: a = "md", className: c, children: s, ...e }, i) {
86
+ const r = l(
87
87
  "magi-card",
88
- `magi-card--${a}`,
89
- `magi-card--padding-${e}`,
90
- t
88
+ `magi-card--${t}`,
89
+ `magi-card--padding-${a}`,
90
+ c
91
91
  );
92
- return /* @__PURE__ */ r("div", { ref: s, className: m, ...c, children: i });
93
- }), I = b(function({ variant: a = "neutral", dot: e = !1, className: t, children: i, ...c }, s) {
94
- const m = o(
92
+ return /* @__PURE__ */ o("div", { ref: i, className: r, ...e, children: s });
93
+ }), R = v(function({ variant: t = "neutral", dot: a = !1, className: c, children: s, ...e }, i) {
94
+ const r = l(
95
95
  "magi-badge",
96
- `magi-badge--${a}`,
97
- t
96
+ `magi-badge--${t}`,
97
+ c
98
98
  );
99
- return /* @__PURE__ */ f("span", { ref: s, className: m, ...c, children: [
100
- e ? /* @__PURE__ */ r("span", { className: "magi-badge__dot", "aria-hidden": "true" }) : null,
101
- i
99
+ return /* @__PURE__ */ p("span", { ref: i, className: r, ...e, children: [
100
+ a ? /* @__PURE__ */ o("span", { className: "magi-badge__dot", "aria-hidden": "true" }) : null,
101
+ s
102
102
  ] });
103
- }), E = b(
103
+ }), _ = v(
104
104
  function({
105
- children: a,
106
- labelPosition: e = "right",
107
- className: t,
108
- disabled: i,
109
- ...c
110
- }, s) {
111
- const m = /* @__PURE__ */ r(
105
+ children: t,
106
+ labelPosition: a = "right",
107
+ className: c,
108
+ disabled: s,
109
+ ...e
110
+ }, i) {
111
+ const r = /* @__PURE__ */ o(
112
112
  "input",
113
113
  {
114
- ref: s,
114
+ ref: i,
115
115
  type: "checkbox",
116
- className: o("magi-checkbox", t),
117
- disabled: i,
118
- ...c
116
+ className: l("magi-checkbox", c),
117
+ disabled: s,
118
+ ...e
119
119
  }
120
120
  );
121
- return a == null ? m : /* @__PURE__ */ r(
121
+ return t == null ? r : /* @__PURE__ */ o(
122
122
  "label",
123
123
  {
124
- className: o(
124
+ className: l(
125
125
  "magi-checkbox-label",
126
- i && "magi-checkbox-label--disabled"
126
+ s && "magi-checkbox-label--disabled"
127
127
  ),
128
- children: e === "left" ? /* @__PURE__ */ f(h, { children: [
129
- /* @__PURE__ */ r("span", { children: a }),
130
- m
131
- ] }) : /* @__PURE__ */ f(h, { children: [
132
- m,
133
- /* @__PURE__ */ r("span", { children: a })
128
+ children: a === "left" ? /* @__PURE__ */ p(y, { children: [
129
+ /* @__PURE__ */ o("span", { children: t }),
130
+ r
131
+ ] }) : /* @__PURE__ */ p(y, { children: [
132
+ r,
133
+ /* @__PURE__ */ o("span", { children: t })
134
134
  ] })
135
135
  }
136
136
  );
137
137
  }
138
- ), j = b(function({ inputSize: a = "md", invalid: e = !1, className: t, ...i }, c) {
139
- const s = o(
138
+ ), H = v(function({ inputSize: t = "md", invalid: a = !1, className: c, ...s }, e) {
139
+ const i = l(
140
140
  "magi-input",
141
- `magi-input--${a}`,
142
- e && "magi-input--invalid",
143
- t
141
+ `magi-input--${t}`,
142
+ a && "magi-input--invalid",
143
+ c
144
144
  );
145
- return /* @__PURE__ */ r(
145
+ return /* @__PURE__ */ o(
146
146
  "input",
147
147
  {
148
- ref: c,
149
- className: s,
150
- "aria-invalid": e || void 0,
151
- ...i
148
+ ref: e,
149
+ className: i,
150
+ "aria-invalid": a || void 0,
151
+ ...s
152
152
  }
153
153
  );
154
154
  });
155
- function F({
155
+ function h(...n) {
156
+ const t = n.filter(
157
+ (a) => typeof a == "string" && a.length > 0
158
+ );
159
+ return t.length > 0 ? t.join(" ") : void 0;
160
+ }
161
+ function M({
156
162
  label: n,
157
- helper: a,
158
- error: e,
159
- children: t,
160
- align: i = "stretch",
161
- className: c,
162
- helperId: s
163
+ helper: t,
164
+ error: a,
165
+ children: c,
166
+ align: s = "stretch",
167
+ className: e,
168
+ helperId: i
163
169
  }) {
164
- const m = N(), g = s ?? `magi-field-${m}`;
165
- return /* @__PURE__ */ f(
170
+ const m = `magi-field-${N()}`, g = `${m}-label`, d = i ?? `${m}-helper`, u = !!(a || t);
171
+ let b = c;
172
+ if (P(c)) {
173
+ const f = c.props;
174
+ b = $(c, {
175
+ id: f.id ?? m,
176
+ // MERGE with consumer-supplied IDs. The order is: consumer's first,
177
+ // then FormField's. This matches ARIA's "consumer-supplied IDs win
178
+ // for ordering" intuition — FormField's helpers are appended.
179
+ "aria-describedby": h(
180
+ f["aria-describedby"],
181
+ u ? d : void 0
182
+ ),
183
+ "aria-labelledby": h(
184
+ f["aria-labelledby"],
185
+ g
186
+ ),
187
+ // aria-invalid: when FormField has an error, force true (overriding
188
+ // consumer). When no error, preserve consumer's setting.
189
+ "aria-invalid": a ? !0 : f["aria-invalid"] ?? void 0
190
+ });
191
+ }
192
+ return /* @__PURE__ */ p(
166
193
  "div",
167
194
  {
168
- className: o(
195
+ className: l(
169
196
  "magi-field",
170
- `magi-field--align-${i}`,
171
- c
197
+ `magi-field--align-${s}`,
198
+ e
172
199
  ),
173
200
  children: [
174
- /* @__PURE__ */ r("label", { className: "magi-field-label", children: n }),
175
- t,
176
- (e || a) && /* @__PURE__ */ r(
201
+ /* @__PURE__ */ o("label", { id: g, className: "magi-field-label", children: n }),
202
+ b,
203
+ u && /* @__PURE__ */ o(
177
204
  "span",
178
205
  {
179
- id: g,
180
- className: o(
206
+ id: d,
207
+ className: l(
181
208
  "magi-field-helper",
182
- e && "magi-field-helper--error"
209
+ a && "magi-field-helper--error"
183
210
  ),
184
- children: e || a
211
+ children: a || t
185
212
  }
186
213
  )
187
214
  ]
188
215
  }
189
216
  );
190
217
  }
191
- function T({
218
+ function W({
192
219
  value: n,
193
- options: a,
194
- onChange: e,
195
- accent: t = !1,
196
- size: i = "md",
197
- disabled: c = !1,
198
- id: s,
199
- className: m,
200
- "aria-label": g,
201
- children: d
220
+ options: t,
221
+ onChange: a,
222
+ accent: c = !1,
223
+ size: s = "md",
224
+ disabled: e = !1,
225
+ id: i,
226
+ className: r,
227
+ "aria-label": m,
228
+ children: g
202
229
  }) {
203
- return /* @__PURE__ */ r(
230
+ return /* @__PURE__ */ o(
204
231
  "div",
205
232
  {
206
233
  role: "radiogroup",
207
- id: s,
208
- "aria-label": g,
209
- className: o(
234
+ id: i,
235
+ "aria-label": m,
236
+ className: l(
210
237
  "magi-segmented",
211
- `magi-segmented--${i}`,
212
- c && "magi-segmented--disabled",
213
- m
238
+ `magi-segmented--${s}`,
239
+ e && "magi-segmented--disabled",
240
+ r
214
241
  ),
215
- children: a.map((l) => {
216
- const u = l.value === n, p = !!(c || l.disabled), v = () => {
217
- p || u || e(l.value);
242
+ children: t.map((d) => {
243
+ const u = d.value === n, b = !!(e || d.disabled), f = () => {
244
+ b || u || a(d.value);
218
245
  };
219
- return d ? /* @__PURE__ */ r("div", { children: d(l, { active: u, disabled: p, onSelect: v }) }, l.value) : /* @__PURE__ */ r(
246
+ return g ? /* @__PURE__ */ o("div", { children: g(d, { active: u, disabled: b, onSelect: f }) }, d.value) : /* @__PURE__ */ o(
220
247
  "button",
221
248
  {
222
249
  type: "button",
223
250
  role: "radio",
224
251
  "aria-checked": u,
225
- disabled: p,
226
- onClick: v,
227
- className: o(
252
+ disabled: b,
253
+ onClick: f,
254
+ className: l(
228
255
  "magi-segmented-item",
229
256
  u && "magi-segmented-item--active",
230
- t && "magi-segmented-item--accent"
257
+ c && "magi-segmented-item--accent"
231
258
  ),
232
- children: l.label
259
+ children: d.label
233
260
  },
234
- l.value
261
+ d.value
235
262
  );
236
263
  })
237
264
  }
238
265
  );
239
266
  }
240
- function _({
267
+ function A({
241
268
  variant: n = "warning",
242
- className: a,
243
- children: e,
244
- ...t
269
+ className: t,
270
+ children: a,
271
+ ...c
245
272
  }) {
246
- return /* @__PURE__ */ r(
273
+ return /* @__PURE__ */ o(
247
274
  "div",
248
275
  {
249
276
  role: n === "error" || n === "warning" ? "alert" : "status",
250
- className: o(
277
+ className: l(
251
278
  "magi-banner",
252
279
  `magi-banner--${n}`,
253
- a
280
+ t
254
281
  ),
255
- ...t,
256
- children: e
282
+ ...c,
283
+ children: a
257
284
  }
258
285
  );
259
286
  }
260
- function P({
287
+ function D({
261
288
  title: n,
262
- description: a,
263
- action: e,
264
- children: t,
265
- className: i,
266
- ...c
289
+ description: t,
290
+ action: a,
291
+ children: c,
292
+ className: s,
293
+ ...e
267
294
  }) {
268
- const s = !!(n || a || e), m = a ?? t;
269
- return /* @__PURE__ */ r(
295
+ const i = !!(n || t || a), r = t ?? c;
296
+ return /* @__PURE__ */ o(
270
297
  "div",
271
298
  {
272
- className: o(
299
+ className: l(
273
300
  "magi-empty",
274
- s && "magi-empty--structured",
275
- i
301
+ i && "magi-empty--structured",
302
+ s
276
303
  ),
277
- ...c,
278
- children: s ? /* @__PURE__ */ f(h, { children: [
279
- n ? /* @__PURE__ */ r("p", { className: "magi-empty-title", children: n }) : null,
280
- m != null ? /* @__PURE__ */ r("p", { className: "magi-empty-description", children: m }) : null,
281
- e ? /* @__PURE__ */ r("div", { className: "magi-empty-action", children: e }) : null
282
- ] }) : t
304
+ ...e,
305
+ children: i ? /* @__PURE__ */ p(y, { children: [
306
+ n ? /* @__PURE__ */ o("p", { className: "magi-empty-title", children: n }) : null,
307
+ r != null ? /* @__PURE__ */ o("p", { className: "magi-empty-description", children: r }) : null,
308
+ a ? /* @__PURE__ */ o("div", { className: "magi-empty-action", children: a }) : null
309
+ ] }) : c
283
310
  }
284
311
  );
285
312
  }
286
- const y = {
313
+ const I = {
287
314
  green: {
288
315
  "--magi-accent": "#00c853",
289
316
  "--magi-accent-hover": "#00e676",
@@ -314,29 +341,43 @@ const y = {
314
341
  "--magi-accent-soft": "rgba(255, 255, 255, 0.08)",
315
342
  "--magi-accent-contrast": "#050505"
316
343
  }
317
- };
318
- function R({
344
+ }, S = k(null);
345
+ function O({
319
346
  accent: n = "green",
320
- name: a,
321
- tokens: e,
322
- children: t
347
+ name: t,
348
+ children: a
323
349
  }) {
324
- const c = { ...y[n], ...e };
325
- return /* @__PURE__ */ r("div", { "data-magi-product": a, style: c, children: t });
350
+ const c = x(() => ({ accent: n }), [n]);
351
+ return C(() => {
352
+ if (typeof document > "u") return;
353
+ const s = I[n], e = document.documentElement, i = {
354
+ accent: e.style.getPropertyValue("--magi-accent"),
355
+ accentHover: e.style.getPropertyValue("--magi-accent-hover"),
356
+ accentSoft: e.style.getPropertyValue("--magi-accent-soft"),
357
+ accentContrast: e.style.getPropertyValue("--magi-accent-contrast"),
358
+ product: e.dataset.magiProduct
359
+ };
360
+ return e.style.setProperty("--magi-accent", s["--magi-accent"]), e.style.setProperty("--magi-accent-hover", s["--magi-accent-hover"]), e.style.setProperty("--magi-accent-soft", s["--magi-accent-soft"]), e.style.setProperty("--magi-accent-contrast", s["--magi-accent-contrast"]), t ? e.dataset.magiProduct = t : delete e.dataset.magiProduct, () => {
361
+ const r = (m, g) => {
362
+ g ? e.style.setProperty(m, g) : e.style.removeProperty(m);
363
+ };
364
+ r("--magi-accent", i.accent), r("--magi-accent-hover", i.accentHover), r("--magi-accent-soft", i.accentSoft), r("--magi-accent-contrast", i.accentContrast), i.product !== void 0 ? e.dataset.magiProduct = i.product : e.dataset.magiProduct !== void 0 && delete e.dataset.magiProduct;
365
+ };
366
+ }, [n, t]), /* @__PURE__ */ o(S.Provider, { value: c, children: a });
326
367
  }
327
368
  export {
328
- I as Badge,
329
- _ as Banner,
330
- B as Button,
331
- S as Card,
332
- E as Checkbox,
333
- x as Container,
334
- P as EmptyState,
335
- F as FormField,
336
- j as Input,
337
- R as ProductTheme,
338
- C as Section,
339
- T as Segmented,
340
- w as Stack
369
+ R as Badge,
370
+ A as Banner,
371
+ V as Button,
372
+ F as Card,
373
+ _ as Checkbox,
374
+ E as Container,
375
+ D as EmptyState,
376
+ M as FormField,
377
+ H as Input,
378
+ O as ProductTheme,
379
+ j as Section,
380
+ W as Segmented,
381
+ T as Stack
341
382
  };
342
383
  //# sourceMappingURL=index.js.map