@astral/ui 4.38.0 → 4.39.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.
@@ -1,20 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { forwardRefWithGeneric } from '../forwardRefWithGeneric';
3
- import { classNames } from '../utils/classNames';
4
- import { buttonClassnames } from './constants';
5
3
  import { ButtonColors, ButtonVariants } from './enums';
6
4
  import { StyledButton, StyledLoader } from './styles';
7
5
  import { useLogic } from './useLogic';
8
6
  const UnwrappedButton = (props, ref) => {
9
- const { loadingIndicatorColor } = useLogic(props);
7
+ const { loadingIndicatorColor, classnames } = useLogic(props);
10
8
  const { variant = ButtonVariants.Contained, color = variant === ButtonVariants.Text
11
9
  ? ButtonColors.Grey
12
10
  : ButtonColors.Primary, loading, disabled, children, className, selected, ...restProps } = props;
13
- return (_jsxs(StyledButton, { variant: variant, ref: ref, color: color, disabled: disabled || loading, selected: selected, ...restProps, className: classNames(className, buttonClassnames.root, {
14
- [buttonClassnames.loading]: loading,
15
- [buttonClassnames.selected]: selected,
16
- [buttonClassnames.disabled]: disabled,
17
- }), "aria-disabled": loading, children: [loading && (_jsx(StyledLoader, { color: loadingIndicatorColor, size: "small", "$color": color, "$variant": variant, "$isDisabled": disabled })), children] }));
11
+ return (_jsxs(StyledButton, { variant: variant, ref: ref, color: color, disabled: disabled || loading, selected: selected, ...restProps, className: classnames, "aria-disabled": loading, children: [loading && (_jsx(StyledLoader, { color: loadingIndicatorColor, size: "small", "$color": color, "$variant": variant, "$isDisabled": disabled })), children] }));
18
12
  };
19
13
  export const Button = forwardRefWithGeneric(UnwrappedButton);
20
14
  export default Button;
@@ -1,5 +1,17 @@
1
1
  export { buttonClasses } from '@mui/material/Button';
