@ovotech/element-native 5.5.0 → 5.6.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.
Files changed (237) hide show
  1. package/dist/components/Accordion/styles.d.ts +9 -0
  2. package/dist/components/ActionList/Action.d.ts +23 -0
  3. package/dist/components/ActionList/Action.js +29 -0
  4. package/dist/components/ActionList/ActionList.d.ts +11 -27
  5. package/dist/components/ActionList/ActionList.js +9 -25
  6. package/dist/components/ActionList/ActionListItems/DataListItem.d.ts +23 -0
  7. package/dist/components/ActionList/ActionListItems/DataListItem.js +21 -0
  8. package/dist/components/ActionList/ActionListItems/EditableListItem.d.ts +43 -0
  9. package/dist/components/ActionList/ActionListItems/EditableListItem.js +134 -0
  10. package/dist/components/ActionList/ActionListItems/NavigationListItem.d.ts +16 -0
  11. package/dist/components/ActionList/ActionListItems/NavigationListItem.js +30 -0
  12. package/dist/components/ActionList/ActionListItems/ProgressRing.d.ts +7 -0
  13. package/dist/components/ActionList/ActionListItems/ProgressRing.js +66 -0
  14. package/dist/components/ActionList/ActionListItems/ToggleListItem.d.ts +9 -0
  15. package/dist/components/ActionList/ActionListItems/ToggleListItem.js +13 -0
  16. package/dist/components/ActionList/ActionListItems/styles.d.ts +10433 -0
  17. package/dist/components/ActionList/ActionListItems/styles.js +171 -0
  18. package/dist/components/ActionList/components/ActionListHeading.d.ts +9 -0
  19. package/dist/components/ActionList/components/ActionListHeading.js +11 -0
  20. package/dist/components/ActionList/index.d.ts +6 -1
  21. package/dist/components/ActionList/index.js +11 -2
  22. package/dist/components/ActionList/styled.d.ts +1187 -7
  23. package/dist/components/ActionList/styled.js +24 -9
  24. package/dist/components/Badge/Badge.d.ts +3 -0
  25. package/dist/components/Button/Button.js +1 -1
  26. package/dist/components/Button/Button.styles.d.ts +12 -0
  27. package/dist/components/Card/Card.d.ts +7 -4
  28. package/dist/components/Card/Card.js +44 -22
  29. package/dist/components/Card/Card.styles.d.ts +11 -1
  30. package/dist/components/Card/Card.styles.js +7 -11
  31. package/dist/components/Cards/AccountCard/AccountCard.styles.d.ts +24 -0
  32. package/dist/components/Cards/BalanceCard/BalanceCard.styles.d.ts +46 -1
  33. package/dist/components/Cards/BalanceCard/BalanceCard.styles.js +2 -2
  34. package/dist/components/Cards/DisruptiveCard/DisruptiveCard.d.ts +13 -0
  35. package/dist/components/Cards/DisruptiveCard/DisruptiveCard.js +45 -0
  36. package/dist/components/Cards/DisruptiveCard/DisruptiveCard.styles.d.ts +580 -0
  37. package/dist/components/Cards/DisruptiveCard/DisruptiveCard.styles.js +11 -0
  38. package/dist/components/Cards/DisruptiveCard/index.d.ts +1 -0
  39. package/dist/components/Cards/DisruptiveCard/index.js +17 -0
  40. package/dist/components/Cards/HeroImageCard/HeroImageCard.d.ts +12 -0
  41. package/dist/components/Cards/HeroImageCard/HeroImageCard.js +65 -0
  42. package/dist/components/Cards/HeroImageCard/HeroImageCard.styles.d.ts +1741 -0
  43. package/dist/components/Cards/HeroImageCard/HeroImageCard.styles.js +27 -0
  44. package/dist/components/Cards/HeroImageCard/index.d.ts +1 -0
  45. package/dist/components/Cards/HeroImageCard/index.js +17 -0
  46. package/dist/components/Cards/IconDataCard/IconDataCard.styles.d.ts +12 -0
  47. package/dist/components/Cards/IconTextCard/IconTextCard.js +3 -16
  48. package/dist/components/Cards/IconTextCard/IconTextCard.styles.d.ts +10 -576
  49. package/dist/components/Cards/IconTextCard/IconTextCard.styles.js +1 -6
  50. package/dist/components/Cards/IllustrationTextCard/IllustrationTextCard.d.ts +14 -0
  51. package/dist/components/Cards/IllustrationTextCard/IllustrationTextCard.js +26 -0
  52. package/dist/components/Cards/IllustrationTextCard/IllustrationTextCard.styles.d.ts +2903 -0
  53. package/dist/components/Cards/IllustrationTextCard/IllustrationTextCard.styles.js +34 -0
  54. package/dist/components/Cards/IllustrationTextCard/index.d.ts +1 -0
  55. package/dist/components/Cards/IllustrationTextCard/index.js +17 -0
  56. package/dist/components/Cards/LinkTextCard/LinkTextCard.d.ts +2 -2
  57. package/dist/components/Cards/LinkTextCard/LinkTextCard.js +7 -6
  58. package/dist/components/Cards/LinkTextCard/LinkTextCard.styles.d.ts +20 -2
  59. package/dist/components/Cards/LinkTextCard/LinkTextCard.styles.js +9 -6
  60. package/dist/components/Cards/ProgressBarCard/ProgressBarCard.styles.d.ts +28 -1
  61. package/dist/components/Cards/QuickLinkCard/QuickLinkCard.d.ts +12 -0
  62. package/dist/components/Cards/QuickLinkCard/QuickLinkCard.js +27 -0
  63. package/dist/components/Cards/QuickLinkCard/QuickLinkCard.styles.d.ts +2897 -0
  64. package/dist/components/Cards/QuickLinkCard/QuickLinkCard.styles.js +31 -0
  65. package/dist/components/Cards/QuickLinkCard/index.d.ts +1 -0
  66. package/dist/components/Cards/QuickLinkCard/index.js +17 -0
  67. package/dist/components/Cards/ServicesImageCard/ServicesImageCard.d.ts +12 -0
  68. package/dist/components/Cards/ServicesImageCard/ServicesImageCard.js +24 -0
  69. package/dist/components/Cards/ServicesImageCard/ServicesImageCard.styles.d.ts +2902 -0
  70. package/dist/components/Cards/ServicesImageCard/ServicesImageCard.styles.js +38 -0
  71. package/dist/components/Cards/ServicesImageCard/index.d.ts +1 -0
  72. package/dist/components/Cards/ServicesImageCard/index.js +17 -0
  73. package/dist/components/Cards/components.d.ts +15 -0
  74. package/dist/components/Cards/components.js +24 -0
  75. package/dist/components/Cards/index.d.ts +5 -0
  76. package/dist/components/Cards/index.js +11 -1
  77. package/dist/components/Cards/shared.styles.d.ts +2835 -505
  78. package/dist/components/Cards/shared.styles.js +18 -2
  79. package/dist/components/Cards/utils.d.ts +1 -0
  80. package/dist/components/Cards/utils.js +13 -1
  81. package/dist/components/Checkbox/Checkbox.d.ts +2 -13
  82. package/dist/components/Checkbox/Checkbox.js +3 -49
  83. package/dist/components/Checkbox/styled.d.ts +3483 -0
  84. package/dist/components/Checkbox/styled.js +52 -0
  85. package/dist/components/Checkbox/types.d.ts +16 -0
  86. package/dist/components/Checkbox/types.js +2 -0
  87. package/dist/components/CurrencyInput/CurrencyInput.d.ts +2 -1
  88. package/dist/components/CurrencyInput/CurrencyInput.js +11 -4
  89. package/dist/components/CurrencyInput/styled.d.ts +2318 -0
  90. package/dist/components/CurrencyInput/styled.js +39 -0
  91. package/dist/components/DataTable/styles.d.ts +39 -0
  92. package/dist/components/Disclosure/Disclosure.d.ts +3 -0
  93. package/dist/components/Divider/Divider.d.ts +1 -1
  94. package/dist/components/Divider/Divider.js +3 -1
  95. package/dist/components/Em/Em.d.ts +3 -0
  96. package/dist/components/EmailInput/EmailInput.d.ts +4 -1
  97. package/dist/components/EmailInput/EmailInput.js +18 -2
  98. package/dist/components/EmptyState/EmptyState.d.ts +2 -0
  99. package/dist/components/EmptyState/EmptyState.js +17 -0
  100. package/dist/components/EmptyState/EmptyState.test.d.ts +1 -0
  101. package/dist/components/EmptyState/EmptyState.test.js +92 -0
  102. package/dist/components/EmptyState/index.d.ts +1 -0
  103. package/dist/components/EmptyState/index.js +17 -0
  104. package/dist/components/EmptyState/styles.d.ts +1156 -0
  105. package/dist/components/EmptyState/styles.js +23 -0
  106. package/dist/components/EmptyState/types.d.ts +18 -0
  107. package/dist/components/EmptyState/types.js +2 -0
  108. package/dist/components/ErrorText/ErrorText.d.ts +3 -0
  109. package/dist/components/Field/Field.d.ts +3 -2
  110. package/dist/components/Field/Field.js +3 -2
  111. package/dist/components/Grid/Col.d.ts +3 -0
  112. package/dist/components/HintText/HintText.d.ts +3 -0
  113. package/dist/components/Input/Input.d.ts +2 -1
  114. package/dist/components/Input/Input.js +6 -97
  115. package/dist/components/Input/styled.d.ts +1747 -0
  116. package/dist/components/Input/styled.js +96 -0
  117. package/dist/components/LabelText/LabelText.d.ts +3 -0
  118. package/dist/components/LargeValueReference/LargeValueReference.d.ts +11 -0
  119. package/dist/components/LargeValueReference/LargeValueReference.js +49 -0
  120. package/dist/components/LargeValueReference/index.d.ts +1 -0
  121. package/dist/components/LargeValueReference/index.js +17 -0
  122. package/dist/components/LargeValueReference/styles.d.ts +1741 -0
  123. package/dist/components/LargeValueReference/styles.js +29 -0
  124. package/dist/components/LineThrough/LineThrough.d.ts +3 -0
  125. package/dist/components/List/styled.d.ts +12 -0
  126. package/dist/components/Margin/Margin.d.ts +3 -0
  127. package/dist/components/NavHeader/NavHeader.styles.d.ts +33 -0
  128. package/dist/components/Notification/Notification.styles.d.ts +27 -0
  129. package/dist/components/PasswordInput/PasswordInput.styled.d.ts +4 -3
  130. package/dist/components/PasswordInput/PasswordInput.styled.js +5 -3
  131. package/dist/components/PasswordInput/PasswordVisibilityToggle.js +2 -8
  132. package/dist/components/RadioCard/RadioCard.d.ts +2 -1
  133. package/dist/components/RadioCard/RadioCard.js +7 -57
  134. package/dist/components/RadioCard/RadioCard.styles.d.ts +2901 -0
  135. package/dist/components/RadioCard/RadioCard.styles.js +97 -0
  136. package/dist/components/SelectField/Select.d.ts +5 -579
  137. package/dist/components/SelectField/Select.js +7 -107
  138. package/dist/components/SelectField/SelectField.d.ts +2 -2
  139. package/dist/components/SelectField/SelectField.js +2 -2
  140. package/dist/components/SelectField/styled.d.ts +4642 -0
  141. package/dist/components/SelectField/styled.js +118 -0
  142. package/dist/components/SkeletonText/SkeletonText.js +4 -4
  143. package/dist/components/Strong/Strong.d.ts +3 -0
  144. package/dist/components/SubLabelText/SubLabelText.d.ts +3 -0
  145. package/dist/components/Tabs/Tab.d.ts +3 -0
  146. package/dist/components/TextareaInput/TextareaInput.js +12 -6
  147. package/dist/components/Toggle/Toggle.d.ts +3 -1
  148. package/dist/components/Toggle/Toggle.js +4 -6
  149. package/dist/components/Toggle/styles.d.ts +13 -0
  150. package/dist/components/Toggle/styles.js +3 -3
  151. package/dist/components/index.d.ts +3 -0
  152. package/dist/components/index.js +3 -0
  153. package/dist/esm/components/ActionList/Action.js +26 -0
  154. package/dist/esm/components/ActionList/ActionList.js +12 -28
  155. package/dist/esm/components/ActionList/ActionListItems/DataListItem.js +17 -0
  156. package/dist/esm/components/ActionList/ActionListItems/EditableListItem.js +131 -0
  157. package/dist/esm/components/ActionList/ActionListItems/NavigationListItem.js +26 -0
  158. package/dist/esm/components/ActionList/ActionListItems/ProgressRing.js +29 -0
  159. package/dist/esm/components/ActionList/ActionListItems/ToggleListItem.js +9 -0
  160. package/dist/esm/components/ActionList/ActionListItems/styles.js +135 -0
  161. package/dist/esm/components/ActionList/components/ActionListHeading.js +7 -0
  162. package/dist/esm/components/ActionList/index.js +6 -1
  163. package/dist/esm/components/ActionList/styled.js +23 -8
  164. package/dist/esm/components/Button/Button.js +1 -1
  165. package/dist/esm/components/Card/Card.js +45 -23
  166. package/dist/esm/components/Card/Card.styles.js +8 -12
  167. package/dist/esm/components/Cards/BalanceCard/BalanceCard.styles.js +2 -2
  168. package/dist/esm/components/Cards/DisruptiveCard/DisruptiveCard.js +41 -0
  169. package/dist/esm/components/Cards/DisruptiveCard/DisruptiveCard.styles.js +5 -0
  170. package/dist/esm/components/Cards/DisruptiveCard/index.js +1 -0
  171. package/dist/esm/components/Cards/HeroImageCard/HeroImageCard.js +28 -0
  172. package/dist/esm/components/Cards/HeroImageCard/HeroImageCard.styles.js +21 -0
  173. package/dist/esm/components/Cards/HeroImageCard/index.js +1 -0
  174. package/dist/esm/components/Cards/IconTextCard/IconTextCard.js +5 -18
  175. package/dist/esm/components/Cards/IconTextCard/IconTextCard.styles.js +0 -5
  176. package/dist/esm/components/Cards/IllustrationTextCard/IllustrationTextCard.js +22 -0
  177. package/dist/esm/components/Cards/IllustrationTextCard/IllustrationTextCard.styles.js +28 -0
  178. package/dist/esm/components/Cards/IllustrationTextCard/index.js +1 -0
  179. package/dist/esm/components/Cards/LinkTextCard/LinkTextCard.js +7 -6
  180. package/dist/esm/components/Cards/LinkTextCard/LinkTextCard.styles.js +9 -6
  181. package/dist/esm/components/Cards/QuickLinkCard/QuickLinkCard.js +23 -0
  182. package/dist/esm/components/Cards/QuickLinkCard/QuickLinkCard.styles.js +25 -0
  183. package/dist/esm/components/Cards/QuickLinkCard/index.js +1 -0
  184. package/dist/esm/components/Cards/ServicesImageCard/ServicesImageCard.js +20 -0
  185. package/dist/esm/components/Cards/ServicesImageCard/ServicesImageCard.styles.js +32 -0
  186. package/dist/esm/components/Cards/ServicesImageCard/index.js +1 -0
  187. package/dist/esm/components/Cards/components.js +19 -0
  188. package/dist/esm/components/Cards/index.js +5 -0
  189. package/dist/esm/components/Cards/shared.styles.js +17 -1
  190. package/dist/esm/components/Cards/utils.js +11 -0
  191. package/dist/esm/components/Checkbox/Checkbox.js +2 -45
  192. package/dist/esm/components/Checkbox/styled.js +46 -0
  193. package/dist/esm/components/Checkbox/types.js +1 -0
  194. package/dist/esm/components/CurrencyInput/CurrencyInput.js +12 -5
  195. package/dist/esm/components/CurrencyInput/styled.js +33 -0
  196. package/dist/esm/components/Divider/Divider.js +3 -1
  197. package/dist/esm/components/EmailInput/EmailInput.js +18 -2
  198. package/dist/esm/components/EmptyState/EmptyState.js +13 -0
  199. package/dist/esm/components/EmptyState/EmptyState.test.js +90 -0
  200. package/dist/esm/components/EmptyState/index.js +1 -0
  201. package/dist/esm/components/EmptyState/styles.js +17 -0
  202. package/dist/esm/components/EmptyState/types.js +1 -0
  203. package/dist/esm/components/Field/Field.js +3 -2
  204. package/dist/esm/components/Input/Input.js +6 -64
  205. package/dist/esm/components/Input/styled.js +60 -0
  206. package/dist/esm/components/LargeValueReference/LargeValueReference.js +45 -0
  207. package/dist/esm/components/LargeValueReference/index.js +1 -0
  208. package/dist/esm/components/LargeValueReference/styles.js +23 -0
  209. package/dist/esm/components/PasswordInput/PasswordInput.styled.js +5 -3
  210. package/dist/esm/components/PasswordInput/PasswordVisibilityToggle.js +2 -8
  211. package/dist/esm/components/RadioCard/RadioCard.js +5 -52
  212. package/dist/esm/components/RadioCard/RadioCard.styles.js +61 -0
  213. package/dist/esm/components/SelectField/Select.js +7 -74
  214. package/dist/esm/components/SelectField/SelectField.js +3 -3
  215. package/dist/esm/components/SelectField/styled.js +82 -0
  216. package/dist/esm/components/SkeletonText/SkeletonText.js +4 -4
  217. package/dist/esm/components/TextareaInput/TextareaInput.js +12 -6
  218. package/dist/esm/components/Toggle/Toggle.js +4 -6
  219. package/dist/esm/components/Toggle/styles.js +3 -3
  220. package/dist/esm/components/index.js +3 -0
  221. package/dist/esm/hooks/use-font-scaling.js +32 -0
  222. package/dist/esm/index.js +1 -0
  223. package/dist/esm/test/utils.js +12 -0
  224. package/dist/esm/utils/utils.js +12 -1
  225. package/dist/hooks/use-font-scaling.d.ts +26 -0
  226. package/dist/hooks/use-font-scaling.js +35 -0
  227. package/dist/index.d.ts +1 -0
  228. package/dist/index.js +1 -0
  229. package/dist/styled.native.d.ts +18 -0
  230. package/dist/test/utils.d.ts +4 -0
  231. package/dist/test/utils.js +28 -0
  232. package/dist/utils/utils.d.ts +11 -1
  233. package/dist/utils/utils.js +12 -0
  234. package/package.json +4 -4
  235. package/dist/components/ErrorWrapper/styles.d.ts +0 -0
  236. package/dist/components/ErrorWrapper/styles.js +0 -1
  237. package/dist/esm/components/ErrorWrapper/styles.js +0 -1
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { usePictograms } from '../../providers';
3
+ import { useTheme } from '../../styled.native';
4
+ import { Heading4 } from '../Heading';
5
+ import { Pictogram } from '../Pictogram';
6
+ import { RemoteImage } from '../RemoteImage';
7
+ import { StyledCard, TextContainer } from './styles';
8
+ export const EmptyState = ({ backgroundStyle = 'filled', children, illustration, heading, pictogramName, }) => {
9
+ const pictograms = usePictograms();
10
+ const theme = useTheme();
11
+ const isFilledBackground = backgroundStyle === 'filled';
12
+ return (_jsxs(StyledCard, { testID: "empty-state-card", background: isFilledBackground ? theme.color.surface.bright : 'transparent', children: [(illustration === null || illustration === void 0 ? void 0 : illustration.uri) ? (_jsx(RemoteImage, Object.assign({ testID: "empty-state-illustration", resizeMode: "contain" }, illustration))) : null, pictogramName && pictograms[pictogramName] ? (_jsx(Pictogram, { testID: "empty-state-pictogram", size: 64, name: pictogramName })) : null, _jsxs(TextContainer, { children: [_jsx(Heading4, { style: { color: theme.color.surface.onSurface }, children: heading }), children] })] }));
13
+ };
@@ -0,0 +1,90 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Text } from 'react-native';
3
+ import { render } from '../../test/utils';
4
+ import { EmptyState } from './EmptyState';
5
+ jest.mock('../../providers', () => (Object.assign(Object.assign({}, jest.requireActual('../../providers')), { usePictograms: () => ({
6
+ 'test-pictogram': 'test-pictogram-data',
7
+ }) })));
8
+ const mockIllustration = {
9
+ uri: 'https://example.com/image.png',
10
+ width: 100,
11
+ height: 100,
12
+ };
13
+ const setup = (props) => {
14
+ return render(_jsx(EmptyState, Object.assign({}, props)));
15
+ };
16
+ describe('EmptyState', () => {
17
+ it('should render the heading and children', () => {
18
+ const { getByText } = setup({
19
+ heading: 'Default Heading',
20
+ children: _jsx(Text, { children: "Default Children" }),
21
+ pictogramName: 'test-pictogram',
22
+ });
23
+ expect(getByText('Default Heading')).toBeDefined();
24
+ expect(getByText('Default Children')).toBeDefined();
25
+ });
26
+ it('should have a filled background by default', () => {
27
+ const { getByTestId } = setup({
28
+ heading: 'Default Heading',
29
+ pictogramName: 'test-pictogram',
30
+ });
31
+ const card = getByTestId('empty-state-card');
32
+ expect(card.props.style.backgroundColor).not.toBe('transparent');
33
+ });
34
+ it("should have a transparent background when backgroundStyle is 'transparent'", () => {
35
+ const { getByTestId } = setup({
36
+ backgroundStyle: 'transparent',
37
+ heading: 'Default Heading',
38
+ pictogramName: 'test-pictogram',
39
+ });
40
+ const card = getByTestId('empty-state-card');
41
+ expect(card.props.style.backgroundColor).toBe('transparent');
42
+ });
43
+ it('should render an illustration if provided', () => {
44
+ const { getByTestId } = setup({
45
+ heading: 'Default Heading',
46
+ illustration: mockIllustration,
47
+ });
48
+ const image = getByTestId('empty-state-illustration');
49
+ expect(image).toBeDefined();
50
+ expect(image.props.source.uri).toBe(mockIllustration.uri);
51
+ });
52
+ it('should not render an illustration if uri is not provided', () => {
53
+ const { queryByTestId } = setup({
54
+ heading: 'Default Heading',
55
+ // @ts-expect-error - we are intentionally providing an illustration without a valid uri to test rendering logic
56
+ illustration: { height: 100, width: 100 },
57
+ });
58
+ expect(queryByTestId('empty-state-illustration')).toBeNull();
59
+ });
60
+ it('should render a pictogram if a valid pictogramName is provided', () => {
61
+ const { getByTestId } = setup({
62
+ heading: 'Default Heading',
63
+ pictogramName: 'test-pictogram',
64
+ });
65
+ expect(getByTestId('empty-state-pictogram')).toBeDefined();
66
+ });
67
+ it('should not render a pictogram if pictogramName is invalid', () => {
68
+ const { queryByTestId } = setup({
69
+ heading: 'Default Heading',
70
+ pictogramName: 'invalid-pictogram',
71
+ });
72
+ expect(queryByTestId('empty-state-pictogram')).toBeNull();
73
+ });
74
+ it('should render custom children', () => {
75
+ const { getByText } = render(_jsx(EmptyState, { heading: "Custom Heading", pictogramName: "test-pictogram", children: _jsx(Text, { children: "My Custom Child" }) }));
76
+ expect(getByText('My Custom Child')).toBeDefined();
77
+ });
78
+ it('should only render illustration when both illustration and pictogramName are provided', () => {
79
+ // According to the EmptyStateProps, only one of them should be present.
80
+ // However, if a user passes both, the component's internal logic will prioritize illustration.
81
+ // @ts-expect-error - we are intentionally passing both props to test runtime behavior
82
+ const { getByTestId, queryByTestId } = setup({
83
+ heading: 'Default Heading',
84
+ illustration: mockIllustration,
85
+ pictogramName: 'test-pictogram',
86
+ });
87
+ expect(getByTestId('empty-state-illustration')).toBeDefined();
88
+ expect(queryByTestId('empty-state-pictogram')).toBeNull();
89
+ });
90
+ });
@@ -0,0 +1 @@
1
+ export * from './EmptyState';
@@ -0,0 +1,17 @@
1
+ import styled from '../../styled.native';
2
+ import { Card } from '../Card';
3
+ export const StyledCard = styled(Card)(({ theme }) => ({
4
+ display: 'flex',
5
+ alignItems: 'center',
6
+ justifyContent: 'center',
7
+ gap: theme.space[100],
8
+ }));
9
+ export const TextContainer = styled.View(({ theme }) => ({
10
+ display: 'flex',
11
+ flexDirection: 'column',
12
+ width: '100%',
13
+ gap: theme.space[50],
14
+ paddingLeft: theme.space[400],
15
+ paddingRight: theme.space[400],
16
+ alignItems: 'center',
17
+ }));
@@ -0,0 +1 @@
1
+ export {};
@@ -20,7 +20,7 @@ import { LabelText } from '../LabelText';
20
20
  import { Stack } from '../Stack';
