@xipkg/button 0.0.3 → 1.0.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,49 +1,14 @@
1
1
 
2
- > @xipkg/button@0.0.2 build
2
+ > @xipkg/button@1.0.0 build
3
3
  > tsup index.ts --format cjs --dts
4
4
 
5
- CLI Building entry: index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v6.7.0
8
- CLI Target: es6
9
- CJS Build start
10
- CJS dist\index.js 2.50 KB
11
- CJS ⚡️ Build success in 37ms
12
- DTS Build start
13
- Button.tsx(17,11): error TS2769: No overload matches this call.
14
- Overload 1 of 3, '(props: { href: string; } & { children?: ReactNode; classes?: Partial<ButtonClasses> | undefined; color?: "primary" | "success" | "error" | "inherit" | "secondary" | "info" | "warning" | undefined; ... 9 more ...; variant?: "contained" | ... 2 more ... | undefined; } & Omit<...> & CommonProps & Omit<...>): Element', gave the following error.
15
- Type '{ children: ReactNode; status?: Status | undefined; size?: "small" | "medium" | "large" | undefined; loadingPosition?: LoadingPosition | undefined; ... 302 more ...; component?: ElementType<...> | undefined; }' is not assignable to type '{ href: string; }'.
16
- Types of property 'href' are incompatible.
17
- Type 'string | undefined' is not assignable to type 'string'.
18
- Type 'undefined' is not assignable to type 'string'.
19
- Overload 2 of 3, '(props: { component: ElementType<any>; } & { children?: ReactNode; classes?: Partial<ButtonClasses> | undefined; color?: "primary" | ... 6 more ... | undefined; ... 9 more ...; variant?: "contained" | ... 2 more ... | undefined; } & Omit<...> & CommonProps & Omit<...>): Element | null', gave the following error.
20
- Type '{ children: ReactNode; status?: Status | undefined; size?: "small" | "medium" | "large" | undefined; loadingPosition?: LoadingPosition | undefined; ... 302 more ...; component?: ElementType<...> | undefined; }' is not assignable to type '{ component: ElementType<any>; }'.
21
- Types of property 'component' are incompatible.
22
- Type 'ElementType<any> | undefined' is not assignable to type 'ElementType<any>'.
23
- Type 'undefined' is not assignable to type 'ElementType<any>'.
24
- Overload 3 of 3, '(props: DefaultComponentProps<ExtendButtonBaseTypeMap<ButtonTypeMap<{}, "button">>>): Element | null', gave the following error.
25
- Type '{ children: ReactNode; status?: Status | undefined; size?: "small" | "medium" | "large" | undefined; loadingPosition?: LoadingPosition | undefined; ... 302 more ...; component?: ElementType<...> | undefined; }' is not assignable to type '{ children?: ReactNode; classes?: Partial<ButtonClasses> | undefined; color?: "primary" | "success" | "error" | "inherit" | "secondary" | "info" | "warning" | undefined; ... 9 more ...; variant?: "contained" | ... 2 more ... | undefined; }'.
26
- Types of property 'color' are incompatible.
27
- Type 'Color | undefined' is not assignable to type '"primary" | "success" | "error" | "inherit" | "secondary" | "info" | "warning" | undefined'.
28
- Type '"gray"' is not assignable to type '"primary" | "success" | "error" | "inherit" | "secondary" | "info" | "warning" | undefined'.
29
-
30
- Error: error occured in dts build
31
- at Worker.<anonymous> (C:\Users\igorb\OneDrive\Рабочий стол\xi.kit\node_modules\tsup\dist\index.js:2281:26)
32
- at Worker.emit (node:events:513:28)
33
- at MessagePort.<anonymous> (node:internal/worker:243:53)
34
- at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
35
- at exports.emitMessage (node:internal/per_context/messageport:23:28)
36
- DTS Build error
37
- RollupError: Failed to compile. Check the logs above.
38
- at error (C:\Users\igorb\OneDrive\Рабочий стол\xi.kit\node_modules\rollup\dist\shared\rollup.js:349:30)
39
- at Object.error (C:\Users\igorb\OneDrive\Рабочий стол\xi.kit\node_modules\rollup\dist\shared\rollup.js:1716:20)
40
- at Object.error (C:\Users\igorb\OneDrive\Рабочий стол\xi.kit\node_modules\rollup\dist\shared\rollup.js:25501:42)
41
- at generateDtsFromTs (C:\Users\igorb\OneDrive\Рабочий стол\xi.kit\node_modules\tsup\dist\rollup.js:7498:22)
42
- at C:\Users\igorb\OneDrive\Рабочий стол\xi.kit\node_modules\tsup\dist\rollup.js:7505:59
43
- at _nullishCoalesce (C:\Users\igorb\OneDrive\Рабочий стол\xi.kit\node_modules\tsup\dist\rollup.js:1:198)
44
- at Object.transform (C:\Users\igorb\OneDrive\Рабочий стол\xi.kit\node_modules\tsup\dist\rollup.js:7505:18)
45
- at C:\Users\igorb\OneDrive\Рабочий стол\xi.kit\node_modules\rollup\dist\shared\rollup.js:1909:40
46
- npm ERR! Lifecycle script `build` failed with error:
47
- npm ERR! Error: command failed
48
- npm ERR! in workspace: @xipkg/button@0.0.2
49
- npm ERR! at location: C:\Users\igorb\OneDrive\Рабочий стол\xi.kit\packages\pkg.button
5
+ CLI Building entry: index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v6.7.0
8
+ CLI Target: es6
9
+ CJS Build start
10
+ CJS dist/index.js 4.66 KB
11
+ CJS ⚡️ Build success in 28ms
12
+ DTS Build start
13
+ DTS ⚡️ Build success in 2936ms
14
+ DTS dist/index.d.ts 734.00 B
package/Button.tsx CHANGED
@@ -1,18 +1,48 @@
1
- import { Button as MuiButton } from '@mui/material';
1
+ import * as React from 'react';
2
+ import { Slot } from '@radix-ui/react-slot';
3
+ import { cva, type VariantProps } from 'class-variance-authority';
2
4
 
