@cleartrip/ct-design-chip 4.0.0 → 5.0.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.
Files changed (55) hide show
  1. package/README.md +89 -0
  2. package/dist/AnimatedContainer.d.ts +6 -0
  3. package/dist/AnimatedContainer.d.ts.map +1 -0
  4. package/dist/AnimatedContainer.native.d.ts +6 -0
  5. package/dist/AnimatedContainer.native.d.ts.map +1 -0
  6. package/dist/Chip.d.ts +3 -2
  7. package/dist/Chip.d.ts.map +1 -1
  8. package/dist/Chip.native.d.ts +6 -0
  9. package/dist/Chip.native.d.ts.map +1 -0
  10. package/dist/Shimmer.d.ts +4 -0
  11. package/dist/Shimmer.d.ts.map +1 -0
  12. package/dist/constants.d.ts +10 -0
  13. package/dist/constants.d.ts.map +1 -0
  14. package/dist/ct-design-chip.browser.cjs.js +1 -1
  15. package/dist/ct-design-chip.browser.cjs.js.map +1 -1
  16. package/dist/ct-design-chip.browser.esm.js +1 -1
  17. package/dist/ct-design-chip.browser.esm.js.map +1 -1
  18. package/dist/ct-design-chip.cjs.js +146 -168
  19. package/dist/ct-design-chip.cjs.js.map +1 -1
  20. package/dist/ct-design-chip.esm.js +147 -165
  21. package/dist/ct-design-chip.esm.js.map +1 -1
  22. package/dist/ct-design-chip.umd.js +143 -195
  23. package/dist/ct-design-chip.umd.js.map +1 -1
  24. package/dist/index.d.ts +2 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/style.d.ts +43 -80
  27. package/dist/style.d.ts.map +1 -1
  28. package/dist/type.d.ts +32 -15
  29. package/dist/type.d.ts.map +1 -1
  30. package/package.json +35 -11
  31. package/src/AnimatedContainer.native.tsx +53 -0
  32. package/src/AnimatedContainer.tsx +28 -0
  33. package/src/Chip.native.tsx +253 -0
  34. package/src/Chip.tsx +242 -0
  35. package/src/Shimmer.tsx +28 -0
  36. package/src/constants.ts +10 -0
  37. package/src/index.ts +3 -0
  38. package/src/style.ts +80 -0
  39. package/src/type.ts +119 -0
  40. package/dist/StyledChip/StyledChip.d.ts +0 -7
  41. package/dist/StyledChip/StyledChip.d.ts.map +0 -1
  42. package/dist/StyledChip/index.d.ts +0 -2
  43. package/dist/StyledChip/index.d.ts.map +0 -1
  44. package/dist/StyledChip/style.d.ts +0 -7
  45. package/dist/StyledChip/style.d.ts.map +0 -1
  46. package/dist/StyledChip/type.d.ts +0 -15
  47. package/dist/StyledChip/type.d.ts.map +0 -1
  48. package/dist/StyledCounter/StyledCounter.d.ts +0 -7
  49. package/dist/StyledCounter/StyledCounter.d.ts.map +0 -1
  50. package/dist/StyledCounter/index.d.ts +0 -2
  51. package/dist/StyledCounter/index.d.ts.map +0 -1
  52. package/dist/StyledCounter/style.d.ts +0 -7
  53. package/dist/StyledCounter/style.d.ts.map +0 -1
  54. package/dist/StyledCounter/type.d.ts +0 -4
  55. package/dist/StyledCounter/type.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../packages/components/Chip/src/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAe,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEpE,eAAO,MAAM,qBAAqB,UAAW,KAAK;;;;;;CAUjD,CAAC;AAEF,eAAO,MAAM,qBAAqB,UAAW,KAAK,eAAe,MAAM;;;;;;CAUtE,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAW,KAAK,WAAW,eAAe;;;;;;CAW1E,CAAC;AAEF,eAAO,MAAM,iBAAiB;gBAKhB,OAAO;gBACP,OAAO;WACZ,KAAK;YAWb,CAAC;AAEF,eAAO,MAAM,gBAAgB;WAAwB,KAAK;;;CAIzD,CAAC;AAEF,eAAO,MAAM,oBAAoB;WAKxB,KAAK;UACN,GAAG,YAAY,EAAE;iBACV,OAAO;;;;;;;;;;;;;;;;CAuBrB,CAAC;AAEF,eAAO,MAAM,aAAa;gBASZ,OAAO;gBACP,OAAO;iBACN,OAAO;WACb,KAAK;iBACC,MAAM;aACV,eAAe;UAClB,GAAG,YAAY,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BxB,CAAC"}
