@blockle/blocks 0.5.1 → 0.7.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.
Files changed (51) hide show
  1. package/dist/index.cjs +264 -186
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.mjs +262 -184
  4. package/dist/momotaro.chunk.d.ts +337 -251
  5. package/dist/styles/components/Input/input.css.cjs +14 -0
  6. package/dist/styles/components/Input/input.css.mjs +15 -0
  7. package/dist/styles/lib/css/atoms/atomicProperties.cjs +17 -17
  8. package/dist/styles/lib/css/atoms/atomicProperties.mjs +1 -1
  9. package/dist/styles/lib/theme/makeComponentTheme.cjs +5 -0
  10. package/dist/styles/lib/theme/makeComponentTheme.mjs +6 -0
  11. package/dist/styles/lib/theme/makeTheme.cjs +12 -0
  12. package/dist/styles/lib/{css/theme → theme}/makeTheme.mjs +3 -2
  13. package/dist/styles/lib/theme/vars.css.cjs +9 -0
  14. package/dist/styles/lib/{css/theme → theme}/vars.css.mjs +1 -1
  15. package/dist/styles/themes/momotaro/components/button.css.cjs +21 -12
  16. package/dist/styles/themes/momotaro/components/button.css.mjs +14 -5
  17. package/dist/styles/themes/momotaro/components/checkbox.css.cjs +53 -0
  18. package/dist/styles/themes/momotaro/components/checkbox.css.mjs +54 -0
  19. package/dist/styles/themes/momotaro/components/dialog.css.cjs +25 -6
  20. package/dist/styles/themes/momotaro/components/dialog.css.mjs +24 -5
  21. package/dist/styles/themes/momotaro/components/divider.css.cjs +2 -2
  22. package/dist/styles/themes/momotaro/components/divider.css.mjs +1 -1
  23. package/dist/styles/themes/momotaro/components/helpers.css.cjs +20 -5
  24. package/dist/styles/themes/momotaro/components/helpers.css.mjs +18 -3
  25. package/dist/styles/themes/momotaro/components/index.cjs +11 -3
  26. package/dist/styles/themes/momotaro/components/index.mjs +11 -3
  27. package/dist/styles/themes/momotaro/components/input.css.cjs +40 -0
  28. package/dist/styles/themes/momotaro/components/input.css.mjs +41 -0
  29. package/dist/styles/themes/momotaro/components/label.css.cjs +33 -0
  30. package/dist/styles/themes/momotaro/components/label.css.mjs +34 -0
  31. package/dist/styles/themes/momotaro/components/link.css.cjs +6 -4
  32. package/dist/styles/themes/momotaro/components/link.css.mjs +5 -3
  33. package/dist/styles/themes/momotaro/components/radio.css.cjs +53 -0
  34. package/dist/styles/themes/momotaro/components/radio.css.mjs +54 -0
  35. package/dist/styles/themes/momotaro/components/spinner.css.cjs +2 -2
  36. package/dist/styles/themes/momotaro/components/spinner.css.mjs +1 -1
  37. package/dist/styles/themes/momotaro/components/transitions.cjs +3 -0
  38. package/dist/styles/themes/momotaro/components/transitions.mjs +4 -0
  39. package/dist/styles/themes/momotaro/momotaro.css.cjs +2 -2
  40. package/dist/styles/themes/momotaro/momotaro.css.mjs +1 -1
  41. package/dist/styles/themes/momotaro/tokens.css.cjs +4 -4
  42. package/dist/styles/themes/momotaro/tokens.css.mjs +4 -4
  43. package/package.json +2 -2
  44. package/dist/styles/lib/css/theme/makeComponentTheme.cjs +0 -3
  45. package/dist/styles/lib/css/theme/makeComponentTheme.mjs +0 -4
  46. package/dist/styles/lib/css/theme/makeTheme.cjs +0 -11
  47. package/dist/styles/lib/css/theme/vars.css.cjs +0 -9
  48. /package/dist/styles/lib/{css/theme → theme}/makeVanillaTheme.cjs +0 -0
  49. /package/dist/styles/lib/{css/theme → theme}/makeVanillaTheme.mjs +0 -0
  50. /package/dist/styles/lib/{css/theme → theme}/tokens.cjs +0 -0
  51. /package/dist/styles/lib/{css/theme → theme}/tokens.mjs +0 -0
