@hero-design/rn 8.27.0 → 8.27.2

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 (44) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/assets/fonts/hero-icons-mobile.ttf +0 -0
  3. package/es/index.js +319 -311
  4. package/lib/assets/fonts/hero-icons-mobile.ttf +0 -0
  5. package/lib/index.js +319 -311
  6. package/package.json +5 -5
  7. package/src/components/DatePicker/__tests__/__snapshots__/DatePicker.spec.tsx.snap +6 -6
  8. package/src/components/DatePicker/__tests__/__snapshots__/DatePickerAndroid.spec.tsx.snap +2 -2
  9. package/src/components/DatePicker/__tests__/__snapshots__/DatePickerCalendar.spec.tsx.snap +2 -2
  10. package/src/components/DatePicker/__tests__/__snapshots__/DatePickerIOS.spec.tsx.snap +2 -2
  11. package/src/components/FAB/ActionGroup/StyledActionGroup.tsx +3 -17
  12. package/src/components/FAB/ActionGroup/__tests__/__snapshots__/index.spec.tsx.snap +1065 -557
  13. package/src/components/FAB/ActionGroup/__tests__/index.spec.tsx +15 -9
  14. package/src/components/FAB/ActionGroup/index.tsx +35 -97
  15. package/src/components/Icon/HeroIcon/glyphMap.json +1 -1
  16. package/src/components/Icon/IconList.ts +1 -0
  17. package/src/components/Select/MultiSelect/__tests__/__snapshots__/index.spec.tsx.snap +10 -10
  18. package/src/components/Select/SingleSelect/__tests__/__snapshots__/index.spec.tsx.snap +10 -10
  19. package/src/components/TextInput/__tests__/__snapshots__/index.spec.tsx.snap +10 -10
  20. package/src/components/TextInput/index.tsx +1 -1
  21. package/src/components/TimePicker/__tests__/__snapshots__/TimePickerAndroid.spec.tsx.snap +2 -2
  22. package/src/components/TimePicker/__tests__/__snapshots__/TimePickerIOS.spec.tsx.snap +2 -2
  23. package/src/components/Toolbar/StyledToolbar.tsx +23 -2
  24. package/src/components/Toolbar/ToolbarGroup.tsx +3 -4
  25. package/src/components/Toolbar/ToolbarItem.tsx +75 -19
  26. package/src/components/Toolbar/__tests__/ToolbarItem.spec.tsx +39 -22
  27. package/src/components/Toolbar/__tests__/__snapshots__/ToolbarGroup.spec.tsx.snap +318 -186
  28. package/src/components/Toolbar/__tests__/__snapshots__/ToolbarItem.spec.tsx.snap +280 -135
  29. package/src/components/Typography/Text/StyledText.tsx +2 -1
  30. package/src/components/Typography/Text/index.tsx +2 -1
  31. package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +11 -2
  32. package/src/theme/components/fab.ts +0 -1
  33. package/src/theme/components/toolbar.ts +14 -2
  34. package/src/theme/components/typography.ts +1 -0
  35. package/types/components/FAB/ActionGroup/StyledActionGroup.d.ts +1 -7
  36. package/types/components/Icon/IconList.d.ts +1 -1
  37. package/types/components/Icon/index.d.ts +1 -1
  38. package/types/components/Icon/utils.d.ts +1 -1
  39. package/types/components/Toolbar/StyledToolbar.d.ts +11 -1
  40. package/types/components/Typography/Text/StyledText.d.ts +1 -1
  41. package/types/components/Typography/Text/index.d.ts +1 -1
  42. package/types/theme/components/fab.d.ts +0 -1
  43. package/types/theme/components/toolbar.d.ts +9 -0
  44. package/types/theme/components/typography.d.ts +1 -0
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { ToolbarGroupWrapper } from './StyledToolbar';
3
3
  import ToolbarItem from './ToolbarItem';
4
4
  import type { ToolbarItemProps } from './ToolbarItem';
5
+ import { useDeprecation } from '../../utils/hooks';
5
6
 
