@telus-uds/components-base 1.6.1 → 1.8.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 (97) hide show
  1. package/.storybook/main.js +7 -0
  2. package/.turbo/turbo-build.log +3 -3
  3. package/.turbo/turbo-lint.log +3 -13
  4. package/CHANGELOG.json +112 -1
  5. package/CHANGELOG.md +41 -2
  6. package/__fixtures__/Accessible.js +1 -2
  7. package/__fixtures__/Accessible.native.js +1 -2
  8. package/__tests__/FlexGrid/Col.test.jsx +5 -0
  9. package/__tests__/InputLabel/InputLabel.test.jsx +28 -0
  10. package/__tests__/InputLabel/__snapshots__/InputLabel.test.jsx.snap +3 -0
  11. package/__tests__/InputSupports/InputSupports.test.jsx +10 -0
  12. package/component-docs.json +278 -40
  13. package/lib/Button/ButtonGroup.js +118 -45
  14. package/lib/Checkbox/CheckboxGroup.js +3 -3
  15. package/lib/ExpandCollapse/Panel.js +2 -1
  16. package/lib/Fieldset/Fieldset.js +7 -0
  17. package/lib/InputLabel/InputLabel.js +8 -1
  18. package/lib/InputSupports/InputSupports.js +7 -0
  19. package/lib/List/ListItem.js +22 -12
  20. package/lib/Notification/Notification.js +1 -1
  21. package/lib/Radio/RadioGroup.js +12 -5
  22. package/lib/RadioCard/RadioCardGroup.js +7 -0
  23. package/lib/Search/Search.js +28 -20
  24. package/lib/Skeleton/Skeleton.js +48 -2
  25. package/lib/TextInput/TextArea.js +1 -1
  26. package/lib/TextInput/TextInput.js +1 -1
  27. package/lib/TextInput/TextInputBase.js +1 -1
  28. package/lib/ToggleSwitch/ToggleSwitch.js +7 -0
  29. package/lib/ToggleSwitch/ToggleSwitchGroup.js +7 -0
  30. package/lib/Tooltip/Tooltip.js +1 -1
  31. package/lib/Typography/Typography.js +12 -10
  32. package/lib/index.js +22 -1
  33. package/lib/utils/animation/useVerticalExpandAnimation.js +26 -13
  34. package/lib/utils/input.js +5 -6
  35. package/lib/utils/props/index.js +18 -0
  36. package/lib/utils/props/inputSupportsProps.js +7 -0
  37. package/lib/utils/props/textInputProps.js +207 -0
  38. package/lib/utils/props/textProps.js +72 -0
  39. package/lib-module/Button/ButtonGroup.js +117 -45
  40. package/lib-module/Checkbox/CheckboxGroup.js +3 -3
  41. package/lib-module/ExpandCollapse/Panel.js +2 -1
  42. package/lib-module/Fieldset/Fieldset.js +7 -0
  43. package/lib-module/InputLabel/InputLabel.js +8 -1
  44. package/lib-module/InputSupports/InputSupports.js +7 -0
  45. package/lib-module/List/ListItem.js +22 -12
  46. package/lib-module/Notification/Notification.js +1 -1
  47. package/lib-module/Radio/RadioGroup.js +12 -5
  48. package/lib-module/RadioCard/RadioCardGroup.js +7 -0
  49. package/lib-module/Search/Search.js +30 -22
  50. package/lib-module/Skeleton/Skeleton.js +49 -3
  51. package/lib-module/TextInput/TextArea.js +2 -2
  52. package/lib-module/TextInput/TextInput.js +2 -2
  53. package/lib-module/TextInput/TextInputBase.js +2 -2
  54. package/lib-module/ToggleSwitch/ToggleSwitch.js +7 -0
  55. package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +7 -0
  56. package/lib-module/Tooltip/Tooltip.js +1 -1
  57. package/lib-module/Typography/Typography.js +13 -11
  58. package/lib-module/index.js +1 -1
  59. package/lib-module/utils/animation/useVerticalExpandAnimation.js +26 -14
  60. package/lib-module/utils/input.js +6 -6
  61. package/lib-module/utils/props/index.js +2 -0
  62. package/lib-module/utils/props/inputSupportsProps.js +7 -0
  63. package/lib-module/utils/props/textInputProps.js +194 -0
  64. package/lib-module/utils/props/textProps.js +59 -0
  65. package/package.json +9 -4
  66. package/src/Button/ButtonGroup.jsx +106 -41
  67. package/src/Checkbox/Checkbox.jsx +7 -4
  68. package/src/Checkbox/CheckboxGroup.jsx +3 -3
  69. package/src/ExpandCollapse/Panel.jsx +3 -1
  70. package/src/Fieldset/Fieldset.jsx +6 -0
  71. package/src/InputLabel/InputLabel.jsx +17 -2
  72. package/src/InputSupports/InputSupports.jsx +9 -1
  73. package/src/List/ListItem.jsx +17 -9
  74. package/src/Notification/Notification.jsx +1 -1
  75. package/src/Radio/Radio.jsx +5 -1
  76. package/src/Radio/RadioGroup.jsx +11 -5
  77. package/src/RadioCard/RadioCard.jsx +5 -1
  78. package/src/RadioCard/RadioCardGroup.jsx +6 -0
  79. package/src/Search/Search.jsx +34 -22
  80. package/src/Skeleton/Skeleton.jsx +56 -3
  81. package/src/TextInput/TextArea.jsx +2 -0
  82. package/src/TextInput/TextInput.jsx +2 -0
  83. package/src/TextInput/TextInputBase.jsx +2 -0
  84. package/src/ToggleSwitch/ToggleSwitch.jsx +6 -0
  85. package/src/ToggleSwitch/ToggleSwitchGroup.jsx +6 -0
  86. package/src/Tooltip/Tooltip.jsx +1 -1
  87. package/src/Typography/Typography.jsx +13 -9
  88. package/src/index.js +4 -1
  89. package/src/utils/animation/useVerticalExpandAnimation.js +25 -12
  90. package/src/utils/input.js +5 -7
  91. package/src/utils/props/index.js +2 -0
  92. package/src/utils/props/inputSupportsProps.js +6 -1
  93. package/src/utils/props/textInputProps.js +178 -0
  94. package/src/utils/props/textProps.js +58 -0
  95. package/src/utils/props/tokens.js +21 -19
  96. package/stories/Search/Search.stories.jsx +49 -2
  97. package/stories/Tabs/Tabs.stories.jsx +4 -3
