@blockle/blocks 0.7.2 → 0.8.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.cjs CHANGED
@@ -12,8 +12,10 @@ const styles_components_Checkbox_checkbox_css_cjs = require("./styles/components
12
12
  const styles_components_Dialog_dialog_css_cjs = require("./styles/components/Dialog/dialog.css.cjs");
13
13
  const reactDom = require("react-dom");
14
14
  const styles_components_Divider_divider_css_cjs = require("./styles/components/Divider/divider.css.cjs");
15
+ const styles_components_Heading_heading_css_cjs = require("./styles/components/Heading/heading.css.cjs");
15
16
  const styles_components_Input_input_css_cjs = require("./styles/components/Input/input.css.cjs");
16
17
  const styles_components_Radio_radio_css_cjs = require("./styles/components/Radio/radio.css.cjs");
18
+ const styles_components_Text_text_css_cjs = require("./styles/components/Text/text.css.cjs");
17
19
  const classnames = (...args) => {
18
20
  const className = args.filter((arg) => arg && typeof arg === "string").join(" ");
19
21
  return className || void 0;
@@ -34,19 +36,130 @@ const BlocksProvider = ({
34
36
  }
35
37
  ) });
36
38
  };
37
- const defaultElement$1 = "div";
38
- const Box = react.forwardRef(function Box2({ className, as, ...restProps }, ref) {
39
- const Component = as || defaultElement$1;
39
+ function getAtomsAndProps(props) {
40
40
  const atomProps = {};
41
41
  const otherProps = {};
42
- for (const [name, value] of Object.entries(restProps)) {
42
+ for (const [name, value] of Object.entries(props)) {
43
43
  if (styles_lib_css_atoms_sprinkles_css_cjs.atoms.properties.has(name)) {
44
44
  atomProps[name] = value;
45
45
  } else {
46
46
  otherProps[name] = value;
47
47
  }
48
48
  }
49
- return /* @__PURE__ */ jsxRuntime.jsx(Component, { ref, className: classnames(className, styles_lib_css_atoms_sprinkles_css_cjs.atoms(atomProps)), ...otherProps });
49
+ return [atomProps, otherProps];
50
+ }
51
+ function setRef(ref, value) {
52
+ if (typeof ref === "function") {
53
+ ref(value);
54
+ } else if (ref !== null && ref !== void 0) {
55
+ ref.current = value;
56
+ }
57
+ }
58
+ function composeRefs(...refs) {
59
+ return (node) => {
60
+ for (const ref of refs) {
61
+ setRef(ref, node);
62
+ }
63
+ };
64
+ }
65
+ function mergeProps(slotProps, childProps) {
66
+ const overrideProps = {};
67
+ for (const propName in childProps) {
68
+ const slotPropValue = slotProps[propName];
69
+ const childPropValue = childProps[propName];
70
+ if (childPropValue === void 0) {
71
+ continue;
72
+ }
73
+ if (slotPropValue === void 0) {
74
+ overrideProps[propName] = childPropValue;
75
+ continue;
76
+ }
77
+ if (typeof slotPropValue === "function" && typeof childPropValue === "function") {
78
+ overrideProps[propName] = (...args) => {
79
+ childPropValue(...args);
80
+ slotPropValue(...args);
81
+ };
82
+ } else if (propName === "style") {
83
+ overrideProps[propName] = { ...slotPropValue, ...childPropValue };
84
+ } else if (propName === "className") {
85
+ overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
86
+ } else {
87
+ overrideProps[propName] = childPropValue;
88
+ }
89
+ }
90
+ return { ...slotProps, ...overrideProps };
91
+ }
92
+ function createSlottable(defaultElement) {
93
+ function Slottable2(props, ref) {
94
+ const { asChild, children, ...slotProps } = props;
95
+ const Component = defaultElement;
96
+ if (!asChild) {
97
+ return /* @__PURE__ */ jsxRuntime.jsx(Component, { ref, ...slotProps, children });
98
+ }
99
+ const childrenArray = react.Children.toArray(children);
100
+ const slot = childrenArray.find((child) => {
101
+ if (!react.isValidElement(child)) {
102
+ return false;
103
+ }
104
+ return child.type === Slot;
105
+ });
106
+ if (!slot) {
107
+ const Slot2 = childrenArray[0];
108
+ if (!react.isValidElement(childrenArray[0])) {
109
+ if (process.env.NODE_ENV === "development") {
110
+ console.warn("Slottable: First child is not a valid React element");
111
+ }
112
+ return null;
113
+ }
114
+ if (!react.isValidElement(Slot2)) {
115
+ return null;
116
+ }
117
+ return react.cloneElement(
118
+ Slot2,
119
+ {
120
+ ...mergeProps(slotProps, Slot2.props),
121
+ ref: composeRefs(ref, Slot2.ref)
122
+ },
123
+ Slot2.props.children
124
+ );
125
+ }
126
+ if (!react.isValidElement(slot) || !react.isValidElement(slot.props.children)) {
127
+ return null;
128
+ }
129
+ const newChildren = childrenArray.map((child) => {
130
+ if (!react.isValidElement(child)) {
131
+ return child;
132
+ }
133
+ if (child.type === Slot) {
134
+ return slot.props.children.props.children;
135
+ }
136
+ return child;
137
+ });
138
+ return react.cloneElement(
139
+ slot.props.children,
140
+ {
141
+ ...mergeProps(slotProps, slot.props),
142
+ ref: composeRefs(ref, slot.props.children.ref)
143
+ },
144
+ newChildren
145
+ );
146
+ }
147
+ return react.forwardRef(Slottable2);
148
+ }
149
+ const Slot = ({ children }) => children;
150
+ const Slottable$2 = createSlottable("div");
151
+ const Box = react.forwardRef(function Box2({ asChild, className, children, ...restProps }, ref) {
152
+ const [atomsProps, otherProps] = getAtomsAndProps(restProps);
153
+ return /* @__PURE__ */ jsxRuntime.jsx(
154
+ Slottable$2,
155
+ {
156
+ ref,
157
+ asChild,
158
+ className: classnames(className, styles_lib_css_atoms_sprinkles_css_cjs.atoms(atomsProps)),
159
+ ...otherProps,
160
+ children
161
+ }
162
+ );
50
163
  });
51
164
  const useTheme = () => {
52
165
  const theme = react.useContext(BlocksProviderContext);
@@ -87,7 +200,7 @@ function useComponentStyles(name, props, useDefaultVariants = true) {
87
200
  const componentVariants = component.variants;
88
201
  for (const key of keys) {
89
202
  const value = variantsWithDefaults[key];
90
- if (value === void 0) {
203
+ if (value === void 0 || componentVariants[key] === void 0) {
91
204
  continue;
92
205
  }
93
206
  if (typeof value === "boolean") {
@@ -131,18 +244,18 @@ const Spinner = ({ className, size, color, ...restProps }) => {
131
244
  const spinnerClassName = useComponentStyles("spinner", { base: true, variants: { size, color } });
132
245
  return /* @__PURE__ */ jsxRuntime.jsx(Box, { color, className: classnames(spinnerClassName, className), ...restProps });
133
246
  };
247
+ const Slottable$1 = createSlottable("button");
134
248
  const Button = react.forwardRef(function Button2({
135
249
  children,
136
250
  className,
137
- type = "button",
138
251
  variant,
139
252
  intent,
140
253
  size,
141
- width,
142
254
  startSlot,
143
255
  endSlot,
144
256
  loading,
145
257
  disabled,
258
+ asChild,
146
259
  ...restProps
147
260
  }, ref) {
148
261
  const buttonClassName = useComponentStyles("button", {
@@ -155,21 +268,20 @@ const Button = react.forwardRef(function Button2({
155
268
  loading
156
269
  }
157
270
  });
271
+ const [atomsProps, otherProps] = getAtomsAndProps(restProps);
158
272
  return /* @__PURE__ */ jsxRuntime.jsxs(
159
- Box,
273
+ Slottable$1,
160
274
  {
161
275
  ref,
162
- as: "button",
163
- className: classnames(styles_components_Button_Button_css_cjs.buttonReset, buttonClassName, className),
164
- width,
165
- type,
276
+ asChild,
166
277
  disabled: disabled || loading,
167
- ...restProps,
278
+ className: classnames(styles_components_Button_Button_css_cjs.buttonReset, buttonClassName, styles_lib_css_atoms_sprinkles_css_cjs.atoms(atomsProps), className),
279
+ ...otherProps,
168
280
  children: [
169
- startSlot && /* @__PURE__ */ jsxRuntime.jsx(Box, { paddingRight: "medium", children: startSlot }),
170
- loading && /* @__PURE__ */ jsxRuntime.jsx(Spinner, { size, marginRight: "medium" }),
171
- children,
172
- endSlot && /* @__PURE__ */ jsxRuntime.jsx(Box, { paddingLeft: "medium", children: endSlot })
281
+ startSlot && /* @__PURE__ */ jsxRuntime.jsx("div", { children: startSlot }),
282
+ loading && /* @__PURE__ */ jsxRuntime.jsx(Spinner, { size }),
283
+ /* @__PURE__ */ jsxRuntime.jsx(Slot, { children }),
284
+ endSlot && /* @__PURE__ */ jsxRuntime.jsx("div", { children: endSlot })
173
285
  ]
174
286
  }
175
287
  );
@@ -263,12 +375,26 @@ const useLayer = () => {
263
375
  const useIsomorphicLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
264
376
  const usePreventBodyScroll = (enabled = true) => {
265
377
  useIsomorphicLayoutEffect(() => {
266
- const prevValue = document.body.style.getPropertyValue("overflow");
267
- if (enabled) {
378
+ if (!enabled) {
379
+ return;
380
+ }
381
+ const prevOverflow = document.body.style.getPropertyValue("overflow");
382
+ const prevScrollTop = document.documentElement.scrollTop;
383
+ if (document.body.scrollHeight > window.innerHeight) {
384
+ document.body.style.position = "fixed";
385
+ document.body.style.overflow = "hidden";
386
+ document.body.style.overflowY = "scroll";
387
+ document.body.style.width = "100%";
388
+ document.body.style.top = `-${prevScrollTop}px`;
389
+ } else {
268
390
  document.body.style.overflow = "hidden";
269
391
  }
270
392
  return () => {
271
- document.body.style.overflow = prevValue;
393
+ document.body.style.position = "";
394
+ document.body.style.overflow = prevOverflow;
395
+ document.body.style.overflowY = "";
396
+ document.body.style.width = "";
397
+ document.documentElement.scrollTop = prevScrollTop;
272
398
  };
273
399
  }, [enabled]);
274
400
  };
@@ -376,10 +502,9 @@ const Dialog = ({
376
502
  onClick: onBackdropClick,
377
503
  onAnimationEnd,
378
504
  children: /* @__PURE__ */ jsxRuntime.jsx(
379
- Box,
505
+ "dialog",
380
506
  {
381
507
  ref: dialogRef,
382
- as: "dialog",
383
508
  "aria-modal": "true",
384
509
  open: true,
385
510
  className: classnames(
@@ -413,28 +538,10 @@ const Heading = ({
413
538
  className,
414
539
  level = 1,
415
540
  children,
416
- align,
417
- fontSize,
418
- fontWeight = "strong",
419
- fontFamily,
420
541
  ...restProps
421
542
  }) => {
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
- );
543
+ const Tag = `h${level}`;
544
+ return /* @__PURE__ */ jsxRuntime.jsx(Box, { asChild: true, className: classnames(styles_components_Heading_heading_css_cjs.heading, className), ...restProps, children: /* @__PURE__ */ jsxRuntime.jsx(Tag, { children }) });
438
545
  };
439
546
  const justifyContentMap = {
440
547
  left: "flex-start",
@@ -452,7 +559,7 @@ const alignItemsMap = {
452
559
  const Inline = ({
453
560
  alignX,
454
561
  alignY,
455
- as = "div",
562
+ tag: Tag = "div",
456
563
  children,
457
564
  display = "flex",
458
565
  gap,
@@ -461,7 +568,7 @@ const Inline = ({
461
568
  return /* @__PURE__ */ jsxRuntime.jsx(
462
569
  Box,
463
570
  {
464
- as,
571
+ asChild: true,
465
572
  display,
466
573
  gap,
467
574
  flexDirection: "row",
@@ -469,7 +576,7 @@ const Inline = ({
469
576
  alignItems: alignY ? alignItemsMap[alignY] : void 0,
470
577
  flexWrap: "wrap",
471
578
  ...props,
472
- children
579
+ children: /* @__PURE__ */ jsxRuntime.jsx(Tag, { children })
473
580
  }
474
581
  );
475
582
  };
@@ -479,32 +586,37 @@ const Input = react.forwardRef(function Input2({ className, name, type = "text",
479
586
  const inputClassName = useComponentStyles("input", { input: true });
480
587
  return /* @__PURE__ */ jsxRuntime.jsx(Box, { children: /* @__PURE__ */ jsxRuntime.jsxs(Box, { display: "flex", alignItems: "center", className: classnames(containerClassName, className), children: [
481
588
  startSlot,
482
- /* @__PURE__ */ jsxRuntime.jsx(
483
- Box,
589
+ /* @__PURE__ */ jsxRuntime.jsx(Box, { asChild: true, width: "full", overflow: "hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
590
+ "input",
484
591
  {
485
- as: "input",
486
592
  id,
487
593
  ref,
488
594
  name,
489
595
  type,
490
596
  placeholder: placeholder || label,
491
- width: "full",
492
- overflow: "hidden",
493
597
  className: classnames(styles_components_Input_input_css_cjs.input, inputClassName),
494
598
  ...restProps
495
599
  }
496
- ),
600
+ ) }),
497
601
  endSlot
498
602
  ] }) });
499
603
  });
500
- const defaultElement = "a";
501
- const Link = react.forwardRef(function Link2({ as, className, variant, underline, ...restProps }, ref) {
502
- const Component = as || defaultElement;
604
+ const Slottable = createSlottable("a");
605
+ const Link = react.forwardRef(function Link2({ asChild, className, children, variant, underline, ...restProps }, ref) {
503
606
  const linkClassName = useComponentStyles("link", {
504
607
  base: true,
505
608
  variants: { variant, underline }
506
609
  });
507
- return /* @__PURE__ */ jsxRuntime.jsx(Box, { ref, as: Component, className: classnames(className, linkClassName), ...restProps });
610
+ return /* @__PURE__ */ jsxRuntime.jsx(
611
+ Slottable,
612
+ {
613
+ asChild,
614
+ ref,
615
+ className: classnames(className, linkClassName),
616
+ ...restProps,
617
+ children
618
+ }
619
+ );
508
620
  });
509
621
  const Radio = react.forwardRef(function Checkbox3({ name, label, className, ...restProps }, ref) {
510
622
  const containerClassName = useComponentStyles("radio", { base: true }, false);
@@ -523,55 +635,32 @@ const Radio = react.forwardRef(function Checkbox3({ name, label, className, ...r
523
635
  ] });
524
636
  });
525
637
  const Stack = ({
526
- as = "div",
638
+ tag: Tag = "div",
527
639
  display = "flex",
528
640
  children,
529
641
  gap,
530
642
  alignX,
531
643
  ...restProps
532
644
  }) => {
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"');
645
+ if (process.env.NODE_ENV === "development" && restProps.start !== void 0 && Tag !== "ol") {
646
+ console.warn('Stack: start prop is only valid when tag="ol"');
535
647
  }
536
648
  return /* @__PURE__ */ jsxRuntime.jsx(
537
649
  Box,
538
650
  {
539
- as,
651
+ asChild: true,
540
652
  display,
541
653
  gap,
542
654
  flexDirection: "column",
543
655
  alignItems: alignX ? alignItemsMap[alignX] : void 0,
544
656
  ...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
657
+ children: /* @__PURE__ */ jsxRuntime.jsx(Tag, { children })
572
658
  }
573
659
  );
574
660
  };
661
+ const Text = react.forwardRef(function Text2({ tag: Tag = "span", asChild, children, className, ...restProps }, ref) {
662
+ return /* @__PURE__ */ jsxRuntime.jsx(Box, { ref, asChild: true, className: classnames(styles_components_Text_text_css_cjs.text, className), ...restProps, children: asChild ? children : /* @__PURE__ */ jsxRuntime.jsx(Tag, { children }) });
663
+ });
575
664
  exports.breakpointQuery = styles_lib_css_atoms_breakpoints_cjs.breakpointQuery;
576
665
  exports.makeComponentTheme = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme;
577
666
  exports.makeTheme = styles_lib_theme_makeTheme_cjs.makeTheme;
@@ -590,9 +679,11 @@ exports.Label = Label;
590
679
  exports.Link = Link;
591
680
  exports.Portal = Portal;
592
681
  exports.Radio = Radio;
682
+ exports.Slot = Slot;
593
683
  exports.Spinner = Spinner;
594
684
  exports.Stack = Stack;
595
685
  exports.Text = Text;
596
686
  exports.classnames = classnames;
687
+ exports.createSlottable = createSlottable;
597
688
  exports.useComponentStyleDefaultProps = useComponentStyleDefaultProps;
598
689
  exports.useComponentStyles = useComponentStyles;
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
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';
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, Slot, Spinner, SpinnerProps, Stack, StackProps, Text, TextProps, ThemeComponentsStyles, ThemeTokens, atoms, breakpointQuery, classnames, createSlottable, makeComponentTheme, makeTheme, useComponentStyleDefaultProps, useComponentStyles, vars } from './momotaro.chunk.js';