@blockle/blocks 0.2.2 → 0.3.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 (43) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs +134 -6
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.mjs +136 -6
  5. package/dist/momotaro.chunk.d.ts +516 -0
  6. package/dist/reset.css.cjs +0 -1
  7. package/dist/reset.css.d.ts +1 -408
  8. package/dist/reset.css.mjs +0 -1
  9. package/dist/styles/components/Button/Button.css.cjs +15 -0
  10. package/dist/styles/components/Button/Button.css.mjs +16 -0
  11. package/dist/styles/lib/css/atoms/index.cjs +1 -0
  12. package/dist/styles/lib/css/atoms/index.mjs +1 -0
  13. package/dist/styles/lib/css/layers/layers.css.cjs +7 -0
  14. package/dist/styles/lib/css/layers/layers.css.mjs +8 -0
  15. package/dist/styles/lib/css/reset/reset.css.cjs +0 -36
  16. package/dist/styles/lib/css/reset/reset.css.mjs +1 -36
  17. package/dist/styles/lib/css/theme/makeComponentTheme.cjs +3 -0
  18. package/dist/styles/lib/css/theme/makeComponentTheme.mjs +4 -0
  19. package/dist/styles/lib/css/theme/makeTheme.cjs +3 -2
  20. package/dist/styles/lib/css/theme/makeTheme.mjs +3 -2
  21. package/dist/styles/lib/css/theme/makeVanillaTheme.cjs +5 -2
  22. package/dist/styles/lib/css/theme/makeVanillaTheme.mjs +5 -2
  23. package/dist/styles/lib/css/theme/tokens.cjs +5 -2
  24. package/dist/styles/lib/css/theme/tokens.mjs +5 -2
  25. package/dist/styles/themes/momotaro/components/button.css.cjs +106 -0
  26. package/dist/styles/themes/momotaro/components/button.css.mjs +107 -0
  27. package/dist/styles/themes/momotaro/components/helpers.css.cjs +26 -0
  28. package/dist/styles/themes/momotaro/components/helpers.css.mjs +27 -0
  29. package/dist/styles/themes/momotaro/components/index.cjs +10 -0
  30. package/dist/styles/themes/momotaro/components/index.mjs +11 -0
  31. package/dist/styles/themes/momotaro/components/link.css.cjs +47 -0
  32. package/dist/styles/themes/momotaro/components/link.css.mjs +48 -0
  33. package/dist/styles/themes/momotaro/components/spinner.css.cjs +44 -0
  34. package/dist/styles/themes/momotaro/components/spinner.css.mjs +45 -0
  35. package/dist/styles/themes/momotaro/momotaro.css.cjs +13 -0
  36. package/dist/styles/themes/momotaro/{momotaroTheme.css.mjs → momotaro.css.mjs} +6 -4
  37. package/dist/styles/themes/momotaro/tokens.cjs +5 -2
  38. package/dist/styles/themes/momotaro/tokens.mjs +5 -2
  39. package/dist/themes/momotaro.cjs +2 -2
  40. package/dist/themes/momotaro.d.ts +1 -1
  41. package/dist/themes/momotaro.mjs +2 -2
  42. package/package.json +49 -20
  43. package/dist/styles/themes/momotaro/momotaroTheme.css.cjs +0 -11
package/README.md CHANGED
@@ -15,7 +15,7 @@ import React from 'react';
15
15
 
16
16
  import '@blockle/blocks/reset.css';
17
17
  import { ThemeProvider } from '@blockle/blocks';
18
- import { theme } from '@blockle/blocks/themes/momotaro';
18
+ import { momotaro } from '@blockle/blocks/themes/momotaro';
19
19
 
20
20
  // const Link = makeLinkComponent(...)
21
21
 
package/dist/index.cjs CHANGED
@@ -1,19 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const jsxRuntime = require("react/jsx-runtime");
3
+ const styles_lib_css_theme_vars_css_cjs = require("./styles/lib/css/theme/vars.css.cjs");
4
4
  const styles_lib_css_atoms_sprinkles_css_cjs = require("./styles/lib/css/atoms/sprinkles.css.cjs");
5
+ const jsxRuntime = require("react/jsx-runtime");
5
6
  const react = require("react");
6
- const styles_lib_css_theme_vars_css_cjs = require("./styles/lib/css/theme/vars.css.cjs");
7
+ const styles_components_Button_Button_css_cjs = require("./styles/components/Button/Button.css.cjs");
7
8
  const classnames = (...args) => {
8
9
  const className = args.filter((arg) => arg && typeof arg === "string").join(" ");
9
10
  return className || void 0;
10
11
  };
