@blockle/blocks 0.6.0 → 0.7.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.
Files changed (27) hide show
  1. package/dist/index.cjs +215 -149
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.mjs +223 -157
  4. package/dist/momotaro.chunk.d.ts +142 -69
  5. package/dist/styles/components/Checkbox/checkbox.css.cjs +31 -0
  6. package/dist/styles/components/Checkbox/checkbox.css.mjs +32 -0
  7. package/dist/styles/components/Radio/radio.css.cjs +31 -0
  8. package/dist/styles/components/Radio/radio.css.mjs +32 -0
  9. package/dist/styles/themes/momotaro/components/button.css.cjs +1 -1
  10. package/dist/styles/themes/momotaro/components/button.css.mjs +1 -1
  11. package/dist/styles/themes/momotaro/components/checkbox.css.cjs +53 -0
  12. package/dist/styles/themes/momotaro/components/checkbox.css.mjs +54 -0
  13. package/dist/styles/themes/momotaro/components/helpers.css.cjs +13 -0
  14. package/dist/styles/themes/momotaro/components/helpers.css.mjs +13 -0
  15. package/dist/styles/themes/momotaro/components/index.cjs +7 -1
  16. package/dist/styles/themes/momotaro/components/index.mjs +7 -1
  17. package/dist/styles/themes/momotaro/components/input.css.cjs +3 -3
  18. package/dist/styles/themes/momotaro/components/input.css.mjs +3 -3
  19. package/dist/styles/themes/momotaro/components/label.css.cjs +33 -0
  20. package/dist/styles/themes/momotaro/components/label.css.mjs +34 -0
  21. package/dist/styles/themes/momotaro/components/link.css.cjs +1 -0
  22. package/dist/styles/themes/momotaro/components/link.css.mjs +1 -0
  23. package/dist/styles/themes/momotaro/components/radio.css.cjs +53 -0
  24. package/dist/styles/themes/momotaro/components/radio.css.mjs +54 -0
  25. package/dist/styles/themes/momotaro/components/transitions.cjs +3 -0
  26. package/dist/styles/themes/momotaro/components/transitions.mjs +4 -0
  27. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -5,13 +5,15 @@ import { makeComponentTheme } from "./styles/lib/theme/makeComponentTheme.mjs";
5
5
  import { makeTheme } from "./styles/lib/theme/makeTheme.mjs";
6
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, useId } from "react";
9
8
  import { jsx, jsxs } from "react/jsx-runtime";
9
+ import { createContext, forwardRef, useContext, useRef, useEffect, useState, useCallback, useLayoutEffect, useId } from "react";
10
10
  import { buttonReset } from "./styles/components/Button/Button.css.mjs";
11
- import { divider } from "./styles/components/Divider/divider.css.mjs";
11
+ import { container, input, icon } from "./styles/components/Checkbox/checkbox.css.mjs";
12
12
  import { backdropLeaveAnimation, backdropLeave, backdrop, dialogLeave, dialog } from "./styles/components/Dialog/dialog.css.mjs";
13
13
  import { createPortal } from "react-dom";
