Skip to content

Commit c127575

Browse files
feat: implemented assist chip
1 parent dbda1f9 commit c127575

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

src/chips/assist-chip/AssistChip.component.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ import {BaseChip, type BaseChipProps} from '../base-chip/BaseChip.component';
88
export interface AssistChipProps<T extends IconProps> extends BaseChipProps {
99
elevated?: boolean;
1010
LeadingIcon?: React.FC<T>;
11+
leadingIconType?: LeadingIconType;
1112
leadingIconProps?: T;
1213
}
1314

15+
export enum LeadingIconType {
16+
COMMON = 'COMMON',
17+
FAVICON = 'FAVICON',
18+
BRANDED = 'BRANDED',
19+
}
20+
1421
export const AssistChip = <T extends IconProps>({
1522
elevated = false,
1623
LeadingIcon,
24+
leadingIconType = LeadingIconType.COMMON,
1725
leadingIconProps = {} as T,
1826
style,
1927
labelStyle,
@@ -23,11 +31,17 @@ export const AssistChip = <T extends IconProps>({
2331
const theme = useTheme();
2432
const colorStyles = useMemo(() => getColorStyles(elevated, disabled, theme), [disabled, elevated, theme]);
2533

34+
const leadingIconPropsMap: Record<LeadingIconType, IconProps> = {
35+
[LeadingIconType.COMMON]: {size: 18, color: colorStyles.icon.color},
36+
[LeadingIconType.FAVICON]: {size: 18},
37+
[LeadingIconType.BRANDED]: {size: 18, style: {opacity: 0.38}},
38+
};
39+
2640
return (
2741
<BaseChip
2842
style={[elevated && !disabled ? styles.elevatedContainer : styles.outlinedContainer, colorStyles.container, style]}
2943
labelStyle={[colorStyles.label, labelStyle]}
30-
leadingIcon={LeadingIcon ? <LeadingIcon size={18} color={colorStyles.icon.color} {...leadingIconProps} /> : null}
44+
leadingIcon={LeadingIcon ? <LeadingIcon {...leadingIconPropsMap[leadingIconType]} {...leadingIconProps} /> : null}
3145
{...props}
3246
/>
3347
);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {StyleSheet} from 'react-native';
2+
3+
import {type Theme} from '../../theme/theme.types';
4+
import {convertToRGBA} from '../../utils/convert-to-rgba';
5+
6+
export const styles = StyleSheet.create({
7+
outlinedContainer: {
8+
borderWidth: 1,
9+
},
10+
elevatedContainer: {
11+
shadowOffset: {
12+
width: 0,
13+
height: 1,
14+
},
15+
shadowOpacity: 0.15,
16+
shadowRadius: 3,
17+
elevation: 1,
18+
},
19+
});
20+
21+
export const getColorStyles = (elevated: boolean, disabled: boolean, theme: Theme) => {
22+
const labelDisabledColor = convertToRGBA(theme.surface.text as string, 0.38);
23+
const containerDisabledColor = convertToRGBA(theme.surface.textVariant as string, 0.12);
24+
25+
const [enabledBorderColor, enabledBackgroundColor] = elevated
26+
? ['transparent', theme.surfaceContainer.backgroundLow]
27+
: [theme.outline, 'transparent'];
28+
const [disabledBorderColor, disabledBackgroundColor] = elevated ? ['transparent', containerDisabledColor] : [containerDisabledColor, 'transparent'];
29+
30+
return StyleSheet.create(
31+
disabled
32+
? {
33+
label: {
34+
color: labelDisabledColor,
35+
},
36+
container: {
37+
backgroundColor: disabledBackgroundColor,
38+
borderColor: disabledBorderColor,
39+
},
40+
icon: {
41+
color: labelDisabledColor,
42+
},
43+
}
44+
: {
45+
label: {
46+
color: theme.surface.text,
47+
},
48+
container: {
49+
borderColor: enabledBorderColor,
50+
backgroundColor: enabledBackgroundColor,
51+
},
52+
icon: {
53+
color: theme.primary.background,
54+
},
55+
}
56+
);
57+
};

0 commit comments

Comments
 (0)