3
- import { ButtonProps } from './types';
5
+ import { cn } from '@xipkg/utils';
4
6
 
5
- declare module '@mui/material/Typography' {
6
- export interface TypographyPropsVariantOverrides {
7
- xl: true;
8
- l: true;
9
- m: true;
10
- s: true;
11
- xs: true;
12
- xxs: true;
13
- }
7
+ export const buttonVariants = cva(
8
+ 'inline-flex items-center w-fit justify-center ring-offset-gray-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
9
+ {
10
+ variants: {
11
+ variant: {
12
+ default: 'text-gray-0 dark:text-gray-100 bg-brand-80 hover:bg-brand-100 active:bg-brand-100 focus:bg-brand-100',
13
+ secondary: 'bg-gray-0 text-gray-100 border-gray-30 border-2 hover:bg-gray-5 active:bg-gray-5 focus:bg-gray-5',
14
+ ghost: 'text-gray-100 bg-gray-0 border-0 hover:bg-gray-5 active:bg-gray-5 focus:bg-gray-5',
15
+ error: 'bg-red-80 text-gray-0 hover:bg-red-100 active:bg-red-100 focus:bg-red-100',
16
+ success: 'bg-green-80 text-gray-0 hover:bg-green-100 active:bg-green-100 focus:bg-green-100'
17
+ },
18
+ size: {
19
+ l: 'h-14 px-8 rounded-xl text-[20px]',
20
+ m: 'h-12 px-6 rounded-lg text-[16px]',
21
+ s: 'h-8 px-4 rounded-md text-[14px]',
22
+ },
23
+ },
24
+ defaultVariants: {
25
+ variant: 'default',
26
+ size: 'l',
27
+ },
28
+ },
29
+ );
30
+
31
+ export interface ButtonProps
32
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
33
+ VariantProps<typeof buttonVariants> {
34
+ asChild?: boolean;
14
35
  }
15
36
 
16
- export const Button = ({ children, ...props }: ButtonProps) => {
17
- return <MuiButton {...props}>{children}</MuiButton>;
18
- };
37
+ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
38
+ ({ className, variant, size, asChild = false, children, ...props }, ref) => {
39
+ const Comp = asChild ? Slot : 'button';
40
+ return (
41
+ <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props}>
42
+ {children}
43
+ </Comp>
44
+ );
45
+ },
46
+ );
47
+
48
+ Button.displayName = 'Button';
package/dist/index.d.ts CHANGED
@@ -1,39 +1,14 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ButtonProps as ButtonProps$1 } from '@mui/material';
1
+ import * as class_variance_authority_dist_types from 'class-variance-authority/dist/types';
2
+ import * as React from 'react';
3
+ import { VariantProps } from 'class-variance-authority';
3
4
 