package/dist/index.mjs CHANGED
@@ -1,23 +1,36 @@
1
1
  'use client';
2
2
 
3
3
  import { breakpointQuery } from "./styles/lib/css/atoms/breakpoints.mjs";
4
- import { makeComponentTheme } from "./styles/lib/css/theme/makeComponentTheme.mjs";
5
- import { makeTheme } from "./styles/lib/css/theme/makeTheme.mjs";
6
- import { vars } from "./styles/lib/css/theme/vars.css.mjs";
4
+ import { makeComponentTheme } from "./styles/lib/theme/makeComponentTheme.mjs";
5
+ import { makeTheme } from "./styles/lib/theme/makeTheme.mjs";
6
+ import { vars } from "./styles/lib/theme/vars.css.mjs";
7
7
  import { atoms } from "./styles/lib/css/atoms/sprinkles.css.mjs";
8
- import { createContext, forwardRef, useContext, useRef, useEffect, useState, useCallback, useLayoutEffect } from "react";
8
+ import { createContext, forwardRef, useContext, useRef, useEffect, useState, useCallback, useLayoutEffect, useId } from "react";
9
9
  import { jsx, jsxs } from "react/jsx-runtime";
10
10
  import { buttonReset } from "./styles/components/Button/Button.css.mjs";
11
- import { divider } from "./styles/components/Divider/divider.css.mjs";
12
11
  import { backdropLeaveAnimation, backdropLeave, backdrop, dialogLeave, dialog } from "./styles/components/Dialog/dialog.css.mjs";
13
12
  import { createPortal } from "react-dom";
13
+ import { divider } from "./styles/components/Divider/divider.css.mjs";
14
+ import { input } from "./styles/components/Input/input.css.mjs";
14
15
  const classnames = (...args) => {
15
16
  const className = args.filter((arg) => arg && typeof arg === "string").join(" ");
16
17
  return className || void 0;
17
18
  };
18
19
  const BlocksProviderContext = createContext(null);
