@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.cjs CHANGED
@@ -5,13 +5,15 @@ const styles_lib_theme_makeComponentTheme_cjs = require("./styles/lib/theme/make
5
5
  const styles_lib_theme_makeTheme_cjs = require("./styles/lib/theme/makeTheme.cjs");
6
6
  const styles_lib_theme_vars_css_cjs = require("./styles/lib/theme/vars.css.cjs");
7
7
  const styles_lib_css_atoms_sprinkles_css_cjs = require("./styles/lib/css/atoms/sprinkles.css.cjs");
8
- const react = require("react");
9
8
  const jsxRuntime = require("react/jsx-runtime");
9
+ const react = require("react");
10
10
  const styles_components_Button_Button_css_cjs = require("./styles/components/Button/Button.css.cjs");
11
- const styles_components_Divider_divider_css_cjs = require("./styles/components/Divider/divider.css.cjs");
11
+ const styles_components_Checkbox_checkbox_css_cjs = require("./styles/components/Checkbox/checkbox.css.cjs");
12
12
  const styles_components_Dialog_dialog_css_cjs = require("./styles/components/Dialog/dialog.css.cjs");
13
13
  const reactDom = require("react-dom");
14
+ const styles_components_Divider_divider_css_cjs = require("./styles/components/Divider/divider.css.cjs");
14
15
  const styles_components_Input_input_css_cjs = require("./styles/components/Input/input.css.cjs");
16
+ const styles_components_Radio_radio_css_cjs = require("./styles/components/Radio/radio.css.cjs");
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 = react.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__ */ jsxRuntime.jsxs(
159
159
  Box,
160
160
  {
161
161
  ref,
162
162
  as: "button",
163
- className: classnames(
164
- styles_components_Button_Button_css_cjs.buttonReset,
165
- isLinkVariant ? linkClassName : buttonClassName,
166
- className
167
- ),
163
+ className: classnames(styles_components_Button_Button_css_cjs.buttonReset, buttonClassName, className),
168
164
  width,
169
165
  type,
170
166
  disabled: disabled || loading,
@@ -178,143 +174,45 @@ const Button = react.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__ */ jsxRuntime.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, styles_lib_css_atoms_sprinkles_css_cjs.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__ */ jsxRuntime.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 = react.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 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classnames(styles_components_Checkbox_checkbox_css_cjs.container, containerClassName, className), children: [
205
+ /* @__PURE__ */ jsxRuntime.jsx("input", { ref, type: "checkbox", name, className: styles_components_Checkbox_checkbox_css_cjs.input, ...restProps }),
206
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: classnames(styles_components_Checkbox_checkbox_css_cjs.icon, iconClassName) })
207
+ ] });
208
+ if (!label) {
209
+ return input;
255
210
  }
256
- return /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.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 = react.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__ */ jsxRuntime.jsx(Box, { ref, as: Component, className: classnames(className, linkClassName), ...restProps });
211
+ return /* @__PURE__ */ jsxRuntime.jsxs("label", { className: labelClassName, children: [
212
+ input,
213
+ label && /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx(
308
- Box,
309
- {
310
- role: "separator",
311
- width: "full",
312
- backgroundColor: color ?? dividerDefaults.color,
313
- className: classnames(className, dividerClass, styles_components_Divider_divider_css_cjs.divider),
314
- ...restProps
315
- }
316
- );
317
- };
318
216
  const useLayer = () => {
319
217
  const layerRef = react.useRef();
320
218
  react.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;
@@ -418,7 +318,14 @@ const Portal = ({ children, container }) => {
418
318
  container || 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 = react.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
  styles_components_Dialog_dialog_css_cjs.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__ */ jsxRuntime.jsx(
402
+ Box,
403
+ {
404
+ role: "separator",
405
+ width: "full",
406
+ backgroundColor: color ?? dividerDefaults.color,
407
+ className: classnames(className, dividerClass, styles_components_Divider_divider_css_cjs.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__ */ jsxRuntime.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__ */ jsxRuntime.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 = react.forwardRef(function Input2({ className, name, type = "text", startSlot, endSlot, label, placeholder, ...restProps }, ref) {
490
477
  const id = react.useId();
491
478
  const containerClassName = useComponentStyles("input", { container: true }, false);
@@ -510,6 +497,81 @@ const Input = react.forwardRef(function Input2({ className, name, type = "text",
510
497
  endSlot
511
498
  ] }) });
512
499
  });
500
+ const defaultElement = "a";
501
+ const Link = react.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__ */ jsxRuntime.jsx(Box, { ref, as: Component, className: classnames(className, linkClassName), ...restProps });
508
+ });
509
+ const Radio = react.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 input = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classnames(styles_components_Radio_radio_css_cjs.container, containerClassName, className), children: [
514
+ /* @__PURE__ */ jsxRuntime.jsx("input", { ref, type: "radio", name, className: styles_components_Radio_radio_css_cjs.input, ...restProps }),
515
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: classnames(styles_components_Radio_radio_css_cjs.icon, iconClassName) })
516
+ ] });
517
+ if (!label) {
518
+ return input;
519
+ }
520
+ return /* @__PURE__ */ jsxRuntime.jsxs("label", { className: labelClassName, children: [
521
+ input,
522
+ label && /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.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__ */ jsxRuntime.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
  exports.breakpointQuery = styles_lib_css_atoms_breakpoints_cjs.breakpointQuery;
514
576
  exports.makeComponentTheme = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme;
515
577
  exports.makeTheme = styles_lib_theme_makeTheme_cjs.makeTheme;
@@ -518,12 +580,16 @@ exports.atoms = styles_lib_css_atoms_sprinkles_css_cjs.atoms;
518
580
  exports.BlocksProvider = BlocksProvider;
519
581
  exports.Box = Box;
520
582
  exports.Button = Button;
583
+ exports.Checkbox = Checkbox;
521
584
  exports.Dialog = Dialog;
522
585
  exports.Divider = Divider;
523
586
  exports.Heading = Heading;
524
587
  exports.Inline = Inline;
525
588
  exports.Input = Input;
589
+ exports.Label = Label;
526
590
  exports.Link = Link;
591
+ exports.Portal = Portal;
592
+ exports.Radio = Radio;
527
593
  exports.Spinner = Spinner;
528
594
  exports.Stack = Stack;
529
595
  exports.Text = Text;
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { BlocksProvider, BlocksProviderProps, Box, BoxProps, Button, ButtonProps, Dialog, DialogProps, Divider, DividerProps, Heading, HeadingProps, Inline, InlineProps, Input, InputProps, Link, LinkProps, Spinner, SpinnerProps, Stack, StackProps, Text, TextProps, ThemeComponentsStyles, ThemeTokens, atoms, breakpointQuery, classnames, makeComponentTheme, makeTheme, useComponentStyleDefaultProps, useComponentStyles, vars } from './momotaro.chunk.js';
1
+ export { BlocksProvider, BlocksProviderProps, Box, BoxProps, Button, ButtonProps, Checkbox, CheckboxProps, Dialog, DialogProps, Divider, DividerProps, Heading, HeadingProps, Inline, InlineProps, Input, InputProps, Label, LabelProps, Link, LinkProps, Portal, PortalProps, Radio, RadioProps, Spinner, SpinnerProps, Stack, StackProps, Text, TextProps, ThemeComponentsStyles, ThemeTokens, atoms, breakpointQuery, classnames, makeComponentTheme, makeTheme, useComponentStyleDefaultProps, useComponentStyles, vars } from './momotaro.chunk.js';