4
- type Status = 'idle' | 'pending' | 'completed';
5
- type Size = 'small' | 'medium' | 'large';
6
- type Variant = 'contained' | 'outlined' | 'text';
7
- type Color = 'primary' | 'success' | 'error' | 'gray';
8
- type LoadingPosition = 'icon' | 'center';
9
- type SnackbarPosition = 'left' | 'right' | 'top' | 'bottom';
10
- type ButtonProps = {
11
- status?: Status;
12
- size?: Size;
13
- loadingPosition?: LoadingPosition;
14
- variant?: Variant;
15
- color?: Color;
16
- startIcon?: any;
17
- endIcon?: any;
18
- isSnackbar?: boolean;
19
- snackbarText?: string;
20
- isSnackbarIconStart?: boolean;
21
- isSnackbarIconEnd?: boolean;
22
- snackbarLoadingPosition?: LoadingPosition;
23
- snackbarPosition?: SnackbarPosition;
24
- sx?: any;
25
- } & Omit<ButtonProps$1, 'startIcon' | 'endIcon' | 'color'>;
5
+ declare const buttonVariants: (props?: ({
6
+ variant?: "default" | "secondary" | "ghost" | "error" | "success" | null | undefined;
7
+ size?: "l" | "m" | "s" | null | undefined;
8
+ } & class_variance_authority_dist_types.ClassProp) | undefined) => string;
9
+ interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
10
+ asChild?: boolean;
11
+ }
12
+ declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
26
13
 
27
- declare module '@mui/material/Typography' {
28
- interface TypographyPropsVariantOverrides {
29
- xl: true;
30
- l: true;
31
- m: true;
32
- s: true;
33
- xs: true;
34
- xxs: true;
35
- }
36
- }
37
- declare const Button: ({ children, ...props }: ButtonProps) => react_jsx_runtime.JSX.Element;
38
-
39
- export { Button, ButtonProps };
14
+ export { Button, ButtonProps, buttonVariants };
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __defProps = Object.defineProperties;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
8
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
8
10
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
11
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
12
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -44,23 +46,63 @@ var __copyProps = (to, from, except, desc) => {
44
46
  }
45
47
  return to;
46
48
  };
49
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
50
+ // If the importer is in node compatibility mode or this is not an ESM
51
+ // file that has been converted to a CommonJS file using a Babel-
52
+ // compatible transform (i.e. "__esModule" has not been set), then set
53
+ // "default" to the CommonJS "module.exports" for node compatibility.
54
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
55
+ mod
56
+ ));
47
57
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
48
58
 
49
59
  // index.ts
50
60
  var pkg_exports = {};
51
61
  __export(pkg_exports, {
52
- Button: () => Button
62
+ Button: () => Button,
63
+ buttonVariants: () => buttonVariants
53
64
  });
54
65
  module.exports = __toCommonJS(pkg_exports);
55
66
 
56
67
  // Button.tsx
57
- var import_material = require("@mui/material");
68
+ var React = __toESM(require("react"));
69
+ var import_react_slot = require("@radix-ui/react-slot");
70
+ var import_class_variance_authority = require("class-variance-authority");
71
+ var import_utils = require("@xipkg/utils");
58
72
  var import_jsx_runtime = require("react/jsx-runtime");
