@jobber/components-native 0.11.0 → 0.13.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.
- package/dist/src/Chip/Chip.js +43 -0
- package/dist/src/Chip/Chip.style.js +32 -0
- package/dist/src/Chip/index.js +1 -0
- package/dist/src/Heading/Heading.js +51 -0
- package/dist/src/Heading/index.js +1 -0
- package/dist/src/index.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/Chip/Chip.d.ts +45 -0
- package/dist/types/src/Chip/Chip.style.d.ts +29 -0
- package/dist/types/src/Chip/index.d.ts +2 -0
- package/dist/types/src/Heading/Heading.d.ts +37 -0
- package/dist/types/src/Heading/index.d.ts +2 -0
- package/dist/types/src/index.d.ts +2 -0
- package/package.json +2 -2
- package/src/Chip/Chip.style.ts +34 -0
- package/src/Chip/Chip.test.tsx +133 -0
- package/src/Chip/Chip.tsx +142 -0
- package/src/Chip/index.ts +2 -0
- package/src/Heading/Heading.test.tsx +83 -0
- package/src/Heading/Heading.tsx +132 -0
- package/src/Heading/__snapshots__/Heading.test.tsx.snap +270 -0
- package/src/Heading/index.ts +2 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { useMemo } from "react";
|
|
2
|
+
import { Pressable, View } from "react-native";
|
|
3
|
+
import { styles } from "./Chip.style";
|
|
4
|
+
import { Icon } from "../Icon";
|
|
5
|
+
import { Typography } from "../Typography";
|
|
6
|
+
import { tokens } from "../utils/design";
|
|
7
|
+
const defaultAccentColor = tokens["color-surface--reverse"];
|
|
8
|
+
export function Chip({ icon, label, onPress, isDismissible, isActive, inactiveBackgroundColor = "background", accessibilityLabel, accessibilityRole = "radio", accent, }) {
|
|
9
|
+
const { chipStyle, iconCustomColor, dismissColor } = useMemo(() => {
|
|
10
|
+
const accentColor = accent ? tokens[`color-${accent}`] : defaultAccentColor;
|
|
11
|
+
const iconColor = isActive ? tokens["color-surface"] : accentColor;
|
|
12
|
+
const chip = [
|
|
13
|
+
styles.container,
|
|
14
|
+
{
|
|
15
|
+
backgroundColor: inactiveBackgroundColor === "surface"
|
|
16
|
+
? tokens["color-surface"]
|
|
17
|
+
: tokens["color-surface--background"],
|
|
18
|
+
},
|
|
19
|
+
isActive && { backgroundColor: accentColor },
|
|
20
|
+
];
|
|
21
|
+
const dismiss = (isActive || inactiveBackgroundColor === "surface") &&
|
|
22
|
+
styles.activeDismissIcon;
|
|
23
|
+
return {
|
|
24
|
+
chipStyle: chip,
|
|
25
|
+
iconCustomColor: iconColor,
|
|
26
|
+
dismissColor: dismiss,
|
|
27
|
+
};
|
|
28
|
+
}, [accent, isActive, inactiveBackgroundColor]);
|
|
29
|
+
const accessibilityState = useMemo(() => {
|
|
30
|
+
const checkableRoles = ["radio", "switch", "togglebutton", "checkbox"];
|
|
31
|
+
if (checkableRoles.includes(accessibilityRole)) {
|
|
32
|
+
return { checked: isActive };
|
|
33
|
+
}
|
|
34
|
+
return {};
|
|
35
|
+
}, [accessibilityRole, isActive]);
|
|
36
|
+
return (React.createElement(Pressable, { testID: "chipTest", hitSlop: { top: 8, bottom: 8, left: 4, right: 4 }, onPress: onPress, disabled: typeof onPress !== "function", style: chipStyle, accessibilityLabel: accessibilityLabel || label, accessibilityRole: accessibilityRole, accessibilityState: accessibilityState },
|
|
37
|
+
icon && (React.createElement(View, { style: styles.iconLeft },
|
|
38
|
+
React.createElement(Icon, { name: icon, size: "base", customColor: iconCustomColor }))),
|
|
39
|
+
label && (React.createElement(View, { style: styles.chipText },
|
|
40
|
+
React.createElement(Typography, { color: "base", fontWeight: "medium", maxFontScaleSize: tokens["typography--fontSize-large"], maxLines: "single", reverseTheme: isActive }, label))),
|
|
41
|
+
isDismissible && (React.createElement(View, { style: [styles.dismissIcon, dismissColor] },
|
|
42
|
+
React.createElement(Icon, { name: "remove", size: "small" })))));
|
|
43
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { tokens } from "../utils/design";
|
|
3
|
+
const chipHeight = tokens["space-larger"] + tokens["space-small"];
|
|
4
|
+
export const styles = StyleSheet.create({
|
|
5
|
+
container: {
|
|
6
|
+
alignItems: "center",
|
|
7
|
+
borderRadius: tokens["radius-circle"],
|
|
8
|
+
flexDirection: "row",
|
|
9
|
+
height: chipHeight,
|
|
10
|
+
justifyContent: "center",
|
|
11
|
+
marginHorizontal: tokens["space-smaller"],
|
|
12
|
+
marginTop: tokens["space-small"],
|
|
13
|
+
paddingHorizontal: tokens["space-small"],
|
|
14
|
+
},
|
|
15
|
+
iconLeft: {
|
|
16
|
+
marginHorizontal: tokens["space-smallest"],
|
|
17
|
+
},
|
|
18
|
+
chipText: {
|
|
19
|
+
flexGrow: 1,
|
|
20
|
+
flexShrink: 1,
|
|
21
|
+
marginHorizontal: tokens["space-smallest"],
|
|
22
|
+
},
|
|
23
|
+
dismissIcon: {
|
|
24
|
+
backgroundColor: tokens["color-surface"],
|
|
25
|
+
borderRadius: tokens["radius-circle"],
|
|
26
|
+
marginLeft: tokens["space-smaller"],
|
|
27
|
+
padding: tokens["space-smaller"],
|
|
28
|
+
},
|
|
29
|
+
activeDismissIcon: {
|
|
30
|
+
backgroundColor: tokens["color-surface--background"],
|
|
31
|
+
},
|
|
32
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Chip } from "./Chip";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Typography, } from "../Typography";
|
|
3
|
+
import { tokens } from "../utils/design";
|
|
4
|
+
const maxScaledFontSize = {
|
|
5
|
+
subHeading: tokens["typography--fontSize-base"] * 1.375,
|
|
6
|
+
heading: tokens["typography--fontSize-base"] * 1.5,
|
|
7
|
+
subtitle: tokens["typography--fontSize-base"] * 1.5,
|
|
8
|
+
title: tokens["typography--fontSize-base"] * 2.125,
|
|
9
|
+
};
|
|
10
|
+
export function Heading({ children, level, variation = "heading", reverseTheme = false, align, maxLines = "unlimited", allowFontScaling = true, selectable, }) {
|
|
11
|
+
const headingStyle = getHeadingStyle(level, variation);
|
|
12
|
+
const accessibilityRole = "header";
|
|
13
|
+
return (React.createElement(Typography, Object.assign({}, Object.assign(Object.assign({}, headingStyle), { accessibilityRole,
|
|
14
|
+
reverseTheme,
|
|
15
|
+
align,
|
|
16
|
+
maxLines,
|
|
17
|
+
allowFontScaling }), { maxFontScaleSize: maxScaledFontSize[level], selectable: selectable }), children));
|
|
18
|
+
}
|
|
19
|
+
function getHeadingStyle(level = "heading", variation) {
|
|
20
|
+
const headingLevelToStyle = {
|
|
21
|
+
title: {
|
|
22
|
+
fontFamily: "display",
|
|
23
|
+
fontWeight: "black",
|
|
24
|
+
size: "jumbo",
|
|
25
|
+
lineHeight: "jumbo",
|
|
26
|
+
color: variation,
|
|
27
|
+
},
|
|
28
|
+
subtitle: {
|
|
29
|
+
fontFamily: "display",
|
|
30
|
+
fontWeight: "extraBold",
|
|
31
|
+
size: "largest",
|
|
32
|
+
lineHeight: "largest",
|
|
33
|
+
color: variation,
|
|
34
|
+
},
|
|
35
|
+
heading: {
|
|
36
|
+
fontFamily: "display",
|
|
37
|
+
fontWeight: "extraBold",
|
|
38
|
+
size: "larger",
|
|
39
|
+
lineHeight: "large",
|
|
40
|
+
color: variation,
|
|
41
|
+
},
|
|
42
|
+
subHeading: {
|
|
43
|
+
fontFamily: "base",
|
|
44
|
+
fontWeight: "semiBold",
|
|
45
|
+
size: "default",
|
|
46
|
+
lineHeight: "base",
|
|
47
|
+
color: variation,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
return headingLevelToStyle[level];
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Heading } from "./Heading";
|