@xipkg/button 0.0.0 → 0.0.3
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/.turbo/turbo-build.log +49 -0
- package/Button.tsx +15 -5
- package/ButtonSnackbar.tsx +104 -0
- package/IconContainer.tsx +52 -0
- package/Loading.tsx +18 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +66 -0
- package/index.ts +1 -1
- package/package.json +5 -4
- package/styles.ts +191 -0
- package/types.ts +38 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
> @xipkg/button@0.0.2 build
|
|
3
|
+
> tsup index.ts --format cjs --dts
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: index.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v6.7.0
|
|
8
|
+
[34mCLI[39m Target: es6
|
|
9
|
+
[34mCJS[39m Build start
|
|
10
|
+
[32mCJS[39m [1mdist\index.js [22m[32m2.50 KB[39m
|
|
11
|
+
[32mCJS[39m ⚡️ Build success in 37ms
|
|
12
|
+
[34mDTS[39m 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
|
+
[31mError: 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)[39m
|
|
36
|
+
[31mDTS[39m [31mBuild error[39m
|
|
37
|
+
[31mRollupError: 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[39m
|
|
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
|
package/Button.tsx
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Button as MuiButton } from '@mui/material';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { ButtonProps } from './types';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const Button = ({ children, ...props }: ButtonProps) => {
|
|
17
|
+
return <MuiButton {...props}>{children}</MuiButton>;
|
|
8
18
|
};
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ButtonProps as ButtonProps$1 } from '@mui/material';
|
|
3
|
+
|
|
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'>;
|
|
26
|
+
|
|
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 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __objRest = (source, exclude) => {
|
|
24
|
+
var target = {};
|
|
25
|
+
for (var prop in source)
|
|
26
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
+
target[prop] = source[prop];
|
|
28
|
+
if (source != null && __getOwnPropSymbols)
|
|
29
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
};
|
|
35
|
+
var __export = (target, all) => {
|
|
36
|
+
for (var name in all)
|
|
37
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
38
|
+
};
|
|
39
|
+
var __copyProps = (to, from, except, desc) => {
|
|
40
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
41
|
+
for (let key of __getOwnPropNames(from))
|
|
42
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
43
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
44
|
+
}
|
|
45
|
+
return to;
|
|
46
|
+
};
|
|
47
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
48
|
+
|
|
49
|
+
// index.ts
|
|
50
|
+
var pkg_exports = {};
|
|
51
|
+
__export(pkg_exports, {
|
|
52
|
+
Button: () => Button
|
|
53
|
+
});
|
|
54
|
+
module.exports = __toCommonJS(pkg_exports);
|
|
55
|
+
|
|
56
|
+
// Button.tsx
|
|
57
|
+
var import_material = require("@mui/material");
|
|
58
|
+
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
|
+
};
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
Button
|
|
66
|
+
});
|
package/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Button } from './Button';
|
|
2
|
-
export type { ButtonProps } from './
|
|
2
|
+
export type { ButtonProps } from './types';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xipkg/button",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,18 +11,18 @@
|
|
|
11
11
|
"lint": "eslint \"**/*.ts*\""
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@xipkg/icons": "^0.3.0",
|
|
15
14
|
"@emotion/react": "^11.11.1",
|
|
16
15
|
"@emotion/styled": "^11.11.0",
|
|
17
16
|
"@mui/material": "^5.14.0",
|
|
17
|
+
"@xipkg/icons": "^0.4.4",
|
|
18
18
|
"react": "^18.2.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^17.0.12",
|
|
22
22
|
"@types/react": "^18.2.14",
|
|
23
23
|
"@types/react-dom": "^18.2.6",
|
|
24
|
+
"@xipkg/eslint": "^0.0.3",
|
|
24
25
|
"@xipkg/typescript": "^0.0.0",
|
|
25
|
-
"@xipkg/eslint": "^0.0.0",
|
|
26
26
|
"eslint": "^7.32.0",
|
|
27
27
|
"typescript": "^5.1.3"
|
|
28
28
|
},
|
|
@@ -30,5 +30,6 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"author": "xi.effect",
|
|
33
|
-
"description": ""
|
|
33
|
+
"description": "",
|
|
34
|
+
"gitHead": "0ee562e7c7723699c85daf61b493d6a57b7c1f08"
|
|
34
35
|
}
|
package/styles.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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'>;
|