@hero-design/rn 8.12.1 → 8.12.3

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 (41) hide show
  1. package/.turbo/turbo-build.log +9 -9
  2. package/es/index.js +102 -46
  3. package/lib/index.js +101 -45
  4. package/package.json +5 -5
  5. package/src/components/Button/Button.tsx +42 -2
  6. package/src/components/Button/LoadingIndicator/StyledLoadingIndicator.tsx +1 -1
  7. package/src/components/Button/LoadingIndicator/__tests__/__snapshots__/StyledLoadingIndicator.spec.tsx.snap +1 -1
  8. package/src/components/Button/LoadingIndicator/__tests__/__snapshots__/index.spec.tsx.snap +3 -3
  9. package/src/components/Button/StyledButton.tsx +21 -14
  10. package/src/components/Button/__tests__/Button.spec.tsx +46 -1
  11. package/src/components/Button/__tests__/__snapshots__/Button.spec.tsx.snap +1564 -0
  12. package/src/components/Button/__tests__/__snapshots__/StyledButton.spec.tsx.snap +126 -110
  13. package/src/components/Carousel/__tests__/__snapshots__/index.spec.tsx.snap +24 -22
  14. package/src/components/DatePicker/__tests__/__snapshots__/DatePickerIOS.spec.tsx.snap +12 -9
  15. package/src/components/FAB/ActionGroup/ActionItem.tsx +17 -6
  16. package/src/components/FAB/ActionGroup/StyledActionItem.tsx +15 -17
  17. package/src/components/FAB/ActionGroup/__tests__/__snapshots__/index.spec.tsx.snap +170 -160
  18. package/src/components/FAB/FAB.tsx +3 -1
  19. package/src/components/Select/MultiSelect/__tests__/__snapshots__/index.spec.tsx.snap +36 -27
  20. package/src/components/Tabs/__tests__/__snapshots__/index.spec.tsx.snap +2 -2
  21. package/src/components/Tabs/__tests__/index.spec.tsx +5 -5
  22. package/src/components/TimePicker/__tests__/__snapshots__/TimePickerIOS.spec.tsx.snap +12 -9
  23. package/src/components/Typography/Text/StyledText.tsx +1 -0
  24. package/src/components/Typography/Text/__tests__/StyledText.spec.tsx +1 -0
  25. package/src/components/Typography/Text/__tests__/__snapshots__/StyledText.spec.tsx.snap +23 -0
  26. package/src/components/Typography/Text/index.tsx +1 -0
  27. package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +19 -0
  28. package/src/theme/components/button.ts +16 -2
  29. package/src/theme/components/fab.ts +2 -0
  30. package/src/theme/components/typography.ts +2 -0
  31. package/src/theme/global/borders.ts +2 -0
  32. package/src/theme/global/colors/__tests__/__snapshots__/eBens.spec.ts.snap +4 -4
  33. package/types/components/Button/Button.d.ts +1 -1
  34. package/types/components/Button/StyledButton.d.ts +4 -3
  35. package/types/components/FAB/ActionGroup/StyledActionItem.d.ts +3 -3
  36. package/types/components/Typography/Text/StyledText.d.ts +1 -1
  37. package/types/components/Typography/Text/index.d.ts +1 -1
  38. package/types/theme/components/button.d.ts +14 -0
  39. package/types/theme/components/fab.d.ts +2 -0
  40. package/types/theme/components/typography.d.ts +2 -0
  41. package/types/theme/global/borders.d.ts +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hero-design/rn",
3
- "version": "8.12.1",
3
+ "version": "8.12.3",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "@emotion/native": "^11.9.3",
23
23
  "@emotion/react": "^11.9.3",
24
- "@hero-design/colors": "8.12.1",
24
+ "@hero-design/colors": "8.12.3",
25
25
  "date-fns": "^2.16.1",
26
26
  "events": "^3.2.0",
27
27
  "hero-editor": "^1.9.21"
@@ -44,7 +44,7 @@
44
44
  "@babel/preset-typescript": "^7.17.12",
45
45
  "@babel/runtime": "^7.18.9",
46
46
  "@emotion/jest": "^11.9.3",
47
- "@hero-design/eslint-plugin": "8.12.1",
47
+ "@hero-design/eslint-plugin": "8.12.3",
48
48
  "@react-native-community/datetimepicker": "^3.5.2",
49
49
  "@react-native-community/slider": "4.1.12",
50
50
  "@rollup/plugin-babel": "^5.3.1",
