@creativecodeco/ui 0.4.0 → 0.4.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.
@@ -1,7 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  /// <reference types="react" />
3
3
  import type { ButtonEvent } from '../types';
4
- export default function useSafeButtonProps({ onClick, onSubmit, ...props }: React.ComponentPropsWithoutRef<'button'>): {
4
+ export default function useSafeButtonProps({ onClick, onSubmit, loading, ...props }: React.ComponentPropsWithoutRef<'button'> & {
5
+ loading?: boolean;
6
+ }): {
5
7
  onClick: (event: ButtonEvent) => void;
6
8
  onSubmit: (event: ButtonEvent) => void;
7
9
  name?: string | undefined;
@@ -1,7 +1,7 @@
1
1
  import { useCallback } from 'react';
2
- export default function useSafeButtonProps({ onClick, onSubmit, ...props }) {
2
+ export default function useSafeButtonProps({ onClick, onSubmit, loading, ...props }) {
3
3
  const wrapper = useCallback((callback, event) => {
4
- !props.disabled && callback(event);
4
+ !props.disabled && !loading && callback(event);
5
5
  }, [props.disabled]);
6
6
  const handleClick = useCallback((event) => {
7
7
  onClick && wrapper(onClick, event);
@@ -57,6 +57,10 @@
57
57
  }
58
58
  }
59
59
 
60
+ &-loading {
61
+ @apply pointer-events-none cursor-default;
62
+ }
63
+
60
64
  &:focus,
61
65
  &:hover,
62
66
  &:active {
@@ -6,4 +6,5 @@
6
6
  @import './button.css';
7
7
  @import './checkbox.css';
8
8
  @import './radio.css';
9
+ @import './span.css';
9
10
  @import './text-box.css';
@@ -0,0 +1,5 @@
1
+ .span {
2
+ &-loading {
3
+ @apply loading loading-spinner;
4
+ }
5
+ }
@@ -1182,6 +1182,36 @@ html {
1182
1182
  margin-bottom: 0px;
1183
1183
  margin-inline-start: -1px;
1184
1184
  }
1185
+ .\!loading {
1186
+ pointer-events: none !important;
1187
+ display: inline-block !important;
1188
+ aspect-ratio: 1 / 1 !important;
1189
+ width: 1.5rem !important;
1190
+ background-color: currentColor !important;
1191
+ -webkit-mask-size: 100% !important;
1192
+ mask-size: 100% !important;
1193
+ -webkit-mask-repeat: no-repeat !important;
1194
+ mask-repeat: no-repeat !important;
1195
+ -webkit-mask-position: center !important;
1196
+ mask-position: center !important;
1197
+ -webkit-mask-image: url("data:image/svg+xml,%3Csvg width='24' height='24' stroke='%23000' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cstyle%3E.spinner_V8m1%7Btransform-origin:center;animation:spinner_zKoa 2s linear infinite%7D.spinner_V8m1 circle%7Bstroke-linecap:round;animation:spinner_YpZS 1.5s ease-out infinite%7D%40keyframes spinner_zKoa%7B100%25%7Btransform:rotate(360deg)%7D%7D%40keyframes spinner_YpZS%7B0%25%7Bstroke-dasharray:0 150;stroke-dashoffset:0%7D47.5%25%7Bstroke-dasharray:42 150;stroke-dashoffset:-16%7D95%25%2C100%25%7Bstroke-dasharray:42 150;stroke-dashoffset:-59%7D%7D%3C%2Fstyle%3E%3Cg class='spinner_V8m1'%3E%3Ccircle cx='12' cy='12' r='9.5' fill='none' stroke-width='3'%3E%3C%2Fcircle%3E%3C%2Fg%3E%3C%2Fsvg%3E") !important;
1198
+ mask-image: url("data:image/svg+xml,%3Csvg width='24' height='24' stroke='%23000' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cstyle%3E.spinner_V8m1%7Btransform-origin:center;animation:spinner_zKoa 2s linear infinite%7D.spinner_V8m1 circle%7Bstroke-linecap:round;animation:spinner_YpZS 1.5s ease-out infinite%7D%40keyframes spinner_zKoa%7B100%25%7Btransform:rotate(360deg)%7D%7D%40keyframes spinner_YpZS%7B0%25%7Bstroke-dasharray:0 150;stroke-dashoffset:0%7D47.5%25%7Bstroke-dasharray:42 150;stroke-dashoffset:-16%7D95%25%2C100%25%7Bstroke-dasharray:42 150;stroke-dashoffset:-59%7D%7D%3C%2Fstyle%3E%3Cg class='spinner_V8m1'%3E%3Ccircle cx='12' cy='12' r='9.5' fill='none' stroke-width='3'%3E%3C%2Fcircle%3E%3C%2Fg%3E%3C%2Fsvg%3E") !important;
1199
+ }
1200
+ .loading {
1201
+ pointer-events: none;
1202
+ display: inline-block;
1203
+ aspect-ratio: 1 / 1;
1204
+ width: 1.5rem;
1205
+ background-color: currentColor;
1206
+ -webkit-mask-size: 100%;
1207
+ mask-size: 100%;
1208
+ -webkit-mask-repeat: no-repeat;
1209
+ mask-repeat: no-repeat;
1210
+ -webkit-mask-position: center;
1211
+ mask-position: center;
1212
+ -webkit-mask-image: url("data:image/svg+xml,%3Csvg width='24' height='24' stroke='%23000' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cstyle%3E.spinner_V8m1%7Btransform-origin:center;animation:spinner_zKoa 2s linear infinite%7D.spinner_V8m1 circle%7Bstroke-linecap:round;animation:spinner_YpZS 1.5s ease-out infinite%7D%40keyframes spinner_zKoa%7B100%25%7Btransform:rotate(360deg)%7D%7D%40keyframes spinner_YpZS%7B0%25%7Bstroke-dasharray:0 150;stroke-dashoffset:0%7D47.5%25%7Bstroke-dasharray:42 150;stroke-dashoffset:-16%7D95%25%2C100%25%7Bstroke-dasharray:42 150;stroke-dashoffset:-59%7D%7D%3C%2Fstyle%3E%3Cg class='spinner_V8m1'%3E%3Ccircle cx='12' cy='12' r='9.5' fill='none' stroke-width='3'%3E%3C%2Fcircle%3E%3C%2Fg%3E%3C%2Fsvg%3E");
1213
+ mask-image: url("data:image/svg+xml,%3Csvg width='24' height='24' stroke='%23000' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cstyle%3E.spinner_V8m1%7Btransform-origin:center;animation:spinner_zKoa 2s linear infinite%7D.spinner_V8m1 circle%7Bstroke-linecap:round;animation:spinner_YpZS 1.5s ease-out infinite%7D%40keyframes spinner_zKoa%7B100%25%7Btransform:rotate(360deg)%7D%7D%40keyframes spinner_YpZS%7B0%25%7Bstroke-dasharray:0 150;stroke-dashoffset:0%7D47.5%25%7Bstroke-dasharray:42 150;stroke-dashoffset:-16%7D95%25%2C100%25%7Bstroke-dasharray:42 150;stroke-dashoffset:-59%7D%7D%3C%2Fstyle%3E%3Cg class='spinner_V8m1'%3E%3Ccircle cx='12' cy='12' r='9.5' fill='none' stroke-width='3'%3E%3C%2Fcircle%3E%3C%2Fg%3E%3C%2Fsvg%3E");
1214
+ }
1185
1215
  :where(.menu li:empty) {
1186
1216
  --tw-bg-opacity: 1;
1187
1217
  background-color: var(--fallback-bc,oklch(var(--bc)/var(--tw-bg-opacity)));
@@ -2684,6 +2714,10 @@ html {
2684
2714
  border-radius: 9999px;
2685
2715
  padding: 0px;
2686
2716
  }
2717
+ .button-loading {
2718
+ pointer-events: none;
2719
+ cursor: default;
2720
+ }
2687
2721
  @supports (color: color-mix(in oklab, black, black)) {
2688
2722
 
2689
2723
  .button:focus,
@@ -3230,6 +3264,21 @@ html {
3230
3264
  height: 2rem;
3231
3265
  width: 2rem;
3232
3266
  }
3267
+ .span-loading {
3268
+ pointer-events: none;
3269
+ display: inline-block;
3270
+ aspect-ratio: 1 / 1;
3271
+ width: 1.5rem;
3272
+ background-color: currentColor;
3273
+ -webkit-mask-size: 100%;
3274
+ mask-size: 100%;
3275
+ -webkit-mask-repeat: no-repeat;
3276
+ mask-repeat: no-repeat;
3277
+ -webkit-mask-position: center;
3278
+ mask-position: center;
3279
+ -webkit-mask-image: url("data:image/svg+xml,%3Csvg width='24' height='24' stroke='%23000' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cstyle%3E.spinner_V8m1%7Btransform-origin:center;animation:spinner_zKoa 2s linear infinite%7D.spinner_V8m1 circle%7Bstroke-linecap:round;animation:spinner_YpZS 1.5s ease-out infinite%7D%40keyframes spinner_zKoa%7B100%25%7Btransform:rotate(360deg)%7D%7D%40keyframes spinner_YpZS%7B0%25%7Bstroke-dasharray:0 150;stroke-dashoffset:0%7D47.5%25%7Bstroke-dasharray:42 150;stroke-dashoffset:-16%7D95%25%2C100%25%7Bstroke-dasharray:42 150;stroke-dashoffset:-59%7D%7D%3C%2Fstyle%3E%3Cg class='spinner_V8m1'%3E%3Ccircle cx='12' cy='12' r='9.5' fill='none' stroke-width='3'%3E%3C%2Fcircle%3E%3C%2Fg%3E%3C%2Fsvg%3E");
3280
+ mask-image: url("data:image/svg+xml,%3Csvg width='24' height='24' stroke='%23000' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cstyle%3E.spinner_V8m1%7Btransform-origin:center;animation:spinner_zKoa 2s linear infinite%7D.spinner_V8m1 circle%7Bstroke-linecap:round;animation:spinner_YpZS 1.5s ease-out infinite%7D%40keyframes spinner_zKoa%7B100%25%7Btransform:rotate(360deg)%7D%7D%40keyframes spinner_YpZS%7B0%25%7Bstroke-dasharray:0 150;stroke-dashoffset:0%7D47.5%25%7Bstroke-dasharray:42 150;stroke-dashoffset:-16%7D95%25%2C100%25%7Bstroke-dasharray:42 150;stroke-dashoffset:-59%7D%7D%3C%2Fstyle%3E%3Cg class='spinner_V8m1'%3E%3Ccircle cx='12' cy='12' r='9.5' fill='none' stroke-width='3'%3E%3C%2Fcircle%3E%3C%2Fg%3E%3C%2Fsvg%3E");
3281
+ }
3233
3282
  .text-box-size-xs {
3234
3283
  height: 1.5rem;
3235
3284
  padding-left: 0.5rem;
@@ -9,5 +9,7 @@ export interface ButtonType extends React.ButtonHTMLAttributes<HTMLButtonElement
9
9
  size?: SizeType;
10
10
  icon?: IconType;
11
11
  iconPosition?: PositionType;
12
+ loading?: boolean;
13
+ loadingLabel?: string;
12
14
  }
13
15
  export type ButtonRef = HTMLButtonElement;
@@ -1,20 +1,27 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef } from 'react';
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useMemo } from 'react';
3
3
  import cls from 'classnames';
4
4
  import { useSafeButtonProps } from '../../../hooks';
5
- const Button = forwardRef(({ children, isLink, color, outline, size = 'md', icon: Icon, iconPosition = 'left', disabled, ...otherProps }, ref) => {
6
- const safeProps = useSafeButtonProps({ disabled, ...otherProps });
7
- const getIcon = () => {
5
+ const Button = forwardRef(({ children, isLink, color, outline, size = 'md', icon: Icon, iconPosition = 'left', loading, loadingLabel, ...otherProps }, ref) => {
6
+ const safeProps = useSafeButtonProps({ loading, ...otherProps });
7
+ const newIcon = useMemo(() => {
8
8
  if (!Icon) {
9
9
  return;
10
10
  }
11
11
  return _jsx(Icon, {});
12
- };
13
- return (_jsxs("button", { ref: ref, className: cls('button', {
12
+ }, [Icon]);
13
+ const content = useMemo(() => {
14
+ if (loading) {
15
+ return (_jsxs(_Fragment, { children: [_jsx("span", { className: 'span-loading' }), loadingLabel] }));
16
+ }
17
+ return (_jsxs(_Fragment, { children: [iconPosition === 'left' && newIcon, children, iconPosition === 'right' && newIcon] }));
18
+ }, [loading, loadingLabel, iconPosition, children, newIcon]);
19
+ return (_jsx("button", { ref: ref, className: cls('button', {
14
20
  'button-link': isLink,
15
21
  'button-outline': !isLink && outline,
16
22
  [`button-color-${color}`]: !isLink && color,
17
- [`button-size-${size}`]: size !== 'md'
18
- }), ...safeProps, children: [iconPosition === 'left' && getIcon(), children, iconPosition === 'right' && getIcon()] }));
23
+ [`button-size-${size}`]: size !== 'md',
24
+ 'button-loading': loading
25
+ }), ...safeProps, children: content }));
19
26
  });
20
27
  export default Button;
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "framework design",
11
11
  "design system"
12
12
  ],
13
- "version": "0.4.0",
13
+ "version": "0.4.1",
14
14
  "homepage": "https://github.com/creativecodeco/ui",
15
15
  "author": {
16
16
  "name": "John Toro",
@@ -70,14 +70,14 @@
70
70
  "@storybook/react-webpack5": "7.6.10",
71
71
  "@storybook/test": "7.6.10",
72
72
  "@testing-library/dom": "9.3.4",
73
- "@testing-library/jest-dom": "6.2.0",
73
+ "@testing-library/jest-dom": "6.2.1",
74
74
  "@testing-library/react": "14.1.2",
75
75
  "@testing-library/user-event": "14.5.2",
76
76
  "@types/jest": "29.5.11",
77
77
  "@types/node": "20.11.5",
78
78
  "@types/react": "18.2.48",
79
79
  "@types/react-dom": "18.2.18",
80
- "@typescript-eslint/eslint-plugin": "6.19.0",
80
+ "@typescript-eslint/eslint-plugin": "6.19.1",
81
81
  "autoprefixer": "10.4.17",
82
82
  "chromatic": "10.3.1",
83
83
  "classnames": "2.5.1",