@jobber/components-native 0.76.1-JOB-116234-d279b0f.20 → 0.76.1-JOB-116234-4bc5afd.23

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.
Files changed (33) hide show
  1. package/dist/package.json +2 -2
  2. package/dist/src/AtlantisThemeContext/AtlantisThemeContext.js +10 -21
  3. package/dist/src/InputFieldWrapper/CommonInputStyles.style.js +6 -2
  4. package/dist/src/InputFieldWrapper/components/Suffix/Suffix.js +2 -1
  5. package/dist/src/InputPressable/InputPressable.style.js +6 -5
  6. package/dist/src/InputText/InputText.style.js +6 -6
  7. package/dist/src/Typography/Typography.js +12 -11
  8. package/dist/src/Typography/Typography.style.js +1 -8
  9. package/dist/src/utils/design/index.js +5 -2
  10. package/dist/src/utils/meta/meta.json +1 -0
  11. package/dist/tsconfig.tsbuildinfo +1 -1
  12. package/dist/types/src/AtlantisThemeContext/types.d.ts +6 -3
  13. package/dist/types/src/Button/Button.d.ts +1 -1
  14. package/dist/types/src/Text/Text.d.ts +1 -1
  15. package/dist/types/src/Typography/Typography.style.d.ts +1 -8
  16. package/dist/types/src/utils/design/index.d.ts +5 -0
  17. package/package.json +2 -2
  18. package/src/AtlantisThemeContext/AtlantisThemeContext.test.tsx +106 -0
  19. package/src/AtlantisThemeContext/AtlantisThemeContext.tsx +12 -54
  20. package/src/AtlantisThemeContext/buildThemedStyles.test.tsx +83 -0
  21. package/src/AtlantisThemeContext/types.ts +7 -3
  22. package/src/Button/Button.tsx +1 -1
  23. package/src/InputFieldWrapper/CommonInputStyles.style.ts +2 -0
  24. package/src/InputFieldWrapper/components/Prefix/Prefix.test.tsx +1 -6
  25. package/src/InputFieldWrapper/components/Suffix/Suffix.test.tsx +9 -2
  26. package/src/InputFieldWrapper/components/Suffix/Suffix.tsx +2 -1
  27. package/src/InputPressable/InputPressable.style.ts +7 -5
  28. package/src/InputText/InputText.style.ts +7 -6
  29. package/src/Text/Text.tsx +1 -1
  30. package/src/Typography/Typography.style.ts +1 -8
  31. package/src/Typography/Typography.tsx +19 -8
  32. package/src/utils/design/index.ts +5 -2
  33. package/src/utils/meta/meta.json +1 -0
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.76.1-JOB-116234-d279b0f.20+d279b0fd",
3
+ "version": "0.76.1-JOB-116234-4bc5afd.23+4bc5afdb",
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": "d279b0fddc435572c48dff35f02db80ee4ca3ee7"
83
+ "gitHead": "4bc5afdb99786f50a9ae8474ac282eb593dd9867"
84
84
  }
@@ -1,5 +1,5 @@
1
1
  import { androidTokens, darkTokens, iosTokens } from "@jobber/design";
2
- import React, { createContext, useContext, useState, } from "react";
2
+ import React, { createContext, useContext, useState } from "react";
3
3
  import merge from "lodash/merge";
4
4
  import { Platform } from "react-native";