2
+ export declare const buttonColorClassnames: {
3
+ primary: string;
4
+ error: string;
5
+ success: string;
6
+ warning: string;
7
+ grey: string;
8
+ };
2
9
  export declare const buttonClassnames: {
10
+ primary: string;
11
+ error: string;
12
+ success: string;
13
+ warning: string;
14
+ grey: string;
3
15
  root: string;
4
16
  loading: string;
5
17
  selected: string;
@@ -1,8 +1,17 @@
1
1
  import { createUIKitClassname } from '../utils/createUIKitClassname';
2
+ import { ButtonColors } from './enums';
2
3
  export { buttonClasses } from '@mui/material/Button';
4
+ export const buttonColorClassnames = {
5
+ [ButtonColors.Primary]: createUIKitClassname('button_color-primary'),
6
+ [ButtonColors.Error]: createUIKitClassname('button_color-error'),
7
+ [ButtonColors.Success]: createUIKitClassname('button_color-success'),
8
+ [ButtonColors.Warning]: createUIKitClassname('button_color-warning'),
9
+ [ButtonColors.Grey]: createUIKitClassname('button_color-grey'),
10
+ };
3
11
  export const buttonClassnames = {
4
12
  root: createUIKitClassname('button'),
5
13
  loading: createUIKitClassname('button_loading'),
6
14
  selected: createUIKitClassname('button_selected'),
7
15
  disabled: createUIKitClassname('button_disabled'),
16
+ ...buttonColorClassnames,
8
17
  };
@@ -1,7 +1,8 @@
1
1
  import { type ButtonProps } from '../types';
2
2
  type UseLogicParam = ButtonProps;
3
3
  type Color = 'primary' | 'inverted';
4
- export declare const useLogic: ({ variant, }: UseLogicParam) => {
4
+ export declare const useLogic: ({ loading, selected, variant, color, disabled, className, }: UseLogicParam) => {
5
5
  loadingIndicatorColor: Color;
6
+ classnames: string;
6
7
  };
7
8
  export {};
@@ -1,11 +1,20 @@
1
1
  import { useMemo } from 'react';
2
- import { ButtonVariants } from '../enums';
3
- export const useLogic = ({ variant = ButtonVariants.Contained, }) => {
2
+ import { classNames } from '../../utils/classNames';
3
+ import { buttonClassnames, buttonColorClassnames } from '../constants';
4
+ import { ButtonColors, ButtonVariants } from '../enums';
5
+ export const useLogic = ({ loading, selected, variant = ButtonVariants.Contained, color = variant === ButtonVariants.Text
6
+ ? ButtonColors.Grey
7
+ : ButtonColors.Primary, disabled, className, }) => {
4
8
  const loadingIndicatorColor = useMemo(() => {
5
9
  if (variant !== ButtonVariants.Contained) {
6
10
  return 'primary';
7
11
  }
8
12
  return 'inverted';
9
13
  }, [variant]);
10
- return { loadingIndicatorColor };
14
+ const classnames = useMemo(() => classNames(buttonClassnames.root, buttonColorClassnames[color], className, {
15
+ [buttonClassnames.loading]: loading,
16
+ [buttonClassnames.disabled]: disabled,
17
+ [buttonClassnames.selected]: selected,
18
+ }), [loading, selected, color, className, disabled]);
19
+ return { loadingIndicatorColor, classnames };
11
20
  };
@@ -3,21 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Button = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const forwardRefWithGeneric_1 = require("../forwardRefWithGeneric");
6
- const classNames_1 = require("../utils/classNames");
7
- const constants_1 = require("./constants");
8
6
  const enums_1 = require("./enums");
9
7
  const styles_1 = require("./styles");
10
8
  const useLogic_1 = require("./useLogic");
11
9
  const UnwrappedButton = (props, ref) => {
12
- const { loadingIndicatorColor } = (0, useLogic_1.useLogic)(props);
10
+ const { loadingIndicatorColor, classnames } = (0, useLogic_1.useLogic)(props);
13
11
  const { variant = enums_1.ButtonVariants.Contained, color = variant === enums_1.ButtonVariants.Text
14
12
  ? enums_1.ButtonColors.Grey
15
13
  : enums_1.ButtonColors.Primary, loading, disabled, children, className, selected, ...restProps } = props;
16
- return ((0, jsx_runtime_1.jsxs)(styles_1.StyledButton, { variant: variant, ref: ref, color: color, disabled: disabled || loading, selected: selected, ...restProps, className: (0, classNames_1.classNames)(className, constants_1.buttonClassnames.root, {
17
- [constants_1.buttonClassnames.loading]: loading,
18
- [constants_1.buttonClassnames.selected]: selected,
19
- [constants_1.buttonClassnames.disabled]: disabled,
20
- }), "aria-disabled": loading, children: [loading && ((0, jsx_runtime_1.jsx)(styles_1.StyledLoader, { color: loadingIndicatorColor, size: "small", "$color": color, "$variant": variant, "$isDisabled": disabled })), children] }));
14
+ return ((0, jsx_runtime_1.jsxs)(styles_1.StyledButton, { variant: variant, ref: ref, color: color, disabled: disabled || loading, selected: selected, ...restProps, className: classnames, "aria-disabled": loading, children: [loading && ((0, jsx_runtime_1.jsx)(styles_1.StyledLoader, { color: loadingIndicatorColor, size: "small", "$color": color, "$variant": variant, "$isDisabled": disabled })), children] }));
21
15
  };
22
16
  exports.Button = (0, forwardRefWithGeneric_1.forwardRefWithGeneric)(UnwrappedButton);
23
17
  exports.default = exports.Button;
@@ -1,5 +1,17 @@
1
1
  export { buttonClasses } from '@mui/material/Button';
2
+ export declare const buttonColorClassnames: {
3
+ primary: string;
4
+ error: string;
5
+ success: string;
6
+ warning: string;
7
+ grey: string;
8
+ };
2
9
  export declare const buttonClassnames: {
10
+ primary: string;
11
+ error: string;
12
+ success: string;
13
+ warning: string;
14
+ grey: string;
3
15
  root: string;
4
16
  loading: string;
5
17
  selected: string;
@@ -1,12 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buttonClassnames = exports.buttonClasses = void 0;
3
+ exports.buttonClassnames = exports.buttonColorClassnames = exports.buttonClasses = void 0;
4
4
  const createUIKitClassname_1 = require("../utils/createUIKitClassname");
5
+ const enums_1 = require("./enums");
5
6
  var Button_1 = require("@mui/material/Button");
6
7
  Object.defineProperty(exports, "buttonClasses", { enumerable: true, get: function () { return Button_1.buttonClasses; } });
8
+ exports.buttonColorClassnames = {
9
+ [enums_1.ButtonColors.Primary]: (0, createUIKitClassname_1.createUIKitClassname)('button_color-primary'),
10
+ [enums_1.ButtonColors.Error]: (0, createUIKitClassname_1.createUIKitClassname)('button_color-error'),
11
+ [enums_1.ButtonColors.Success]: (0, createUIKitClassname_1.createUIKitClassname)('button_color-success'),
12
+ [enums_1.ButtonColors.Warning]: (0, createUIKitClassname_1.createUIKitClassname)('button_color-warning'),
13
+ [enums_1.ButtonColors.Grey]: (0, createUIKitClassname_1.createUIKitClassname)('button_color-grey'),
14
+ };
7
15
  exports.buttonClassnames = {
8
16
  root: (0, createUIKitClassname_1.createUIKitClassname)('button'),
9
17
  loading: (0, createUIKitClassname_1.createUIKitClassname)('button_loading'),
10
18
  selected: (0, createUIKitClassname_1.createUIKitClassname)('button_selected'),
11
19
  disabled: (0, createUIKitClassname_1.createUIKitClassname)('button_disabled'),
20
+ ...exports.buttonColorClassnames,
12
21
  };
@@ -1,7 +1,8 @@
1
1
  import { type ButtonProps } from '../types';
2
2
  type UseLogicParam = ButtonProps;
3
3
  type Color = 'primary' | 'inverted';
4
- export declare const useLogic: ({ variant, }: UseLogicParam) => {
4
+ export declare const useLogic: ({ loading, selected, variant, color, disabled, className, }: UseLogicParam) => {
5
5
  loadingIndicatorColor: Color;
6
+ classnames: string;
6
7
  };
7
8
  export {};
@@ -2,14 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useLogic = void 0;
4
4
  const react_1 = require("react");
5
+ const classNames_1 = require("../../utils/classNames");
6
+ const constants_1 = require("../constants");
5
7
  const enums_1 = require("../enums");
6
- const useLogic = ({ variant = enums_1.ButtonVariants.Contained, }) => {
8
+ const useLogic = ({ loading, selected, variant = enums_1.ButtonVariants.Contained, color = variant === enums_1.ButtonVariants.Text
9
+ ? enums_1.ButtonColors.Grey
10
+ : enums_1.ButtonColors.Primary, disabled, className, }) => {
7
11
  const loadingIndicatorColor = (0, react_1.useMemo)(() => {
8
12
  if (variant !== enums_1.ButtonVariants.Contained) {
9
13
  return 'primary';
10
14
  }
11
15
  return 'inverted';
12
16
  }, [variant]);
13
- return { loadingIndicatorColor };
17
+ const classnames = (0, react_1.useMemo)(() => (0, classNames_1.classNames)(constants_1.buttonClassnames.root, constants_1.buttonColorClassnames[color], className, {
18
+ [constants_1.buttonClassnames.loading]: loading,
19
+ [constants_1.buttonClassnames.disabled]: disabled,
20
+ [constants_1.buttonClassnames.selected]: selected,
21
+ }), [loading, selected, color, className, disabled]);
22
+ return { loadingIndicatorColor, classnames };
14
23
  };
15
24
  exports.useLogic = useLogic;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astral/ui",
3
- "version": "4.38.0",
3
+ "version": "4.39.0",
4
4
  "browser": "./index.js",
5
5
  "main": "./node/index.js",
6
6
  "dependencies": {