@cleartrip/ct-design-button 4.0.0-TEST.1 → 4.1.0-SNAPSHOT-native-main.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.
package/dist/style.d.ts CHANGED
@@ -21,8 +21,8 @@ export declare const getButtonVariantStyles: (theme: Theme, variant: ButtonVaria
21
21
  borderWidth: 1;
22
22
  borderStyle: "solid";
23
23
  };
24
- export declare const getContainedButtonColorStyles: (theme: Theme, color: ButtonColorType, disabled: boolean, isHover: boolean) => {
25
- backgroundColor: any;
24
+ export declare const getContainedButtonColorStyles: (theme: Theme, color: ButtonColorType, disabled: boolean) => {
25
+ backgroundColor: string;
26
26
  };
27
27
  export declare const getOutlinedButtonColorStyles: (theme: Theme, color: ButtonColorType, disabled: boolean) => {
28
28
  backgroundColor: string;
@@ -31,75 +31,66 @@ export declare const getOutlinedButtonColorStyles: (theme: Theme, color: ButtonC
31
31
  backgroundColor: string;
32
32
  borderColor: string;
33
33
  };
34
- export declare const getButtonVariantColorStyles: (theme: Theme, color: ButtonColorType, variant: ButtonVariantType, disabled: boolean, isHover: boolean) => {
35
- backgroundColor: any;
34
+ export declare const getButtonVariantColorStyles: (theme: Theme, color: ButtonColorType, variant: ButtonVariantType, disabled: boolean, _isHover: boolean) => {
35
+ backgroundColor: string;
36
36
  };
37
37
  export declare const getContainedButtonLabelColor: (color: ButtonColorType, disabled: boolean, theme: Theme) => string;
38
38
  export declare const getOutlinedButtonLabelColor: (color: ButtonColorType, disabled: boolean, theme: Theme) => string;
39
39
  export declare const getButtonVariantLabelColor: (variant: ButtonVariantType, color: ButtonColorType, disabled: boolean, theme: Theme, loading: boolean) => string;
40
40
  export declare const getTypographyVariant: (size: ButtonSizeType) => TypographyVariant.HM3 | TypographyVariant.HM4;
41
- export declare const getDefaultButtonStyles: (disabled: boolean) => {
42
- cursor: string;
43
- };
44
- export declare const getButtonStyles: ({ theme, size, variant, color, disabled, minWidth, isFullWidth, loading, isHover, }: {
41
+ export declare const getDefaultButtonStyles: (disabled: boolean) => {};
42
+ export declare const getButtonStyles: ({ theme, size, variant, color, disabled, isFullWidth, loading, isHover, }: {
45
43
  theme: Theme;
46
44
  size: ButtonSizeType;
47
45
  variant: ButtonVariantType;
48
46
  color: ButtonColorType;
49
47
  disabled: boolean;
50
- minWidth: string;
51
48
  isFullWidth: boolean;
52
49
  loading: boolean;
53
50
  isHover: boolean;
54
51
  }) => {
55
- minWidth: string;
56
- cursor: string;
57
- backgroundColor: any;
52
+ minWidth: number;
53
+ backgroundColor: string;
58
54
  borderWidth: 0;
59
55
  borderStyle?: undefined;
60
56
  height: 32;
61
57
  paddingTop: 4;
62
58
  paddingBottom: 4;
63
59
  } | {
64
- minWidth: string;
65
- cursor: string;
66
- backgroundColor: any;
60
+ minWidth: number;
61
+ backgroundColor: string;
67
62
  borderWidth: 1;
68
63
  borderStyle: "solid";
69
64
  height: 32;
70
65
  paddingTop: 4;
71
66
  paddingBottom: 4;
72
67
  } | {
73
- minWidth: string;
74
- cursor: string;
75
- backgroundColor: any;
68
+ minWidth: number;
69
+ backgroundColor: string;
76
70
  borderWidth: 0;
77
71
  borderStyle?: undefined;
78
72
  height: 40;
79
73
  paddingTop: 8;
80
74
  paddingBottom: 8;
81
75
  } | {
82
- minWidth: string;
83
- cursor: string;
84
- backgroundColor: any;
76
+ minWidth: number;
77
+ backgroundColor: string;
85
78
  borderWidth: 1;
86
79
  borderStyle: "solid";
87
80
  height: 40;
88
81
  paddingTop: 8;
89
82
  paddingBottom: 8;
90
83
  } | {
91
- minWidth: string;
92
- cursor: string;
93
- backgroundColor: any;
84
+ minWidth: number;
85
+ backgroundColor: string;
94
86
  borderWidth: 0;
95
87
  borderStyle?: undefined;
96
88
  height: 48;
97
89
  paddingTop: 12;
98
90
  paddingBottom: 12;
99
91
  } | {
100
- minWidth: string;
101
- cursor: string;
102
- backgroundColor: any;
92
+ minWidth: number;
93
+ backgroundColor: string;
103
94
  borderWidth: 1;
104
95
  borderStyle: "solid";
105
96
  height: 48;
@@ -1 +1 @@
1
- {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../packages/components/Button/src/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAe,eAAe,EAAc,cAAc,EAAiB,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAEpH,eAAO,MAAM,mBAAmB,UAAW,KAAK,QAAQ,cAAc;;;;;;;;;;;;CA+BrE,CAAC;AAEF,eAAO,MAAM,sBAAsB,UAAW,KAAK,WAAW,iBAAiB,YAAY,OAAO;;;;;;CAyBjG,CAAC;AAEF,eAAO,MAAM,6BAA6B,UACjC,KAAK,SACL,eAAe,YACZ,OAAO,WACR,OAAO;;CAsCjB,CAAC;AAEF,eAAO,MAAM,4BAA4B,UAAW,KAAK,SAAS,eAAe,YAAY,OAAO;;;;;;CAuCnG,CAAC;AAEF,eAAO,MAAM,2BAA2B,UAC/B,KAAK,SACL,eAAe,WACb,iBAAiB,YAChB,OAAO,WACR,OAAO;;CAcjB,CAAC;AAEF,eAAO,MAAM,4BAA4B,UAAW,eAAe,YAAY,OAAO,SAAS,KAAK,WAmBnG,CAAC;AAEF,eAAO,MAAM,2BAA2B,UAAW,eAAe,YAAY,OAAO,SAAS,KAAK,WAsBlG,CAAC;AAEF,eAAO,MAAM,0BAA0B,YAC5B,iBAAiB,SACnB,eAAe,YACZ,OAAO,SACV,KAAK,WACH,OAAO,WAgBjB,CAAC;AAEF,eAAO,MAAM,oBAAoB,SAAU,cAAc,kDAexD,CAAC;AAEF,eAAO,MAAM,sBAAsB,aAAc,OAAO;;CAUvD,CAAC;AAEF,eAAO,MAAM,eAAe;WAWnB,KAAK;UACN,cAAc;aACX,iBAAiB;WACnB,eAAe;cACZ,OAAO;cACP,MAAM;iBACH,OAAO;aACX,OAAO;aACP,OAAO;;;;;;;;;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CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,MAAM,cAAc,kDAexD,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,UAAU,OAAO,OAUvD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,2EAS7B;IACD,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,iBAAiB,CAAC;IAC3B,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CAClB;cAM2D,MAAM;;;;;;;;cAAN,MAAM;;;;;;;;cAAN,MAAM;;;;;;;;cAAN,MAAM;;;;;;;;cAAN,MAAM;;;;;;;;cAAN,MAAM;;;;;;;CAEjE,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,MAAM,cAAc,EAAE,OAAO,KAAK,iBAStE,CAAC"}
package/dist/type.d.ts CHANGED
@@ -1,55 +1,29 @@
1
- import { ReactNode } from 'react';
2
- import { HtmlCompositeAttributes, Styles } from '@cleartrip/ct-design-types';
1
+ import type { Styles } from '@cleartrip/ct-design-types';
3
2
  import { TypographyStyleConfigProps } from '@cleartrip/ct-design-typography';
4
- export declare enum ButtonSize {
5
- SMALL = "small",
6
- MEDIUM = "medium",
7
- LARGE = "large"
8
- }
9
- export declare enum IconPosition {
10
- LEFT = "left",
11
- RIGHT = "right"
12
- }
13
- export declare enum ButtonVariant {
14
- OUTLINE = "outline",
15
- CONTAINED = "contained",
16
- BARE = "bare"
17
- }
18
- export declare enum ButtonColor {
19
- PRIMARY = "primary",
20
- SECONDARY = "secondary",
21
- TERTIARY = "tertiary",
22
- NEUTRAL = "neutral"
23
- }
3
+ import { INativeUIEvent } from '@cleartrip/ct-design-types';
4
+ import { ButtonSize, ButtonVariant, ButtonColor } from './constants';
24
5
  export type ButtonSizeType = `${ButtonSize}`;
25
- export type IconPositionType = `${IconPosition}`;
26
6
  export type ButtonVariantType = `${ButtonVariant}`;
27
7
  export type ButtonColorType = `${ButtonColor}`;
28
- export type OwnButtonProps = Partial<{
29
- type: 'submit' | 'reset' | 'button';
8
+ export type IClickEvent = INativeUIEvent;
9
+ export type IButtonProps = Partial<{
10
+ children: React.ReactNode;
30
11
  size: 'small' | 'medium' | 'large';
31
12
  variant: 'bare' | 'contained' | 'outline';
32
- color: 'primary' | 'secondary' | 'tertiary' | 'neutral';
13
+ color: 'primary' | 'secondary' | 'tertiary';
33
14
  isFullWidth: boolean;
34
15
  loading: boolean;
35
16
  disabled: boolean;
36
- minWidth: string;
37
- showLeftIcon: boolean;
38
- showRightIcon: boolean;
39
- LeftIcon: ReactNode;
40
- RightIcon: ReactNode;
41
- prefixIcon?: ReactNode;
42
- suffixIcon?: ReactNode;
17
+ prefixIcon: React.ReactNode;
18
+ suffixIcon: React.ReactNode;
19
+ onClick: (event: IClickEvent) => void;
43
20
  styleConfig?: {
44
21
  root?: Styles[];
45
22
  container?: Styles[];
46
23
  typography?: TypographyStyleConfigProps;
47
- iconContainer?: Styles[];
48
24
  prefixIconContainer?: Styles[];
49
25
  suffixIconContainer?: Styles[];
50
26
  };
51
27
  noHover?: boolean;
52
28
  }>;
53
- export interface ButtonProps extends HtmlCompositeAttributes<OwnButtonProps, 'Button'>, OwnButtonProps {
54
- }
55
29
  //# sourceMappingURL=type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../packages/components/Button/src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAE7E,oBAAY,UAAU;IACpB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,KAAK,UAAU;CAChB;AAED,oBA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AO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAItC,WAAW,CAAC,EAAE;QAIZ,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAIhB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QAIrB,UAAU,CAAC,EAAE,0BAA0B,CAAC;QAKxC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;QAI/B,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;KAChC,CAAC;IAIF,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,28 +1,39 @@
1
1
  {
2
2
  "name": "@cleartrip/ct-design-button",
3
- "version": "4.0.0-TEST.1",
3
+ "version": "4.1.0-SNAPSHOT-native-main.1",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
- "main": "dist/ct-design-button.cjs.js",
6
+ "react-native": "src/index.ts",
7
+ "main": "./dist/ct-design-button.cjs.js",
7
8
  "jsnext:main": "dist/ct-design-button.esm.js",
8
9
  "module": "dist/ct-design-button.esm.js",
9
10
  "sideEffects": false,
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/ct-design-button.esm.js",
15
+ "default": "./dist/ct-design-button.cjs.js"
16
+ }
17
+ },
10
18
  "browser": {
11
19
  "./dist/ct-design-button.esm.js": "./dist/ct-design-button.browser.esm.js",
12
20
  "./dist/ct-design-button.cjs.js": "./dist/ct-design-button.browser.cjs.js"
13
21
  },
14
22
  "files": [
15
- "dist"
23
+ "dist",
24
+ "src"
16
25
  ],
17
26
  "dependencies": {
18
27
  "@emotion/react": "^11.14.0",
19
28
  "@emotion/styled": "^11.14.0",
20
- "@cleartrip/ct-design-types": "4.0.0-TEST.1",
21
- "@cleartrip/ct-design-theme": "4.0.0-TEST.1",
22
- "@cleartrip/ct-design-typography": "4.0.0-TEST.1",
23
- "@cleartrip/ct-design-container": "4.0.0-TEST.1",
24
- "@cleartrip/ct-design-dotted-loader": "4.0.0-TEST.1",
25
- "@cleartrip/ct-design-style-manager": "4.0.0-TEST.1"
29
+ "@cleartrip/ct-design-typography": "4.0.0-SNAPSHOT-native-main.12",
30
+ "@cleartrip/ct-design-container": "4.1.0-SNAPSHOT-native-main.1",
31
+ "@cleartrip/ct-design-conditional-wrap": "4.1.0-SNAPSHOT-native-main.1",
32
+ "@cleartrip/ct-design-types": "4.0.0-SNAPSHOT-native-main.12",
33
+ "@cleartrip/ct-design-dotted-loader": "4.1.0-SNAPSHOT-native-main.1",
34
+ "@cleartrip/ct-design-theme": "4.0.0-SNAPSHOT-native-main.12",
35
+ "@cleartrip/ct-design-style-manager": "4.0.0-SNAPSHOT-native-main.12",
36
+ "@cleartrip/ct-design-event-propagation": "4.0.0-SNAPSHOT-native-main.12"
26
37
  },
27
38
  "devDependencies": {
28
39
  "@emotion/babel-plugin": "^11.12.0"
@@ -40,6 +51,8 @@
40
51
  "test": "echo \"Error: no test specified\" && exit 1",
41
52
  "watch-package": "rollup -c -w",
42
53
  "build-package": "rollup -c",
43
- "build-package:clean": "rm -rf dist && rollup -c"
54
+ "build-package:clean": "rm -rf dist && rollup -c",
55
+ "publish-package:local": "yalc publish --no-scripts",
56
+ "publish-package:local:registry": "pnpm publish --registry http://localhost:4873 --no-git-checks --access public"
44
57
  }
45
58
  }
@@ -0,0 +1,126 @@
1
+ import React, { forwardRef, useMemo } from 'react';
2
+
3
+ import { Pressable, View } from 'react-native';
4
+ import { useStyles } from '@cleartrip/ct-design-style-manager';
5
+ import { useTheme } from '@cleartrip/ct-design-theme';
6
+ import { makeStyles } from '@cleartrip/ct-design-style-manager';
7
+ import { useNativeMergeStyles } from '@cleartrip/ct-design-style-manager';
8
+ import { Typography } from '@cleartrip/ct-design-typography';
9
+ import { Container } from '@cleartrip/ct-design-container';
10
+ import EventCollectorProvider, { useMergeEvents } from '@cleartrip/ct-design-event-propagation';
11
+ import { DottedLoader } from '@cleartrip/ct-design-dotted-loader';
12
+ import Conditional from '@cleartrip/ct-design-conditional-wrap';
13
+ import { getButtonStyles, getButtonVariantLabelColor, getTypographyVariant } from './style';
14
+ import { IButtonProps } from './type';
15
+ import { ButtonColor, ButtonSize, ButtonVariant } from './constants';
16
+
17
+ const staticButtonStyles = makeStyles((theme) => {
18
+ return {
19
+ root: {
20
+ display: 'flex',
21
+ flexDirection: 'row',
22
+ justifyContent: 'center',
23
+ alignItems: 'center',
24
+ position: 'relative',
25
+ paddingHorizontal: theme?.spacing[3],
26
+ borderRadius: theme?.border.radius[8],
27
+ },
28
+ prefixIcon: {
29
+ display: 'flex',
30
+ alignItems: 'center',
31
+ justifyContent: 'center',
32
+ paddingRight: theme?.spacing[1],
33
+ },
34
+ suffixIcon: {
35
+ display: 'flex',
36
+ alignItems: 'center',
37
+ justifyContent: 'center',
38
+ paddingLeft: theme?.spacing[1],
39
+ },
40
+ };
41
+ });
42
+
43
+ const Button = forwardRef(
44
+ (
45
+ {
46
+ children,
47
+ color = ButtonColor.PRIMARY,
48
+ disabled = false,
49
+ isFullWidth = false,
50
+ loading = false,
51
+ prefixIcon,
52
+ suffixIcon,
53
+ size = ButtonSize.MEDIUM,
54
+ variant = ButtonVariant.CONTAINED,
55
+ onClick,
56
+ styleConfig,
57
+ }: IButtonProps,
58
+ ref: React.ForwardedRef<View>,
59
+ ) => {
60
+ const globalTheme = useTheme();
61
+
62
+ const {
63
+ root: customRootStyles = [],
64
+ prefixIconContainer: customPrefixIconContainerStyles = [],
65
+ suffixIconContainer: customSuffixIconContainerStyles = [],
66
+ typography: customTypograpyStyles = {},
67
+ } = styleConfig || {};
68
+
69
+ const buttonStyles = useStyles(
70
+ (theme) => {
71
+ return {
72
+ root: getButtonStyles({ theme: theme, color, disabled, isFullWidth, loading, size, variant, isHover: false }),
73
+ };
74
+ },
75
+ [color, disabled, isFullWidth, loading, size, variant],
76
+ );
77
+
78
+ const buttonLabelColor = useMemo(() => {
79
+ return getButtonVariantLabelColor(variant, color, disabled, globalTheme, loading);
80
+ }, [variant, color, disabled, globalTheme, loading]);
81
+
82
+ const mergedRootStyles = useNativeMergeStyles(
83
+ [staticButtonStyles?.root, buttonStyles?.root, ...customRootStyles],
84
+ [customRootStyles, buttonStyles?.root],
85
+ );
86
+
87
+ const mergedEvents = useMergeEvents({ onClick: [onClick] });
88
+
89
+ return (
90
+ <Conditional
91
+ condition={!!onClick}
92
+ wrap={(children) => <EventCollectorProvider value={mergedEvents}>{children}</EventCollectorProvider>}
93
+ >
94
+ <Pressable ref={ref} disabled={disabled || loading} style={mergedRootStyles} onPress={onClick}>
95
+ {loading ? (
96
+ <DottedLoader />
97
+ ) : (
98
+ <>
99
+ {prefixIcon && (
100
+ <Container styleConfig={{ root: [staticButtonStyles?.prefixIcon, ...customPrefixIconContainerStyles] }}>
101
+ {prefixIcon}
102
+ </Container>
103
+ )}
104
+ <Typography
105
+ variant={getTypographyVariant(size)}
106
+ colorCode={buttonLabelColor}
107
+ styleConfig={customTypograpyStyles}
108
+ >
109
+ {children}
110
+ </Typography>
111
+ {suffixIcon && (
112
+ <Container styleConfig={{ root: [staticButtonStyles?.suffixIcon, ...customSuffixIconContainerStyles] }}>
113
+ {suffixIcon}
114
+ </Container>
115
+ )}
116
+ </>
117
+ )}
118
+ </Pressable>
119
+ </Conditional>
120
+ );
121
+ },
122
+ );
123
+
124
+ Button.displayName = 'Button';
125
+
126
+ export default Button;
package/src/Button.tsx ADDED
@@ -0,0 +1,146 @@
1
+ import { forwardRef, useCallback, useMemo, useState } from 'react';
2
+ import { Typography } from '@cleartrip/ct-design-typography';
3
+ import { Container } from '@cleartrip/ct-design-container';
4
+
5
+ import { useTheme } from '@cleartrip/ct-design-theme';
6
+ import { makeStyles, useStyles, useWebMergeStyles } from '@cleartrip/ct-design-style-manager';
7
+ import { getButtonStyles, getButtonVariantLabelColor, getTypographyVariant } from './style';
8
+ import { IButtonProps } from './type';
9
+ import { ButtonColor, ButtonSize, ButtonVariant } from './constants';
10
+ import { DottedLoader } from '@cleartrip/ct-design-dotted-loader';
11
+
12
+ const staticButtonStyles = makeStyles((theme) => {
13
+ return {
14
+ root: {
15
+ display: 'flex',
16
+ flexDirection: 'row',
17
+ justifyContent: 'center',
18
+ alignItems: 'center',
19
+ position: 'relative',
20
+ paddingHorizontal: theme.spacing[3],
21
+ // borderRadius: theme.border.radius[8],
22
+ },
23
+ prefixIcon: {
24
+ display: 'flex',
25
+ alignItems: 'center',
26
+ justifyContent: 'center',
27
+ paddingRight: theme.spacing[1],
28
+ },
29
+ suffixIcon: {
30
+ display: 'flex',
31
+ alignItems: 'center',
32
+ justifyContent: 'center',
33
+ paddingLeft: theme.spacing[1],
34
+ },
35
+ };
36
+ });
37
+
38
+ const Button = forwardRef<HTMLButtonElement, IButtonProps>(
39
+ (
40
+ {
41
+ size = ButtonSize.MEDIUM,
42
+ variant = ButtonVariant.CONTAINED,
43
+ color = ButtonColor.PRIMARY,
44
+ isFullWidth = false,
45
+ disabled = false,
46
+ onClick = () => {
47
+ // no-op
48
+ },
49
+ prefixIcon,
50
+ suffixIcon,
51
+ children,
52
+ loading = false,
53
+ styleConfig = {},
54
+ noHover = false,
55
+ ...rest
56
+ },
57
+ forwardedRef,
58
+ ) => {
59
+ const theme = useTheme();
60
+ const [isHover, setHover] = useState(false);
61
+
62
+ const buttonStyles = useStyles(
63
+ (theme) => {
64
+ return {
65
+ root: getButtonStyles({
66
+ theme: theme,
67
+ size,
68
+ variant,
69
+ color,
70
+ disabled,
71
+ isFullWidth,
72
+ loading,
73
+ isHover: noHover ? false : isHover,
74
+ }),
75
+ };
76
+ },
77
+ [size, variant, color, disabled, isFullWidth, loading, isHover, noHover, theme],
78
+ );
79
+
80
+ const {
81
+ root: customRootStyles = [],
82
+ container: customContainerStyles = [],
83
+ typography: customTypographyStyles = {},
84
+ prefixIconContainer: customPrefixIconContainerStyles = [],
85
+ suffixIconContainer: customSuffixIconContainerStyles = [],
86
+ } = styleConfig || {};
87
+
88
+ const buttonLabelColor = useMemo(() => {
89
+ return getButtonVariantLabelColor(variant, color, disabled, theme, loading);
90
+ }, [variant, color, disabled, theme, loading]);
91
+
92
+ const mergedRootStyles = useWebMergeStyles(
93
+ [staticButtonStyles.root, buttonStyles.root, ...customRootStyles],
94
+ [staticButtonStyles.root, buttonStyles.root, customRootStyles],
95
+ );
96
+
97
+ const handleClick = useCallback(
98
+ (event: React.MouseEvent<HTMLButtonElement>) => {
99
+ if (!disabled && onClick && !loading)
100
+ onClick({ stopPropagation: () => event.stopPropagation(), preventDefault: () => event.preventDefault() });
101
+ if (disabled || loading) event.preventDefault();
102
+ },
103
+ [disabled, onClick, loading],
104
+ );
105
+
106
+ return (
107
+ <button
108
+ ref={forwardedRef}
109
+ onClick={handleClick}
110
+ className={mergedRootStyles}
111
+ {...rest}
112
+ onMouseEnter={() => setHover(true)}
113
+ onMouseLeave={() => setHover(false)}
114
+ >
115
+ {loading ? (
116
+ <DottedLoader />
117
+ ) : (
118
+ <>
119
+ {prefixIcon && (
120
+ <Container styleConfig={{ root: [staticButtonStyles.prefixIcon, ...customPrefixIconContainerStyles] }}>
121
+ {prefixIcon}
122
+ </Container>
123
+ )}
124
+ <Container styleConfig={{ root: customContainerStyles }}>
125
+ <Typography
126
+ variant={getTypographyVariant(size)}
127
+ colorCode={buttonLabelColor}
128
+ styleConfig={customTypographyStyles}
129
+ >
130
+ {children}
131
+ </Typography>
132
+ </Container>
133
+ {suffixIcon && (
134
+ <Container styleConfig={{ root: [staticButtonStyles.suffixIcon, ...customSuffixIconContainerStyles] }}>
135
+ {suffixIcon}
136
+ </Container>
137
+ )}
138
+ </>
139
+ )}
140
+ </button>
141
+ );
142
+ },
143
+ );
144
+
145
+ Button.displayName = 'Button';
146
+ export default Button;
@@ -0,0 +1,18 @@
1
+ export enum ButtonSize {
2
+ SMALL = 'small',
3
+ MEDIUM = 'medium',
4
+ LARGE = 'large',
5
+ }
6
+
7
+ export enum ButtonVariant {
8
+ OUTLINE = 'outline',
9
+ CONTAINED = 'contained',
10
+ BARE = 'bare',
11
+ }
12
+
13
+ export enum ButtonColor {
14
+ PRIMARY = 'primary',
15
+ SECONDARY = 'secondary',
16
+ TERTIARY = 'tertiary',
17
+ NEUTRAL = 'neutral',
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { default as Button } from './Button';
2
+
3
+ export type * from './type';
4
+ export * from './constants';