1
+ {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../packages/components/Chip/src/style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,UAAU,cAAc;IACtB,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AA2DD,QAAA,MAAM,aAAa,GAAI,YAAY,OAAO,KAAG,eAE5C,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,kDAA0D,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIpG,CAAC;AAEH,OAAO,EAAE,aAAa,EAAE,CAAC"}
package/dist/type.d.ts CHANGED
@@ -1,31 +1,48 @@
1
- import { ReactNode } from 'react';
2
- import { ChipStyleConfigProps, IconPosition } from '@cleartrip/ct-design-types';
3
- export declare enum ChipVariant {
4
- DEFAULT = "default",
5
- DISABLED = "disabled"
6
- }
7
- export declare enum ChipSizeType {
8
- SMALL = "sm",
9
- MEDIUM = "md"
10
- }
1
+ import type { ReactNode, SVGProps } from 'react';
2
+ import type { IconPosition, Styles } from '@cleartrip/ct-design-types';
3
+ import type { TypographyStyleConfigProps, TypographyVariantType } from '@cleartrip/ct-design-typography';
4
+ import { ChipVariant, ChipSizeType } from './constants';
11
5
  export type ChipVariantType = `${ChipVariant}`;
12
- export interface ChipProps {
6
+ export type ChipSize = `${ChipSizeType}`;
7
+ export type ChipBorderWidth = 'none' | 'sm' | 'md' | 'lg';
8
+ export interface IChipStyleConfig {
9
+ relativeContainer?: Styles[];
10
+ root?: Styles[];
11
+ chipContainer?: Styles[];
12
+ prefixIconContainer?: Styles[];
13
+ suffixIconContainer?: Styles[];
14
+ topIconContainer?: Styles[];
15
+ labelContainer?: Styles[];
16
+ labelTypography?: TypographyStyleConfigProps;
17
+ crossContainer?: Styles[];
18
+ counterContainer?: Styles[];
19
+ counter?: Styles[];
20
+ counterTypography?: TypographyStyleConfigProps;
21
+ }
22
+ export interface IChipProps {
13
23
  id?: string;
24
+ crossIconProps?: SVGProps<SVGSVGElement>;
14
25
  label?: ReactNode | string;
26
+ labelVariant?: TypographyVariantType;
15
27
  showIcon?: boolean;
16
28
  iconPosition?: `${IconPosition}`;
17
29
  Icon?: ReactNode;
30
+ prefixIcon?: ReactNode;
31
+ suffixIcon?: ReactNode;
32
+ topIcon?: ReactNode;
18
33
  showCounter?: boolean;
19
34
  count?: number;
20
35
  isDismissible?: boolean;
21
36
  isSelected?: boolean;
22
37
  isDisabled?: boolean;
38
+ disabled?: boolean;
23
39
  onClick?: () => void;
24
40
  onDismiss?: () => void;
25
- borderWidth?: 'none' | 'sm' | 'md' | 'lg';
26
- backgroundColor?: string;
41
+ borderWidth?: ChipBorderWidth;
27
42
  variant?: ChipVariantType;
28
- size?: `${ChipSizeType}`;
29
- styleConfig?: ChipStyleConfigProps;
43
+ size?: ChipSize;
44
+ styleConfig?: IChipStyleConfig;
45
+ showShimmerAnimation?: boolean;
30
46
  }
47
+ export type ChipProps = IChipProps;
31
48
  //# sourceMappingURL=type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../packages/components/Chip/src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAEhF,oBAAY,W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AW,CAAC,EAAE,OAAO,CAAC;IAGtB,KAAK,CAAC,EAAE,MAAM,CAAC;IAGf,aAAa,CAAC,EAAE,OAAO,CAAC;IAGxB,UAAU,CAAC,EAAE,OAAO,CAAC;IAGrB,UAAU,CAAC,EAAE,OAAO,CAAC;IAGrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAGnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAGrB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IAGvB,WAAW,CAAC,EAAE,eAAe,CAAC;IAG9B,OAAO,CAAC,EAAE,eAAe,CAAC;IAG1B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAGhB,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAG/B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAQD,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC"}
package/package.json CHANGED
@@ -1,31 +1,53 @@
1
1
  {
2
2
  "name": "@cleartrip/ct-design-chip",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "Chip Component",
5
5
  "types": "dist/index.d.ts",
6
- "main": "dist/ct-design-chip.cjs.js",
6
+ "main": "./dist/ct-design-chip.cjs.js",
7
+ "react-native": "src/index.ts",
7
8
  "jsnext:main": "dist/ct-design-chip.esm.js",
8
9
  "module": "dist/ct-design-chip.esm.js",
9
10
  "sideEffects": false,
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/ct-design-chip.esm.js",
15
+ "default": "./dist/ct-design-chip.cjs.js"
16
+ }
17
+ },
10
18
  "browser": {
11
19
  "./dist/ct-design-chip.esm.js": "./dist/ct-design-chip.browser.esm.js",
12
20
  "./dist/ct-design-chip.cjs.js": "./dist/ct-design-chip.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-theme": "4.0.0",
20
- "@cleartrip/ct-design-types": "4.0.0",
21
- "@cleartrip/ct-design-icons": "26.0.0",
22
- "@cleartrip/ct-design-typography": "4.0.0"
27
+ "@cleartrip/ct-design-style-manager": "5.0.0",
28
+ "@cleartrip/ct-design-container": "5.0.0",
29
+ "@cleartrip/ct-design-icons": "5.0.0",
30
+ "@cleartrip/ct-design-typography": "5.0.0",
31
+ "@cleartrip/ct-design-theme": "5.0.0",
32
+ "@cleartrip/ct-design-conditional-wrap": "5.0.0",
33
+ "@cleartrip/ct-design-event-propagation": "5.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@cleartrip/ct-design-types": "5.0.0"
23
37
  },
24
- "devDependencies": {},
25
38
  "peerDependencies": {
26
39
  "react": ">=16.8.0",
27
40
  "react-dom": ">=16.8.0",
28
- "styled-components": "^5.3.6"
41
+ "react-native": ">=0.68.0",
42
+ "react-native-reanimated": ">=3.0.0"
43
+ },
44
+ "peerDependenciesMeta": {
45
+ "react-native": {
46
+ "optional": true
47
+ },
48
+ "react-native-reanimated": {
49
+ "optional": true
50
+ }
29
51
  },
30
52
  "publishConfig": {
31
53
  "access": "public"
@@ -36,6 +58,8 @@
36
58
  "test": "echo \"Error: no test specified\" && exit 1",
37
59
  "watch-package": "rollup -c -w",
38
60
  "build-package": "rollup -c",
39
- "build-package:clean": "rm -rf dist && rollup -c"
61
+ "build-package:clean": "rm -rf dist && rollup -c",
62
+ "publish-package:local": "yalc publish --no-scripts",
63
+ "publish-package:local:registry": "pnpm publish --registry http://localhost:4873 --no-git-checks --access public"
40
64
  }
41
65
  }