59
- var Button = (_a) => {
60
- var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
61
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Button, __spreadProps(__spreadValues({}, props), { children }));
62
- };
73
+ var buttonVariants = (0, import_class_variance_authority.cva)(
74
+ "inline-flex items-center w-fit justify-center ring-offset-gray-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
75
+ {
76
+ variants: {
77
+ variant: {
78
+ default: "text-gray-0 dark:text-gray-100 bg-brand-80 hover:bg-brand-100 active:bg-brand-100 focus:bg-brand-100",
79
+ secondary: "bg-gray-0 text-gray-100 border-gray-30 border-2 hover:bg-gray-5 active:bg-gray-5 focus:bg-gray-5",
80
+ ghost: "text-gray-100 bg-gray-0 border-0 hover:bg-gray-5 active:bg-gray-5 focus:bg-gray-5",
81
+ error: "bg-red-80 text-gray-0 hover:bg-red-100 active:bg-red-100 focus:bg-red-100",
82
+ success: "bg-green-80 text-gray-0 hover:bg-green-100 active:bg-green-100 focus:bg-green-100"
83
+ },
84
+ size: {
85
+ l: "h-14 px-8 rounded-xl text-[20px]",
86
+ m: "h-12 px-6 rounded-lg text-[16px]",
87
+ s: "h-8 px-4 rounded-md text-[14px]"
88
+ }
89
+ },
90
+ defaultVariants: {
91
+ variant: "default",
92
+ size: "l"
93
+ }
94
+ }
95
+ );
96
+ var Button = React.forwardRef(
97
+ (_a, ref) => {
98
+ var _b = _a, { className, variant, size, asChild = false, children } = _b, props = __objRest(_b, ["className", "variant", "size", "asChild", "children"]);
99
+ const Comp = asChild ? import_react_slot.Slot : "button";
100
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Comp, __spreadProps(__spreadValues({ className: (0, import_utils.cn)(buttonVariants({ variant, size, className })), ref }, props), { children }));
101
+ }
102
+ );
103
+ Button.displayName = "Button";
63
104
  // Annotate the CommonJS export names for ESM import in node:
64
105
  0 && (module.exports = {
65
- Button
106
+ Button,
107
+ buttonVariants
66
108
  });
package/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { Button } from './Button';
2
- export type { ButtonProps } from './types';
1
+ export { Button, buttonVariants } from './Button';
2
+ export type { ButtonProps } from './Button';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xipkg/button",
3
- "version": "0.0.3",
3
+ "version": "1.0.1",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",
@@ -11,19 +11,19 @@
11
11
  "lint": "eslint \"**/*.ts*\""
12
12
  },
13
13
  "dependencies": {
14
- "@emotion/react": "^11.11.1",
15
- "@emotion/styled": "^11.11.0",
16
- "@mui/material": "^5.14.0",
17
- "@xipkg/icons": "^0.4.4",
14
+ "@radix-ui/react-slot": "^1.0.2",
15
+ "@xipkg/utils": "^1.0.1",
16
+ "class-variance-authority": "^0.7.0",
18
17
  "react": "^18.2.0"
19
18
  },
20
19
  "devDependencies": {
21
20
  "@types/node": "^17.0.12",
22
21
  "@types/react": "^18.2.14",
23
22
  "@types/react-dom": "^18.2.6",
24
- "@xipkg/eslint": "^0.0.3",
23
+ "@xipkg/eslint": "^0.0.4",
25
24
  "@xipkg/typescript": "^0.0.0",
26
25
  "eslint": "^7.32.0",
26
+ "tailwindcss": "^3.3.2",
27
27
  "typescript": "^5.1.3"
28
28
  },
29
29
  "publishConfig": {
@@ -31,5 +31,5 @@
31
31
  },
32
32
  "author": "xi.effect",
33
33
  "description": "",
34
- "gitHead": "0ee562e7c7723699c85daf61b493d6a57b7c1f08"
34
+ "gitHead": "33022d3bd6e72a5ccc9097b187742f9139f7d905"
35
35
  }
