-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIconContained.tsx
76 lines (66 loc) · 1.84 KB
/
IconContained.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import * as React from "react";
import { useMemo } from "react";
import { StyleSheet, View } from "react-native";
import { IOVisualCostants, IOColors } from "../../core";
import { IOIcons, Icon } from "./Icon";
type IconContained = {
variant: "tonal";
color: "neutral";
icon: IOIcons;
};
type IconContainedVisualAttrs = {
background: IOColors;
foreground: IOColors;
};
type IconContainedColorVariants = Record<
IconContained["color"],
IconContainedVisualAttrs
>;
const tonalColorMap: IconContainedColorVariants = {
neutral: {
background: "blueIO-50",
foreground: "grey-450"
}
};
const variantMap: Record<IconContained["variant"], IconContainedColorVariants> =
{
tonal: tonalColorMap
};
const IconContainedDefaultSize = IOVisualCostants.iconContainedSizeDefault;
const styles = StyleSheet.create({
iconContainedWrapper: {
overflow: "hidden",
display: "flex",
alignItems: "center",
justifyContent: "center",
width: IconContainedDefaultSize,
height: IconContainedDefaultSize,
borderRadius: IconContainedDefaultSize / 2
}
});
/*
`IconContained` is just a special wrapper for the `Icon` component.
It's also not an interactive component, unlike the `IconButton`.
When adding new styles, you should be aware of this context and be careful
not to add variants that look like interactive counterparts.
*/
export const IconContained = ({ variant, color, icon }: IconContained) => {
const backgroundColor = useMemo(
() => variantMap[variant][color].background,
[variant, color]
);
const foregroundColor = useMemo(
() => variantMap[variant][color].foreground,
[variant, color]
);
return (
<View
style={[
styles.iconContainedWrapper,
{ backgroundColor: IOColors[backgroundColor] }
]}
>
<Icon name={icon} color={foregroundColor} />
</View>
);
};