@cleartrip/ct-design-button 4.0.0 → 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/type.d.ts CHANGED
@@ -1,48 +1,29 @@
1
- import { ReactNode } from 'react';
2
- import { BaseStyleConfigProps, HtmlCompositeAttributes, TypographyStyleConfigProps } from '@cleartrip/ct-design-types';
3
- export declare enum ButtonSize {
4
- SMALL = "small",
5
- MEDIUM = "medium",
6
- LARGE = "large"
7
- }
8
- export declare enum IconPosition {
9
- LEFT = "left",
10
- RIGHT = "right"
11
- }
12
- export declare enum ButtonVariant {
13
- OUTLINE = "outline",
14
- CONTAINED = "contained",
15
- BARE = "bare"
16
- }
17
- export declare enum ButtonColor {
18
- PRIMARY = "primary",
19
- SECONDARY = "secondary",
20
- TERTIARY = "tertiary"
21
- }
1
+ import type { Styles } from '@cleartrip/ct-design-types';
2
+ import { TypographyStyleConfigProps } from '@cleartrip/ct-design-typography';
3
+ import { INativeUIEvent } from '@cleartrip/ct-design-types';
4
+ import { ButtonSize, ButtonVariant, ButtonColor } from './constants';
22
5
  export type ButtonSizeType = `${ButtonSize}`;
23
- export type IconPositionType = `${IconPosition}`;
24
6
  export type ButtonVariantType = `${ButtonVariant}`;
25
7
  export type ButtonColorType = `${ButtonColor}`;
26
- export type OwnButtonProps = Partial<{
27
- type: 'submit' | 'reset' | 'button';
8
+ export type IClickEvent = INativeUIEvent;
9
+ export type IButtonProps = Partial<{
10
+ children: React.ReactNode;
28
11
  size: 'small' | 'medium' | 'large';
29
12
  variant: 'bare' | 'contained' | 'outline';
30
13
  color: 'primary' | 'secondary' | 'tertiary';
31
14
  isFullWidth: boolean;
32
15
  loading: boolean;
33
16
  disabled: boolean;
34
- minWidth: string;
35
- showLeftIcon: boolean;
36
- showRightIcon: boolean;
37
- LeftIcon: ReactNode;
38
- RightIcon: ReactNode;
17
+ prefixIcon: React.ReactNode;
18
+ suffixIcon: React.ReactNode;
19
+ onClick: (event: IClickEvent) => void;
39
20
  styleConfig?: {
40
- root?: BaseStyleConfigProps;
41
- container?: BaseStyleConfigProps;
21
+ root?: Styles[];
22
+ container?: Styles[];
42
23
  typography?: TypographyStyleConfigProps;
43
- iconContainer?: BaseStyleConfigProps;
24
+ prefixIconContainer?: Styles[];
25
+ suffixIconContainer?: Styles[];
44
26
  };
27
+ noHover?: boolean;
45
28
  }>;
46
- export interface ButtonProps extends HtmlCompositeAttributes<OwnButtonProps, 'Button'>, OwnButtonProps {
47
- }
48
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,oBAAoB,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAEvH,oBAAY,UAAU;IACpB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,KAAK,UAAU;CAChB;AAED,oBAAY,YAAY;IACtB,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,oBAAY,aAAa;IACvB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,IAAI,SAAS;CACd;AAED,oBAAY,WAAW;IACrB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,QAAQ,aAAa;CACtB;AAED,MAAM,MAAM,cAAc,GAAG,GAAG,UAAU,EAAE,CAAC;AAE7C,MAAM,MAAM,gBAAgB,GAAG,GAAG,YAAY,EAAE,CAAC;AAEjD,MAAM,MAAM,iBAAiB,GAAG,GAAG,aAAa,EAAE,CAAC;AAEnD,MAAM,MAAM,eAAe,GAAG,GAAG,WAAW,EAAE,CAAC;AAE/C,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC;IAKnC,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;IAKpC,IAAI,EAAE,OAAO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MAAM,YAAY,GAAG,OAAO,CAAC;IACjC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAK1B,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IAKnC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;IAK1C,KAAK,EAAE,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;IAI5C,WAAW,EAAE,OAAO,CAAC;IAIrB,OAAO,EAAE,OAAO,CAAC;IAIjB,QAAQ,EAAE,OAAO,CAAC;IAIlB,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC;IAI5B,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC;IAI5B,OAAO,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,31 +1,46 @@
1
1
  {
2
2
  "name": "@cleartrip/ct-design-button",
3
- "version": "4.0.0",
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
- "@cleartrip/ct-design-container": "4.0.0",
19
- "@cleartrip/ct-design-typography": "4.0.0",
20
- "@cleartrip/ct-design-theme": "4.0.0",
21
- "@cleartrip/ct-design-dotted-loader": "4.0.0",
22
- "@cleartrip/ct-design-types": "4.0.0"
27
+ "@emotion/react": "^11.14.0",
28
+ "@emotion/styled": "^11.14.0",
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"
37
+ },
38
+ "devDependencies": {
39
+ "@emotion/babel-plugin": "^11.12.0"
23
40
  },
24
- "devDependencies": {},
25
41
  "peerDependencies": {
26
42
  "react": ">=16.8.0",
27
- "react-dom": ">=16.8.0",
28
- "styled-components": "^5.3.6"
43
+ "react-dom": ">=16.8.0"
29
44
  },
30
45
  "publishConfig": {
31
46
  "access": "public"
@@ -36,6 +51,8 @@
36
51
  "test": "echo \"Error: no test specified\" && exit 1",
37
52
  "watch-package": "rollup -c -w",
38
53
  "build-package": "rollup -c",
39
- "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"
40
57
  }
41
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';