@@ -1,104 +0,0 @@
1
- import { Typography, Stack } from '@mui/material';
2
- import React, { FC } from 'react';
3
-
4
- import {
5
- buttonSizes,
6
- typographyVariants,
7
- buttonDisabledStyle,
8
- getButtonPadding,
9
- getSnackbarCurrentPosition,
10
- buttonBorderStyle,
11
- } from './styles';
12
- import { LoadingPosition, Size, SnackbarPosition, Status, Variant } from './types';
13
- import { IconContainer } from './IconContainer';
14
- import { Loading } from './Loading';
15
-
16
- export const ButtonSnackbar: FC<ButtonSnackbarProps> = ({
17
- size,
18
- variant,
19
- status,
20
- snackbarText,
21
- isSnackbarIconStart,
22
- isSnackbarIconEnd,
23
- snackbarLoadingPosition = 'center',
24
- snackbarPosition = 'right',
25
- }) => {
26
- const snackbarRef = React.useRef<HTMLDivElement | null>(null);
27
- const [snackbarSize, setSnackbarSize] = React.useState(0);
28
- const snackbarCurrentPosition = getSnackbarCurrentPosition(snackbarSize, snackbarPosition);
29
-
30
- const buttonBorder = variant === 'outlined' ? buttonBorderStyle[size] : 'none';
31
-
32
- const snackbarPadding = getButtonPadding(
33
- !!snackbarText,
34
- !!isSnackbarIconStart,
35
- !!isSnackbarIconEnd,
36
- );
37
-
38
- React.useLayoutEffect(() => {
39
- if (!snackbarRef?.current) return;
40
- if (snackbarPosition === 'left' || snackbarPosition === 'right') {
41
- setSnackbarSize(snackbarRef.current.clientWidth);
42
- }
43
- if (snackbarPosition === 'top' || snackbarPosition === 'bottom') {
44
- setSnackbarSize(snackbarRef.current.clientHeight);
45
- }
46
- }, [snackbarPosition, size, snackbarText]);
47
-
48
- return (
49
- <Stack
50
- ref={snackbarRef}
51
- direction="row"
52
- alignItems="center"
53
- sx={{
54
- position: 'absolute',
55
- border: buttonBorder,
56
- ...snackbarCurrentPosition,
57
- ...buttonSizes[size],
58
- ...snackbarPadding[size],
59
- ...buttonDisabledStyle[variant],
60
- }}
61
- >
62
- {status === 'pending' && snackbarLoadingPosition === 'center' && (
63
- <Loading top="50%" left="50%" transform="translate(-50%,-50%)" size={size} />
64
- )}
65
- {isSnackbarIconStart && (
66
- <IconContainer
67
- size={size}
68
- order={0}
69
- status={status}
70
- isLoadingIcon={snackbarLoadingPosition !== 'center'}
71
- />
72
- )}
73
- {isSnackbarIconEnd && (
74
- <IconContainer
75
- size={size}
76
- order={2}
77
- status={status}
78
- isLoadingIcon={snackbarLoadingPosition !== 'center'}
79
- />
80
- )}
81
-
82
- {snackbarText && (
83
- <Typography
84
- color="inherit"
85
- sx={{ opacity: snackbarLoadingPosition === 'center' && status === 'pending' ? 0 : 1 }}
86
- variant={typographyVariants[size]}
87
- >
88
- {snackbarText}
89
- </Typography>
90
- )}
91
- </Stack>
92
- );
93
- };
94
-
95
- type ButtonSnackbarProps = {
96
- size: Size;
97
- variant: Variant;
98
- status: Status;
99
- snackbarText?: string;
100
- isSnackbarIconStart?: boolean;
101
- isSnackbarIconEnd?: boolean;
102
- snackbarLoadingPosition?: LoadingPosition;
103
- snackbarPosition?: SnackbarPosition;
104
- };
package/IconContainer.tsx DELETED
@@ -1,52 +0,0 @@
1
- import { Stack } from '@mui/material';
2
- import { Check } from '@xipkg/icons';
3
- import { FC } from 'react';
4
- import { Loading } from './Loading';
5
- import { iconSizes } from './styles';
6
- import { Size, Status } from './types';
7
-
8
- export const IconContainer: FC<IconComponentProps> = ({
9
- order,
10
- Icon,
11
- size,
12
- status,
13
- isLoadingIcon,
14
- }) => (
15
- <Stack order={order} sx={{ position: 'relative', ...iconSizes[size] }}>
16
- {!!Icon && (
17
- <Icon
18
- sx={{
19
- opacity: status === 'idle' ? 1 : 0,
20
- color: 'inherit',
21
- ...iconSizes[size],
22
- }}
23
- />
24
- )}
25
- <Check
26
- sx={{
27
- opacity: status === 'completed' ? 1 : 0,
28
- position: 'absolute',
29
- top: '50%',
30
- transform: 'translateY(-50%)',
31
- color: 'inherit',
32
- ...iconSizes[size],
33
- }}
34
- />
35
- {isLoadingIcon && (
36
- <Loading
37
- size={size}
38
- top="50%"
39
- transform="translateY(-50%)"
40
- opacity={status === 'pending' ? 1 : 0}
41
- />
42
- )}
43
- </Stack>
44
- );
45
-
46
- type IconComponentProps = {
47
- Icon?: any;
48
- order: number;
49
- size: Size;
50
- status: Status;
51
- isLoadingIcon: boolean;
52
- };
package/Loading.tsx DELETED
@@ -1,18 +0,0 @@
1
- import { FC } from 'react';
2
- import { CircularProgress, Stack, SxProps } from '@mui/material';
3
- import { iconSizes, spinnerSizes } from './styles';
4
- import { Size } from './types';
5
-
6
- export const Loading: FC<LoadingProps> = ({ size, ...props }) => (
7
- <Stack
8
- sx={{
9
- position: 'absolute',
10
- ...iconSizes[size],
11
- ...props,
12
- }}
13
- >
14
- <CircularProgress size={spinnerSizes[size]} color="inherit" />
15
- </Stack>
16
- );
17
-
18
- type LoadingProps = { size: Size } & SxProps;
package/styles.ts DELETED
@@ -1,191 +0,0 @@
1
- import { SnackbarPosition, Variant } from './types';
2
-
3
- export const buttonSizes = {
4
- large: {
5
- height: '56px',
6
- borderRadius: '12px',
7
- gap: '16px',
8
- },
9
- medium: {
10
- height: '48px',
11
- borderRadius: '8px',
12
- gap: '8px',
13
- },
14
- small: {
15
- height: '32px',
16
- borderRadius: '6px',
17
- gap: '6px',
18
- },
19
- };
20
-
21
- export const buttonVariantsColor = {
22
- contained: {
23
- primary: {
24
- bgcolor: 'var(--xi-brand-80)',
25
- color: 'var(--xi-gray-0)',
26
- },
27
- success: {
28
- bgcolor: 'var(--xi-green-80)',
29
- color: 'var(--xi-gray-0)',
30
- },
31
- error: {
32
- bgcolor: 'var(--xi-red-80)',
33
- color: 'var(--xi-gray-0)',
34
- },
35
- gray: {
36
- bgcolor: 'var(--xi-gray-40)',
37
- color: 'var(--xi-gray-100)',
38
- },
39
- },
40
- outlined: {
41
- primary: {
42
- borderColor: 'var(--xi-brand-80)',
43
- color: 'var(--xi-brand-80)',
44
- },
45
- success: {
46
- borderColor: 'var(--xi-green-80)',
47
- color: 'var(--xi-green-80)',
48
- },
49
- error: {
50
- borderColor: 'var(--xi-red-80)',
51
- color: 'var(--xi-red-80)',
52
- },
53
- gray: {
54
- color: 'var(--xi-gray-100)',
55
- borderColor: 'var(--xi-gray-40)',
56
- },
57
- },
58
- text: {
59
- primary: { color: 'var(--xi-brand-80)' },
60
- success: { color: 'var(--xi-green-80)' },
61
- error: { color: 'var(--xi-red-80)' },
62
- gray: { color: 'var(--xi-gray-100)' },
63
- },
64
- };
65
-
66
- export const buttonDisabledStyle = {
67
- contained: {
68
- backgroundColor: 'var(--xi-gray-10)',
69
- color: 'var(--xi-gray-40)',
70
- },
71
- outlined: {
72
- border: '1px solid',
73
- borderColor: 'var(--xi-gray-10)',
74
- color: 'var(--xi-gray-40)',
75
- },
76
- text: {
77
- color: 'var(--xi-gray-40)',
78
- },
79
- };
80
-
81
- export const buttonBorderStyle = {
82
- large: '2px solid',
83
- medium: '2px solid',
84
- small: '1px solid',
85
- };
86
-
87
- export const clickedPadding = {
88
- large: { pt: '14px', pb: '12px' },
89
- medium: { pt: '13px', pb: '11px' },
90
- small: { pt: '9px', pb: '7px' },
91
- };
92
-
93
- export const typographyVariants = {
94
- large: 'l' as 'l',
95
- medium: 'm' as 'm',
96
- small: 's' as 's',
97
- };
98
-
99
- export const iconSizes = {
100
- large: {
101
- width: '32px',
102
- height: '32px',
103
- },
104
- medium: {
105
- width: '24px',
106
- height: '24px',
107
- },
108
- small: {
109
- width: '16px',
110
- height: '16px',
111
- },
112
- };
113
-
114
- export const spinnerSizes = {
115
- large: 32,
116
- medium: 24,
117
- small: 16,
118
- };
119
-
120
- const style = {
121
- large: {
122
- padding: '13px 32px',
123
- },
124
- medium: {
125
- padding: '12px 24px',
126
- },
127
- small: {
128
- padding: '8px 16px',
129
- },
130
- };
131
-
132
- export const getButtonPadding = (isText: boolean, startIcon: boolean, endIcon: boolean) => {
133
- const isTextIconButton = isText && (startIcon || endIcon);
134
- const isIconButton = !isText && (startIcon || endIcon);
135
-
136
- if (isTextIconButton) {
137
- if (startIcon) {
138
- style.large.padding = '13px 24px 13px 12px';
139
- style.medium.padding = '12px 16px 12px 12px';
140
- style.small.padding = '8px 12px 8px 8px';
141
- return style;
142
- }
143
- if (endIcon) {
144
- style.large.padding = '13px 12px 13px 24px';
145
- style.medium.padding = '12px 12px 12px 16px';
146
- style.small.padding = '8px 8px 8px 12px';
147
- return style;
148
- }
149
- }
150
-
151
- if (isIconButton) {
152
- style.large.padding = '13px 12px';
153
- style.medium.padding = '12px 12px';
154
- style.small.padding = '8px 8px';
155
- return style;
156
- }
157
-
158
- return style;
159
- };
160
-
161
- export const getSnackbarCurrentPosition = (snackbarSize: number, position: SnackbarPosition) => {
162
- switch (position) {
163
- case 'top':
164
- return { top: `-${snackbarSize + 8}px`, right: '50%', transform: 'translateX(50%)' };
165
- case 'bottom':
166
- return { bottom: `-${snackbarSize + 8}px`, right: '50%', transform: 'translateX(50%)' };
167
- case 'left':
168
- return { left: `-${snackbarSize + 16}px`, top: 0 };
169
- default: {
170
- return { right: `-${snackbarSize + 16}px` };
171
- }
172
- }
173
- };
174
-
175
- export const getActionButtonStyle = (variant: Variant, color: string) => {
176
- if (color === 'gray') {
177
- return { bgcolor: 'var(--xi-gray-5)', color: 'var(--xi-gray-100)' };
178
- }
179
-
180
- switch (variant) {
181
- case 'contained':
182
- return { bgcolor: color, color: 'var(--xi-gray-0)' };
183
- case 'outlined':
184
- return { bgcolor: 'var(--xi-gray-5)', borderColor: color, color };
185
- default:
186
- return {
187
- bgcolor: 'var(--xi-gray-5)',
188
- color,
189
- };
190
- }
191
- };
package/types.ts DELETED
@@ -1,38 +0,0 @@
1
- import { ButtonProps as MuiButtonProps } from '@mui/material';
2
-
3
- export type Status = 'idle' | 'pending' | 'completed';
4
- export type Size = 'small' | 'medium' | 'large';
5
- export type Variant = 'contained' | 'outlined' | 'text';
6
- export type Color = 'primary' | 'success' | 'error' | 'gray';
7
- export type LoadingPosition = 'icon' | 'center';
8
- export type SnackbarPosition = 'left' | 'right' | 'top' | 'bottom';
9
-
10
- export type ButtonProps = {
11
- // button status: pending = spinner appears, completed button disabled with active color
12
- // completed and startIcon or endIcon or only icon without text appears check
13
- status?: Status;
14
- size?: Size; // button size
15
- // button spinner position: icon above icon and center
16
- loadingPosition?: LoadingPosition;
17
- // button variant
18
- variant?: Variant;
19
- // button color
20
- color?: Color;
21
- // start or end button icon if icon without text, icon position will be center
22
- startIcon?: any;
23
- endIcon?: any;
24
- // whether to display snackbar
25
- isSnackbar?: boolean;
26
- // snackbar text
27
- snackbarText?: string;
28
- // start or end snackbar icon if icon without text, icon position will be center
29
- isSnackbarIconStart?: boolean;
30
- isSnackbarIconEnd?: boolean;
31
- // snackbar spinner position: icon above icon and center
32
- snackbarLoadingPosition?: LoadingPosition;
33
- // snackbar position: default right
34
- snackbarPosition?: SnackbarPosition;
35
- // styles
36
- sx?: any;
37
- // you can also pass default mui button attributes
38
- } & Omit<MuiButtonProps, 'startIcon' | 'endIcon' | 'color'>;