@jobber/components-native 0.79.0 → 0.80.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.
@@ -1,5 +1,10 @@
1
1
  import { ReactNode } from "react";
2
+ import { StyleProp, ViewStyle } from "react-native";
2
3
  export type Spacing = "none" | "base" | "small" | "smaller" | "smallest" | "large";
4
+ export interface ContentUnsafeStyle {
5
+ container?: StyleProp<ViewStyle>;
6
+ childWrapper?: StyleProp<ViewStyle>;
7
+ }
3
8
  export interface ContentProps {
4
9
  /**
5
10
  * The child or children that will be given spacing.
@@ -14,5 +19,11 @@ export interface ContentProps {
14
19
  */
15
20
  readonly childSpacing?: Spacing;
16
21
  readonly direction?: "horizontal" | "vertical";
22
+ /**
23
+ * **Use at your own risk:** Custom style for specific elements. This should only be used as a
24
+ * **last resort**. Using this may result in unexpected side effects.
25
+ * More information in the [Customizing components Guide](https://atlantis.getjobber.com/guides/customizing-components).
26
+ */
27
+ readonly UNSAFE_style?: ContentUnsafeStyle;
17
28
  }
18
- export declare function Content({ children, spacing, childSpacing, direction, }: ContentProps): JSX.Element;
29
+ export declare function Content({ children, spacing, childSpacing, direction, UNSAFE_style, }: ContentProps): JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.79.0",
3
+ "version": "0.80.0",
4
4
  "license": "MIT",
5
5
  "description": "React Native implementation of Atlantis",
6
6
  "repository": {
@@ -80,5 +80,5 @@
80
80
  "react-native-safe-area-context": "^4.5.2",
81
81
  "react-native-svg": ">=12.0.0"
82
82
  },
83
- "gitHead": "0fbaebc80bf2e27b4be4fc36c93cd90e59300477"
83
+ "gitHead": "2a7c200ed284bace9d37382de5b7c4b5eda007f1"
84
84
  }
@@ -21,7 +21,10 @@ function getContentChildren(contentView: ReactTestInstance) {
21
21
  const text = "🌚 I am the text 🌞";
22
22
 
23
23
  function setupContent(
24
- props?: Pick<ContentProps, "spacing" | "childSpacing" | "direction">,
24
+ props?: Pick<
25
+ ContentProps,
26
+ "spacing" | "childSpacing" | "direction" | "UNSAFE_style"
27
+ >,
25
28
  ) {
26
29
  const container = render(
27
30
  <View accessibilityLabel="contentView">
@@ -29,6 +32,7 @@ function setupContent(
29
32
  spacing={props?.spacing}
30
33
  childSpacing={props?.childSpacing}
31
34
  direction={props?.direction}
35
+ UNSAFE_style={props?.UNSAFE_style}
32
36
  >
33
37
  <Text>{text}</Text>
34
38
  <Text>{text}</Text>
@@ -269,3 +273,77 @@ describe("Horizontal", () => {
269
273
  });
270
274
  });
271
275
  });
276
+
277
+ describe("UNSAFE_style", () => {
278
+ it("applies custom styles to container", () => {
279
+ const customStyle = {
280
+ backgroundColor: "red",
281
+ padding: 16,
282
+ };
283
+
284
+ const { parentView } = setupContent({
285
+ UNSAFE_style: {
286
+ container: customStyle,
287
+ },
288
+ });
289
+
290
+ const contentView = getContentComponent(parentView);
291
+ expect(contentView.props.style).toEqual(
292
+ expect.arrayContaining([expect.objectContaining(customStyle)]),
293
+ );
294
+ });
295
+
296
+ it("applies custom styles to child wrapper", () => {
297
+ const customStyle = {
298
+ backgroundColor: "blue",
299
+ marginLeft: 8,
300
+ };
301
+
302
+ const { parentView } = setupContent({
303
+ UNSAFE_style: {
304
+ childWrapper: customStyle,
305
+ },
306
+ });
307
+
308
+ const contentView = getContentComponent(parentView);
309
+ const contentChildren = getContentChildren(contentView);
310
+
311
+ contentChildren.forEach(child => {
312
+ expect(child.props.style).toEqual(
313
+ expect.arrayContaining([expect.objectContaining(customStyle)]),
314
+ );
315
+ });
316
+ });
317
+
318
+ it("applies custom styles to both container and child wrapper", () => {
319
+ const containerStyle = {
320
+ backgroundColor: "red",
321
+ padding: 16,
322
+ };
323
+
324
+ const childWrapperStyle = {
325
+ backgroundColor: "blue",
326
+ marginLeft: 8,
327
+ };
328
+
329
+ const { parentView } = setupContent({
330
+ UNSAFE_style: {
331
+ container: containerStyle,
332
+ childWrapper: childWrapperStyle,
333
+ },
334
+ });
335
+
336
+ const contentView = getContentComponent(parentView);
337
+ const contentChildren = getContentChildren(contentView);
338
+
339
+ expect(contentView.props.style).toEqual(
340
+ expect.arrayContaining([expect.objectContaining(containerStyle)]),
341
+ );
342
+
343
+ contentChildren.forEach(child => {
344
+ expect(child.props.style).toEqual(
345
+ expect.arrayContaining([expect.objectContaining(childWrapperStyle)]),
346
+ );
347
+ });
348
+ });
349
+ });
@@ -1,5 +1,5 @@
1
1
  import React, { ReactNode } from "react";