@@ -1,4 +1,7 @@
1
1
  import { useCallback, useRef, useState } from 'react'
2
+ /**
3
+ * @typedef {import('react').SyntheticEvent} Event
4
+ */
2
5
 
3
6
  const pluralHooks = ['useMultipleInputValues']
4
7
 
@@ -51,16 +54,13 @@ Consumers of this hook must be one of:
51
54
  *
52
55
  * @param {string} hookName - optional, used for tailoring error messages
53
56
  *
54
- * @typedef {(oldValue: string|number|null) => string|number|null} UpdaterFunction - `setValue` takes a value or
55
- * a function returning a new value from the old value
56
57
  * @returns {{
57
58
  * currentValue: string|number|null
58
- * setValue: (newValue: string|number|null|UpdaterFunction) => void
59
+ * setValue: (newValue: string|number|null|(oldValue: string|number) => string|number, event: Event) => void
59
60
  * resetValue: () => void
60
61
  * isControlled: bool
61
62
  * }}
62
63
  */
63
-
64
64
  export const useInputValue = (props = {}, hookName = 'useInputValue') => {
65
65
  const isCurrentlyControlled = props.value !== undefined
66
66
  const [isControlled] = useState(isCurrentlyControlled)
@@ -108,12 +108,10 @@ export const useInputValue = (props = {}, hookName = 'useInputValue') => {
108
108
  *
109
109
  * @param {string} componentName - optional, used in error messages
110
110
  *
111
- * @typedef {(oldValues: string[]|number[]) => string[]|number[]} UpdaterFunction - `setValues` takes values or
112
- * a function returning new values from old values
113
111
  * @returns {{
114
112
  * currentValues: any
115
113
  * resetValues: () => void
116
- * setValues: (newValues: string[]|number[]|UpdaterFunction) => void
114
+ * setValues: (newValues: string[]|number[]|(oldValues: string[]|number[]) => string[]|number[], event: Event) => void
117
115
  * toggleOneValue: (value: string|number) => void
118
116
  * unsetValues: () => void
119
117
  * }}
@@ -13,5 +13,7 @@ export { default as rectProp } from './rectProp'
13
13
  export { default as responsiveProps } from './responsiveProps'
14
14
  export { default as spacingProps } from './spacingProps'
15
15
  export { default as selectSystemProps } from './selectSystemProps'
16
+ export { default as textInputProps } from './textInputProps'
17
+ export { default as textProps } from './textProps'
16
18
  export { default as variantProp } from './variantProp'
17
19
  export { default as viewProps } from './viewProps'
@@ -2,6 +2,10 @@ import PropTypes from 'prop-types'
2
2
 
3
3
  export default {
4
4
  types: {
5
+ /**
6
+ * Whether the English or French copy will be used (e.g. for accessibility labels).
7
+ */
8
+ copy: PropTypes.oneOf(['en', 'fr']),
5
9
  /**
6
10
  * The input label.
7
11
  */
@@ -28,8 +32,9 @@ export default {
28
32
  */
29
33
  validation: PropTypes.oneOf(['error', 'success'])
30
34
  },
31
- select: ({ label, hint, hintPosition, feedback, tooltip, validation }) => ({
35
+ select: ({ copy, label, hint, hintPosition, feedback, tooltip, validation }) => ({
32
36
  supportsProps: {
37
+ copy,
33
38
  label,
34
39
  hint,
35
40
  hintPosition,
@@ -0,0 +1,178 @@
1
+ import PropTypes from 'prop-types'
2
+ import { Platform } from 'react-native'
3
+ import getPropSelector from './getPropSelector'
4
+
5
+ // This file contains common props for components that render a React Native TextInput
6
+ // It excludes interaction handler functions which are in `./handlerProps.js`
7
+
8
+ /**
9
+ * TextInput (web and native) supports some common React Native props
10
+ * shared with React Native's Text component.
11
+ */
12
+ const textProps = {
13
+ maxFontSizeMultiplier: PropTypes.number,
14
+ nativeId: PropTypes.string,
15
+ onLayout: PropTypes.func
16
+ }
17
+
18
+ /**
19
+ * UDS text inputs accept props related to UDS's useInputValue hook
20
+ */
21
+ const inputValueProps = {
22
+ value: PropTypes.string,
23
+ initialValue: PropTypes.string,
24
+ readOnly: PropTypes.bool,
25
+ inactive: PropTypes.bool
26
+ }
27
+
28
+ /**
29
+ * This collection adds props that can be passed through to both React Native's
30
+ * and React Native Web's implementations of the React Native TextInput component.
31
+ */
32
+ const crossPlatform = {
33
+ ...textProps,
34
+ ...inputValueProps,
35
+ /**
36
+ * Web and Android; 'off' disables device autocomplete, other strings are platform-specific.
37
+ * Valid values on Native: https://reactnative.dev/docs/textinput#autocomplete-android
38
+ * Valid values on Web: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
39
+ */
40
+ autoComplete: PropTypes.string,
41
+ /**
42
+ * On Native, default is `true`, passing `false` disables autoCorrect.
43
+ * On web, only supported by Safari and expects "on" or "off" strings.
44
+ */
45
+ autoCorrect: PropTypes.oneOf([true, false, 'on', 'off']),
46
+ /**
47
+ * Focuses the element on mount. On Web, only the first form element with autoFocus is focussed.
48
+ */
49
+ autoFocus: PropTypes.bool,
50
+ /**
51
+ * Default is `true` for single line, `false` for multi-line
52
+ */
53
+ blurOnSubmit: PropTypes.bool,
54
+ /**
55
+ * iOS and Web only, no effect on Android
56
+ */
57
+ clearTextOnFocus: PropTypes.bool,
58
+ /**
59
+ * Default is `true`. On web, this works by mapping to input's `readonly` attribute
60
+ */
61
+ editable: PropTypes.bool,
62
+ /**
63
+ * See documentation for allowed values (varies between Web, Android and iOS) and important notes:
64
+ * - Native: https://reactnative.dev/docs/textinput#keyboardtype
65
+ * - Web: equivalent to `inputmode` but see https://necolas.github.io/react-native-web/docs/text-input/
66
+ */
67
+ keyboardType: PropTypes.string,
68
+ /**
69
+ * Uses native tools (no flicker) to cap the maximum number of characters.
70
+ * On Web, works via `maxlength` attr.
71
+ */
72
+ maxLength: PropTypes.number,
73
+ /**
74
+ * If passed as true, the text input can be multiple lines.
75
+ *
76
+ * > It is important to note that this aligns the text to the top on iOS, and centers it on Android.
77
+ * > Use with textAlignVertical set to top for the same behavior in both platforms.
78
+ */
79
+ multiline: PropTypes.bool,
80
+ /**
81
+ * Web and Android only, requires `multiline` to be `true`.
82
+ */
83
+ numberOfLines: PropTypes.number,
84
+ /**
85
+ * Text to display when no value set.
86
+ * Accesibility guidelines recommend using labels to describe the input and using
87
+ * placeholders rarely and sparingly to prompt a particular format.
88
+ */
89
+ placeholder: PropTypes.string,
90
+ /**
91
+ * Sets placeholder colour. On Web, uses `::placeholder { color: ... }` selector.
92
+ */
93
+ placeholderTextColor: PropTypes.string,
94
+ /**
95
+ * One of a subset of platform-specific options that controls labelling and presentation
96
+ * in on-screen keyboards and accessibility tools. Uses `enterkeyhint` attr on Web.
97
+ *
98
+ * 'done', 'go', 'next', 'search', and 'send' are available for Web, Android and iOS.
99
+ */
100
+ returnKeyType: PropTypes.string,
101
+ /**
102
+ * Obscures passwords and similar. Equivalent to type="password" on Web.
103
+ * Does not work if multiline is true.
104
+ */
105
+ secureTextEntry: PropTypes.bool,
106
+ /**
107
+ * If true, all text will automatically be selected on focus.
108
+ */
109
+ selectTextOnFocus: PropTypes.bool,
110
+ /**
111
+ * Web and iOS. On iOS, default inherits from `autoCorrect`.
112
+ * On Web, equivalent to `spellcheck` attr.
113
+ */
114
+ spellCheck: PropTypes.bool
115
+ }
116
+
117
+ /**
118
+ * These web-only props all control HTML `input` attributes of the same name.
119
+ * Refer to general HTML documentation for more details.
120
+ */
121
+ const webOnly = {
122
+ disabled: PropTypes.bool,
123
+ dir: PropTypes.oneOf(['auto', 'ltr', 'rtl']),
124
+ lang: PropTypes.string
125
+ }
126
+
127
+ /**
128
+ * These props are supported in React Native but not React Native Web.
129
+ *
130
+ * React Native text inputs can be quirky, so a full set of props should be allowed to handle edge cases.
131
+ * Refer to React Native documentation for details, allowed values, and Android/iOS support and versions:
132
+ * https://reactnative.dev/docs/textinput
133
+ *
134
+ * Beware that many React Native text input props apply via complicated logic that chooses a built-in
135
+ * native component based on the values of multiple boolean flags, and may sometimes appear to pick an
136
+ * option that is inappropriate for one flag based on the values of one or more other other flags.
137
+ */
138
+ const nativeOnly = {
139
+ caretHidden: PropTypes.bool,
140
+ clearButtonMode: PropTypes.string,
141
+ contextMenuHidden: PropTypes.bool,
142
+ dataDetectorTypes: PropTypes.string,
143
+ disableFullscreenUI: PropTypes.bool,
144
+ enablesReturnKeyAutomatically: PropTypes.bool,
145
+ importantForAutofill: PropTypes.string,
146
+ inlineImageLeft: PropTypes.string,
147
+ keyboardAppearance: PropTypes.string,
148
+ returnKeyLabel: PropTypes.string,
149
+ rejectResponderTermination: PropTypes.bool,
150
+ scrollEnabled: PropTypes.bool,
151
+ selection: PropTypes.object,
152
+ selectionColor: PropTypes.string,
153
+ showSoftInputOnFocus: PropTypes.bool,
154
+ textAlign: PropTypes.string,
155
+ textContentType: PropTypes.string,
156
+ passwordRules: PropTypes.string,
157
+ textBreakStrategy: PropTypes.string,
158
+ underlineColorAndroid: PropTypes.string
159
+ }
160
+
161
+ export default {
162
+ /**
163
+ * Subset of proptypes that can be passed down to a React Native or React Native Web
164
+ * `TextInput` component. Allow regardless of platform, so cross-platform apps don't warn.
165
+ */
166
+ types: { ...crossPlatform, ...webOnly, ...nativeOnly },
167
+ /**
168
+ * Filters a props object. Return only platform-appropriate TextInput props, native inputs
169
+ * may throw errors on receiving unknown props.
170
+ */
171
+ select: getPropSelector({
172
+ ...crossPlatform,
173
+ ...Platform.select({
174
+ web: webOnly,
175
+ default: nativeOnly
176
+ })
177
+ })
178
+ }
@@ -0,0 +1,58 @@
1
+ import PropTypes from 'prop-types'
2
+ import { Platform } from 'react-native'
3
+ import getPropSelector from './getPropSelector'
4
+
5
+ // These are the props accepted specifically on React Native (Web) `Text` elements.
6
+ // They are generally concerned with the behaviour of multiline text.
7
+
8
+ const crossPlatform = {
9
+ /**
10
+ * Truncates text after this many lines with an ellipsis at the end.
11
+ * On native, ellipsis behaviour may be changed with `ellipsizeMode` prop.
12
+ */
13
+ numberOfLines: PropTypes.number,
14
+ /**
15
+ * Default is true on web and false on native
16
+ */
17
+ selectable: PropTypes.bool
18
+ }
19
+
20
+ /**
21
+ * See React Native docs for latest details on these.
22
+ * https://reactnative.dev/docs/text
23
+ */
24
+ const nativeOnly = {
25
+ ellipsizeMode: PropTypes.string,
26
+ maxFontSizeMultiplier: PropTypes.number,
27
+ minimumFontScale: PropTypes.number,
28
+ onTextLayout: PropTypes.func,
29
+ suppressHighlighting: PropTypes.bool,
30
+ textBreakStrategy: PropTypes.string
31
+ }
32
+
33
+ /**
34
+ * These set HTML attributes of the same name.
35
+ */
36
+ const webOnly = {
37
+ dir: PropTypes.oneOf(['auto', 'ltr', 'rtl']),
38
+ lang: PropTypes.string
39
+ }
40
+
41
+ export default {
42
+ /**
43
+ * Set of prop types specific to React Native and React Native Web `Text`,
44
+ * which largely revolve around the behaviour of multiline non-pressable text.
45
+ */
46
+ types: { ...crossPlatform, ...webOnly, ...nativeOnly },
47
+ /**
48
+ * Filters a props object, returning only props specific to `Text` elements
49
+ * on the current platform. Does not include props applicable to `Text` and `View`.
50
+ */
51
+ select: getPropSelector({
52
+ ...crossPlatform,
53
+ ...Platform.select({
54
+ web: webOnly,
55
+ default: nativeOnly
56
+ })
57
+ })
58
+ }
@@ -86,33 +86,35 @@ export const selectTokens = (specifier, tokens, prefix) => {
86
86
  * tokens: getTokensPropType('Component1', 'Component2')
87
87
  * }
88
88
  */
89
- export const getTokensPropType = (...componentsNames) => (props, propName, componentName) => {
90
- PropTypes.checkPropTypes(
91
- {
92
- [propName]: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
93
- },
94
- props,
95
- propName,
96
- componentName
97
- )
98
-
99
- if (typeof props[propName] !== 'function') {
89
+ export const getTokensPropType =
90
+ (...componentsNames) =>
91
+ (props, propName, componentName) => {
100
92
  PropTypes.checkPropTypes(
101
93
  {
102
- [propName]: PropTypes.exact(
103
- Object.fromEntries(
104
- componentsNames.flatMap((component) =>
105
- getTokenNames(component).map((key) => [key, tokenValueType])
106
- )
107
- )
108
- )
94
+ [propName]: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
109
95
  },
110
96
  props,
111
97
  propName,
112
98
  componentName
113
99
  )
100
+
101
+ if (typeof props[propName] !== 'function') {
102
+ PropTypes.checkPropTypes(
103
+ {
104
+ [propName]: PropTypes.exact(
105
+ Object.fromEntries(
106
+ componentsNames.flatMap((component) =>
107
+ getTokenNames(component).map((key) => [key, tokenValueType])
108
+ )
109
+ )
110
+ )
111
+ },
112
+ props,
113
+ propName,
114
+ componentName
115
+ )
116
+ }
114
117
  }
115
- }
116
118
 
117
119
  /**
118
120
  * Get a proptypes validator for a set of tokens that is not based on a component in the theme schema.
@@ -1,6 +1,7 @@
1
- import React from 'react'
1
+ /* eslint-disable react/no-multi-comp */
2
+ import React, { useRef, useState } from 'react'
2
3
 
3
- import { Search } from '../../src'
4
+ import { Search, StackView, TextButton, Typography, List, ListItem } from '../../src'
4
5
 
5
6
  export default {
6
7
  title: 'Search',
@@ -17,3 +18,49 @@ Default.args = {}
17
18
 
18
19
  export const Inactive = Template.bind({})
19
20
  Inactive.args = { inactive: true }
21
+
22
+ // Lots of smartphone brands. No need to make the file really long, let them sit on one line.
23
+ // eslint-disable-next-line prettier/prettier
24
+ const options = ['Acer', 'Aermoo', 'AGM', 'Alcatel', 'Allcall', 'Allview', 'Amigoo', 'Amoi', 'Apple', 'Archos', 'Asus', 'Axgio', 'Black Shark', 'BlackBerry', 'Blackview', 'BLU', 'Bluboo', 'BQ', 'Bsimb', 'Cagabi', 'Cat', 'Caterpillar', 'Centric', 'China Mobile', 'Cong', 'Coolpad', 'Cubot', 'Dakele', 'Doogee', 'Doopro', 'E&L', 'Ecoo', 'Elephone', 'Energizer', 'Energy', 'Essential', 'EStar', 'Faea', 'Fairphone', 'Geotel', 'Gigabyte', 'Gigaset', 'Gionee', 'Gome', 'Google', 'Goophone', 'Gretel', 'Hafury', 'Haier', 'Hike', 'HiSense', 'HomTom', 'Honor', 'HP', 'HTC', 'Huawei', 'I Kall', 'iiiF150', 'iLA', 'iMan', 'iNew', 'Infinix', 'InFocus', 'InnJoo', 'Innos', 'Intex', 'iOcean', 'iRULU', 'IUNI', 'iVooMi', 'Jesy', 'Jiake', 'Jiayu', 'Karbonn', 'Kazam', 'Keecoo', 'Kenxinda', 'KingSing', 'KingZone', 'Kodak', 'Kolina', 'Koolnee', 'Landvo', 'Laude', 'Lava', 'Leagoo', 'LeEco (LeTV)', 'Lenovo', 'Leotec', 'LeRee', 'LG', 'Ly', 'Lyf', 'M-Horse', 'M-Net', 'Mann', 'Maze', 'Meiigoo', 'Meitu', 'Meizu', 'Micromax', 'Microsoft', 'Mijue', 'Milai', 'Mlais', 'Morefine', 'Motorola', 'Mpie', 'Mstar', 'MyWigo', 'Neken', 'Neo', 'Newman', 'NO.1', 'Noa', 'Nokia', 'Nomu', 'Nubia', 'Nubia Red Magic', 'NZone', 'OnePlus', 'Oppo', 'Otium', 'Oukitel', 'Palm', 'Panasonic', 'Pantech', 'Pepsi', 'Phicomm', 'Philips', 'Phonemax', 'Plunk', 'POCO', 'Pomp', 'Poptel', 'PPTV', 'Prestigio', 'Qiku', 'Ramos', 'Razer', 'realme', 'Runbo', 'Samsung', 'Sharp', 'Silent Circle', 'Siswoo', 'Smartisan', 'Snopow', 'Sony', 'Sony Ericsson', 'Star', 'Swipe', 'TCL', 'Tengda', 'THL', 'Tianhe', 'Timmy', 'TP-Link', 'Ubro', 'Uhans', 'Uhappy', 'Uimi', 'Ukozi', 'Ulefone', 'UMi', 'UMiDIGI', 'Vargo', 'Vernee', 'ViewSonic', 'Vivo', 'VKworld', 'Voto', 'VPhone', 'Vsmart', 'Weimei', 'Wico', 'Wiko', 'Wileyfox', 'Wolder', 'Woxter', 'Xiaomi', 'Xolo', 'Yota Devices', 'YU', 'Zoji', 'Zopo', 'ZTE', 'Zuk']
25
+
26
+ export const Controlled = (args) => {
27
+ const [value, setValue] = useState('')
28
+ const [searchedValue, setSearchedValue] = useState(null)
29
+ const searchRef = useRef()
30
+ const selectOption = (option) => {
31
+ setValue(option)
32
+ if (searchRef.current?.focus) searchRef.current?.focus()
33
+ }
34
+
35
+ return (
36
+ <StackView space={4}>
37
+ {searchedValue ? (
38
+ <>
39
+ <Typography>Search results page for {searchedValue}.</Typography>
40
+ <Typography>{searchedValue} phones are really good. You should buy one.</Typography>
41
+ <TextButton onPress={() => setSearchedValue(null)}>Go back</TextButton>
42
+ </>
43
+ ) : (
44
+ <>
45
+ <Search
46
+ {...args}
47
+ value={value}
48
+ onChange={setValue}
49
+ ref={searchRef}
50
+ onSubmit={setSearchedValue}
51
+ />
52
+ <List>
53
+ {options
54
+ .filter((option) => !value || option.toLowerCase().match(value.toLowerCase()))
55
+ .map((option) => (
56
+ <ListItem key={option}>
57
+ <TextButton onPress={() => selectOption(option)}>{option}</TextButton>
58
+ </ListItem>
59
+ ))}
60
+ </List>
61
+ </>
62
+ )}
63
+ </StackView>
64
+ )
65
+ }
66
+ Controlled.args = {}
@@ -40,9 +40,10 @@ TabsWithHref.args = {
40
40
  ]
41
41
  }
42
42
 
43
- const loremIpsumArray = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. '
44
- .repeat(5)
45
- .split('. ')
43
+ const loremIpsumArray =
44
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. '
45
+ .repeat(5)
46
+ .split('. ')
46
47
 
47
48
  export const TabsControlled = (args) => {
48
49
  const [page, setPage] = useState('1')