@@ -60,9 +60,9 @@
60
60
  "@types/react-native": "^0.67.7",
61
61
  "@types/react-native-vector-icons": "^6.4.10",
62
62
  "babel-plugin-inline-import": "^3.0.0",
63
- "eslint-config-hd": "8.12.1",
63
+ "eslint-config-hd": "8.12.3",
64
64
  "jest": "^27.3.1",
65
- "prettier-config-hd": "8.12.1",
65
+ "prettier-config-hd": "8.12.3",
66
66
  "react": "18.0.0",
67
67
  "react-native": "0.69.7",
68
68
  "react-native-gesture-handler": "~2.1.0",
@@ -1,6 +1,6 @@
1
- import type { ReactChild } from 'react';
2
- import React from 'react';
1
+ import React, { ReactChild, useMemo } from 'react';
3
2
  import type { StyleProp, ViewStyle } from 'react-native';
3
+ import { Theme, useTheme } from '../../theme';
4
4
  import type { IconName } from '../Icon';
5
5
  import LoadingIndicator from './LoadingIndicator';
6
6
  import type { Intent, ThemeVariant } from './StyledButton';
@@ -10,6 +10,7 @@ import {
10
10
  StyledButtonIconWrapper,
11
11
  StyledButtonText,
12
12
  } from './StyledButton';
13
+ import { useDeprecation } from '../../utils/hooks';
13
14
 
