@telus-uds/components-base 1.6.1 → 1.7.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 (40) hide show
  1. package/.turbo/turbo-build.log +8 -8
  2. package/.turbo/turbo-lint.log +13 -13
  3. package/CHANGELOG.json +36 -1
  4. package/CHANGELOG.md +16 -2
  5. package/component-docs.json +14 -22
  6. package/lib/List/ListItem.js +22 -12
  7. package/lib/Search/Search.js +27 -19
  8. package/lib/TextInput/TextArea.js +1 -1
  9. package/lib/TextInput/TextInput.js +1 -1
  10. package/lib/TextInput/TextInputBase.js +1 -1
  11. package/lib/Typography/Typography.js +12 -10
  12. package/lib/index.js +22 -1
  13. package/lib/utils/input.js +5 -6
  14. package/lib/utils/props/index.js +18 -0
  15. package/lib/utils/props/textInputProps.js +206 -0
  16. package/lib/utils/props/textProps.js +72 -0
  17. package/lib-module/List/ListItem.js +22 -12
  18. package/lib-module/Search/Search.js +29 -21
  19. package/lib-module/TextInput/TextArea.js +2 -2
  20. package/lib-module/TextInput/TextInput.js +2 -2
  21. package/lib-module/TextInput/TextInputBase.js +2 -2
  22. package/lib-module/Typography/Typography.js +13 -11
  23. package/lib-module/index.js +1 -1
  24. package/lib-module/utils/input.js +6 -6
  25. package/lib-module/utils/props/index.js +2 -0
  26. package/lib-module/utils/props/textInputProps.js +193 -0
  27. package/lib-module/utils/props/textProps.js +59 -0
  28. package/package.json +1 -1
  29. package/src/List/ListItem.jsx +17 -9
  30. package/src/Search/Search.jsx +33 -21
  31. package/src/TextInput/TextArea.jsx +2 -0
  32. package/src/TextInput/TextInput.jsx +2 -0
  33. package/src/TextInput/TextInputBase.jsx +2 -0
  34. package/src/Typography/Typography.jsx +13 -9
  35. package/src/index.js +4 -1
  36. package/src/utils/input.js +5 -7
  37. package/src/utils/props/index.js +2 -0
  38. package/src/utils/props/textInputProps.js +177 -0
  39. package/src/utils/props/textProps.js +58 -0
  40. package/stories/Search/Search.stories.jsx +49 -2