5
5
  const lightTokens = Platform.select({
@@ -11,31 +11,20 @@ const completeDarkTokens = merge({}, lightTokens, darkTokens);
11
11
  const AtlantisThemeContext = createContext({
12
12
  theme: "light",
13
13
  tokens: lightTokens,
14
+ setTheme: () => {
15
+ console.error("useAtlantisTheme accessed outside of AtlantisThemeContextProvider");
16
+ },
14
17
  });
15
18
  export function AtlantisThemeContextProvider({ children, dangerouslyOverrideTheme, }) {
16
- if (dangerouslyOverrideTheme) {
17
- return (React.createElement(InternalStaticThemeProvider, { dangerouslyOverrideTheme: dangerouslyOverrideTheme }, children));
18
- }
19
- return (React.createElement(InternalDynamicThemeProvider, null, children));
20
- }
21
- function InternalDynamicThemeProvider({ children }) {
22
- // TODO: check initial theme from local/device storage?
23
- // const initialTheme: Theme = (globalThis.document.documentElement.dataset.theme as Theme) ?? "light";
19
+ // TODO: check last saved theme from local/device storage
24
20
  const initialTheme = "light";
25
- const [internalTheme] = useState(initialTheme);
26
- const currentTokens = internalTheme === "dark" ? completeDarkTokens : lightTokens;
27
- // TODO: listen for global theme update -> setInternalTheme
28
- // See web's AtlantisThemeContext for an example of how it does this.
29
- return (React.createElement(AtlantisThemeContext.Provider, { value: {
30
- theme: internalTheme,
31
- tokens: currentTokens,
32
- } }, children));
33
- }
34
- function InternalStaticThemeProvider({ dangerouslyOverrideTheme, children, }) {
35
- const currentTokens = dangerouslyOverrideTheme === "dark" ? completeDarkTokens : lightTokens;
21
+ const [globalTheme, setGlobalTheme] = useState(initialTheme);
22
+ const currentTheme = dangerouslyOverrideTheme !== null && dangerouslyOverrideTheme !== void 0 ? dangerouslyOverrideTheme : globalTheme;
23
+ const currentTokens = currentTheme === "dark" ? completeDarkTokens : lightTokens;
36
24
  return (React.createElement(AtlantisThemeContext.Provider, { value: {
37
- theme: dangerouslyOverrideTheme,
25
+ theme: currentTheme,
38
26
  tokens: currentTokens,
27
+ setTheme: setGlobalTheme,
39
28
  } }, children));
40
29
  }
41
30
  export function useAtlantisTheme() {
@@ -1,6 +1,8 @@
1
1
  import { StyleSheet } from "react-native";
2
2
  import { buildThemedStyles, } from "../AtlantisThemeContext";
3
- import { typographyStyles as staticTypographyStyles, useTypographyStyles, } from "../Typography";
3
+ import {
4
+ // eslint-disable-next-line import/no-deprecated
5
+ typographyStyles as staticTypographyStyles, useTypographyStyles, } from "../Typography";
4
6
  import { tokens as staticTokens } from "../utils/design";
5
7
  export const createCommonInputTokens = (tokens, typographyStyles) => ({
6
8
  input: {
@@ -37,7 +39,9 @@ export const createCommonInputTokens = (tokens, typographyStyles) => ({
37
39
  /**
38
40
  * @deprecated Use useCommonInputStyles instead
39
41
  */
40
- export const commonInputStyles = StyleSheet.create(createCommonInputTokens(staticTokens, staticTypographyStyles));
42
+ export const commonInputStyles = StyleSheet.create(
43
+ // eslint-disable-next-line import/no-deprecated
44
+ createCommonInputTokens(staticTokens, staticTypographyStyles));
41
45
  export const useCommonInputStyles = () => {
42
46
  const typographyStyles = useTypographyStyles();
43
47
  const themedStyles = buildThemedStyles(tokens => createCommonInputTokens(tokens, typographyStyles))();
@@ -2,13 +2,14 @@ import React from "react";
2
2
  import { Pressable, Text as RNText, View, } from "react-native";
3
3
  import { Icon } from "../../../Icon";
4
4
  import { Text } from "../../../Text";
5
- import { typographyStyles } from "../../../Typography";
5
+ import { useTypographyStyles } from "../../../Typography";
6
6
  import { useAtlantisTheme } from "../../../AtlantisThemeContext";
7
7
  import { useStyles } from "../../InputFieldWrapper.style";
8
8
  export const suffixLabelTestId = "ATL-InputFieldWrapper-SuffixLabel";
9
9
  export const suffixIconTestId = "ATL-InputFieldWrapper-SuffixIcon";
10
10
  export function SuffixLabel({ focused, disabled, hasMiniLabel, inputInvalid, label, hasLeftMargin = true, styleOverride, }) {
11
11
  const styles = useStyles();
12
+ const typographyStyles = useTypographyStyles();
12
13
  return (React.createElement(View, { testID: suffixLabelTestId, style: [
13
14
  styles.fieldAffix,
14
15
  focused && styles.inputFocused,
@@ -1,7 +1,8 @@
1
1
  import { buildThemedStyles } from "../AtlantisThemeContext";
2
- import { typographyStyles } from "../Typography/Typography.style";
3
- export const useStyles = buildThemedStyles(tokens => {
4
- return {
2
+ import { useTypographyStyles } from "../Typography";
3
+ export const useStyles = () => {
4
+ const typographyStyles = useTypographyStyles();
5
+ return buildThemedStyles(tokens => ({
5
6
  pressable: {
6
7
  flex: 1,
7
8
  },
@@ -20,5 +21,5 @@ export const useStyles = buildThemedStyles(tokens => {
20
21
  inputInvalid: {
21
22
  borderColor: tokens["color-critical"],
22
23
  },
23
- };
24
- });
24
+ }))();
25
+ };
@@ -1,7 +1,8 @@
1
1
  import { buildThemedStyles } from "../AtlantisThemeContext";
2
- import { typographyStyles } from "../Typography";
3
- export const useStyles = buildThemedStyles(tokens => {
4
- return {
2
+ import { useTypographyStyles } from "../Typography";
3
+ export const useStyles = () => {
4
+ const typographyStyles = useTypographyStyles();
5
+ return buildThemedStyles(tokens => ({
5
6
  inputPaddingTop: {
6
7
  paddingTop: (typographyStyles.smallSize.fontSize || 0) +
7
8
  tokens["space-smaller"] +
@@ -17,8 +18,7 @@ export const useStyles = buildThemedStyles(tokens => {
17
18
  paddingBottom: tokens["space-small"] - tokens["space-smallest"],
18
19
  },
19
20
  multilineInputiOS: {
20
- // for placeholder
21
21
  paddingTop: (typographyStyles.defaultSize.fontSize || 0) + tokens["space-smallest"],
22
22
  },
23
- };
24
- });
23
+ }))();
24
+ };
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { I18nManager, StyleSheet, Text, } from "react-native";
3
3
  import { TypographyGestureDetector } from "./TypographyGestureDetector";
4
- import { typographyStyles as styles } from "./Typography.style";
4
+ import { useTypographyStyles } from "./Typography.style";
5
5
  import { capitalize } from "../utils/intl";
6
6
  import { useAtlantisTheme } from "../AtlantisThemeContext";
7
7
  const maxNumberOfLines = {
@@ -15,13 +15,14 @@ const maxNumberOfLines = {
15
15
  export const Typography = React.memo(InternalTypography);
16
16
  // eslint-disable-next-line max-statements
17
17
  function InternalTypography({ fontFamily, fontStyle, fontWeight, transform, color, align, size = "default", children, maxLines = "unlimited", allowFontScaling = true, maxFontScaleSize, adjustsFontSizeToFit = false, lineHeight, letterSpacing, reverseTheme = false, hideFromScreenReader = false, accessibilityRole = "text", strikeThrough = false, underline, UNSAFE_style, selectable = true, }) {
18
- const sizeAndHeight = getSizeAndHeightStyle(size, lineHeight);
18
+ const styles = useTypographyStyles();
19
+ const sizeAndHeight = getSizeAndHeightStyle(size, styles, lineHeight);
19
20
  const style = [
20
- getFontStyle(fontFamily, fontStyle, fontWeight),
21
- getColorStyle(color, reverseTheme),
22
- getAlignStyle(align),
21
+ getFontStyle(fontFamily, fontStyle, fontWeight, styles),
22
+ getColorStyle(styles, color, reverseTheme),
23
+ getAlignStyle(styles, align),
23
24
  sizeAndHeight,
24
- getLetterSpacingStyle(letterSpacing),
25
+ getLetterSpacingStyle(letterSpacing, styles),
25
26
  ];
26
27
  if (strikeThrough) {
27
28
  style.push(styles.strikeThrough);
@@ -57,7 +58,7 @@ function getScaleMultiplier(maxFontScaleSize = 0, size = 1) {
57
58
  return undefined;
58
59
  return maxFontScaleSize / size;
59
60
  }
60
- function getFontStyle(fontFamily = "base", fontStyle = "regular", fontWeight = "regular") {
61
+ function getFontStyle(fontFamily = "base", fontStyle = "regular", fontWeight = "regular", styles) {
61
62
  const defaultBaseFontStyling = styles.baseRegularRegular;
62
63
  const defaultDisplayFontStyling = styles.displayRegularBold;
63
64
  const styleKey = `${fontFamily}${capitalize(fontStyle)}${capitalize(fontWeight)}`;
@@ -83,17 +84,17 @@ function getTransformedText(text, transform) {
83
84
  return text;
84
85
  }
85
86
  }
86
- function getColorStyle(color, reverseTheme) {
87
+ function getColorStyle(styles, color, reverseTheme) {
87
88
  if (color === "default" || !color) {
88
89
  return styles.greyBlue;
89
90
  }
90
91
  const colorStyleKey = `${color}${reverseTheme ? "Reverse" : ""}`;
91
92
  return styles[`${colorStyleKey}`];
92
93
  }
93
- function getAlignStyle(alignStyle = I18nManager.isRTL ? "end" : "start") {
94
+ function getAlignStyle(styles, alignStyle = I18nManager.isRTL ? "end" : "start") {
94
95
  return styles[`${alignStyle}Align`];
95
96
  }
96
- function getSizeAndHeightStyle(textSize, lineHeightOverwrite) {
97
+ function getSizeAndHeightStyle(textSize, styles, lineHeightOverwrite) {
97
98
  const fontSize = styles[`${textSize}Size`];
98
99
  if (lineHeightOverwrite) {
99
100
  const lineHeight = styles[`${lineHeightOverwrite}LineHeight`];
@@ -101,6 +102,6 @@ function getSizeAndHeightStyle(textSize, lineHeightOverwrite) {
101
102
  }
102
103
  return fontSize;
103
104
  }
104
- function getLetterSpacingStyle(letterSpacing = "base") {
105
+ function getLetterSpacingStyle(letterSpacing = "base", styles) {
105
106
  return styles[`${letterSpacing}LetterSpacing`];
106
107
  }
@@ -354,14 +354,7 @@ export const createTypographyTokens = (tokens) => (Object.assign(Object.assign({
354
354
  textDecorationLine: "line-through",
355
355
  } }));
356
356
  /**
357
- * `StyleSheet` for Typography.tsx.
358
- *
359
- * If you find yourself needing to use what's inside this object on files other
360
- * than `<Typography />`, please import from `@jobber/components-native` instead.
361
- *
362
- * ```
363
- * import { typographyStyles } from "@jobber/components-native"
364
- * ```
357
+ * @deprecated Use useTypographyStyles instead
365
358
  */
366
359
  export const typographyStyles = StyleSheet.create(createTypographyTokens(staticTokens));
367
360
  export const useTypographyStyles = buildThemedStyles(createTypographyTokens);
@@ -1,7 +1,10 @@
1
1
  import { Platform } from "react-native";
2
2
  import { androidTokens, iosTokens } from "@jobber/design";
3
- // TODO: remove all references to const in JM and Atlantis. Replace with useAtlantisTheme.
4
- // Rename to `nonThemedTokens` in the meantime?
3
+ /**
4
+ * These design tokens don't react to theme changes. Only use these if you need to access
5
+ * tokens that are not affected by the current theme, otherwise you should be using our
6
+ * useAtlantisTheme() hook to access the current theme's tokens.
7
+ */
5
8
  export const tokens = Platform.select({
6
9
  ios: () => iosTokens,
7
10
  android: () => androidTokens,
@@ -8,6 +8,7 @@
8
8
  "AtlantisContext.Provider",
9
9
  "AtlantisFormContext.Consumer",
10
10
  "AtlantisFormContext.Provider",
11
+ "AtlantisThemeContextProvider",
11
12
  "AutoLink",
12
13
  "Banner",
13
14
  "BottomSheet",