19
- const BlocksProvider = ({ children, theme }) => {
20
- return /* @__PURE__ */ jsx(BlocksProviderContext.Provider, { value: theme, children: /* @__PURE__ */ jsx("div", { className: classnames(theme.vars, atoms({ fontFamily: "primary" })), children }) });
20
+ const BlocksProvider = ({
21
+ children,
22
+ theme,
23
+ className,
24
+ ...restProps
25
+ }) => {
26
+ return /* @__PURE__ */ jsx(BlocksProviderContext.Provider, { value: theme, children: /* @__PURE__ */ jsx(
27
+ "div",
28
+ {
29
+ className: classnames(theme.vars, atoms({ fontFamily: "primary" }), className),
30
+ ...restProps,
31
+ children
32
+ }
33
+ ) });
21
34
  };
22
35
  const defaultElement$1 = "div";
23
36
  const Box = forwardRef(function Box2({ className, as, ...restProps }, ref) {
@@ -40,55 +53,58 @@ const useTheme = () => {
40
53
  }
41
54
  return theme;
42
55
  };
43
- const hasOwnProperty = Object.prototype.hasOwnProperty;
44
- function useComponentStyles(name, props) {
56
+ function useComponentStyles(name, props, useDefaultVariants = true) {
45
57
  const { components } = useTheme();
46
58
  const component = components[name];
47
59
  if (!component) {
48
- console.info(`Component ${name} is not defined in the theme`);
60
+ console.warn(`Component ${name} is not defined in the theme`);
49
61
  return "";
50
62
  }
51
63
  const classNames = [];
52
- const propsWithDefaults = { ...props };
53
- if (component.defaultVariants) {
54
- const keys2 = Object.keys(component.defaultVariants);
55
- for (const key of keys2) {
56
- if (propsWithDefaults[key] === void 0) {
57
- propsWithDefaults[key] = component.defaultVariants[key];
58
- }
64
+ const variants = props.variants ?? {};
65
+ const variantsWithDefaults = { ...variants };
66
+ for (const key in props) {
67
+ const value = props[key];
68
+ if (typeof value === "boolean" && value) {
69
+ classNames.push(component[key]);
59
70
  }
60
71
  }
61
- if (propsWithDefaults.base && component.base) {
62
- classNames.push(component.base);
63
- }
64
72
  if (!component.variants) {
65
73
  return classNames.join(" ");
66
74
  }
67
- const keys = Object.keys(propsWithDefaults);
68
- for (const key of keys) {
69
- const value = propsWithDefaults[key];
70
- if (key === "base" || value === void 0) {
71
- continue;
75
+ const { defaultVariants } = component;
76
+ if (useDefaultVariants && defaultVariants) {
77
+ const keys2 = Object.keys(defaultVariants);
78
+ for (const key of keys2) {
79
+ if (variantsWithDefaults[key] === void 0 && defaultVariants[key]) {
80
+ variantsWithDefaults[key] = defaultVariants[key];
81
+ }
72
82
  }
73
- if (!hasOwnProperty.call(component.variants, key)) {
83
+ }
84
+ const keys = Object.keys(variantsWithDefaults);
85
+ const componentVariants = component.variants;
86
+ for (const key of keys) {
87
+ const value = variantsWithDefaults[key];
88
+ if (value === void 0) {
74
89
  continue;
75
90
  }
76
91
  if (typeof value === "boolean") {
77
- if (value) {
78
- classNames.push(component.variants[key]);
92
+ if (value && componentVariants[key]) {
93
+ classNames.push(componentVariants[key]);
79
94
  }
80
95
  continue;
81
96
  }
82
- const variant = component.variants[key][value];
97
+ const variant = componentVariants[key][value];
83
98
  if (variant) {
84
99
  classNames.push(variant);
85
100
  }
86
101
  }
87
- if (component.compoundVariants) {
88
- for (const compoundVariant of component.compoundVariants) {
102
+ const { compoundVariants } = component;
103
+ if (compoundVariants) {
104
+ for (const compoundVariant of compoundVariants) {
89
105
  const keys2 = Object.keys(compoundVariant.variants);
90
106
  const matches = keys2.every((key) => {
91
- const value = propsWithDefaults[key];
107
+ const value = variantsWithDefaults[key];
92
108
  if (value === void 0) {
93
109
  return false;
94
110
  }
@@ -104,10 +120,13 @@ function useComponentStyles(name, props) {
104
120
  const useComponentStyleDefaultProps = (name) => {
105
121
  const { components } = useTheme();
106
122
  const component = components[name];
107
- return (component == null ? void 0 : component.defaultVariants) ?? {};
123
+ if (!component) {
124
+ return {};
125
+ }
126
+ return component.defaultVariants ?? {};
108
127
  };
109
128
  const Spinner = ({ className, size, color, ...restProps }) => {
110
- const spinnerClassName = useComponentStyles("spinner", { base: true, size, color });
129
+ const spinnerClassName = useComponentStyles("spinner", { base: true, variants: { size, color } });
111
130
  return /* @__PURE__ */ jsx(Box, { color, className: classnames(spinnerClassName, className), ...restProps });
112
131
  };
113
132
  const Button = forwardRef(function Button2({
@@ -124,26 +143,22 @@ const Button = forwardRef(function Button2({
124
143
  disabled,
125
144
  ...restProps
126
145
  }, ref) {
127
- const isLinkVariant = variant === "link";
128
146
  const buttonClassName = useComponentStyles("button", {
129
147
  base: true,
130
- variant: isLinkVariant ? "solid" : variant,
131
- intent,
132
- size,
133
- disabled,
134
- loading
148
+ variants: {
149
+ variant,
150
+ intent,
151
+ size,
152
+ disabled,
153
+ loading
154
+ }
135
155
  });
136
- const linkClassName = useComponentStyles("link", { base: true, variant: "primary" });
137
156
  return /* @__PURE__ */ jsxs(
138
157
  Box,
139
158
  {
140
159
  ref,
141
160
  as: "button",
142
- className: classnames(
143
- buttonReset,
144
- isLinkVariant ? linkClassName : buttonClassName,
145
- className
146
- ),
161
+ className: classnames(buttonReset, buttonClassName, className),
147
162
  width,
148
163
  type,
149
164
  disabled: disabled || loading,
@@ -157,140 +172,6 @@ const Button = forwardRef(function Button2({
157
172
  }
158
173
  );
159
174
  });
160
- const Heading = ({
161
- className,
162
- level = 1,
163
- children,
164
- align,
165
- fontSize,
166
- fontWeight = "strong",
167
- fontFamily,
168
- ...restProps
169
- }) => {
170
- const as = `h${level}`;
171
- return /* @__PURE__ */ jsx(
172
- Box,
173
- {
174
- as,
175
- className,
176
- fontFamily,
177
- fontWeight,
178
- fontSize,
179
- textAlign: align,
180
- padding: "none",
181
- margin: "none",
182
- ...restProps,
183
- children
184
- }
185
- );
186
- };
187
- const justifyContentMap = {
188
- left: "flex-start",
189
- right: "flex-end",
190
- center: "center",
191
- between: "space-between",
192
- around: "space-around"
193
- };
194
- const alignItemsMap = {
195
- left: "flex-start",
196
- right: "flex-end",
197
- center: "center",
198
- stretch: "stretch"
199
- };
200
- const Inline = ({
201
- alignX,
202
- alignY,
203
- as = "div",
204
- children,
205
- display = "flex",
206
- gap,
207
- ...props
208
- }) => {
209
- return /* @__PURE__ */ jsx(
210
- Box,
211
- {
212
- as,
213
- display,
214
- gap,
215
- flexDirection: "row",
216
- justifyContent: alignX ? justifyContentMap[alignX] : void 0,
217
- alignItems: alignY ? alignItemsMap[alignY] : void 0,
218
- flexWrap: "wrap",
219
- ...props,
220
- children
221
- }
222
- );
223
- };
224
- const Stack = ({
225
- as = "div",
226
- display = "flex",
227
- children,
228
- gap,
229
- alignX,
230
- ...restProps
231
- }) => {
232
- if (process.env.NODE_ENV === "development" && restProps.start !== void 0 && as !== "ol") {
233
- console.warn('Stack: start prop is only valid when as="ol"');
234
- }
235
- return /* @__PURE__ */ jsx(
236
- Box,
237
- {
238
- as,
239
- display,
240
- gap,
241
- flexDirection: "column",
242
- alignItems: alignX ? alignItemsMap[alignX] : void 0,
243
- ...restProps,
244
- children
245
- }
246
- );
247
- };
248
- const Text = ({
249
- as = "span",
250
- children,
251
- color,
252
- fontSize,
253
- fontWeight,
254
- fontFamily,
255
- textAlign,
256
- ...restProps
257
- }) => {
258
- return /* @__PURE__ */ jsx(
259
- Box,
260
- {
261
- as,
262
- color,
263
- fontSize,
264
- fontWeight,
265
- fontFamily,
266
- textAlign,
267
- padding: "none",
268
- margin: "none",
269
- ...restProps,
270
- children
271
- }
272
- );
273
- };
274
- const defaultElement = "a";
275
- const Link = forwardRef(function Link2({ as, className, variant, underline, ...restProps }, ref) {
276
- const Component = as || defaultElement;
277
- const linkClassName = useComponentStyles("link", { base: true, variant, underline });
278
- return /* @__PURE__ */ jsx(Box, { ref, as: Component, className: classnames(className, linkClassName), ...restProps });
279
- });
280
- const Divider = ({ className, color, ...restProps }) => {
281
- const dividerClass = useComponentStyles("divider", { base: true });
282
- const dividerDefaults = useComponentStyleDefaultProps("divider");
283
- return /* @__PURE__ */ jsx(
284
- Box,
285
- {
286
- role: "separator",
287
- width: "full",
288
- backgroundColor: color ?? dividerDefaults.color,
289
- className: classnames(className, dividerClass, divider),
290
- ...restProps
291
- }
292
- );
293
- };
294
175
  const useLayer = () => {
295
176
  const layerRef = useRef();
296
177
  useEffect(
@@ -303,7 +184,9 @@ const useLayer = () => {
303
184
  );
304
185
  return () => {
305
186
  if (!layerRef.current) {
306
- layerRef.current = document.createElement("div");
187
+ const div = document.createElement("div");
188
+ div.dataset.layer = "blocks";
189
+ layerRef.current = div;
307
190
  document.body.append(layerRef.current);
308
191
  }
309
192
  return layerRef.current;
@@ -394,7 +277,14 @@ const Portal = ({ children, container }) => {
394
277
  container || document.body
395
278
  );
396
279
  };
397
- const Dialog = ({ children, open, className, onRequestClose }) => {
280
+ const Dialog = ({
281
+ children,
282
+ open,
283
+ className,
284
+ onRequestClose,
285
+ size,
286
+ ...restProps
287
+ }) => {
398
288
  const dialogRef = useRef(null);
399
289
  const layer = useLayer();
400
290
  const [visible, hide] = useVisibilityState(open);
@@ -431,8 +321,8 @@ const Dialog = ({ children, open, className, onRequestClose }) => {
431
321
  document.removeEventListener("keydown", handleKeyDown);
432
322
  };
433
323
  }, [open, enabled]);
434
- const backdropClassName = useComponentStyles("dialog", { backdrop: true });
435
- const dialogClassName = useComponentStyles("dialog", { base: true });
324
+ const backdropClassName = useComponentStyles("dialog", { backdrop: true }, false);
325
+ const dialogClassName = useComponentStyles("dialog", { base: true, variants: { size } });
436
326
  if (!visible) {
437
327
  return null;
438
328
  }
@@ -449,6 +339,7 @@ const Dialog = ({ children, open, className, onRequestClose }) => {
449
339
  {
450
340
  ref: dialogRef,
451
341
  as: "dialog",
342
+ "aria-modal": "true",
452
343
  open: true,
453
344
  className: classnames(
454
345
  dialog,
@@ -456,12 +347,197 @@ const Dialog = ({ children, open, className, onRequestClose }) => {
456
347
  dialogClassName,
457
348
  className
458
349
  ),
350
+ ...restProps,
459
351
  children
460
352
  }
461
353
  )
462
354
  }
463
355
  ) }) });
464
356
  };
357
+ const Divider = ({ className, color, ...restProps }) => {
358
+ const dividerClass = useComponentStyles("divider", { base: true });
359
+ const dividerDefaults = useComponentStyleDefaultProps("divider");
360
+ return /* @__PURE__ */ jsx(
361
+ Box,
362
+ {
363
+ role: "separator",
364
+ width: "full",
365
+ backgroundColor: color ?? dividerDefaults.color,
366
+ className: classnames(className, dividerClass, divider),
367
+ ...restProps
368
+ }
369
+ );
370
+ };
371
+ const Heading = ({
372
+ className,
373
+ level = 1,
374
+ children,
375
+ align,
376
+ fontSize,
377
+ fontWeight = "strong",
378
+ fontFamily,
379
+ ...restProps
380
+ }) => {
381
+ const as = `h${level}`;
382
+ return /* @__PURE__ */ jsx(
383
+ Box,
384
+ {
385
+ as,
386
+ className,
387
+ fontFamily,
388
+ fontWeight,
389
+ fontSize,
390
+ textAlign: align,
391
+ padding: "none",
392
+ margin: "none",
393
+ ...restProps,
394
+ children
395
+ }
396
+ );
397
+ };
398
+ const justifyContentMap = {
399
+ left: "flex-start",
400
+ right: "flex-end",
401
+ center: "center",
402
+ between: "space-between",
403
+ around: "space-around"
404
+ };
405
+ const alignItemsMap = {
406
+ left: "flex-start",
407
+ right: "flex-end",
408
+ center: "center",
409
+ stretch: "stretch"
410
+ };
411
+ const Inline = ({
412
+ alignX,
413
+ alignY,
414
+ as = "div",
415
+ children,
416
+ display = "flex",
417
+ gap,
418
+ ...props
419
+ }) => {
420
+ return /* @__PURE__ */ jsx(
421
+ Box,
422
+ {
423
+ as,
424
+ display,
425
+ gap,
426
+ flexDirection: "row",
427
+ justifyContent: alignX ? justifyContentMap[alignX] : void 0,
428
+ alignItems: alignY ? alignItemsMap[alignY] : void 0,
429
+ flexWrap: "wrap",
430
+ ...props,
431
+ children
432
+ }
433
+ );
434
+ };
435
+ const Input = forwardRef(function Input2({ className, name, type = "text", startSlot, endSlot, label, placeholder, ...restProps }, ref) {
436
+ const id = useId();
437
+ const containerClassName = useComponentStyles("input", { container: true }, false);
438
+ const inputClassName = useComponentStyles("input", { input: true });
439
+ return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", className: classnames(containerClassName, className), children: [
440
+ startSlot,
441
+ /* @__PURE__ */ jsx(
442
+ Box,
443
+ {
444
+ as: "input",
445
+ id,
446
+ ref,
447
+ name,
448
+ type,
449
+ placeholder: placeholder || label,
450
+ width: "full",
451
+ overflow: "hidden",
452
+ className: classnames(input, inputClassName),
453
+ ...restProps
454
+ }
455
+ ),
456
+ endSlot
457
+ ] }) });
458
+ });
459
+ const Label = ({
460
+ visualOnly,
461
+ children,
462
+ className,
463
+ required,
464
+ size,
465
+ cursor,
466
+ ...restProps
467
+ }) => {
468
+ const Component = visualOnly ? "span" : "label";
469
+ const containerClassName = useComponentStyles("label", {
470
+ base: true,
471
+ variants: { required, size }
472
+ });
473
+ return /* @__PURE__ */ jsx(
474
+ Component,
475
+ {
476
+ className: classnames(containerClassName, className, atoms({ cursor })),
477
+ ...restProps,
478
+ children
479
+ }
480
+ );
481
+ };
482
+ const defaultElement = "a";
483
+ const Link = forwardRef(function Link2({ as, className, variant, underline, ...restProps }, ref) {
484
+ const Component = as || defaultElement;
485
+ const linkClassName = useComponentStyles("link", {
486
+ base: true,
487
+ variants: { variant, underline }
488
+ });
489
+ return /* @__PURE__ */ jsx(Box, { ref, as: Component, className: classnames(className, linkClassName), ...restProps });
490
+ });
491
+ const Stack = ({
492
+ as = "div",
493
+ display = "flex",
494
+ children,
495
+ gap,
496
+ alignX,
497
+ ...restProps
498
+ }) => {
499
+ if (process.env.NODE_ENV === "development" && restProps.start !== void 0 && as !== "ol") {
500
+ console.warn('Stack: start prop is only valid when as="ol"');
501
+ }
502
+ return /* @__PURE__ */ jsx(
503
+ Box,
504
+ {
505
+ as,
506
+ display,
507
+ gap,
508
+ flexDirection: "column",
509
+ alignItems: alignX ? alignItemsMap[alignX] : void 0,
510
+ ...restProps,
511
+ children
512
+ }
513
+ );
514
+ };
515
+ const Text = ({
516
+ as = "span",
517
+ children,
518
+ color,
519
+ fontSize,
520
+ fontWeight,
521
+ fontFamily,
522
+ textAlign,
523
+ ...restProps
524
+ }) => {
525
+ return /* @__PURE__ */ jsx(
526
+ Box,
527
+ {
528
+ as,
529
+ color,
530
+ fontSize,
531
+ fontWeight,
532
+ fontFamily,
533
+ textAlign,
534
+ padding: "none",
535
+ margin: "none",
536
+ ...restProps,
537
+ children
538
+ }
539
+ );
540
+ };
465
541
  export {
466
542
  BlocksProvider,
467
543
  Box,
@@ -470,6 +546,8 @@ export {
470
546
  Divider,
471
547
  Heading,
472
548
  Inline,
549
+ Input,
550
+ Label,
473
551
  Link,
474
552
  Spinner,
475
553
  Stack,