14
15
  export interface ButtonProps {
15
16
  /**
@@ -93,7 +94,35 @@ export const getThemeVariant = (
93
94
  return TEXT_VARIANTS[intent];
94
95
  }
95
96
  };
97
+ const getUnderlayColor = (theme: Theme, themeVariant: ThemeVariant) => {
98
+ switch (themeVariant) {
99
+ case 'filled-primary':
100
+ return theme.__hd__.button.colors.pressedBackground.filledPrimary;
101
+ case 'filled-secondary':
102
+ return theme.__hd__.button.colors.pressedBackground.filledSecondary;
103
+ case 'filled-danger':
104
+ return theme.__hd__.button.colors.pressedBackground.filledDanger;
105
+ case 'outlined-primary':
106
+ return theme.__hd__.button.colors.pressedBackground.outlinedPrimary;
107
+ case 'outlined-secondary':
108
+ return theme.__hd__.button.colors.pressedBackground.outlinedSecondary;
109
+ case 'outlined-danger':
110
+ return theme.__hd__.button.colors.pressedBackground.outlineDanger;
111
+ case 'text-primary':
112
+ return theme.__hd__.button.colors.pressedBackground.textPrimary;
113
+ case 'text-secondary':
114
+ return theme.__hd__.button.colors.pressedBackground.textSecondary;
115
+ case 'text-danger':
116
+ return theme.__hd__.button.colors.pressedBackground.textDanger;
117
+ }
118
+ };
96
119
 
120
+ const deprecatedVariants: ThemeVariant[] = [
121
+ 'filled-secondary',
122
+ 'filled-danger',
123
+ 'outlined-secondary',
124
+ 'outlined-danger',
125
+ ];
97
126
  const Button = ({
98
127
  accessibilityHint,
99
128
  accessibilityLabel,
@@ -109,16 +138,27 @@ const Button = ({
109
138
  variant = 'filled',
110
139
  }: ButtonProps): JSX.Element => {
111
140
  const themeVariant = getThemeVariant(variant, intent);
141
+ const theme = useTheme();
142
+ const underlayColor = useMemo(() => {
143
+ return getUnderlayColor(theme, themeVariant);
144
+ }, [theme, themeVariant]);
145
+
146
+ useDeprecation(
147
+ `Button variant ${deprecatedVariants.join(', ')} are deprecated.`,
148
+ deprecatedVariants.includes(themeVariant)
149
+ );
112
150
 
113
151
  return (
114
152
  <StyledButtonContainer
115
153
  accessibilityHint={accessibilityHint}
116
154
  accessibilityLabel={accessibilityLabel}
117
155
  disabled={disabled || loading}
156
+ loading={loading}
118
157
  onPress={onPress}
119
158
  testID={testID}
120
159
  themeVariant={themeVariant}
121
160
  style={style}
161
+ underlayColor={underlayColor}
122
162
  >
123
163
  {loading === true ? (
124
164
  <LoadingIndicator
@@ -46,8 +46,8 @@ const StyledLoadingDot = styled(View)<{
46
46
  backgroundColor: theme.__hd__.button.colors.invertedText,
47
47
  };
48
48
  case 'outlined-primary':
49
- case 'text-primary':
50
49
  return genLoadingIndicatorStyles(theme, 'primary');
50
+ case 'text-primary':
51
51
  case 'outlined-secondary':
52
52
  case 'text-secondary':
53
53
  return genLoadingIndicatorStyles(theme, 'secondary');
@@ -165,7 +165,7 @@ exports[`StyledLoadingIndicator has text-primary style 1`] = `
165
165
  style={
166
166
  Array [
167
167
  Object {
168
- "backgroundColor": "#401960",
168
+ "backgroundColor": "#795e90",
169
169
  "borderRadius": 8,
170
170
  "height": 12,
171
171
  "marginBottom": 4,
@@ -945,7 +945,7 @@ exports[`LoadingIndicator renders correctly when themeVariant is text-primary 1`
945
945
  style={
946
946
  Array [
947
947
  Object {
948
- "backgroundColor": "#401960",
948
+ "backgroundColor": "#795e90",
949
949
  "borderRadius": 8,
950
950
  "height": 12,
951
951
  "marginBottom": 4,
@@ -977,7 +977,7 @@ exports[`LoadingIndicator renders correctly when themeVariant is text-primary 1`
977
977
  style={
978
978
  Array [
979
979
  Object {
980
- "backgroundColor": "#401960",
980
+ "backgroundColor": "#795e90",
981
981
  "borderRadius": 8,
982
982
  "height": 12,
983
983
  "marginBottom": 4,
@@ -1009,7 +1009,7 @@ exports[`LoadingIndicator renders correctly when themeVariant is text-primary 1`
1009
1009
  style={
1010
1010
  Array [
1011
1011
  Object {
1012
- "backgroundColor": "#401960",
1012
+ "backgroundColor": "#795e90",
1013
1013
  "borderRadius": 8,
1014
1014
  "height": 12,
1015
1015
  "marginBottom": 4,
@@ -1,4 +1,4 @@
1
- import { TouchableOpacity, View } from 'react-native';
1
+ import { TouchableHighlight, View } from 'react-native';
2
2
  import styled from '@emotion/native';
3
3
  import type { ReactNativeStyle } from '@emotion/native';
4
4
  import type { Theme } from '@emotion/react';
@@ -21,10 +21,11 @@ type ThemeVariant =
21
21
  const genFilledContainerStyles = (
22
22
  theme: Theme,
23
23
  intent: Intent,
24
- disabled: boolean
24
+ disabled: boolean,
25
+ loading: boolean
25
26
  ): ReactNativeStyle => {
26
27
  const backgroundColorStyling = () => {
27
- if (disabled) {
28
+ if (!loading && disabled) {
28
29
  return {
29
30
  backgroundColor: theme.__hd__.button.colors.disabledBorder,
30
31
  };
@@ -47,10 +48,11 @@ const genFilledContainerStyles = (
47
48
  const genOutlineContainerStyles = (
48
49
  theme: Theme,
49
50
  intent: Intent,
50
- disabled: boolean
51
+ disabled: boolean,
52
+ loading: boolean
51
53
  ): ReactNativeStyle => {
52
54
  const borderColorStyling = () => {
53
- if (disabled) {
55
+ if (!loading && disabled) {
54
56
  return {
55
57
  borderColor: theme.__hd__.button.colors.disabledBorder,
56
58
  };
@@ -118,32 +120,37 @@ const genTextVariantTextStyles = (
118
120
  };
119
121
  };
120
122
 
121
- const StyledButtonContainer = styled(TouchableOpacity)<{
123
+ const StyledButtonContainer = styled(TouchableHighlight)<{
122
124
  disabled?: boolean;
123
125
  themeVariant: ThemeVariant;
124
- }>(({ disabled = false, themeVariant, theme }) => {
126
+ loading?: boolean;
127
+ }>(({ disabled = false, loading = false, themeVariant, theme }) => {
125
128
  switch (themeVariant) {
126
129
  case 'filled-primary':
127
- return genFilledContainerStyles(theme, 'primary', disabled);
130
+ return genFilledContainerStyles(theme, 'primary', disabled, loading);
128
131
  case 'filled-secondary':
129
- return genFilledContainerStyles(theme, 'secondary', disabled);
132
+ return genFilledContainerStyles(theme, 'secondary', disabled, loading);
130
133
  case 'filled-danger':
131
- return genFilledContainerStyles(theme, 'danger', disabled);
134
+ return genFilledContainerStyles(theme, 'danger', disabled, loading);
132
135
  case 'outlined-primary':
133
- return genOutlineContainerStyles(theme, 'primary', disabled);
136
+ return genOutlineContainerStyles(theme, 'primary', disabled, loading);
134
137
  case 'outlined-secondary':
135
- return genOutlineContainerStyles(theme, 'secondary', disabled);
138
+ return genOutlineContainerStyles(theme, 'secondary', disabled, loading);
136
139
  case 'outlined-danger':
137
- return genOutlineContainerStyles(theme, 'danger', disabled);
140
+ return genOutlineContainerStyles(theme, 'danger', disabled, loading);
138
141
  case 'text-primary':
139
142
  case 'text-secondary':
140
143
  case 'text-danger':
141
144
  return {
145
+ borderRadius: theme.__hd__.button.radii.text,
142
146
  flexDirection: 'row',
143
147
  justifyContent: 'center',
144
148
  alignItems: 'center',
145
- padding: theme.__hd__.button.space.buttonPadding,
149
+ padding: theme.__hd__.button.space.textButtonPadding,
146
150
  borderWidth: 0,
151
+ backgroundColor: loading
152
+ ? theme.__hd__.button.colors.textLoadingBackground
153
+ : 'transparent',
147
154
  };
148
155
  }
149
156
  });
@@ -46,9 +46,11 @@ describe('Button', () => {
46
46
  });
47
47
 
48
48
  it('renders loading icon', () => {
49
- const { getByTestId } = renderWithTheme(
49
+ const { getByTestId, toJSON } = renderWithTheme(
50
50
  <Button text="A button" testID="button" onPress={jest.fn()} loading />
51
51
  );
52
+
53
+ expect(toJSON()).toMatchSnapshot();
52
54
  expect(getByTestId('button-loading-indicator')).toBeDefined();
53
55
  });
54
56
 
@@ -64,6 +66,17 @@ describe('Button', () => {
64
66
  });
65
67
  });
66
68
 
69
+ describe('button is loading', () => {
70
+ it('NOT allows to click on', () => {
71
+ const onPress = jest.fn();
72
+ const { getByTestId } = renderWithTheme(
73
+ <Button text="A button" testID="button" loading onPress={onPress} />
74
+ );
75
+ fireEvent.press(getByTestId('button-loading-indicator'));
76
+ expect(onPress).not.toHaveBeenCalled();
77
+ });
78
+ });
79
+
67
80
  describe('button is enabled', () => {
68
81
  it('allows to click on', () => {
69
82
  const onPress = jest.fn();
@@ -75,6 +88,38 @@ describe('Button', () => {
75
88
  });
76
89
  });
77
90
  });
91
+
92
+ it.each`
93
+ variant | intent | loading | disabled
94
+ ${'filled'} | ${'primary'} | ${false} | ${false}
95
+ ${'filled'} | ${'primary'} | ${true} | ${false}
96
+ ${'filled'} | ${'primary'} | ${false} | ${true}
97
+ ${'outlined'} | ${'primary'} | ${false} | ${false}
98
+ ${'outlined'} | ${'primary'} | ${true} | ${false}
99
+ ${'outlined'} | ${'primary'} | ${false} | ${true}
100
+ ${'text'} | ${'primary'} | ${false} | ${false}
101
+ ${'text'} | ${'primary'} | ${true} | ${false}
102
+ ${'text'} | ${'primary'} | ${false} | ${true}
103
+ ${'text'} | ${'secondary'} | ${false} | ${false}
104
+ ${'text'} | ${'secondary'} | ${true} | ${false}
105
+ ${'text'} | ${'secondary'} | ${false} | ${true}
106
+ ${'text'} | ${'danger'} | ${false} | ${false}
107
+ ${'text'} | ${'danger'} | ${true} | ${false}
108
+ ${'text'} | ${'danger'} | ${false} | ${true}
109
+ `('renders correctly', ({ variant, intent, loading, disabled }) => {
110
+ const { toJSON } = renderWithTheme(
111
+ <Button
112
+ text="A button"
113
+ variant={variant}
114
+ intent={intent}
115
+ loading={loading}
116
+ disabled={disabled}
117
+ onPress={jest.fn()}
118
+ />
119
+ );
120
+
121
+ expect(toJSON()).toMatchSnapshot();
122
+ });
78
123
  });
79
124
 
80
125
  describe('getThemeVariant', () => {