12
+ const BlocksProviderContext = react.createContext(null);
11
13
  const BlocksProvider = ({ children, theme }) => {
12
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: classnames(theme.vars, styles_lib_css_atoms_sprinkles_css_cjs.atoms({ fontFamily: "standard" })), children });
14
+ return /* @__PURE__ */ jsxRuntime.jsx(BlocksProviderContext.Provider, { value: theme, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: classnames(theme.vars, styles_lib_css_atoms_sprinkles_css_cjs.atoms({ fontFamily: "standard" })), children }) });
13
15
  };
14
- const defaultElement = "div";
16
+ const defaultElement$1 = "div";
15
17
  const Box = react.forwardRef(function Box2({ className, as, ...restProps }, ref) {
16
- const Component = as || defaultElement;
18
+ const Component = as || defaultElement$1;
17
19
  const atomProps = {};
18
20
  const otherProps = {};
19
21
  for (const [name, value] of Object.entries(restProps)) {
@@ -25,6 +27,123 @@ const Box = react.forwardRef(function Box2({ className, as, ...restProps }, ref)
25
27
  }
26
28
  return /* @__PURE__ */ jsxRuntime.jsx(Component, { ref, className: classnames(className, styles_lib_css_atoms_sprinkles_css_cjs.atoms(atomProps)), ...otherProps });
27
29
  });
30
+ const useTheme = () => {
31
+ const theme = react.useContext(BlocksProviderContext);
32
+ if (!theme) {
33
+ throw new Error("useTheme must be used within a BlocksProvider");
34
+ }
35
+ return theme;
36
+ };
37
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
38
+ function useComponentStyles(name, props) {
39
+ const { components } = useTheme();
40
+ const component = components[name];
41
+ if (!component) {
42
+ console.info(`Component ${name} is not defined in the theme`);
43
+ return "";
44
+ }
45
+ const classNames = [];
46
+ const propsWithDefaults = { ...props };
47
+ if (component.defaultVariants) {
48
+ const keys2 = Object.keys(component.defaultVariants);
49
+ for (const key of keys2) {
50
+ if (propsWithDefaults[key] === void 0) {
51
+ propsWithDefaults[key] = component.defaultVariants[key];
52
+ }
53
+ }
54
+ }
55
+ if (propsWithDefaults.base && component.base) {
56
+ classNames.push(component.base);
57
+ }
58
+ if (!component.variants) {
59
+ return classNames.join(" ");
60
+ }
61
+ const keys = Object.keys(propsWithDefaults);
62
+ for (const key of keys) {
63
+ const value = propsWithDefaults[key];
64
+ if (key === "base" || value === void 0) {
65
+ continue;
66
+ }
67
+ if (!hasOwnProperty.call(component.variants, key)) {
68
+ continue;
69
+ }
70
+ if (typeof value === "boolean") {
71
+ if (value) {
72
+ classNames.push(component.variants[key]);
73
+ }
74
+ continue;
75
+ }
76
+ const variant = component.variants[key][value];
77
+ if (variant) {
78
+ classNames.push(variant);
79
+ }
80
+ }
81
+ if (component.compoundVariants) {
82
+ for (const compoundVariant of component.compoundVariants) {
83
+ const keys2 = Object.keys(compoundVariant.variants);
84
+ const matches = keys2.every((key) => {
85
+ const value = propsWithDefaults[key];
86
+ if (value === void 0) {
87
+ return false;
88
+ }
89
+ return value === compoundVariant.variants[key];
90
+ });
91
+ if (matches) {
92
+ classNames.push(compoundVariant.style);
93
+ }
94
+ }
95
+ }
96
+ return classNames.join(" ");
97
+ }
98
+ const Spinner = ({ className, size, color, ...restProps }) => {
99
+ const spinnerClassName = useComponentStyles("spinner", { base: true, size, color });
100
+ return /* @__PURE__ */ jsxRuntime.jsx(Box, { color, className: classnames(spinnerClassName, className), ...restProps });
101
+ };
102
+ const Button = react.forwardRef(function Button2({
103
+ children,
104
+ className,
105
+ type = "button",
106
+ variant,
107
+ intent,
108
+ size,
109
+ width,
110
+ startSlot,
111
+ endSlot,
112
+ loading,
113
+ disabled,
114
+ ...restProps
115
+ }, ref) {
116
+ const isLinkVariant = variant === "link";
117
+ const buttonClassName = useComponentStyles("button", {
118
+ base: true,
119
+ variant: isLinkVariant ? "solid" : variant,
120
+ intent,
121
+ size
122
+ });
123
+ const linkClassName = useComponentStyles("link", { base: true, variant: "primary" });
124
+ return /* @__PURE__ */ jsxRuntime.jsxs(
125
+ Box,
126
+ {
127
+ ref,
128
+ as: "button",
129
+ className: classnames(
130
+ styles_components_Button_Button_css_cjs.buttonReset,
131
+ isLinkVariant ? linkClassName : buttonClassName,
132
+ className
133
+ ),
134
+ width,
135
+ type,
136
+ disabled: disabled || loading,
137
+ ...restProps,
138
+ children: [
139
+ startSlot && /* @__PURE__ */ jsxRuntime.jsx(Box, { paddingRight: "medium", children: startSlot }),
140
+ loading && /* @__PURE__ */ jsxRuntime.jsx(Spinner, { size, marginRight: "medium" }),
141
+ children,
142
+ endSlot && /* @__PURE__ */ jsxRuntime.jsx(Box, { paddingLeft: "medium", children: endSlot })
143
+ ]
144
+ }
145
+ );
146
+ });
28
147
  const Heading = ({
29
148
  className,
30
149
  level = 1,
@@ -139,12 +258,21 @@ const Text = ({
139
258
  }
140
259
  );
141
260
  };
142
- exports.atoms = styles_lib_css_atoms_sprinkles_css_cjs.atoms;
261
+ const defaultElement = "a";
262
+ const Link = react.forwardRef(function Link2({ as, className, variant, underline, ...restProps }, ref) {
263
+ const Component = as || defaultElement;
264
+ const linkClassName = useComponentStyles("link", { base: true, variant, underline });
265
+ return /* @__PURE__ */ jsxRuntime.jsx(Box, { ref, as: Component, className: classnames(className, linkClassName), ...restProps });
266
+ });
143
267
  exports.vars = styles_lib_css_theme_vars_css_cjs.vars;
268
+ exports.atoms = styles_lib_css_atoms_sprinkles_css_cjs.atoms;
144
269
  exports.BlocksProvider = BlocksProvider;
145
270
  exports.Box = Box;
271
+ exports.Button = Button;
146
272
  exports.Heading = Heading;
147
273
  exports.Inline = Inline;
274
+ exports.Link = Link;
275
+ exports.Spinner = Spinner;
148
276
  exports.Stack = Stack;
149
277
  exports.Text = Text;
150
278
  exports.classnames = classnames;
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { BlocksProvider, BlocksProviderProps, Box, BoxProps, Heading, HeadingProps, Inline, InlineProps, Stack, StackProps, Text, TextProps, atoms, classnames, vars } from './reset.css.js';
1
+ export { BlocksProvider, BlocksProviderProps, Box, BoxProps, Button, ButtonProps, Heading, HeadingProps, Inline, InlineProps, Link, LinkProps, Spinner, SpinnerProps, Stack, StackProps, Text, TextProps, atoms, classnames, vars } from './momotaro.chunk.js';
package/dist/index.mjs CHANGED
@@ -1,17 +1,21 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { atoms } from "./styles/lib/css/atoms/sprinkles.css.mjs";
3
- import { forwardRef } from "react";
1
+ 'use client';
2
+
4
3
  import { vars } from "./styles/lib/css/theme/vars.css.mjs";
4
+ import { atoms } from "./styles/lib/css/atoms/sprinkles.css.mjs";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ import { createContext, forwardRef, useContext } from "react";
7
+ import { buttonReset } from "./styles/components/Button/Button.css.mjs";
5
8
  const classnames = (...args) => {
6
9
  const className = args.filter((arg) => arg && typeof arg === "string").join(" ");
7
10
  return className || void 0;
8
11
  };
12
+ const BlocksProviderContext = createContext(null);
9
13
  const BlocksProvider = ({ children, theme }) => {
10
- return /* @__PURE__ */ jsx("div", { className: classnames(theme.vars, atoms({ fontFamily: "standard" })), children });
14
+ return /* @__PURE__ */ jsx(BlocksProviderContext.Provider, { value: theme, children: /* @__PURE__ */ jsx("div", { className: classnames(theme.vars, atoms({ fontFamily: "standard" })), children }) });
11
15
  };
12
- const defaultElement = "div";
16
+ const defaultElement$1 = "div";
13
17
  const Box = forwardRef(function Box2({ className, as, ...restProps }, ref) {
14
- const Component = as || defaultElement;
18
+ const Component = as || defaultElement$1;
15
19
  const atomProps = {};
16
20
  const otherProps = {};
17
21
  for (const [name, value] of Object.entries(restProps)) {
@@ -23,6 +27,123 @@ const Box = forwardRef(function Box2({ className, as, ...restProps }, ref) {
23
27
  }
24
28
  return /* @__PURE__ */ jsx(Component, { ref, className: classnames(className, atoms(atomProps)), ...otherProps });
25
29
  });
30
+ const useTheme = () => {
31
+ const theme = useContext(BlocksProviderContext);
32
+ if (!theme) {
33
+ throw new Error("useTheme must be used within a BlocksProvider");
34
+ }
35
+ return theme;
36
+ };
37
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
38
+ function useComponentStyles(name, props) {
39
+ const { components } = useTheme();
40
+ const component = components[name];
41
+ if (!component) {
42
+ console.info(`Component ${name} is not defined in the theme`);
43
+ return "";
44
+ }
45
+ const classNames = [];
46
+ const propsWithDefaults = { ...props };
47
+ if (component.defaultVariants) {
48
+ const keys2 = Object.keys(component.defaultVariants);
49
+ for (const key of keys2) {
50
+ if (propsWithDefaults[key] === void 0) {
51
+ propsWithDefaults[key] = component.defaultVariants[key];
52
+ }
53
+ }
54
+ }
55
+ if (propsWithDefaults.base && component.base) {
56
+ classNames.push(component.base);
57
+ }
58
+ if (!component.variants) {
59
+ return classNames.join(" ");
60
+ }
61
+ const keys = Object.keys(propsWithDefaults);
62
+ for (const key of keys) {
63
+ const value = propsWithDefaults[key];
64
+ if (key === "base" || value === void 0) {
65
+ continue;
66
+ }
67
+ if (!hasOwnProperty.call(component.variants, key)) {
68
+ continue;
69
+ }
70
+ if (typeof value === "boolean") {
71
+ if (value) {
72
+ classNames.push(component.variants[key]);
73
+ }
74
+ continue;
75
+ }
76
+ const variant = component.variants[key][value];
77
+ if (variant) {
78
+ classNames.push(variant);
79
+ }
80
+ }
81
+ if (component.compoundVariants) {
82
+ for (const compoundVariant of component.compoundVariants) {
83
+ const keys2 = Object.keys(compoundVariant.variants);
84
+ const matches = keys2.every((key) => {
85
+ const value = propsWithDefaults[key];
86
+ if (value === void 0) {
87
+ return false;
88
+ }
89
+ return value === compoundVariant.variants[key];
90
+ });
91
+ if (matches) {
92
+ classNames.push(compoundVariant.style);
93
+ }
94
+ }
95
+ }
96
+ return classNames.join(" ");
97
+ }
98
+ const Spinner = ({ className, size, color, ...restProps }) => {
99
+ const spinnerClassName = useComponentStyles("spinner", { base: true, size, color });
100
+ return /* @__PURE__ */ jsx(Box, { color, className: classnames(spinnerClassName, className), ...restProps });
101
+ };
102
+ const Button = forwardRef(function Button2({
103
+ children,
104
+ className,
105
+ type = "button",
106
+ variant,
107
+ intent,
108
+ size,
109
+ width,
110
+ startSlot,
111
+ endSlot,
112
+ loading,
113
+ disabled,
114
+ ...restProps
115
+ }, ref) {
116
+ const isLinkVariant = variant === "link";
117
+ const buttonClassName = useComponentStyles("button", {
118
+ base: true,
119
+ variant: isLinkVariant ? "solid" : variant,
120
+ intent,
121
+ size
122
+ });
123
+ const linkClassName = useComponentStyles("link", { base: true, variant: "primary" });
124
+ return /* @__PURE__ */ jsxs(
125
+ Box,
126
+ {
127
+ ref,
128
+ as: "button",
129
+ className: classnames(
130
+ buttonReset,
131
+ isLinkVariant ? linkClassName : buttonClassName,
132
+ className
133
+ ),
134
+ width,
135
+ type,
136
+ disabled: disabled || loading,
137
+ ...restProps,
138
+ children: [
139
+ startSlot && /* @__PURE__ */ jsx(Box, { paddingRight: "medium", children: startSlot }),
140
+ loading && /* @__PURE__ */ jsx(Spinner, { size, marginRight: "medium" }),
141
+ children,
142
+ endSlot && /* @__PURE__ */ jsx(Box, { paddingLeft: "medium", children: endSlot })
143
+ ]
144
+ }
145
+ );
146
+ });
26
147
  const Heading = ({
27
148
  className,
28
149
  level = 1,
@@ -137,11 +258,20 @@ const Text = ({
137
258
  }
138
259
  );
139
260
  };
261
+ const defaultElement = "a";
262
+ const Link = forwardRef(function Link2({ as, className, variant, underline, ...restProps }, ref) {
263
+ const Component = as || defaultElement;
264
+ const linkClassName = useComponentStyles("link", { base: true, variant, underline });
265
+ return /* @__PURE__ */ jsx(Box, { ref, as: Component, className: classnames(className, linkClassName), ...restProps });
266
+ });
140
267
  export {
141
268
  BlocksProvider,
142
269
  Box,
270
+ Button,
143
271
  Heading,
144
272
  Inline,
273
+ Link,
274
+ Spinner,
145
275
  Stack,
146
276
  Text,
147
277
  atoms,