21
21
  import { Stretch } from '../Stretch';
22
22
  export const Field = (_a) => {
23
- var { children, label, optional = false, hint, error, fullWidth, characters = 25, affixWidth = 0, ref } = _a, rest = __rest(_a, ["children", "label", "optional", "hint", "error", "fullWidth", "characters", "affixWidth", "ref"]);
23
+ var { children, label, optional = false, hint, error, fullWidth, characters = 25, affixWidth = 0, ref, selected } = _a, rest = __rest(_a, ["children", "label", "optional", "hint", "error", "fullWidth", "characters", "affixWidth", "ref", "selected"]);
24
24
  const hasError = !!error;
25
25
  const inputRef = createRef();
26
26
  const labelText = optional ? `${label} (optional)` : label;
@@ -39,6 +39,7 @@ export const Field = (_a) => {
39
39
  }
40
40
  }
41
41
  }, children: _jsxs(View, { children: [_jsxs(LabelText, { children: [label, optional ? ' (optional)' : null] }), hint ? _jsx(HintText, { children: hint }) : null, error ? _jsx(ErrorText, { children: error }) : null] }) }), _jsx(Stretch, { defaultWidth: `${Math.ceil(characters * 0.8 * 16) + affixWidth}px`, fullWidth: fullWidth, children: Children.map(children, child => isValidElement(child)
42
- ? cloneElement(child, Object.assign({ invalid: hasError || undefined, ref: mergeRefs(inputRef, ref), accessibilityLabel }, rest))
42
+ ? cloneElement(child, Object.assign({ invalid: hasError || undefined, ref: mergeRefs(inputRef, ref), accessibilityLabel,
43
+ selected }, rest))
43
44
  : child) })] }) }));
