@jobber/components-native 0.8.0 → 0.9.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/Card/Card.js +38 -0
- package/dist/src/Card/Card.style.js +31 -0
- package/dist/src/Card/components/InternalCardHeader.js +14 -0
- package/dist/src/Card/components/InternalCardHeader.style.js +16 -0
- package/dist/src/Card/components/index.js +1 -0
- package/dist/src/Card/index.js +1 -0
- package/dist/src/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/Card/Card.d.ts +40 -0
- package/dist/types/src/Card/Card.style.d.ts +56 -0
- package/dist/types/src/Card/components/InternalCardHeader.d.ts +9 -0
- package/dist/types/src/Card/components/InternalCardHeader.style.d.ts +14 -0
- package/dist/types/src/Card/components/index.d.ts +1 -0
- package/dist/types/src/Card/index.d.ts +2 -0
- package/dist/types/src/index.d.ts +1 -0
- package/package.json +2 -2
- package/src/Card/Card.style.ts +46 -0
- package/src/Card/Card.test.tsx +128 -0
- package/src/Card/Card.tsx +145 -0
- package/src/Card/components/InternalCardHeader.style.ts +19 -0
- package/src/Card/components/InternalCardHeader.test.tsx +31 -0
- package/src/Card/components/InternalCardHeader.tsx +41 -0
- package/src/Card/components/index.ts +1 -0
- package/src/Card/index.ts +2 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Pressable, View, } from "react-native";
|
|
3
|
+
import { styles } from "./Card.style";
|
|
4
|
+
// eslint-disable-next-line import/no-internal-modules
|
|
5
|
+
import { InternalCardHeader } from "./components/InternalCardHeader";
|
|
6
|
+
import { ErrorMessageWrapper } from "../ErrorMessageWrapper";
|
|
7
|
+
import { ActionLabel } from "../ActionLabel";
|
|
8
|
+
import { Typography } from "../Typography";
|
|
9
|
+
import { Icon } from "../Icon";
|
|
10
|
+
function getElevationStyle(elevation) {
|
|
11
|
+
if (elevation === "none") {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
return styles[`${elevation}Elevation`];
|
|
15
|
+
}
|
|
16
|
+
export function Card({ header, footer, children, reportCardHeight: onCardHeightChange, testID = "card", error, elevation = "none", }) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
return (React.createElement(ErrorMessageWrapper, { message: error, wrapFor: "card" },
|
|
19
|
+
React.createElement(View, { onLayout: handleLayoutChange, style: [styles.container, getElevationStyle(elevation)], testID: testID },
|
|
20
|
+
header && (React.createElement(React.Fragment, null,
|
|
21
|
+
React.createElement(InternalCardHeader, { onPress: header.onPress, testID: `${testID}Header`, collapsable: !!children },
|
|
22
|
+
React.createElement(View, { style: styles.headerTitle },
|
|
23
|
+
React.createElement(Typography, { color: "heading", fontFamily: "base", fontWeight: "bold", size: "default", lineHeight: "base", accessibilityRole: "header" }, header.title)),
|
|
24
|
+
React.createElement(View, { style: styles.actionItem },
|
|
25
|
+
!!((_a = header.actionItem) === null || _a === void 0 ? void 0 : _a.label) && (React.createElement(View, { style: styles.actionLabel },
|
|
26
|
+
React.createElement(ActionLabel, { type: "cardTitle" }, header.actionItem.label))),
|
|
27
|
+
((_b = header.actionItem) === null || _b === void 0 ? void 0 : _b.iconName) && (React.createElement(Icon, { name: header.actionItem.iconName, color: "interactive" })))))),
|
|
28
|
+
children,
|
|
29
|
+
footer && (React.createElement(Pressable, { testID: `${testID}Footer`, onPress: footer.onPress, style: ({ pressed }) => [
|
|
30
|
+
styles.footer,
|
|
31
|
+
pressed && styles.pressed,
|
|
32
|
+
], accessibilityRole: "button" },
|
|
33
|
+
React.createElement(ActionLabel, null, footer.title))))));
|
|
34
|
+
function handleLayoutChange(event) {
|
|
35
|
+
const { height } = event.nativeEvent.layout;
|
|
36
|
+
onCardHeightChange === null || onCardHeightChange === void 0 ? void 0 : onCardHeightChange(height);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { tokens } from "../utils/design";
|
|
3
|
+
export const styles = StyleSheet.create({
|
|
4
|
+
container: {
|
|
5
|
+
width: "100%",
|
|
6
|
+
backgroundColor: tokens["color-surface"],
|
|
7
|
+
},
|
|
8
|
+
lowElevation: Object.assign({}, tokens["shadow-low"]),
|
|
9
|
+
baseElevation: Object.assign({}, tokens["shadow-base"]),
|
|
10
|
+
highElevation: Object.assign({}, tokens["shadow-high"]),
|
|
11
|
+
headerTitle: {
|
|
12
|
+
flexGrow: 1,
|
|
13
|
+
flex: 1,
|
|
14
|
+
},
|
|
15
|
+
footer: {
|
|
16
|
+
height: tokens["space-largest"],
|
|
17
|
+
flex: 1,
|
|
18
|
+
justifyContent: "center",
|
|
19
|
+
alignItems: "center",
|
|
20
|
+
},
|
|
21
|
+
pressed: {
|
|
22
|
+
opacity: tokens["opacity-pressed"],
|
|
23
|
+
},
|
|
24
|
+
actionItem: {
|
|
25
|
+
height: tokens["typography--lineHeight-base"],
|
|
26
|
+
justifyContent: "center",
|
|
27
|
+
},
|
|
28
|
+
actionLabel: {
|
|
29
|
+
paddingTop: tokens["space-smallest"],
|
|
30
|
+
},
|
|
31
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Pressable, View } from "react-native";
|
|
3
|
+
import { styles } from "./InternalCardHeader.style";
|
|
4
|
+
export function InternalCardHeader({ onPress, children, testID, collapsable, }) {
|
|
5
|
+
const conditionalChildStyling = collapsable ? undefined : styles.noChildren;
|
|
6
|
+
if (onPress) {
|
|
7
|
+
return (React.createElement(Pressable, { testID: testID, onPress: onPress, style: ({ pressed }) => [
|
|
8
|
+
styles.header,
|
|
9
|
+
pressed && styles.pressed,
|
|
10
|
+
conditionalChildStyling,
|
|
11
|
+
], accessibilityRole: "button" }, children));
|
|
12
|
+
}
|
|
13
|
+
return (React.createElement(View, { testID: testID, style: [styles.header, conditionalChildStyling] }, children));
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { tokens } from "../../utils/design";
|
|
3
|
+
export const styles = StyleSheet.create({
|
|
4
|
+
header: {
|
|
5
|
+
flexDirection: "row",
|
|
6
|
+
alignItems: "flex-start",
|
|
7
|
+
paddingTop: tokens["space-small"] + tokens["space-smaller"],
|
|
8
|
+
paddingHorizontal: tokens["space-base"],
|
|
9
|
+
},
|
|
10
|
+
pressed: {
|
|
11
|
+
opacity: tokens["opacity-pressed"],
|
|
12
|
+
},
|
|
13
|
+
noChildren: {
|
|
14
|
+
paddingBottom: tokens["space-small"] + tokens["space-smaller"],
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InternalCardHeader } from "./InternalCardHeader";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Card } from "./Card";
|
package/dist/src/index.js
CHANGED