@@ -0,0 +1,177 @@
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
+ }
26
+
27
+ /**
28
+ * This collection adds props that can be passed through to both React Native's
29
+ * and React Native Web's implementations of the React Native TextInput component.
30
+ */
31
+ const crossPlatform = {
32
+ ...textProps,
33
+ ...inputValueProps,
34
+ /**
35
+ * Web and Android; 'off' disables device autocomplete, other strings are platform-specific.
36
+ * Valid values on Native: https://reactnative.dev/docs/textinput#autocomplete-android
37
+ * Valid values on Web: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
38
+ */
39
+ autoComplete: PropTypes.string,
40
+ /**
41
+ * On Native, default is `true`, passing `false` disables autoCorrect.
42
+ * On web, only supported by Safari and expects "on" or "off" strings.
43
+ */
44
+ autoCorrect: PropTypes.oneOf([true, false, 'on', 'off']),
45
+ /**
46
+ * Focuses the element on mount. On Web, only the first form element with autoFocus is focussed.
47
+ */
48
+ autoFocus: PropTypes.bool,
49
+ /**
50
+ * Default is `true` for single line, `false` for multi-line
51
+ */
52
+ blurOnSubmit: PropTypes.bool,
53
+ /**
54
+ * iOS and Web only, no effect on Android
55
+ */
56
+ clearTextOnFocus: PropTypes.bool,
57
+ /**
58
+ * Default is `true`. On web, this works by mapping to input's `readonly` attribute
59
+ */
60
+ editable: PropTypes.bool,
61
+ /**
62
+ * See documentation for allowed values (varies between Web, Android and iOS) and important notes:
63
+ * - Native: https://reactnative.dev/docs/textinput#keyboardtype
64
+ * - Web: equivalent to `inputmode` but see https://necolas.github.io/react-native-web/docs/text-input/
65
+ */
66
+ keyboardType: PropTypes.string,
67
+ /**
68
+ * Uses native tools (no flicker) to cap the maximum number of characters.
69
+ * On Web, works via `maxlength` attr.
70
+ */
71
+ maxLength: PropTypes.number,
72
+ /**
73
+ * If passed as true, the text input can be multiple lines.
74
+ *
75
+ * > It is important to note that this aligns the text to the top on iOS, and centers it on Android.
76
+ * > Use with textAlignVertical set to top for the same behavior in both platforms.
77
+ */
78
+ multiline: PropTypes.bool,
79
+ /**
80
+ * Web and Android only, requires `multiline` to be `true`.
81
+ */
82
+ numberOfLines: PropTypes.number,
83
+ /**
84
+ * Text to display when no value set.
85
+ * Accesibility guidelines recommend using labels to describe the input and using
86
+ * placeholders rarely and sparingly to prompt a particular format.
87
+ */
88
+ placeholder: PropTypes.string,
89
+ /**
90
+ * Sets placeholder colour. On Web, uses `::placeholder { color: ... }` selector.
91
+ */
92
+ placeholderTextColor: PropTypes.string,
93
+ /**
94
+ * One of a subset of platform-specific options that controls labelling and presentation
95
+ * in on-screen keyboards and accessibility tools. Uses `enterkeyhint` attr on Web.
96
+ *
97
+ * 'done', 'go', 'next', 'search', and 'send' are available for Web, Android and iOS.
98
+ */
99
+ returnKeyType: PropTypes.string,
100
+ /**
101
+ * Obscures passwords and similar. Equivalent to type="password" on Web.
102
+ * Does not work if multiline is true.
103
+ */
104
+ secureTextEntry: PropTypes.bool,
105
+ /**
106
+ * If true, all text will automatically be selected on focus.
107
+ */
108
+ selectTextOnFocus: PropTypes.bool,
109
+ /**
110
+ * Web and iOS. On iOS, default inherits from `autoCorrect`.
111
+ * On Web, equivalent to `spellcheck` attr.
112
+ */
113
+ spellCheck: PropTypes.bool
114
+ }
115
+
116
+ /**
117
+ * These web-only props all control HTML `input` attributes of the same name.
118
+ * Refer to general HTML documentation for more details.
119
+ */
120
+ const webOnly = {
121
+ disabled: PropTypes.bool,
122
+ dir: PropTypes.oneOf(['auto', 'ltr', 'rtl']),
123
+ lang: PropTypes.string
124
+ }
125
+
126
+ /**
127
+ * These props are supported in React Native but not React Native Web.
128
+ *
129
+ * React Native text inputs can be quirky, so a full set of props should be allowed to handle edge cases.
130
+ * Refer to React Native documentation for details, allowed values, and Android/iOS support and versions:
131
+ * https://reactnative.dev/docs/textinput
132
+ *
133
+ * Beware that many React Native text input props apply via complicated logic that chooses a built-in
134
+ * native component based on the values of multiple boolean flags, and may sometimes appear to pick an
135
+ * option that is inappropriate for one flag based on the values of one or more other other flags.
136
+ */
137
+ const nativeOnly = {
138
+ caretHidden: PropTypes.bool,
139
+ clearButtonMode: PropTypes.string,
140
+ contextMenuHidden: PropTypes.bool,
141
+ dataDetectorTypes: PropTypes.string,
142
+ disableFullscreenUI: PropTypes.bool,
143
+ enablesReturnKeyAutomatically: PropTypes.bool,
144
+ importantForAutofill: PropTypes.string,
145
+ inlineImageLeft: PropTypes.string,
146
+ keyboardAppearance: PropTypes.string,
147
+ returnKeyLabel: PropTypes.string,
148
+ rejectResponderTermination: PropTypes.bool,
149
+ scrollEnabled: PropTypes.bool,
150
+ selection: PropTypes.object,
151
+ selectionColor: PropTypes.string,
152
+ showSoftInputOnFocus: PropTypes.bool,
153
+ textAlign: PropTypes.string,
154
+ textContentType: PropTypes.string,
155
+ passwordRules: PropTypes.string,
156
+ textBreakStrategy: PropTypes.string,
157
+ underlineColorAndroid: PropTypes.string
158
+ }
159
+
160
+ export default {
161
+ /**
162
+ * Subset of proptypes that can be passed down to a React Native or React Native Web
163
+ * `TextInput` component. Allow regardless of platform, so cross-platform apps don't warn.
164
+ */
165
+ types: { ...crossPlatform, ...webOnly, ...nativeOnly },
166
+ /**
167
+ * Filters a props object. Return only platform-appropriate TextInput props, native inputs
168
+ * may throw errors on receiving unknown props.
169
+ */
170
+ select: getPropSelector({
171
+ ...crossPlatform,
172
+ ...Platform.select({
173
+ web: webOnly,
174
+ default: nativeOnly
175
+ })
176
+ })
177
+ }
@@ -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
+ }
@@ -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 = {}