6
7
  export interface ToolbarGroupProps {
7
8
  /**
@@ -15,9 +16,8 @@ export interface ToolbarGroupProps {
15
16
  }
16
17
 
17
18
  const ToolbarGroup = ({ align = 'right', items = [] }: ToolbarGroupProps) => {
18
- // set maxWidth prevents overflow of items
19
- // issue: https://github.com/Thinkei/hero-design/issues/1619
20
- const maxWidth = items.length > 0 ? `${100 / items.length}%` : undefined;
19
+ useDeprecation("Toolbar's align prop is deprecated", align !== 'right');
20
+
21
21
  return (
22
22
  <ToolbarGroupWrapper align={align}>
23
23
  {items.map(({ label, icon, onPress, disabled, intent }) => (
@@ -28,7 +28,6 @@ const ToolbarGroup = ({ align = 'right', items = [] }: ToolbarGroupProps) => {
28
28
  intent={intent}
29
29
  onPress={onPress}
30
30
  disabled={disabled}
31
- style={{ maxWidth }}
32
31
  />
33
32
  ))}
34
33
  </ToolbarGroupWrapper>
@@ -2,7 +2,11 @@ import React from 'react';
2
2
  import { StyleProp, ViewStyle } from 'react-native';
3
3
  import Icon from '../Icon';
4
4
  import Typography from '../Typography';
5
- import { ToolbarItemWrapper } from './StyledToolbar';
5
+ import {
6
+ IconButtonLabel,
7
+ IconButtonWrapper,
8
+ ToolbarItemWrapper,
9
+ } from './StyledToolbar';
6
10
  import type { IconName } from '../Icon';
7
11
 
8
12
  export interface ToolbarItemProps {
@@ -33,35 +37,87 @@ export interface ToolbarItemProps {
33
37
  style?: StyleProp<ViewStyle>;
34
38
  }
35
39
 
36
- const ToolbarItem = ({
37
- icon,
38
- label,
39
- onPress,
40
- intent = 'primary',
41
- disabled = false,
42
- style,
43
- }: ToolbarItemProps) => (
44
- <ToolbarItemWrapper onPress={onPress} disabled={disabled} style={style}>
45
- {icon ? (
40
+ type IconItemProps = {
41
+ icon: IconName;
42
+ label?: string;
43
+ intent?: ToolbarItemProps['intent'];
44
+ disabled?: boolean;
45
+ };
46
+
47
+ const IconItem = ({ icon, intent, disabled, label }: IconItemProps) => {
48
+ return (
49
+ <IconButtonWrapper>
46
50
  <Icon
47
51
  icon={icon}
48
- size={label ? 'medium' : 'large'}
52
+ size="medium"
49
53
  intent={disabled ? 'disabled-text' : intent}
50
54
  testID={`toolbar-item-icon-${icon}`}
51
55
  />
52
- ) : null}
53
- {label ? (
56
+ {label ? (
57
+ <IconButtonLabel
58
+ fontSize="large"
59
+ fontWeight="semi-bold"
60
+ intent={disabled ? 'subdued' : intent}
61
+ allowFontScaling={false}
62
+ numberOfLines={1}
63
+ >
64
+ {label}
65
+ </IconButtonLabel>
66
+ ) : null}
67
+ </IconButtonWrapper>
68
+ );
69
+ };
70
+
71
+ type ToolbarItemContentProps = {
72
+ icon?: IconName;
73
+ label?: string;
74
+ intent?: ToolbarItemProps['intent'];
75
+ disabled?: boolean;
76
+ };
77
+ const ToolbarItemContent = ({
78
+ icon,
79
+ label,
80
+ intent = 'primary',
81
+ disabled = false,
82
+ }: ToolbarItemContentProps): JSX.Element | null => {
83
+ if (icon) {
84
+ return (
85
+ <IconItem icon={icon} intent={intent} disabled={disabled} label={label} />
86
+ );
87
+ }
88
+ if (label) {
89
+ return (
54
90
  <Typography.Text
55
- fontSize={icon ? 'small' : 'large'}
91
+ fontSize="large"
56
92
  fontWeight="semi-bold"
57
- intent={disabled ? 'subdued' : intent}
93
+ intent={disabled ? 'disabled' : intent}
58
94
  allowFontScaling={false}
59
95
  numberOfLines={1}
60
96
  >
61
97
  {label}
62
98
  </Typography.Text>
63
- ) : null}
64
- </ToolbarItemWrapper>
65
- );
99
+ );
100
+ }
101
+ return null;
102
+ };
103
+ const ToolbarItem = ({
104
+ icon,
105
+ label,
106
+ onPress,
107
+ intent = 'primary',
108
+ disabled = false,
109
+ style,
110
+ }: ToolbarItemProps) => {
111
+ return (
112
+ <ToolbarItemWrapper onPress={onPress} disabled={disabled} style={style}>
113
+ <ToolbarItemContent
114
+ icon={icon}
115
+ label={label}
116
+ intent={intent}
117
+ disabled={disabled}
118
+ />
119
+ </ToolbarItemWrapper>
120
+ );
121
+ };
66
122
 
67
123
  export default ToolbarItem;
@@ -5,30 +5,47 @@ import ToolbarItem from '../ToolbarItem';
5
5
 
6
6
  describe('ToolbarItems', () => {
7
7
  it.each`
8
- intent
9
- ${'primary'}
10
- ${'info'}
11
- ${'success'}
12
- ${'danger'}
13
- ${'warning'}
14
- `('renders correctly when intent is $intent', ({ intent }) => {
15
- const onPress = jest.fn();
16
- const { toJSON, getByText, getByTestId } = renderWithTheme(
17
- <ToolbarItem
18
- label="Action"
19
- intent={intent}
20
- icon="home"
21
- onPress={onPress}
22
- />
23
- );
8
+ intent | icon | label | disabled
9
+ ${'primary'} | ${'ai-outlined'} | ${'Try again'} | ${false}
10
+ ${'primary'} | ${'ai-outlined'} | ${undefined} | ${false}
11
+ ${'primary'} | ${'ai-outlined'} | ${'Try again'} | ${true}
12
+ ${'info'} | ${undefined} | ${'Save'} | ${false}
13
+ ${'success'} | ${undefined} | ${'Save'} | ${false}
14
+ ${'danger'} | ${undefined} | ${'Discard'} | ${false}
15
+ ${'warning'} | ${undefined} | ${'Warning'} | ${false}
16
+ `(
17
+ 'renders correctly when intent is $intent, icon is $icon, label is $label and disabled is $disabled',
18
+ ({ intent, icon, label, disabled }) => {
19
+ const onPress = jest.fn();
20
+ const { toJSON, getByText, getByTestId } = renderWithTheme(
21
+ <ToolbarItem
22
+ label={label}
23
+ intent={intent}
24
+ icon={icon}
25
+ onPress={onPress}
26
+ disabled={disabled}
27
+ />
28
+ );
24
29
 
25
- expect(toJSON()).toMatchSnapshot();
26
- expect(getByText('Action')).toBeDefined();
27
- expect(getByTestId('toolbar-item-icon-home')).toBeDefined();
30
+ expect(toJSON()).toMatchSnapshot();
31
+ if (icon) {
32
+ expect(getByTestId(`toolbar-item-icon-${icon}`)).toBeDefined();
33
+ }
28
34
 
29
- fireEvent.press(getByText('Action'));
30
- expect(onPress).toBeCalled();
31
- });
35
+ if (label) {
36
+ expect(getByText(label)).toBeDefined();
37
+ fireEvent.press(getByText(label));
38
+ if (disabled) {
39
+ expect(onPress).not.toBeCalled();
40
+ } else {
41
+ expect(onPress).toBeCalled();
42
+ }
43
+ } else {
44
+ fireEvent.press(getByTestId(`toolbar-item-icon-${icon}`));
45
+ expect(onPress).toBeCalled();
46
+ }
47
+ }
48
+ );
32
49
 
33
50
  it('renders correctly when disabled', () => {
34
51
  const onPress = jest.fn();