44
45
  };
@@ -10,30 +10,16 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { numToPx } from '@ovotech/element-core';
14
13
  import { useState } from 'react';
15
14
  import { useBreakpoint } from '../../hooks';
16
- import styled, { css } from '../../styled.native';
17
- import { Icon } from '../Icon/Icon';
18
- const StyledIcon = styled(Icon)(({ theme, side, focused }) => {
19
- const focusCompensation = focused ? theme.space[50] : 0;
20
- return css `
21
- position: absolute;
22
- z-index: 1;
23
- top: ${numToPx(theme.space[350] + focusCompensation)};
24
- ${side === 'left'
25
- ? `left: ${numToPx(theme.space[200] + focusCompensation)}`
26
- : ''};
27
- ${side === 'right'
28
- ? `right: ${numToPx(theme.space[200] + focusCompensation)}`
29
- : ''};
30
- `;
31
- });
15
+ import { useTheme } from '../../styled.native';
16
+ import { ICON_SIZE, StyledIcon, StyledInput, StyledInputWrapper, } from './styled';
32
17
  const Input = (_a) => {
33
- var { onFocus, onBlur, style, iconLeft, iconRight, rightSlot, ref } = _a, rest = __rest(_a, ["onFocus", "onBlur", "style", "iconLeft", "iconRight", "rightSlot", "ref"]);
18
+ var { onFocus, onBlur, style, iconLeft, iconRight, invalid, rightSlot, ref, selected } = _a, rest = __rest(_a, ["onFocus", "onBlur", "style", "iconLeft", "iconRight", "invalid", "rightSlot", "ref", "selected"]);
34
19
  const [focused, setFocused] = useState(false);
35
20
  const breakpoints = useBreakpoint();
36
- return (_jsxs(InputWrapper, { focused: focused, children: [iconLeft ? (_jsx(StyledIcon, { name: iconLeft, size: 16, focused: focused, pointerEvents: "none", side: "left" })) : null, _jsx(StyledInput, Object.assign({}, rest, breakpoints, { iconLeft: !!iconLeft, iconRight: !!iconRight, hasRightSlot: !!rightSlot, style: style, ref: ref, onFocus: (event) => {
21
+ const theme = useTheme();
22
+ return (_jsxs(StyledInputWrapper, { focused: focused, hasError: invalid, isSelected: selected, children: [iconLeft ? (_jsx(StyledIcon, { name: iconLeft, size: ICON_SIZE, pointerEvents: "none", side: "left" })) : null, _jsx(StyledInput, Object.assign({}, rest, breakpoints, { hasRightSlot: !!rightSlot, iconLeft: !!iconLeft, iconRight: !!iconRight, invalid: invalid, placeholderTextColor: theme.color.surface.onSurfaceVariant, ref: ref, style: style, onFocus: (event) => {
37
23
  setFocused(true);
38
24
  if (onFocus) {
39
25
  onFocus(event);
@@ -43,50 +29,6 @@ const Input = (_a) => {
43
29
  if (onBlur) {
44
30
  onBlur(event);
45
31
  }
46
- } })), iconRight && !rightSlot ? (_jsx(StyledIcon, { name: iconRight, size: 16, focused: focused, pointerEvents: "none", side: "right" })) : null, rightSlot] }));
32
+ } })), iconRight && !rightSlot ? (_jsx(StyledIcon, { name: iconRight, size: ICON_SIZE, pointerEvents: "none", side: "right" })) : null, rightSlot] }));
47
33
  };
48
- const InputWrapper = styled.View(({ theme, focused }) => css `
49
- align-self: stretch;
50
- border-radius: ${numToPx(theme.border.radius.md)};
51
- border-width: 0;
52
- border-style: solid;
53
- border-color: ${theme.input.color.border};
54
- flex-direction: row;
55
-
56
- ${focused
57
- ? `
58
- border-width: ${numToPx(theme.border.width.md)};
59
- border-color: ${theme.color.outline.outer};
60
- padding: 2px;
61
- margin: -4px;`
62
- : null}
63
- `);
64
- const StyledInput = styled.TextInput(({ theme, invalid, smallAndUp, iconLeft, iconRight, hasRightSlot }) => {
65
- const fontSize = smallAndUp
66
- ? theme.font.size.md.mediaQuery.lg
67
- : theme.font.size.md.mediaQuery.sm;
68
- const errorStyles = invalid
69
- ? `
70
- border-color: ${theme.color.alert.error};
71
- `
72
- : '';
73
- return css `
74
- font-family: ${theme.native.font.family.book};
75
- color: ${theme.color.surface.onSurface};
76
- font-size: ${numToPx(fontSize)};
77
- height: ${numToPx(theme.space[1100])};
78
- line-height: 18px; /* Corrects for responsive line height in fixed height input */
79
- border: ${numToPx(theme.border.width.md)} solid ${theme.input.color.border};
80
- border-radius: ${numToPx(theme.border.radius.sm)};
81
- padding: ${numToPx(theme.space[200])};
82
- flex: 1;
83
-
84
- ${iconLeft ? `padding-left: ${numToPx(theme.space[800])};` : ''}
85
- ${iconRight || hasRightSlot
86
- ? `padding-right: ${numToPx(theme.space[800])};`
87
- : ''}
88
-
89
- ${errorStyles}
90
- `;
91
- });
92
34
  export { Input };
@@ -0,0 +1,60 @@
1
+ import styled, { css } from '../../styled.native';
2
+ import { numToPx } from '../../theme';
3
+ import { getShadowCSS } from '../../utils';
4
+ import { Icon } from '../Icon';
5
+ export const ICON_SIZE = 20;
6
+ export const StyledInputWrapper = styled.View(({ theme, focused, hasError, isSelected }) => {
7
+ let borderColor = 'transparent';
8
+ /* prioritise error and selected states for border, even when focused */
9
+ if (hasError) {
10
+ borderColor = theme.color.alert.error;
11
+ }
12
+ else if (isSelected) {
13
+ borderColor = theme.color.surface.onSurface;
14
+ }
15
+ else if (focused) {
16
+ borderColor = theme.color.outline.outer;
17
+ }
18
+ return css `
19
+ align-self: stretch;
20
+ background-color: ${theme.color.surface.bright};
21
+ border-radius: ${numToPx(theme.border.radius.md)};
22
+ border-width: ${numToPx(theme.border.width.md)};
23
+ border-style: solid;
24
+ border-color: ${borderColor};
25
+ flex-direction: row;
26
+ ${getShadowCSS({ theme })}
27
+ `;
28
+ });
29
+ export const StyledInput = styled.TextInput(({ theme, smallAndUp, iconLeft, iconRight, hasRightSlot }) => {
30
+ const fontSize = smallAndUp
31
+ ? theme.font.size.md.mediaQuery.lg
32
+ : theme.font.size.md.mediaQuery.sm;
33
+ return css `
34
+ position: relative;
35
+ flex: 1;
36
+ padding: ${numToPx(theme.space[400])};
37
+ border-radius: ${numToPx(theme.border.radius.lg)};
38
+ color: ${theme.color.surface.onSurface};
39
+ font-family: ${theme.native.font.family.book};
40
+ font-size: ${numToPx(fontSize)};
41
+
42
+ /* NOTE: height being queried with design, subject to change */
43
+ min-height: ${numToPx(theme.space[1600])};
44
+
45
+ ${iconLeft ? `padding-left: ${numToPx(theme.space[800])};` : ''}
46
+ ${iconRight || hasRightSlot
47
+ ? `padding-right: ${numToPx(theme.space[800])};`
48
+ : ''}
49
+ `;
50
+ });
51
+ export const StyledIcon = styled(Icon)(({ theme, side }) => {
52
+ return css `
53
+ position: absolute;
54
+ z-index: 1;
55
+ top: 50%;
56
+ margin-top: -${ICON_SIZE / 2}px;
57
+ ${side === 'left' ? `left: ${numToPx(theme.space[200])}` : ''};
58
+ ${side === 'right' ? `right: ${numToPx(theme.space[200])}` : ''};
59
+ `;
60
+ });
@@ -0,0 +1,45 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { useCallback, useMemo } from 'react';
14
+ import { TouchableOpacity } from 'react-native';
15
+ import { useTheme } from '../../styled.native';
16
+ import { Icon } from '../Icon';
17
+ import { LabelText } from '../LabelText';
18
+ import { Stack } from '../Stack';
19
+ import { LargeValue, LargeValueContainer, StyledLargeValueReferenceWrapper, } from './styles';
20
+ export const LargeValueReference = (_a) => {
21
+ var { value, autoSpacing = false, autoSpacingInterval = 5, label, onCopy, theme = 'bright' } = _a, rest = __rest(_a, ["value", "autoSpacing", "autoSpacingInterval", "label", "onCopy", "theme"]);
22
+ if (value === undefined || value === null || String(value).length === 0)
23
+ return null;
24
+ const elementTheme = useTheme();
25
+ // Normalizes JS's default scientific notation
26
+ const valueAsString = useMemo(() => typeof value === 'number'
27
+ ? value.toLocaleString('fullwide', {
28
+ useGrouping: false,
29
+ })
30
+ : value.toString(), [value]);
31
+ const splitValue = useMemo(() => {
32
+ if (autoSpacing && valueAsString.length > autoSpacingInterval) {
33
+ const matches = valueAsString.match(new RegExp(`.{1,${autoSpacingInterval}}`, 'g'));
34
+ return matches || [];
35
+ }
36
+ return [];
37
+ }, [autoSpacing, valueAsString, autoSpacingInterval]);
38
+ const handlePress = useCallback(() => {
39
+ // Call onCopy callback
40
+ if (typeof onCopy === 'function') {
41
+ onCopy(valueAsString);
42
+ }
43
+ }, [valueAsString, onCopy]);
44
+ return (_jsxs(Stack, { spaceBetween: 2, children: [label ? _jsx(LabelText, { children: label }) : null, _jsx(StyledLargeValueReferenceWrapper, Object.assign({ backgroundTheme: theme }, rest, { children: _jsxs(LargeValueContainer, { children: [autoSpacing && splitValue.length > 0 ? (splitValue.map((val, index) => (_jsx(LargeValue, { children: val }, index)))) : (_jsx(LargeValue, { children: valueAsString })), onCopy ? (_jsx(TouchableOpacity, { activeOpacity: 0.8, onPress: handlePress, hitSlop: 10, testID: "large-value-reference-copy-button", children: _jsx(Icon, { name: "copy", size: 20, color: elementTheme.color.surface.onSurface, testID: "large-value-reference-copy-icon" }) })) : null] }) }))] }));
45
+ };
@@ -0,0 +1 @@
1
+ export * from './LargeValueReference';
@@ -0,0 +1,23 @@
1
+ import { numToPx } from '@ovotech/element-core';
2
+ import styled from '../../styled.native';
3
+ import { P } from '../P';
4
+ export const StyledLargeValueReferenceWrapper = styled.View(({ theme, backgroundTheme }) => `
5
+ align-items: center;
6
+ max-width: ${'100%'};
7
+ gap: ${numToPx(theme.space[200])};
8
+ padding: ${numToPx(theme.space[400])};
9
+ background-color: ${theme.color.surface[backgroundTheme]};
10
+ border-radius: ${numToPx(theme.border.radius.lg)};
11
+ border: ${numToPx(theme.border.width.sm)} solid ${theme.color.surface.borderDim};
12
+ `);
13
+ export const LargeValueContainer = styled.View(({ theme }) => `
14
+ flex-direction: row;
15
+ flex-wrap: wrap;
16
+ align-items: center;
17
+ justify-content: center;
18
+ gap: ${numToPx(theme.space[200])};
19
+ `);
20
+ export const LargeValue = styled(P)(() => `
21
+ font-family: monospace;
22
+ letter-spacing: 2px;
23
+ `);
@@ -1,14 +1,16 @@
1
1
  import { numToPx } from '@ovotech/element-core';
2
2
  import { Pressable } from 'react-native';
3
3
  import styled, { css } from '../../styled.native';
4
- export const StyledPressable = styled(Pressable)(({ theme, focused, }) => {
4
+ import { ICON_SIZE } from '../Input/styled';
5
+ export const StyledPressable = styled(Pressable)(({ theme }) => {
5
6
  return css `
6
7
  display: flex;
7
8
  align-items: center;
8
9
  position: absolute;
9
10
  width: ${numToPx(theme.space[400])};
10
11
  z-index: 1;
11
- top: ${focused ? '16px' : '14px'};
12
- right: ${numToPx(theme.space[300])};
12
+ top: 50%;
13
+ margin-top: -${numToPx(ICON_SIZE / 2)};
14
+ right: ${numToPx(theme.space[400])};
13
15
  `;
14
16
  });
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
3
  import { Icon } from '../Icon';
4
+ import { ICON_SIZE } from '../Input/styled';
4
5
  import { StyledPressable } from './PasswordInput.styled';
5
6
  export const useTogglePasswordVisibility = () => {
6
7
  const [isPasswordVisible, setIsPasswordVisible] = useState(false);
@@ -12,11 +13,4 @@ export const useTogglePasswordVisibility = () => {
12
13
  handlePasswordVisibility,
13
14
  };
14
15
  };
15
- export const PasswordVisibilityToggle = ({ iconName, visibilityToggleLabel, handlePasswordVisibility, }) => {
16
- const [focused, setFocused] = useState(false);
17
- return (_jsx(StyledPressable, { testID: "password-input-visibility-toggle", focused: focused, accessible: true, accessibilityRole: "button", accessibilityLabel: visibilityToggleLabel, onPress: handlePasswordVisibility, hitSlop: 16, onFocus: () => {
18
- setFocused(true);
19
- }, onBlur: () => {
20
- setFocused(false);
21
- }, children: _jsx(Icon, { name: iconName, size: 16, pointerEvents: "none" }) }));
22
- };
16
+ export const PasswordVisibilityToggle = ({ iconName, visibilityToggleLabel, handlePasswordVisibility, }) => (_jsx(StyledPressable, { testID: "password-input-visibility-toggle", accessible: true, accessibilityRole: "button", accessibilityLabel: visibilityToggleLabel, onPress: handlePasswordVisibility, hitSlop: ICON_SIZE, children: _jsx(Icon, { name: iconName, size: ICON_SIZE, pointerEvents: "none" }) }));
@@ -10,61 +10,14 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { numToPx } from '@ovotech/element-core';
14
13
  import { TouchableOpacity, } from 'react-native';
15
- import { css } from 'styled-components';
16
- import styled from '../../styled.native';
17
14
  import { LabelText } from '../LabelText';
18
- const StyledRadioInputWrapper = styled.View(({ theme }) => {
19
- return `
20
- width: ${numToPx(theme.space[600])};
21
- height: ${numToPx(theme.space[600])};
22
- margin-top: ${numToPx(theme.space[200])};
23
- `;
24
- });
25
- const StyledRadioInput = styled.View(({ theme, invalid, checked }) => {
26
- return `
27
- width: ${numToPx(theme.space[600])};
28
- height: ${numToPx(theme.space[600])};
29
- border: ${numToPx(theme.border.width.md)} solid;
30
- align-items: center;
31
- justify-content: center;
32
- border-radius: ${numToPx(theme.space[600])};
33
- border-color: ${invalid
34
- ? theme.input.color.borderError
35
- : checked
36
- ? theme.input.color.selected
37
- : theme.input.color.border};
38
- background: ${checked ? theme.input.color.selectedTint : 'transparent'};
39
- `;
40
- });
41
- const StyledRadioInputDot = styled.View(({ theme, checked }) => {
42
- return `
43
- width: ${numToPx(theme.space[300])};
44
- height: ${numToPx(theme.space[300])};
45
- border-radius: ${numToPx(theme.space[300])};
46
- background: ${theme.input.color.selected};
47
- opacity: ${checked ? 1 : 0};
48
- `;
49
- });
15
+ import { StyledRadioInput, StyledRadioInputDot, StyledRadioInputWrapper, StyledWrapper, TextContainer, } from './RadioCard.styles';
16
+ export const RadioCard = (_a) => {
17
+ var { label, checked, invalid, activeOpacity = 0.8, testID, alignment = 'center', ref } = _a, rest = __rest(_a, ["label", "checked", "invalid", "activeOpacity", "testID", "alignment", "ref"]);
18
+ return (_jsx(TouchableOpacity, Object.assign({ ref: ref, accessible: true, accessibilityRole: "radio", activeOpacity: activeOpacity, accessibilityState: { checked } }, rest, { children: _jsxs(StyledWrapper, { checked: checked, invalid: invalid, alignment: alignment, children: [_jsx(TextContainer, { children: typeof label === 'string' ? _jsx(LabelText, { children: label }) : label }), _jsx(Input, { checked: checked, invalid: invalid, testID: testID })] }) })));
19
+ };
50
20
  const Input = (_a) => {
51
21
  var { checked, invalid, testID } = _a, rest = __rest(_a, ["checked", "invalid", "testID"]);
52
22
  return (_jsx(StyledRadioInputWrapper, Object.assign({}, rest, { children: _jsx(StyledRadioInput, { invalid: invalid, checked: checked, testID: testID, children: _jsx(StyledRadioInputDot, { checked: checked }) }) })));
53
23
  };
54
- const StyledWrapper = styled.View(({ theme, checked, invalid }) => css `
55
- align-items: center;
56
- background: ${theme.color.surface.bright};
57
- padding: ${numToPx(theme.space[200])};
58
- min-width: 82px;
59
- border-radius: ${numToPx(theme.border.radius.lg)};
60
- border: ${numToPx(theme.border.width.md)} solid;
61
- border-color: ${invalid
62
- ? theme.input.color.borderError
63
- : checked
64
- ? theme.input.color.selected
65
- : 'transparent'};
66
- `);
67
- export const RadioCard = (_a) => {
68
- var { label, checked, invalid, activeOpacity = 0.8, testID, ref } = _a, rest = __rest(_a, ["label", "checked", "invalid", "activeOpacity", "testID", "ref"]);
69
- return (_jsx(TouchableOpacity, Object.assign({ ref: ref, accessible: true, accessibilityRole: "radio", activeOpacity: activeOpacity, accessibilityState: { checked } }, rest, { children: _jsxs(StyledWrapper, { checked: checked, invalid: invalid, children: [typeof label === 'string' ? _jsx(LabelText, { children: label }) : label, _jsx(Input, { checked: checked, invalid: invalid, testID: testID })] }) })));
70
- };
@@ -0,0 +1,61 @@
1
+ import { numToPx } from '@ovotech/element-core';
2
+ import styled, { css } from '../../styled.native';
3
+ export const StyledRadioInputWrapper = styled.View(({ theme }) => {
4
+ return `
5
+ width: ${numToPx(theme.space[600])};
6
+ height: ${numToPx(theme.space[600])};
7
+ margin-top: ${numToPx(theme.space[200])};
8
+ `;
9
+ });
10
+ export const StyledRadioInput = styled.View(({ theme, invalid, checked }) => {
11
+ return `
12
+ width: ${numToPx(theme.space[600])};
13
+ height: ${numToPx(theme.space[600])};
14
+ border: ${numToPx(theme.border.width.md)} solid;
15
+ align-items: center;
16
+ justify-content: center;
17
+ border-radius: ${numToPx(theme.space[600])};
18
+ border-color: ${invalid
19
+ ? theme.input.color.borderError
20
+ : checked
21
+ ? theme.input.color.selected
22
+ : theme.input.color.border};
23
+ background: ${checked ? theme.input.color.selectedTint : 'transparent'};
24
+ `;
25
+ });
26
+ export const StyledRadioInputDot = styled.View(({ theme, checked }) => {
27
+ return `
28
+ width: ${numToPx(theme.space[300])};
29
+ height: ${numToPx(theme.space[300])};
30
+ border-radius: ${numToPx(theme.space[300])};
31
+ background: ${theme.input.color.selected};
32
+ opacity: ${checked ? 1 : 0};
33
+ `;
34
+ });
35
+ export const StyledWrapper = styled.View(({ theme, checked, invalid, alignment }) => css `
36
+ align-items: center;
37
+ text-align: center;
38
+ justify-content: ${alignment === 'center' ? 'center' : 'flex-end'};
39
+ flex-direction: ${alignment === 'left'
40
+ ? 'row-reverse'
41
+ : alignment === 'right'
42
+ ? 'row'
43
+ : 'column'};
44
+ background: ${theme.color.surface.bright};
45
+ padding: ${alignment === 'center'
46
+ ? numToPx(theme.space[200])
47
+ : numToPx(theme.space[400])};
48
+ border-radius: ${numToPx(theme.border.radius.lg)};
49
+ border: ${numToPx(theme.border.width.md)} solid;
50
+ border-color: ${invalid
51
+ ? theme.input.color.borderError
52
+ : checked
53
+ ? theme.input.color.selected
54
+ : 'transparent'};
55
+ gap: ${alignment === 'center' ? 0 : numToPx(theme.space[400])};
56
+ `);
57
+ export const TextContainer = styled.View(({ alignment }) => css `
58
+ flex-direction: column;
59
+ flex-grow: 1;
60
+ text-align: ${alignment === 'center' ? 'center' : 'left'};
61
+ `);
@@ -1,94 +1,27 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { numToPx } from '@ovotech/element-core';
3
2
  import groupBy from 'lodash.groupby';
4
3
  import { Fragment, useState } from 'react';
5
4
  import { Dimensions, Modal, ScrollView, View, } from 'react-native';
6
- import { SafeAreaView } from 'react-native-safe-area-context';
7
- import styled, { css } from '../../styled.native';
8
5
  import { Icon } from '../Icon';
9
6
  import { P } from '../P';
10
7
  import { Strong } from '../Strong';
11
- const SelectInput = styled.TouchableOpacity(({ theme, hasError }) => {
12
- return css `
13
- flex-direction: row;
14
- align-items: center;
15
- background-color: transparent;
16
- border-color: ${hasError
17
- ? theme.input.color.borderError
18
- : theme.input.color.border};
19
- border-width: ${numToPx(theme.border.width.md)};
20
- border-radius: ${numToPx(theme.border.radius.sm)};
21
- padding: ${numToPx(theme.space[200])};
22
- padding-right: ${numToPx(theme.space[350])};
23
- height: ${numToPx(theme.space[1100])};
24
- `;
25
- });
26
- const DropdownWrapper = styled.TouchableOpacity(({ theme }) => css `
27
- flex: 1;
28
- justify-content: center;
29
- align-items: center;
30
-
31
- /* 80 is an opacity for hex https://gist.github.com/lopspower/03fb1cc0ac9f32ef38f4 */
32
- background-color: ${theme.color.brand.dark}80;
33
- `);
34
- const DropdownContainer = styled(SafeAreaView)(({ theme }) => css `
35
- width: 95%;
36
- max-height: 70%;
37
- border-radius: ${numToPx(theme.border.radius.sm)};
38
- background-color: ${theme.color.surface.bright};
39
- `);
40
- const SelectOption = styled.TouchableOpacity(({ theme, isLastOption }) => css `
41
- flex-direction: row;
42
- align-items: center;
43
- border-bottom-color: ${theme.color.input.borderDim};
44
- border-bottom-width: ${isLastOption ? 0 : 1}px;
45
- padding: 0 ${numToPx(theme.space[400])};
46
- `);
47
- const Radio = styled.View(({ theme, isChecked }) => css `
48
- background-color: ${isChecked
49
- ? theme.input.color.selectedTint
50
- : 'transparent'};
51
- width: ${numToPx(theme.space[600])};
52
- height: ${numToPx(theme.space[600])};
53
- margin-left: auto;
54
- border-radius: ${numToPx(theme.space[600])};
55
- border-width: ${numToPx(theme.border.width.md)};
56
- border-color: ${theme.input.color[isChecked ? 'selected' : 'border']};
57
- `);
58
- const RadioDot = styled.View(({ theme, isChecked }) => css `
59
- background-color: ${theme.input.color.selected};
60
- position: absolute;
61
- top: ${numToPx(theme.space[100])};
62
- width: ${numToPx(theme.space[300])};
63
- height: ${numToPx(theme.space[300])};
64
- border-radius: ${numToPx(theme.space[300])};
65
- align-self: center;
66
- opacity: ${isChecked ? 1 : 0};
67
- `);
68
- const StyledP = styled(P)(({ theme }) => css `
69
- margin-top: ${numToPx(theme.space[300])};
70
- margin-bottom: ${numToPx(theme.space[300])};
71
- `);
72
- const StyledCategory = styled(P)(({ theme }) => css `
73
- font-size: ${numToPx(theme.font.size.xs.mediaQuery.lg)};
74
- color: ${theme.color.surface.onSurface};
75
- background-color: ${theme.color.surface.surface};
76
- padding: ${numToPx(theme.space[100])} ${numToPx(theme.space[400])};
77
- `);
78
- export const Select = ({ options = [], defaultSelected = { label: '', value: 'default' }, noOptionMessage = 'No option selected', onSelected = () => null, hasError = false, testID = 'select', ref, }) => {
8
+ import { DropdownContainer, DropdownWrapper, Radio, RadioDot, SelectInput, SelectOption, StyledCategory, StyledP, } from './styled';
9
+ export const Select = ({ options = [], defaultSelected = { label: '', value: 'default' }, noOptionMessage = 'No option selected', onSelected = () => null, hasError = false, selected, size = 'medium', testID = 'select', ref, }) => {
79
10
  const [isOpen, setOpen] = useState(false);
80
- const [selected, setSelected] = useState(defaultSelected);
11
+ const [selectedVal, setSelectedVal] = useState(defaultSelected);
12
+ const isSmall = size === 'small';
13
+ const iconName = `chevron-down${isSmall ? '-small' : ''}`;
81
14
  const height = Dimensions.get('window').height;
82
15
  const dropdownContainerMaxHeight = height * 0.7;
83
16
  const handleOptionPress = (val) => {
84
17
  onSelected(val);
85
18
  setOpen(false);
86
- setSelected(val);
19
+ setSelectedVal(val);
87
20
  };
88
21
  const optionsByCategories = groupBy(options, 'category');
89
22
  const requiredOption = {
90
23
  label: `-- ${noOptionMessage} --`,
91
24
  value: 'default',
92
25
  };
93
- return (_jsxs(View, { children: [_jsxs(SelectInput, { testID: testID, hasError: hasError, onPress: () => setOpen(!isOpen), ref: ref, children: [_jsx(P, { style: { marginTop: 0, marginBottom: 0 }, children: selected.value === 'default' ? '' : selected.label }), _jsx(Icon, { name: "chevron-down", size: 16, style: { marginLeft: 'auto' } })] }), _jsx(Modal, { transparent: true, visible: isOpen, animationType: "fade", onRequestClose: () => setOpen(false), children: _jsx(DropdownWrapper, { onPress: () => setOpen(false), children: _jsx(DropdownContainer, { style: { maxHeight: dropdownContainerMaxHeight }, children: _jsxs(ScrollView, { nestedScrollEnabled: true, testID: `${testID}-OptionsScrollView`, children: [_jsxs(SelectOption, { accessible: true, accessibilityRole: "radio", onPress: () => handleOptionPress(requiredOption), children: [_jsx(StyledP, { children: _jsx(Strong, { children: requiredOption.label }) }), _jsx(Radio, { isChecked: selected.value === requiredOption.value, children: _jsx(RadioDot, { isChecked: selected.value === requiredOption.value }) })] }), Object.keys(optionsByCategories).map(category => (_jsxs(Fragment, { children: [category !== 'undefined' ? (_jsx(StyledCategory, { children: category })) : null, optionsByCategories[category].map((option, i) => (_jsxs(SelectOption, { accessible: true, accessibilityRole: "radio", isLastOption: i === optionsByCategories[category].length - 1, onPress: () => handleOptionPress(option), children: [_jsx(StyledP, { children: _jsx(Strong, { children: option.label }) }), _jsx(Radio, { isChecked: selected.value === option.value, children: _jsx(RadioDot, { isChecked: selected.value === option.value }) })] }, option.label)))] }, category)))] }) }) }) })] }));
26
+ return (_jsxs(View, { children: [_jsxs(SelectInput, { testID: testID, hasError: hasError, isSelected: selected, size: size, onPress: () => setOpen(!isOpen), ref: ref, children: [_jsx(P, { style: { marginTop: 0, marginBottom: 0 }, children: selectedVal.value === 'default' ? '' : selectedVal.label }), _jsx(Icon, { name: iconName, size: isSmall ? 16 : 20, style: { marginLeft: 'auto' } })] }), _jsx(Modal, { transparent: true, visible: isOpen, animationType: "fade", onRequestClose: () => setOpen(false), children: _jsx(DropdownWrapper, { onPress: () => setOpen(false), children: _jsx(DropdownContainer, { style: { maxHeight: dropdownContainerMaxHeight }, children: _jsxs(ScrollView, { nestedScrollEnabled: true, testID: `${testID}-OptionsScrollView`, children: [_jsxs(SelectOption, { accessible: true, accessibilityRole: "radio", onPress: () => handleOptionPress(requiredOption), children: [_jsx(StyledP, { children: _jsx(Strong, { children: requiredOption.label }) }), _jsx(Radio, { isChecked: selectedVal.value === requiredOption.value, children: _jsx(RadioDot, { isChecked: selectedVal.value === requiredOption.value }) })] }), Object.keys(optionsByCategories).map(category => (_jsxs(Fragment, { children: [category !== 'undefined' ? (_jsx(StyledCategory, { children: category })) : null, optionsByCategories[category].map((option, i) => (_jsxs(SelectOption, { accessible: true, accessibilityRole: "radio", isLastOption: i === optionsByCategories[category].length - 1, onPress: () => handleOptionPress(option), children: [_jsx(StyledP, { children: _jsx(Strong, { children: option.label }) }), _jsx(Radio, { isChecked: selectedVal.value === option.value, children: _jsx(RadioDot, { isChecked: selectedVal.value === option.value }) })] }, option.label)))] }, category)))] }) }) }) })] }));
94
27
  };