@jobber/components-native 0.76.1-JOB-116234-314c5ff.22 → 0.76.1-JOB-116234-d279b0f.20

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,19 +1,16 @@
1
1
  import { iosTokens } from "@jobber/design";
2
+ import { PropsWithChildren } from "react";
2
3
  export interface AtlantisThemeContextValue {
3
4
  /**
4
- * The active theme.
5
+ * The theme of the application.
5
6
  */
6
7
  readonly theme: Theme;
7
8
  /**
8
9
  * The design tokens for the current theme.
9
10
  */
10
11
  readonly tokens: typeof iosTokens;
11
- /**
12
- * Change the current theme globally.
13
- */
14
- readonly setTheme: (theme: Theme) => void;
15
12
  }
16
- export interface AtlantisThemeContextProviderProps {
13
+ export interface AtlantisThemeContextProviderProps extends PropsWithChildren {
17
14
  /**
18
15
  * The children to render.
19
16
  */
@@ -62,7 +62,7 @@ interface CommonButtonProps {
62
62
  /**
63
63
  * **Use at your own risk:** Custom style for specific elements. This should only be used as a
64
64
  * **last resort**. Using this may result in unexpected side effects.
65
- * More information in the [Customizing components Guide](https://atlantis.getjobber.com/guides/customizing-components).
65
+ * More information [here](https://atlantis.getjobber.com/storybook/?path=/docs/guides-customizing-components--docs#unsafe_-props).
66
66
  */
67
67
  readonly UNSAFE_style?: ButtonUnsafeStyle;
68
68
  }
@@ -63,7 +63,7 @@ export interface TextProps extends Pick<TypographyProps<"base">, "maxFontScaleSi
63
63
  /**
64
64
  * **Use at your own risk:** Custom style for specific elements. This should only be used as a
65
65
  * **last resort**. Using this may result in unexpected side effects.
66
- * More information in the [Customizing components Guide](https://atlantis.getjobber.com/guides/customizing-components).
66
+ * More information [here](https://atlantis.getjobber.com/storybook/?path=/docs/guides-customizing-components--docs#unsafe_-props).
67
67
  */
68
68
  readonly UNSAFE_style?: TypographyUnsafeStyle;
69
69
  }
@@ -8,7 +8,14 @@ export declare const createTypographyTokens: (tokens: AtlantisThemeContextValue[
8
8
  [index: string]: TextStyle;
9
9
  };
10
10
  /**
11
- * @deprecated Use useCommonInputStyles instead
11
+ * `StyleSheet` for Typography.tsx.
12
+ *
13
+ * If you find yourself needing to use what's inside this object on files other
14
+ * than `<Typography />`, please import from `@jobber/components-native` instead.
15
+ *
16
+ * ```
17
+ * import { typographyStyles } from "@jobber/components-native"
18
+ * ```
12
19
  */
13
20
  export declare const typographyStyles: Record<string, TextStyle>;
14
21
  export declare const useTypographyStyles: () => {
@@ -1,7 +1,2 @@
1
1
  import { iosTokens } from "@jobber/design";
2
- /**
3
- * These design tokens don't react to theme changes. Only use these if you need to access
4
- * tokens that are not affected by the current theme, otherwise you should be using our
5
- * useAtlantisTheme() hook to access the current theme's tokens.
6
- */
7
2
  export declare const tokens: typeof iosTokens;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.76.1-JOB-116234-314c5ff.22+314c5ff4",
3
+ "version": "0.76.1-JOB-116234-d279b0f.20+d279b0fd",
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": "314c5ff4e8322594d2fc7ffce54a204f4a6731cb"
83
+ "gitHead": "d279b0fddc435572c48dff35f02db80ee4ca3ee7"
84
84
  }
@@ -1,5 +1,10 @@
1
1
  import { androidTokens, darkTokens, iosTokens } from "@jobber/design";
2
- import React, { createContext, useContext, useState } from "react";
2
+ import React, {
3
+ PropsWithChildren,
4
+ createContext,
5
+ useContext,
6
+ useState,
7
+ } from "react";
3
8
  import merge from "lodash/merge";
4
9
  import { Platform } from "react-native";
5
10
  import {
@@ -19,31 +24,68 @@ const completeDarkTokens = merge({}, lightTokens, darkTokens);
19
24
  const AtlantisThemeContext = createContext<AtlantisThemeContextValue>({
20
25
  theme: "light",
21
26
  tokens: lightTokens,
22
- setTheme: () => {
23
- console.error(
24
- "useAtlantisTheme accessed outside of AtlantisThemeContextProvider",
25
- );
26
- },
27
27
  });
28
28
 
29
29
  export function AtlantisThemeContextProvider({
30
30
  children,
31
31
  dangerouslyOverrideTheme,
32
32
  }: AtlantisThemeContextProviderProps) {
33
- // TODO: check last saved theme from local/device storage
33
+ if (dangerouslyOverrideTheme) {
34
+ return (
35
+ <InternalStaticThemeProvider
36
+ dangerouslyOverrideTheme={dangerouslyOverrideTheme}
37
+ >
38
+ {children}
39
+ </InternalStaticThemeProvider>
40
+ );
41
+ }
42
+
43
+ return (
44
+ <InternalDynamicThemeProvider>{children}</InternalDynamicThemeProvider>
45
+ );
46
+ }
47
+
48
+ function InternalDynamicThemeProvider({ children }: PropsWithChildren) {
49
+ // TODO: check initial theme from local/device storage?
50
+ // const initialTheme: Theme = (globalThis.document.documentElement.dataset.theme as Theme) ?? "light";
34
51
  const initialTheme: Theme = "light";
35
- const [globalTheme, setGlobalTheme] = useState<Theme>(initialTheme);
36
52
 
37
- const currentTheme = dangerouslyOverrideTheme ?? globalTheme;
53
+ const [internalTheme] = useState<Theme>(initialTheme);
54
+ const currentTokens =
55
+ internalTheme === "dark" ? completeDarkTokens : lightTokens;
56
+
57
+ // TODO: listen for global theme update -> setInternalTheme
58
+ // See web's AtlantisThemeContext for an example of how it does this.
59
+
60
+ return (
61
+ <AtlantisThemeContext.Provider
62
+ value={{
63
+ theme: internalTheme,
64
+ tokens: currentTokens,
65
+ }}
66
+ >
67
+ {children}
68
+ </AtlantisThemeContext.Provider>
69
+ );
70
+ }
71
+
72
+ function InternalStaticThemeProvider({
73
+ dangerouslyOverrideTheme,
74
+ children,
75
+ }: Required<
76
+ Pick<
77
+ AtlantisThemeContextProviderProps,
78
+ "dangerouslyOverrideTheme" | "children"
79
+ >
80
+ >) {
38
81
  const currentTokens =
39
- currentTheme === "dark" ? completeDarkTokens : lightTokens;
82
+ dangerouslyOverrideTheme === "dark" ? completeDarkTokens : lightTokens;
40
83
 
41
84
  return (
42
85
  <AtlantisThemeContext.Provider
43
86
  value={{
44
- theme: currentTheme,
87
+ theme: dangerouslyOverrideTheme,
45
88
  tokens: currentTokens,
46
- setTheme: setGlobalTheme,
47
89
  }}
48
90
  >
49
91
  {children}
@@ -1,8 +1,9 @@
1
1
  import { iosTokens } from "@jobber/design";
2
+ import { PropsWithChildren } from "react";
2
3
 
3
4
  export interface AtlantisThemeContextValue {
4
5
  /**
5
- * The active theme.
6
+ * The theme of the application.
6
7
  */
7
8
  readonly theme: Theme;
8
9
 
@@ -10,14 +11,9 @@ export interface AtlantisThemeContextValue {
10
11
  * The design tokens for the current theme.
11
12
  */
12
13
  readonly tokens: typeof iosTokens;
13
-
14
- /**
15
- * Change the current theme globally.
16
- */
17
- readonly setTheme: (theme: Theme) => void;
18
14
  }
19
15
 
20
- export interface AtlantisThemeContextProviderProps {
16
+ export interface AtlantisThemeContextProviderProps extends PropsWithChildren {
21
17
  /**
22
18
  * The children to render.
23
19
  */
@@ -81,7 +81,7 @@ interface CommonButtonProps {
81
81
  /**
82
82
  * **Use at your own risk:** Custom style for specific elements. This should only be used as a
83
83
  * **last resort**. Using this may result in unexpected side effects.
84
- * More information in the [Customizing components Guide](https://atlantis.getjobber.com/guides/customizing-components).
84
+ * More information [here](https://atlantis.getjobber.com/storybook/?path=/docs/guides-customizing-components--docs#unsafe_-props).
85
85
  */
86
86
  readonly UNSAFE_style?: ButtonUnsafeStyle;
87
87
  }
package/src/Text/Text.tsx CHANGED
@@ -90,7 +90,7 @@ export interface TextProps
90
90
  /**
91
91
  * **Use at your own risk:** Custom style for specific elements. This should only be used as a
92
92
  * **last resort**. Using this may result in unexpected side effects.
93
- * More information in the [Customizing components Guide](https://atlantis.getjobber.com/guides/customizing-components).
93
+ * More information [here](https://atlantis.getjobber.com/storybook/?path=/docs/guides-customizing-components--docs#unsafe_-props).
94
94
  */
95
95
  readonly UNSAFE_style?: TypographyUnsafeStyle;
96
96
  }
@@ -620,7 +620,14 @@ export const createTypographyTokens = (
620
620
  });
621
621
 
622
622
  /**
623
- * @deprecated Use useCommonInputStyles instead
623
+ * `StyleSheet` for Typography.tsx.
624
+ *
625
+ * If you find yourself needing to use what's inside this object on files other
626
+ * than `<Typography />`, please import from `@jobber/components-native` instead.
627
+ *
628
+ * ```
629
+ * import { typographyStyles } from "@jobber/components-native"
630
+ * ```
624
631
  */
625
632
  export const typographyStyles: Record<string, TextStyle> = StyleSheet.create(
626
633
  createTypographyTokens(staticTokens),
@@ -1,11 +1,8 @@
1
1
  import { Platform } from "react-native";
2
2
  import { androidTokens, iosTokens } from "@jobber/design";
3
3
 
4
- /**
5
- * These design tokens don't react to theme changes. Only use these if you need to access
6
- * tokens that are not affected by the current theme, otherwise you should be using our
7
- * useAtlantisTheme() hook to access the current theme's tokens.
8
- */
4
+ // TODO: remove all references to const in JM and Atlantis. Replace with useAtlantisTheme.
5
+ // Rename to `nonThemedTokens` in the meantime?
9
6
  export const tokens: typeof iosTokens = Platform.select({
10
7
  ios: () => iosTokens,
11
8
  android: () => androidTokens,
@@ -8,7 +8,6 @@
8
8
  "AtlantisContext.Provider",
9
9
  "AtlantisFormContext.Consumer",
10
10
  "AtlantisFormContext.Provider",
11
- "AtlantisThemeContextProvider",
12
11
  "AutoLink",
13
12
  "Banner",
14
13
  "BottomSheet",
@@ -1,106 +0,0 @@
1
- import React from "react";
2
- import { act, renderHook } from "@testing-library/react-native";
3
- import { darkTokens, iosTokens } from "@jobber/design";
4
- import merge from "lodash/merge";
5
- import {
6
- AtlantisThemeContextProvider,
7
- useAtlantisTheme,
8
- } from "./AtlantisThemeContext";
9
- import { AtlantisThemeContextProviderProps, Theme } from "./types";
10
-
11
- const expectedDarkTokens = merge({}, iosTokens, darkTokens);
12
- const expectedLightTokens = iosTokens;
13
-
14
- function Wrapper({
15
- children,
16
- dangerouslyOverrideTheme,
17
- }: AtlantisThemeContextProviderProps) {
18
- return (
19
- <AtlantisThemeContextProvider
20
- dangerouslyOverrideTheme={dangerouslyOverrideTheme}
21
- >
22
- {children}
23
- </AtlantisThemeContextProvider>
24
- );
25
- }
26
-
27
- function WrapperWithOverride({
28
- children,
29
- dangerouslyOverrideTheme,
30
- }: AtlantisThemeContextProviderProps) {
31
- return (
32
- <Wrapper>
33
- <AtlantisThemeContextProvider
34
- dangerouslyOverrideTheme={dangerouslyOverrideTheme}
35
- >
36
- {children}
37
- </AtlantisThemeContextProvider>
38
- </Wrapper>
39
- );
40
- }
41
-
42
- describe("ThemeContext", () => {
43
- it("defaults to the light theme", () => {
44
- const { result } = renderHook(useAtlantisTheme, {
45
- wrapper: (props: AtlantisThemeContextProviderProps) => (
46
- <Wrapper {...props} />
47
- ),
48
- });
49
-
50
- expect(result.current.theme).toBe("light");
51
- expect(result.current.tokens).toEqual(expectedLightTokens);
52
- });
53
-
54
- it("updates the theme and tokens", () => {
55
- const { result } = renderHook(useAtlantisTheme, {
56
- wrapper: (props: AtlantisThemeContextProviderProps) => (
57
- <Wrapper {...props} />
58
- ),
59
- });
60
-
61
- act(() => result.current.setTheme("dark"));
62
- expect(result.current.theme).toBe("dark");
63
- expect(result.current.tokens).toEqual(expectedDarkTokens);
64
-
65
- act(() => result.current.setTheme("light"));
66
- expect(result.current.theme).toBe("light");
67
- expect(result.current.tokens).toEqual(expectedLightTokens);
68
- });
69
-
70
- describe("when theme is forced for provider", () => {
71
- it("ignores updates to the global theme", () => {
72
- const { result } = renderHook(useAtlantisTheme, {
73
- wrapper: (props: AtlantisThemeContextProviderProps) => (
74
- <WrapperWithOverride {...props} dangerouslyOverrideTheme="light" />
75
- ),
76
- });
77
-
78
- // Update the global theme
79
- act(() => result.current.setTheme("dark"));
80
-
81
- // This hook shouldn't be affected by it because it's set to the light theme
82
- expect(result.current.theme).toBe("light");
83
- expect(result.current.tokens).toEqual(expectedLightTokens);
84
- });
85
-
86
- it.each([
87
- { defaultTheme: "light", expectedTokens: expectedLightTokens },
88
- { defaultTheme: "dark", expectedTokens: expectedDarkTokens },
89
- ] as { defaultTheme: Theme; expectedTokens: typeof iosTokens }[])(
90
- "provides the dangerouslyOverrideTheme $defaultTheme tokens",
91
- ({ defaultTheme, expectedTokens }) => {
92
- const { result } = renderHook(useAtlantisTheme, {
93
- wrapper: (props: AtlantisThemeContextProviderProps) => (
94
- <WrapperWithOverride
95
- {...props}
96
- dangerouslyOverrideTheme={defaultTheme}
97
- />
98
- ),
99
- });
100
-
101
- expect(result.current.theme).toBe(defaultTheme);
102
- expect(result.current.tokens).toEqual(expectedTokens);
103
- },
104
- );
105
- });
106
- });
@@ -1,83 +0,0 @@
1
- import React from "react";
2
- import { renderHook } from "@testing-library/react-native";
3
- import { buildThemedStyles } from "./buildThemedStyles";
4
- import { AtlantisThemeContextProvider } from "./AtlantisThemeContext";
5
-
6
- describe("buildThemedStyles", () => {
7
- const wrapper = ({ children }: { children: React.ReactNode }) => (
8
- <AtlantisThemeContextProvider>{children}</AtlantisThemeContextProvider>
9
- );
10
-
11
- it("creates styles using theme tokens", () => {
12
- const useTestStyles = buildThemedStyles(tokens => ({
13
- container: {
14
- backgroundColor: tokens["color-surface"],
15
- padding: tokens["space-base"],
16
- },
17
- }));
18
-
19
- const { result } = renderHook(() => useTestStyles(), { wrapper });
20
-
21
- expect(result.current).toEqual({
22
- container: {
23
- backgroundColor: expect.any(String),
24
- padding: expect.any(Number),
25
- },
26
- });
27
- });
28
-
29
- it("memoizes styles and only updates when tokens change", () => {
30
- const styleFactory = jest.fn(tokens => ({
31
- container: {
32
- backgroundColor: tokens["color-surface"],
33
- },
34
- }));
35
-
36
- const useTestStyles = buildThemedStyles(styleFactory);
37
-
38
- const { result, rerender } = renderHook(() => useTestStyles(), { wrapper });
39
-
40
- // Initial render should call styleFactory
41
- expect(styleFactory).toHaveBeenCalledTimes(1);
42
- const initialResult = result.current;
43
-
44
- // Rerender without token changes should not call styleFactory again
45
- rerender({ wrapper });
46
- expect(styleFactory).toHaveBeenCalledTimes(1);
47
- expect(result.current).toBe(initialResult);
48
- });
49
-
50
- it("creates styles with dependent hooks", () => {
51
- const useDependentStyles = () => ({
52
- text: { color: "red" },
53
- });
54
-
55
- const useTestStyles = () => {
56
- const dependentStyles = useDependentStyles();
57
-
58
- return buildThemedStyles(tokens => ({
59
- container: {
60
- ...dependentStyles.text,
61
- padding: tokens["space-base"],
62
- },
63
- }))();
64
- };
65
-
66
- const { result } = renderHook(() => useTestStyles(), { wrapper });
67
-
68
- expect(result.current).toEqual({
69
- container: {
70
- color: "red",
71
- padding: expect.any(Number),
72
- },
73
- });
74
- });
75
-
76
- it("handles empty style objects", () => {
77
- const useTestStyles = buildThemedStyles(() => ({}));
78
-
79
- const { result } = renderHook(() => useTestStyles(), { wrapper });
80
-
81
- expect(result.current).toEqual({});
82
- });
83
- });