2
- import { View } from "react-native";
2
+ import { StyleProp, View, ViewStyle } from "react-native";
3
3
  import { useHorizontalStyles } from "./ContentHorizontal.style";
4
4
  import { useVerticalStyles } from "./ContentVertical.style";
5
5
  import { useSpaceAroundStyles } from "./ContentSpaceAround.style";
@@ -12,6 +12,11 @@ export type Spacing =
12
12
  | "smallest"
13
13
  | "large";
14
14
 
15
+ export interface ContentUnsafeStyle {
16
+ container?: StyleProp<ViewStyle>;
17
+ childWrapper?: StyleProp<ViewStyle>;
18
+ }
19
+
15
20
  export interface ContentProps {
16
21
  /**
17
22
  * The child or children that will be given spacing.
@@ -29,6 +34,13 @@ export interface ContentProps {
29
34
  readonly childSpacing?: Spacing;
30
35
 
31
36
  readonly direction?: "horizontal" | "vertical";
37
+
38
+ /**
39
+ * **Use at your own risk:** Custom style for specific elements. This should only be used as a
40
+ * **last resort**. Using this may result in unexpected side effects.
41
+ * More information in the [Customizing components Guide](https://atlantis.getjobber.com/guides/customizing-components).
42
+ */
43
+ readonly UNSAFE_style?: ContentUnsafeStyle;
32
44
  }
33
45
 
34
46
  export function Content({
@@ -36,6 +48,7 @@ export function Content({
36
48
  spacing = "base",
37
49
  childSpacing = "base",
38
50
  direction = "vertical",
51
+ UNSAFE_style,
39
52
  }: ContentProps): JSX.Element {
40
53
  const horizontalStyles = useHorizontalStyles();
41
54
  const verticalStyles = useVerticalStyles();
@@ -46,7 +59,9 @@ export function Content({
46
59
  const containerStyle = spaceAroundStyles[styleName];
47
60
 
48
61
  return (
49
- <View style={[styles.wrapper, containerStyle]}>{renderChildren()}</View>
62
+ <View style={[styles.wrapper, containerStyle, UNSAFE_style?.container]}>
63
+ {renderChildren()}
64
+ </View>
50
65
  );
51
66
 
52
67
  function renderChildren() {
@@ -57,12 +72,17 @@ export function Content({
57
72
  const childContainerStyle = styles[spaceName];
58
73
 
59
74
  return childArray.map((child, index) => {
60
- // In order to get spacing between the children, we apply the child spacing on each of
61
- // the children except for the first (top) child
62
75
  const childStyle = index !== 0 ? [childContainerStyle] : [];
63
76
 
64
77
  return (
65
- <View key={index} style={[styles.childWrapper, ...childStyle]}>
78
+ <View
79
+ key={index}
80
+ style={[
81
+ styles.childWrapper,
82
+ ...childStyle,
83
+ UNSAFE_style?.childWrapper,
84
+ ]}
85
+ >
66
86
  {child}
67
87
  </View>
68
88
  );
@@ -16,6 +16,7 @@ exports[`TextList when the bulletItems is provided displays the text list 1`] =
16
16
  {
17
17
  "padding": 0,
18
18
  },
19
+ undefined,
19
20
  ]
20
21
  }
21
22
  >
@@ -23,6 +24,7 @@ exports[`TextList when the bulletItems is provided displays the text list 1`] =
23
24
  style={
24
25
  [
25
26
  {},
27
+ undefined,
26
28
  ]
27
29
  }
28
30
  >
@@ -114,6 +116,7 @@ exports[`TextList when the bulletItems is provided displays the text list 1`] =
114
116
  {
115
117
  "padding": 0,
116
118
  },
119
+ undefined,
117
120
  ]
118
121
  }
119
122
  >