14
- import { input } from "./styles/components/Input/input.css.mjs";
14
+ import { divider } from "./styles/components/Divider/divider.css.mjs";
15
+ import { input as input$1 } from "./styles/components/Input/input.css.mjs";
16
+ import { container as container$1, input as input$2, icon as icon$1 } from "./styles/components/Radio/radio.css.mjs";
15
17
  const classnames = (...args) => {
16
18
  const className = args.filter((arg) => arg && typeof arg === "string").join(" ");
17
19
  return className || void 0;
@@ -72,33 +74,36 @@ function useComponentStyles(name, props, useDefaultVariants = true) {
72
74
  if (!component.variants) {
73
75
  return classNames.join(" ");
74
76
  }
75
- if (useDefaultVariants && component.defaultVariants) {
76
- const keys2 = Object.keys(component.defaultVariants);
77
+ const { defaultVariants } = component;
78
+ if (useDefaultVariants && defaultVariants) {
79
+ const keys2 = Object.keys(defaultVariants);
77
80
  for (const key of keys2) {
78
- if (variantsWithDefaults[key] === void 0) {
79
- variantsWithDefaults[key] = component.defaultVariants[key];
81
+ if (variantsWithDefaults[key] === void 0 && defaultVariants[key]) {
82
+ variantsWithDefaults[key] = defaultVariants[key];
80
83
  }
81
84
  }
82
85
  }
83
86
  const keys = Object.keys(variantsWithDefaults);
87
+ const componentVariants = component.variants;
84
88
  for (const key of keys) {
85
89
  const value = variantsWithDefaults[key];
86
90
  if (value === void 0) {
87
91
  continue;
88
92
  }
89
93
  if (typeof value === "boolean") {
90
- if (value && component.variants[key]) {
91
- classNames.push(component.variants[key]);
94
+ if (value && componentVariants[key]) {
95
+ classNames.push(componentVariants[key]);
92
96
  }
93
97
  continue;
94
98
  }
95
- const variant = component.variants[key][value];
99
+ const variant = componentVariants[key][value];
96
100
  if (variant) {
97
101
  classNames.push(variant);
98
102
  }
99
103
  }
100
- if (component.compoundVariants) {
101
- for (const compoundVariant of component.compoundVariants) {
104
+ const { compoundVariants } = component;
105
+ if (compoundVariants) {
106
+ for (const compoundVariant of compoundVariants) {
102
107
  const keys2 = Object.keys(compoundVariant.variants);
103
108
  const matches = keys2.every((key) => {
104
109
  const value = variantsWithDefaults[key];
@@ -140,31 +145,22 @@ const Button = forwardRef(function Button2({
140
145
  disabled,
141
146
  ...restProps
142
147
  }, ref) {
143
- const isLinkVariant = variant === "link";
144
148
  const buttonClassName = useComponentStyles("button", {
145
149
  base: true,
146
150
  variants: {
147
- variant: isLinkVariant ? "solid" : variant,
151
+ variant,
148
152
  intent,
149
153
  size,
150
154
  disabled,
151
155
  loading
152
156
  }
153
157
  });
154
- const linkClassName = useComponentStyles("link", {
155
- base: true,
156
- variants: { variant: "primary" }
157
- });
158
158
  return /* @__PURE__ */ jsxs(
159
159
  Box,
160
160
  {
161
161
  ref,
162
162
  as: "button",
163
- className: classnames(
164
- buttonReset,
165
- isLinkVariant ? linkClassName : buttonClassName,
166
- className
167
- ),
163
+ className: classnames(buttonReset, buttonClassName, className),
168
164
  width,
169
165
  type,
170
166
  disabled: disabled || loading,
@@ -178,143 +174,45 @@ const Button = forwardRef(function Button2({
178
174
  }
179
175
  );
180
176
  });
181
- const Heading = ({
182
- className,
183
- level = 1,
177
+ const Label = ({
178
+ visualOnly,
184
179
  children,
185
- align,
186
- fontSize,
187
- fontWeight = "strong",
188
- fontFamily,
180
+ className,
181
+ required,
182
+ size,
183
+ cursor,
189
184
  ...restProps
190
185
  }) => {
191
- const as = `h${level}`;
186
+ const Component = visualOnly ? "span" : "label";
187
+ const containerClassName = useComponentStyles("label", {
188
+ base: true,
189
+ variants: { required, size }
190
+ });
192
191
  return /* @__PURE__ */ jsx(
193
- Box,
192
+ Component,
194
193
  {
195
- as,
196
- className,
197
- fontFamily,
198
- fontWeight,
199
- fontSize,
200
- textAlign: align,
201
- padding: "none",
202
- margin: "none",
194
+ className: classnames(containerClassName, className, atoms({ cursor })),
203
195
  ...restProps,
204
196
  children
205
197
  }
206
198
  );
207
199
  };
208
- const justifyContentMap = {
209
- left: "flex-start",
210
- right: "flex-end",
211
- center: "center",
212
- between: "space-between",
213
- around: "space-around"
214
- };
215
- const alignItemsMap = {
216
- left: "flex-start",
217
- right: "flex-end",
218
- center: "center",
219
- stretch: "stretch"
220
- };
221
- const Inline = ({
222
- alignX,
223
- alignY,
224
- as = "div",
225
- children,
226
- display = "flex",
227
- gap,
228
- ...props
229
- }) => {
230
- return /* @__PURE__ */ jsx(
231
- Box,
232
- {
233
- as,
234
- display,
235
- gap,
236
- flexDirection: "row",
237
- justifyContent: alignX ? justifyContentMap[alignX] : void 0,
238
- alignItems: alignY ? alignItemsMap[alignY] : void 0,
239
- flexWrap: "wrap",
240
- ...props,
241
- children
242
- }
243
- );
244
- };
245
- const Stack = ({
246
- as = "div",
247
- display = "flex",
248
- children,
249
- gap,
250
- alignX,
251
- ...restProps
252
- }) => {
253
- if (process.env.NODE_ENV === "development" && restProps.start !== void 0 && as !== "ol") {
254
- console.warn('Stack: start prop is only valid when as="ol"');
200
+ const Checkbox = forwardRef(function Checkbox2({ name, label, required, className, ...restProps }, ref) {
201
+ const containerClassName = useComponentStyles("checkbox", { base: true }, false);
202
+ const iconClassName = useComponentStyles("checkbox", { icon: true }, false);
203
+ const labelClassName = useComponentStyles("checkbox", { label: true }, false);
204
+ const input$12 = /* @__PURE__ */ jsxs("div", { className: classnames(container, containerClassName, className), children: [
205
+ /* @__PURE__ */ jsx("input", { ref, type: "checkbox", name, className: input, ...restProps }),
206
+ /* @__PURE__ */ jsx("div", { className: classnames(icon, iconClassName) })
207
+ ] });
208
+ if (!label) {
209
+ return input$12;
255
210
  }
256
- return /* @__PURE__ */ jsx(
257
- Box,
258
- {
259
- as,
260
- display,
261
- gap,
262
- flexDirection: "column",
263
- alignItems: alignX ? alignItemsMap[alignX] : void 0,
264
- ...restProps,
265
- children
266
- }
267
- );
268
- };
269
- const Text = ({
270
- as = "span",
271
- children,
272
- color,
273
- fontSize,
274
- fontWeight,
275
- fontFamily,
276
- textAlign,
277
- ...restProps
278
- }) => {
279
- return /* @__PURE__ */ jsx(
280
- Box,
281
- {
282
- as,
283
- color,
284
- fontSize,
285
- fontWeight,
286
- fontFamily,
287
- textAlign,
288
- padding: "none",
289
- margin: "none",
290
- ...restProps,
291
- children
292
- }
293
- );
294
- };
295
- const defaultElement = "a";
296
- const Link = forwardRef(function Link2({ as, className, variant, underline, ...restProps }, ref) {
297
- const Component = as || defaultElement;
298
- const linkClassName = useComponentStyles("link", {
299
- base: true,
300
- variants: { variant, underline }
301
- });
302
- return /* @__PURE__ */ jsx(Box, { ref, as: Component, className: classnames(className, linkClassName), ...restProps });
211
+ return /* @__PURE__ */ jsxs("label", { className: labelClassName, children: [
212
+ input$12,
213
+ label && /* @__PURE__ */ jsx(Label, { visualOnly: true, required, children: label })
214
+ ] });
303
215
  });
304
- const Divider = ({ className, color, ...restProps }) => {
305
- const dividerClass = useComponentStyles("divider", { base: true });
306
- const dividerDefaults = useComponentStyleDefaultProps("divider");
307
- return /* @__PURE__ */ jsx(
308
- Box,
309
- {
310
- role: "separator",
311
- width: "full",
312
- backgroundColor: color ?? dividerDefaults.color,
313
- className: classnames(className, dividerClass, divider),
314
- ...restProps
315
- }
316
- );
317
- };
318
216
  const useLayer = () => {
319
217
  const layerRef = useRef();
320
218
  useEffect(
@@ -327,7 +225,9 @@ const useLayer = () => {
327
225
  );
328
226
  return () => {
329
227
  if (!layerRef.current) {
330
- layerRef.current = document.createElement("div");
228
+ const div = document.createElement("div");
229
+ div.dataset.layer = "blocks";
230
+ layerRef.current = div;
331
231
  document.body.append(layerRef.current);
332
232
  }
333
233
  return layerRef.current;
@@ -346,12 +246,12 @@ const useVisibilityState = (open) => {
346
246
  return [visible, hide];
347
247
  };
348
248
  const focusableSelectors = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
349
- const getFirstFocusableElement = (container) => {
350
- const focusable = container.querySelector(focusableSelectors);
249
+ const getFirstFocusableElement = (container2) => {
250
+ const focusable = container2.querySelector(focusableSelectors);
351
251
  return focusable || null;
352
252
  };
353
- const focusFirstElement = (container) => {
354
- const focusable = getFirstFocusableElement(container);
253
+ const focusFirstElement = (container2) => {
254
+ const focusable = getFirstFocusableElement(container2);
355
255
  if (focusable) {
356
256
  focusable.focus();
357
257
  }
@@ -411,14 +311,21 @@ const usePreventBodyScroll = (enabled = true) => {
411
311
  };
412
312
  }, [enabled]);
413
313
  };
414
- const Portal = ({ children, container }) => {
314
+ const Portal = ({ children, container: container2 }) => {
415
315
  const context = useTheme();
416
316
  return createPortal(
417
317
  /* @__PURE__ */ jsx(BlocksProvider, { theme: context, children }),
418
- container || document.body
318
+ container2 || document.body
419
319
  );
420
320
  };
421
- const Dialog = ({ children, open, className, onRequestClose, size }) => {
321
+ const Dialog = ({
322
+ children,
323
+ open,
324
+ className,
325
+ onRequestClose,
326
+ size,
327
+ ...restProps
328
+ }) => {
422
329
  const dialogRef = useRef(null);
423
330
  const layer = useLayer();
424
331
  const [visible, hide] = useVisibilityState(open);
@@ -473,6 +380,7 @@ const Dialog = ({ children, open, className, onRequestClose, size }) => {
473
380
  {
474
381
  ref: dialogRef,
475
382
  as: "dialog",
383
+ "aria-modal": "true",
476
384
  open: true,
477
385
  className: classnames(
478
386
  dialog,
@@ -480,12 +388,91 @@ const Dialog = ({ children, open, className, onRequestClose, size }) => {
480
388
  dialogClassName,
481
389
  className
482
390
  ),
391
+ ...restProps,
483
392
  children
484
393
  }
485
394
  )
486
395
  }
487
396
  ) }) });
488
397
  };
398
+ const Divider = ({ className, color, ...restProps }) => {
399
+ const dividerClass = useComponentStyles("divider", { base: true });
400
+ const dividerDefaults = useComponentStyleDefaultProps("divider");
401
+ return /* @__PURE__ */ jsx(
402
+ Box,
403
+ {
404
+ role: "separator",
405
+ width: "full",
406
+ backgroundColor: color ?? dividerDefaults.color,
407
+ className: classnames(className, dividerClass, divider),
408
+ ...restProps
409
+ }
410
+ );
411
+ };
412
+ const Heading = ({
413
+ className,
414
+ level = 1,
415
+ children,
416
+ align,
417
+ fontSize,
418
+ fontWeight = "strong",
419
+ fontFamily,
420
+ ...restProps
421
+ }) => {
422
+ const as = `h${level}`;
423
+ return /* @__PURE__ */ jsx(
424
+ Box,
425
+ {
426
+ as,
427
+ className,
428
+ fontFamily,
429
+ fontWeight,
430
+ fontSize,
431
+ textAlign: align,
432
+ padding: "none",
433
+ margin: "none",
434
+ ...restProps,
435
+ children
436
+ }
437
+ );
438
+ };
439
+ const justifyContentMap = {
440
+ left: "flex-start",
441
+ right: "flex-end",
442
+ center: "center",
443
+ between: "space-between",
444
+ around: "space-around"
445
+ };
446
+ const alignItemsMap = {
447
+ left: "flex-start",
448
+ right: "flex-end",
449
+ center: "center",
450
+ stretch: "stretch"
451
+ };
452
+ const Inline = ({
453
+ alignX,
454
+ alignY,
455
+ as = "div",
456
+ children,
457
+ display = "flex",
458
+ gap,
459
+ ...props
460
+ }) => {
461
+ return /* @__PURE__ */ jsx(
462
+ Box,
463
+ {
464
+ as,
465
+ display,
466
+ gap,
467
+ flexDirection: "row",
468
+ justifyContent: alignX ? justifyContentMap[alignX] : void 0,
469
+ alignItems: alignY ? alignItemsMap[alignY] : void 0,
470
+ flexWrap: "wrap",
471
+ ...props,
472
+ children
473
+ }
474
+ );
475
+ };
489
476
  const Input = forwardRef(function Input2({ className, name, type = "text", startSlot, endSlot, label, placeholder, ...restProps }, ref) {
490
477
  const id = useId();
491
478
  const containerClassName = useComponentStyles("input", { container: true }, false);
@@ -503,23 +490,102 @@ const Input = forwardRef(function Input2({ className, name, type = "text", start
503
490
  placeholder: placeholder || label,
504
491
  width: "full",
505
492
  overflow: "hidden",
506
- className: classnames(input, inputClassName),
493
+ className: classnames(input$1, inputClassName),
507
494
  ...restProps
508
495
  }
509
496
  ),
510
497
  endSlot
511
498
  ] }) });
512
499
  });
500
+ const defaultElement = "a";
501
+ const Link = forwardRef(function Link2({ as, className, variant, underline, ...restProps }, ref) {
502
+ const Component = as || defaultElement;
503
+ const linkClassName = useComponentStyles("link", {
504
+ base: true,
505
+ variants: { variant, underline }
506
+ });
507
+ return /* @__PURE__ */ jsx(Box, { ref, as: Component, className: classnames(className, linkClassName), ...restProps });
508
+ });
509
+ const Radio = forwardRef(function Checkbox3({ name, label, className, ...restProps }, ref) {
510
+ const containerClassName = useComponentStyles("radio", { base: true }, false);
511
+ const iconClassName = useComponentStyles("radio", { icon: true }, false);
512
+ const labelClassName = useComponentStyles("checkbox", { label: true }, false);
513
+ const input2 = /* @__PURE__ */ jsxs("div", { className: classnames(container$1, containerClassName, className), children: [
514
+ /* @__PURE__ */ jsx("input", { ref, type: "radio", name, className: input$2, ...restProps }),
515
+ /* @__PURE__ */ jsx("div", { className: classnames(icon$1, iconClassName) })
516
+ ] });
517
+ if (!label) {
518
+ return input2;
519
+ }
520
+ return /* @__PURE__ */ jsxs("label", { className: labelClassName, children: [
521
+ input2,
522
+ label && /* @__PURE__ */ jsx(Label, { visualOnly: true, children: label })
523
+ ] });
524
+ });
525
+ const Stack = ({
526
+ as = "div",
527
+ display = "flex",
528
+ children,
529
+ gap,
530
+ alignX,
531
+ ...restProps
532
+ }) => {
533
+ if (process.env.NODE_ENV === "development" && restProps.start !== void 0 && as !== "ol") {
534
+ console.warn('Stack: start prop is only valid when as="ol"');
535
+ }
536
+ return /* @__PURE__ */ jsx(
537
+ Box,
538
+ {
539
+ as,
540
+ display,
541
+ gap,
542
+ flexDirection: "column",
543
+ alignItems: alignX ? alignItemsMap[alignX] : void 0,
544
+ ...restProps,
545
+ children
546
+ }
547
+ );
548
+ };
549
+ const Text = ({
550
+ as = "span",
551
+ children,
552
+ color,
553
+ fontSize,
554
+ fontWeight,
555
+ fontFamily,
556
+ textAlign,
557
+ ...restProps
558
+ }) => {
559
+ return /* @__PURE__ */ jsx(
560
+ Box,
561
+ {
562
+ as,
563
+ color,
564
+ fontSize,
565
+ fontWeight,
566
+ fontFamily,
567
+ textAlign,
568
+ padding: "none",
569
+ margin: "none",
570
+ ...restProps,
571
+ children
572
+ }
573
+ );
574
+ };
513
575
  export {
514
576
  BlocksProvider,
515
577
  Box,
516
578
  Button,
579
+ Checkbox,
517
580
  Dialog,
518
581
  Divider,
519
582
  Heading,
520
583
  Inline,
521
584
  Input,
585
+ Label,
522
586
  Link,
587
+ Portal,
588
+ Radio,
523
589
  Spinner,
524
590
  Stack,
525
591
  Text,