@jobber/components-native 0.17.0 → 0.18.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.
@@ -0,0 +1,31 @@
1
+ import React, { Children } from "react";
2
+ import { View } from "react-native";
3
+ import chunk from "lodash.chunk";
4
+ import { columnStyles, gapStyles, styles } from "./Flex.styles";
5
+ import { Content } from "../Content";
6
+ export function Flex({ template = [], align = "center", gap = "base", children, }) {
7
+ if (template.length === 1) {
8
+ console.warn("Please use <Content /> component for a stacked layout");
9
+ }
10
+ const childrenArray = Children.toArray(children);
11
+ const chunkedChildren = chunk(childrenArray, template.length || childrenArray.length);
12
+ return (React.createElement(Content, { spacing: "none", childSpacing: gap }, chunkedChildren.map((childArray, rowIndex) => (React.createElement(Row, { key: rowIndex, template: template, align: align, gap: gap }, injectChild(childArray))))));
13
+ function injectChild(value) {
14
+ const hasMoreRows = chunkedChildren.length > 1;
15
+ const childrenCount = value.length;
16
+ const templateCount = template.length;
17
+ if (hasMoreRows && childrenCount < templateCount) {
18
+ const missingChildCount = templateCount - childrenCount;
19
+ for (let index = 0; index < missingChildCount; index++) {
20
+ value.push(React.createElement(React.Fragment, { key: index }));
21
+ }
22
+ }
23
+ return value;
24
+ }
25
+ }
26
+ function Row({ template = [], align = "center", gap = "base", children, }) {
27
+ return (React.createElement(View, { testID: "ATL-Flex-Row", style: [styles.row, { alignItems: align }] }, Children.map(children, (child, index) => (React.createElement(View, { style: [
28
+ columnStyles[template[index]] || columnStyles.grow,
29
+ index > 0 && gap && gapStyles[gap],
30
+ ] }, child)))));
31
+ }
@@ -0,0 +1,24 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { spacing } from "./types";
3
+ import { tokens } from "../utils/design";
4
+ export const styles = StyleSheet.create({
5
+ row: { flexDirection: "row" },
6
+ });
7
+ export const columnStyles = StyleSheet.create({
8
+ shrink: {
9
+ flexGrow: 0,
10
+ flexShrink: 1,
11
+ },
12
+ grow: {
13
+ flexGrow: 1,
14
+ flexShrink: 0,
15
+ flexBasis: 0,
16
+ },
17
+ });
18
+ export const gapStyles = StyleSheet.create(spacing.reduce((gapObj, space) => {
19
+ let paddingLeft = 0;
20
+ if (space !== "none")
21
+ paddingLeft = tokens[`space-${space}`];
22
+ gapObj[space] = { paddingLeft };
23
+ return gapObj;
24
+ }, {}));
@@ -0,0 +1 @@
1
+ export * from "./Flex";
@@ -0,0 +1,8 @@
1
+ export const spacing = [
2
+ "none",
3
+ "smallest",
4
+ "smaller",
5
+ "small",
6
+ "base",
7
+ "large",
8
+ ];
package/dist/src/index.js CHANGED
@@ -8,6 +8,7 @@ export * from "./Chip";
8
8
  export * from "./Content";
9
9
  export * from "./Divider";
10
10
  export * from "./ErrorMessageWrapper";
11
+ export * from "./Flex";
11
12
  export * from "./Heading";
12
13
  export * from "./Icon";
13
14
  export * from "./IconButton";