@blockle/blocks 0.6.0 → 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.
package/dist/index.cjs CHANGED
@@ -8,9 +8,9 @@ const styles_lib_css_atoms_sprinkles_css_cjs = require("./styles/lib/css/atoms/s
8
8
  const react = require("react");
9
9
  const jsxRuntime = require("react/jsx-runtime");
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");
12
11
  const styles_components_Dialog_dialog_css_cjs = require("./styles/components/Dialog/dialog.css.cjs");
13
12
  const reactDom = require("react-dom");
13
+ const styles_components_Divider_divider_css_cjs = require("./styles/components/Divider/divider.css.cjs");
14
14
  const styles_components_Input_input_css_cjs = require("./styles/components/Input/input.css.cjs");
15
15
  const classnames = (...args) => {
16
16
  const className = args.filter((arg) => arg && typeof arg === "string").join(" ");
@@ -72,33 +72,36 @@ function useComponentStyles(name, props, useDefaultVariants = true) {
72
72
  if (!component.variants) {
73
73
  return classNames.join(" ");
74
74
  }
75
- if (useDefaultVariants && component.defaultVariants) {
76
- const keys2 = Object.keys(component.defaultVariants);
75
+ const { defaultVariants } = component;
76
+ if (useDefaultVariants && defaultVariants) {
77
+ const keys2 = Object.keys(defaultVariants);
77
78
  for (const key of keys2) {
78
- if (variantsWithDefaults[key] === void 0) {
79
- variantsWithDefaults[key] = component.defaultVariants[key];
79
+ if (variantsWithDefaults[key] === void 0 && defaultVariants[key]) {
80
+ variantsWithDefaults[key] = defaultVariants[key];
80
81
  }
81
82
  }
82
83
  }
83
84
  const keys = Object.keys(variantsWithDefaults);
85
+ const componentVariants = component.variants;
84
86
  for (const key of keys) {
85
87
  const value = variantsWithDefaults[key];
86
88
  if (value === void 0) {
87
89
  continue;
88
90
  }
89
91
  if (typeof value === "boolean") {
90
- if (value && component.variants[key]) {
91
- classNames.push(component.variants[key]);
92
+ if (value && componentVariants[key]) {
93
+ classNames.push(componentVariants[key]);
92
94
  }
93
95
  continue;
94
96
  }
95
- const variant = component.variants[key][value];
97
+ const variant = componentVariants[key][value];
96
98
  if (variant) {
97
99
  classNames.push(variant);
98
100
  }
99
101
  }
100
- if (component.compoundVariants) {
101
- for (const compoundVariant of component.compoundVariants) {
102
+ const { compoundVariants } = component;
103
+ if (compoundVariants) {
104
+ for (const compoundVariant of compoundVariants) {
102
105
  const keys2 = Object.keys(compoundVariant.variants);
103
106
  const matches = keys2.every((key) => {
104
107
  const value = variantsWithDefaults[key];
@@ -140,31 +143,22 @@ const Button = react.forwardRef(function Button2({
140
143
  disabled,
141
144
  ...restProps
142
145
  }, ref) {
143
- const isLinkVariant = variant === "link";
144
146
  const buttonClassName = useComponentStyles("button", {
145
147
  base: true,
146
148
  variants: {
147
- variant: isLinkVariant ? "solid" : variant,
149
+ variant,
148
150
  intent,
149
151
  size,
150
152
  disabled,
151
153
  loading
152
154
  }
153
155
  });
154
- const linkClassName = useComponentStyles("link", {
155
- base: true,
156
- variants: { variant: "primary" }
157
- });
158
156
  return /* @__PURE__ */ jsxRuntime.jsxs(
159
157
  Box,
160
158
  {
161
159
  ref,
162
160
  as: "button",
163
- className: classnames(
164
- styles_components_Button_Button_css_cjs.buttonReset,
165
- isLinkVariant ? linkClassName : buttonClassName,
166
- className
167
- ),
161
+ className: classnames(styles_components_Button_Button_css_cjs.buttonReset, buttonClassName, className),
168
162
  width,
169
163
  type,
170
164
  disabled: disabled || loading,
@@ -178,143 +172,6 @@ const Button = react.forwardRef(function Button2({
178
172
  }
179
173
  );
180
174
  });
181
- const Heading = ({
182
- className,
183
- level = 1,
184
- children,
185
- align,
186
- fontSize,
187
- fontWeight = "strong",
188
- fontFamily,
189
- ...restProps
190
- }) => {
191
- const as = `h${level}`;
192
- return /* @__PURE__ */ jsxRuntime.jsx(
193
- Box,
194
- {
195
- as,
196
- className,
197
- fontFamily,
198
- fontWeight,
199
- fontSize,
200
- textAlign: align,
201
- padding: "none",
202
- margin: "none",
203
- ...restProps,
204
- children
205
- }
206
- );
207
- };
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"');
255
- }
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 });
303
- });
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
175
  const useLayer = () => {
319
176
  const layerRef = react.useRef();
320
177
  react.useEffect(
@@ -327,7 +184,9 @@ const useLayer = () => {
327
184
  );
328
185
  return () => {
329
186
  if (!layerRef.current) {
330
- layerRef.current = document.createElement("div");
187
+ const div = document.createElement("div");
188
+ div.dataset.layer = "blocks";
189
+ layerRef.current = div;
331
190
  document.body.append(layerRef.current);
332
191
  }
333
192
  return layerRef.current;
@@ -418,7 +277,14 @@ const Portal = ({ children, container }) => {
418
277
  container || document.body
419
278
  );
420
279
  };
421
- const Dialog = ({ children, open, className, onRequestClose, size }) => {
280
+ const Dialog = ({
281
+ children,
282
+ open,
283
+ className,
284
+ onRequestClose,
285
+ size,
286
+ ...restProps
287
+ }) => {
422
288
  const dialogRef = react.useRef(null);
423
289
  const layer = useLayer();
424
290
  const [visible, hide] = useVisibilityState(open);
@@ -473,6 +339,7 @@ const Dialog = ({ children, open, className, onRequestClose, size }) => {
473
339
  {
474
340
  ref: dialogRef,
475
341
  as: "dialog",
342
+ "aria-modal": "true",
476
343
  open: true,
477
344
  className: classnames(
478
345
  styles_components_Dialog_dialog_css_cjs.dialog,
@@ -480,12 +347,91 @@ const Dialog = ({ children, open, className, onRequestClose, size }) => {
480
347
  dialogClassName,
481
348
  className
482
349
  ),
350
+ ...restProps,
483
351
  children
484
352
  }
485
353
  )
486
354
  }
487
355
  ) }) });
488
356
  };
357
+ const Divider = ({ className, color, ...restProps }) => {
358
+ const dividerClass = useComponentStyles("divider", { base: true });
359
+ const dividerDefaults = useComponentStyleDefaultProps("divider");
360
+ return /* @__PURE__ */ jsxRuntime.jsx(
361
+ Box,
362
+ {
363
+ role: "separator",
364
+ width: "full",
365
+ backgroundColor: color ?? dividerDefaults.color,
366
+ className: classnames(className, dividerClass, styles_components_Divider_divider_css_cjs.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__ */ jsxRuntime.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__ */ jsxRuntime.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
+ };
489
435
  const Input = react.forwardRef(function Input2({ className, name, type = "text", startSlot, endSlot, label, placeholder, ...restProps }, ref) {
490
436
  const id = react.useId();
491
437
  const containerClassName = useComponentStyles("input", { container: true }, false);
@@ -510,6 +456,88 @@ const Input = react.forwardRef(function Input2({ className, name, type = "text",
510
456
  endSlot
511
457
  ] }) });
512
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__ */ jsxRuntime.jsx(
474
+ Component,
475
+ {
476
+ className: classnames(containerClassName, className, styles_lib_css_atoms_sprinkles_css_cjs.atoms({ cursor })),
477
+ ...restProps,
478
+ children
479
+ }
480
+ );
481
+ };
482
+ const defaultElement = "a";
483
+ const Link = react.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__ */ jsxRuntime.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__ */ jsxRuntime.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__ */ jsxRuntime.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
+ };
513
541
  exports.breakpointQuery = styles_lib_css_atoms_breakpoints_cjs.breakpointQuery;
514
542
  exports.makeComponentTheme = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme;
515
543
  exports.makeTheme = styles_lib_theme_makeTheme_cjs.makeTheme;
@@ -523,6 +551,7 @@ exports.Divider = Divider;
523
551
  exports.Heading = Heading;
524
552
  exports.Inline = Inline;
525
553
  exports.Input = Input;
554
+ exports.Label = Label;
526
555
  exports.Link = Link;
527
556
  exports.Spinner = Spinner;
528
557
  exports.Stack = Stack;
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, Dialog, DialogProps, Divider, DividerProps, Heading, HeadingProps, Inline, InlineProps, Input, InputProps, Label, LabelProps, Link, LinkProps, Spinner, SpinnerProps, Stack, StackProps, Text, TextProps, ThemeComponentsStyles, ThemeTokens, atoms, breakpointQuery, classnames, makeComponentTheme, makeTheme, useComponentStyleDefaultProps, useComponentStyles, vars } from './momotaro.chunk.js';