@@ -0,0 +1,53 @@
1
+ import { useEffect, type ReactNode } from 'react';
2
+ import type { LayoutChangeEvent } from 'react-native';
3
+ import Animated, { Easing, useAnimatedStyle, useSharedValue, withRepeat, withTiming } from 'react-native-reanimated';
4
+
5
+ import { makeStyles } from '@cleartrip/ct-design-style-manager';
6
+
7
+ const styledClass = makeStyles(() => ({
8
+ root: {
9
+ position: 'absolute',
10
+ top: -14,
11
+ left: 0,
12
+ overflow: 'hidden',
13
+ flexDirection: 'row',
14
+ alignItems: 'center',
15
+ },
16
+ }));
17
+
18
+ const DURATION_MS = 5000;
19
+ const REPEAT_COUNT = 2;
20
+
21
+ export const AnimatedContainer = ({ children }: { children: ReactNode }) => {
22
+ const progress = useSharedValue(0);
23
+ const measuredWidth = useSharedValue(0);
24
+
25
+ useEffect(() => {
26
+ progress.value = withRepeat(withTiming(1, { duration: DURATION_MS, easing: Easing.linear }), REPEAT_COUNT, false);
27
+ }, [progress]);
28
+
29
+ const animatedStyle = useAnimatedStyle(() => {
30
+ const w = Math.max(measuredWidth.value, 1);
31
+ const p = progress.value;
32
+ const translateX = -0.5 * w + p * 4.5 * w;
33
+ const opacity = p <= 0.8 ? 1 + ((0.3 - 1) * p) / 0.8 : 0.3 + ((0 - 0.3) * (p - 0.8)) / 0.2;
34
+
35
+ return {
36
+ transform: [{ translateX }],
37
+ opacity,
38
+ };
39
+ });
40
+
41
+ return (
42
+ <Animated.View
43
+ onLayout={(e: LayoutChangeEvent) => {
44
+ measuredWidth.value = e.nativeEvent.layout.width;
45
+ }}
46
+ style={[styledClass.root, animatedStyle]}
47
+ >
48
+ {children}
49
+ </Animated.View>
50
+ );
51
+ };
52
+
53
+ export default AnimatedContainer;
@@ -0,0 +1,28 @@
1
+ /** @jsxImportSource @emotion/react */
2
+ import { css, keyframes } from '@emotion/css';
3
+ import type { ReactNode } from 'react';
4
+
5
+ const breatheAnimation = keyframes`
6
+ 0% { transform: translateX(-50%); opacity:1}
7
+ 80% {opacity: 0.3}
8
+ 100% { transform: translateX(400%); opacity:0}
9
+ `;
10
+
11
+ const animatedContainerStyles = css`
12
+ position: absolute;
13
+ display: inline-flex;
14
+ top: -14px;
15
+ left: 0;
16
+ opacity: 5;
17
+ overflow: hidden;
18
+ animation-name: ${breatheAnimation};
19
+ animation-duration: 5s;
20
+ animation-iteration-count: 2;
21
+ animation-fill-mode: forwards;
22
+ `;
23
+
24
+ export const AnimatedContainer = ({ children }: { children: ReactNode }) => (
25
+ <div className={animatedContainerStyles}>{children}</div>
26
+ );
27
+
28
+ export default AnimatedContainer;
@@ -0,0 +1,253 @@
1
+ import React, { forwardRef, useMemo } from 'react';
2
+
3
+ import { Pressable } from 'react-native';
4
+ import { Container, ContainerRef } from '@cleartrip/ct-design-container';
5
+ import { Typography, TypographyStyleConfigProps } from '@cleartrip/ct-design-typography';
6
+ import { useStyles } from '@cleartrip/ct-design-style-manager';
7
+ import { makeStyles } from '@cleartrip/ct-design-style-manager';
8
+ import EventCollectorProvider, { useMergeEvents } from '@cleartrip/ct-design-event-propagation';
9
+ import Conditional from '@cleartrip/ct-design-conditional-wrap';
10
+ import { Cross } from '@cleartrip/ct-design-icons';
11
+ import { getChipStyles, getLabelColor } from './style';
12
+ import { IChipProps } from './type';
13
+ import { Styles } from '@cleartrip/ct-design-types';
14
+ import { useTheme } from '@cleartrip/ct-design-theme';
15
+
16
+ const staticChipStyles = makeStyles((theme) => {
17
+ return {
18
+ relativeContainer: {
19
+ position: 'relative',
20
+ },
21
+ root: {
22
+ display: 'flex',
23
+ alignSelf: 'baseline',
24
+ flexDirection: 'row',
25
+ alignItems: 'center',
26
+ gap: theme?.spacing[2],
27
+ paddingHorizontal: theme?.spacing[2],
28
+ },
29
+ prefixIconContainer: {
30
+ display: 'flex',
31
+ alignItems: 'center',
32
+ justifyContent: 'center',
33
+ },
34
+ suffixIconContainer: {
35
+ display: 'flex',
36
+ alignItems: 'center',
37
+ justifyContent: 'center',
38
+ },
39
+ topIconContainer: {
40
+ display: 'flex',
41
+ alignItems: 'center',
42
+ justifyContent: 'center',
43
+ },
44
+ chipCountRoot: {
45
+ display: 'flex',
46
+ alignItems: 'center',
47
+ justifyContent: 'center',
48
+ backgroundColor: theme?.color.chip.selectedPrimaryLabel,
49
+ height: theme?.size[4],
50
+ minWidth: theme?.size[4],
51
+ borderRadius: 50,
52
+ borderColor: '#fff',
53
+ top: 1,
54
+ borderWidth: theme?.border.width.sm,
55
+ paddingHorizontal: theme?.spacing[1],
56
+ marginLeft: -theme?.spacing[2],
57
+ },
58
+ labelContainerStyles: {
59
+ paddingLeft: theme?.spacing[1],
60
+ paddingRight: theme?.spacing[1],
61
+ },
62
+ };
63
+ });
64
+
65
+ const ChipCounter = ({
66
+ count,
67
+ styleConfig,
68
+ }: {
69
+ count: number;
70
+ styleConfig: {
71
+ root: Styles[];
72
+ typography: TypographyStyleConfigProps;
73
+ };
74
+ }) => {
75
+ const { root = [], typography = {} } = styleConfig || {};
76
+ return (
77
+ <Container
78
+ styleConfig={{
79
+ root: [staticChipStyles.chipCountRoot, ...root],
80
+ }}
81
+ >
82
+ <Typography variant='TAG' color='neutral' styleConfig={typography}>
83
+ {count}
84
+ </Typography>
85
+ </Container>
86
+ );
87
+ };
88
+
89
+ const Chip = forwardRef(
90
+ (
91
+ {
92
+ id,
93
+ label,
94
+ onClick,
95
+ size = 'sm',
96
+ labelVariant = 'B2',
97
+ isSelected = false,
98
+ disabled = false,
99
+ prefixIcon,
100
+ suffixIcon,
101
+ topIcon,
102
+ styleConfig,
103
+ showCounter,
104
+ count = 0,
105
+ isDismissible = false,
106
+ onDismiss,
107
+ }: IChipProps,
108
+ ref: React.ForwardedRef<ContainerRef>,
109
+ ) => {
110
+ const {
111
+ relativeContainer: customRelativeContainerStyles = [],
112
+ root: customRootStyles = [],
113
+ labelContainer: customLabelContainerStyles = [],
114
+ prefixIconContainer: customPrefixIconContainerStyles = [],
115
+ suffixIconContainer: customSuffixIconContainerStyles = [],
116
+ topIconContainer: customTopIconContainerStyles = [],
117
+ counter: customChipCountRootStyles = [],
118
+ counterTypography: customChipCountTypographyStyles = {},
119
+ } = styleConfig || {};
120
+
121
+ const theme = useTheme();
122
+
123
+ const labelColor = useMemo(() => {
124
+ return getLabelColor(disabled);
125
+ }, [disabled]);
126
+
127
+ const isTopIcon = Boolean(topIcon);
128
+
129
+ const chipStyles = useStyles(
130
+ (theme) => {
131
+ return {
132
+ root: getChipStyles({
133
+ theme,
134
+ size,
135
+ isDisabled: disabled,
136
+ isSelected,
137
+ topIcon: isTopIcon,
138
+ }),
139
+ };
140
+ },
141
+ [size, isSelected, disabled, isTopIcon],
142
+ );
143
+
144
+ const chipStylesForTopIcon = useStyles(
145
+ (theme) => {
146
+ if (topIcon) {
147
+ return {
148
+ root: {
149
+ flexDirection: 'column',
150
+ alignItems: 'flex-start',
151
+ gap: theme?.spacing[0],
152
+ borderRadius: theme?.border.radius[16],
153
+ },
154
+ };
155
+ }
156
+ return {};
157
+ },
158
+ [topIcon],
159
+ );
160
+
161
+ const mergedEvents = useMergeEvents({ onClick: [onClick] });
162
+
163
+ return (
164
+ <Conditional
165
+ condition={!!onClick}
166
+ wrap={(children) => <EventCollectorProvider value={mergedEvents}>{children}</EventCollectorProvider>}
167
+ >
168
+ <Container
169
+ styleConfig={{
170
+ root: [staticChipStyles?.relativeContainer, ...customRelativeContainerStyles],
171
+ }}
172
+ id={id}
173
+ >
174
+ <Container
175
+ ref={ref}
176
+ onClick={onClick ? onClick : undefined}
177
+ styleConfig={{
178
+ root: [staticChipStyles?.root, chipStyles.root, chipStylesForTopIcon?.root, ...customRootStyles],
179
+ }}
180
+ >
181
+ {!!topIcon && (
182
+ <Container
183
+ styleConfig={{
184
+ root: [staticChipStyles?.topIconContainer, ...customTopIconContainerStyles],
185
+ }}
186
+ >
187
+ {topIcon}
188
+ </Container>
189
+ )}
190
+ {!!prefixIcon && (
191
+ <Container
192
+ styleConfig={{
193
+ root: [staticChipStyles?.prefixIconContainer, ...customPrefixIconContainerStyles],
194
+ }}
195
+ >
196
+ {prefixIcon}
197
+ </Container>
198
+ )}
199
+ {!!label && (
200
+ <Container
201
+ styleConfig={{
202
+ root: [staticChipStyles?.labelContainerStyles, ...customLabelContainerStyles],
203
+ }}
204
+ >
205
+ {typeof label === 'string' ? (
206
+ <Typography lineClamp={1} variant={labelVariant} color={labelColor}>
207
+ {label}
208
+ </Typography>
209
+ ) : (
210
+ label
211
+ )}
212
+ </Container>
213
+ )}
214
+ {showCounter && !!count && (
215
+ <ChipCounter
216
+ count={count}
217
+ styleConfig={{ root: customChipCountRootStyles, typography: customChipCountTypographyStyles }}
218
+ />
219
+ )}
220
+ {!!suffixIcon && (
221
+ <Container
222
+ styleConfig={{
223
+ root: [staticChipStyles?.suffixIconContainer, ...customSuffixIconContainerStyles],
224
+ }}
225
+ >
226
+ {suffixIcon}
227
+ </Container>
228
+ )}
229
+ {isDismissible && (
230
+ <Pressable
231
+ onPress={() => {
232
+ onDismiss?.();
233
+ }}
234
+ >
235
+ <Cross
236
+ height={16}
237
+ width={16}
238
+ crossColor={
239
+ isSelected ? theme.color.chip.selectedPrimaryLabel : theme.color.chip.nonSelectedPrimaryLabel
240
+ }
241
+ />
242
+ </Pressable>
243
+ )}
244
+ </Container>
245
+ </Container>
246
+ </Conditional>
247
+ );
248
+ },
249
+ );
250
+
251
+ Chip.displayName = 'Chip';
252
+
253
+ export default Chip;