@telus-uds/components-web 2.0.0 → 2.1.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.
@@ -0,0 +1,256 @@
1
+ // These types are copied out of react-native because web projects don't have that dependency.
2
+ export type AccessibilityActionName =
3
+ /**
4
+ * Generated when a screen reader user double taps the component.
5
+ */
6
+ | 'activate'
7
+ /**
8
+ * Generated when a screen reader user increments an adjustable component.
9
+ */
10
+ | 'increment'
11
+ /**
12
+ * Generated when a screen reader user decrements an adjustable component.
13
+ */
14
+ | 'decrement'
15
+ /**
16
+ * Generated when a TalkBack user places accessibility focus on the component and double taps and holds one finger on the screen.
17
+ * @platform android
18
+ */
19
+ | 'longpress'
20
+ /**
21
+ * Generated when a VoiceOver user places focus on or inside the component and double taps with two fingers.
22
+ * @platform ios
23
+ * */
24
+ | 'magicTap'
25
+ /**
26
+ * Generated when a VoiceOver user places focus on or inside the component and performs a two finger scrub gesture (left, right, left).
27
+ * @platform ios
28
+ * */
29
+ | 'escape'
30
+
31
+ export type AccessibilityActionInfo = Readonly<{
32
+ name: AccessibilityActionName | string
33
+ label?: string | undefined
34
+ }>
35
+
36
+ export type AccessibilityRole =
37
+ | 'none'
38
+ | 'button'
39
+ | 'togglebutton'
40
+ | 'link'
41
+ | 'search'
42
+ | 'image'
43
+ | 'keyboardkey'
44
+ | 'text'
45
+ | 'adjustable'
46
+ | 'imagebutton'
47
+ | 'header'
48
+ | 'summary'
49
+ | 'alert'
50
+ | 'checkbox'
51
+ | 'combobox'
52
+ | 'menu'
53
+ | 'menubar'
54
+ | 'menuitem'
55
+ | 'progressbar'
56
+ | 'radio'
57
+ | 'radiogroup'
58
+ | 'scrollbar'
59
+ | 'spinbutton'
60
+ | 'switch'
61
+ | 'tab'
62
+ | 'tabbar'
63
+ | 'tablist'
64
+ | 'timer'
65
+ | 'list'
66
+ | 'toolbar'
67
+
68
+ export interface AccessibilityState {
69
+ /**
70
+ * When true, informs accessible tools if the element is disabled
71
+ */
72
+ disabled?: boolean | undefined
73
+ /**
74
+ * When true, informs accessible tools if the element is selected
75
+ */
76
+ selected?: boolean | undefined
77
+ /**
78
+ * For items like Checkboxes and Toggle switches, reports their state to accessible tools
79
+ */
80
+ checked?: boolean | 'mixed' | undefined
81
+ /**
82
+ * When present, informs accessible tools if the element is busy
83
+ */
84
+ busy?: boolean | undefined
85
+ /**
86
+ * When present, informs accessible tools the element is expanded or collapsed
87
+ */
88
+ expanded?: boolean | undefined
89
+ }
90
+
91
+ export interface AccessibilityValue {
92
+ /**
93
+ * The minimum value of this component's range. (should be an integer)
94
+ */
95
+ min?: number | undefined
96
+
97
+ /**
98
+ * The maximum value of this component's range. (should be an integer)
99
+ */
100
+ max?: number | undefined
101
+
102
+ /**
103
+ * The current value of this component's range. (should be an integer)
104
+ */
105
+ now?: number | undefined
106
+
107
+ /**
108
+ * A textual description of this component's value. (will override minimum, current, and maximum if set)
109
+ */
110
+ text?: string | undefined
111
+ }
112
+
113
+ export interface AccessibilityPropsAndroid {
114
+ /**
115
+ * Indicates to accessibility services whether the user should be notified when this view changes.
116
+ * Works for Android API >= 19 only.
117
+ * See http://developer.android.com/reference/android/view/View.html#attr_android:accessibilityLiveRegion for references.
118
+ * @platform android
119
+ */
120
+ accessibilityLiveRegion?: 'none' | 'polite' | 'assertive' | undefined
121
+
122
+ /**
123
+ * Controls how view is important for accessibility which is if it fires accessibility events
124
+ * and if it is reported to accessibility services that query the screen.
125
+ * Works for Android only. See http://developer.android.com/reference/android/R.attr.html#importantForAccessibility for references.
126
+ *
127
+ * Possible values:
128
+ * 'auto' - The system determines whether the view is important for accessibility - default (recommended).
129
+ * 'yes' - The view is important for accessibility.
130
+ * 'no' - The view is not important for accessibility.
131
+ * 'no-hide-descendants' - The view is not important for accessibility, nor are any of its descendant views.
132
+ */
133
+ importantForAccessibility?: 'auto' | 'yes' | 'no' | 'no-hide-descendants' | undefined
134
+ }
135
+
136
+ type NodeHandle = number
137
+
138
+ export interface TargetedEvent {
139
+ target: number
140
+ }
141
+
142
+ interface TextLayoutLine {
143
+ ascender: number
144
+ capHeight: number
145
+ descender: number
146
+ height: number
147
+ text: string
148
+ width: number
149
+ x: number
150
+ xHeight: number
151
+ y: number
152
+ }
153
+
154
+ export interface TextLayoutEventData extends TargetedEvent {
155
+ lines: TextLayoutLine[]
156
+ }
157
+
158
+ // Similar to React.SyntheticEvent except for nativeEvent
159
+ export interface NativeSyntheticEvent<T>
160
+ extends React.BaseSyntheticEvent<T, NodeHandle, NodeHandle> {}
161
+
162
+ export type AccessibilityActionEvent = NativeSyntheticEvent<
163
+ Readonly<{
164
+ actionName: string
165
+ }>
166
+ >
167
+
168
+ export interface LayoutRectangle {
169
+ x: number
170
+ y: number
171
+ width: number
172
+ height: number
173
+ }
174
+
175
+ // @see TextProps.onLayout
176
+ export type LayoutChangeEvent = NativeSyntheticEvent<{ layout: LayoutRectangle }>
177
+
178
+ export interface AccessibilityPropsIOS {
179
+ /**
180
+ * A Boolean value indicating whether the accessibility elements contained within this accessibility element
181
+ * are hidden to the screen reader.
182
+ * @platform ios
183
+ */
184
+ accessibilityElementsHidden?: boolean | undefined
185
+
186
+ /**
187
+ * A Boolean value indicating whether VoiceOver should ignore the elements within views that are siblings of the receiver.
188
+ * @platform ios
189
+ */
190
+ accessibilityViewIsModal?: boolean | undefined
191
+
192
+ /**
193
+ * When accessibile is true, the system will invoke this function when the user performs the escape gesture (scrub with two fingers).
194
+ * @platform ios
195
+ */
196
+ onAccessibilityEscape?: (() => void) | undefined
197
+
198
+ /**
199
+ * When `accessible` is true, the system will try to invoke this function when the user performs accessibility tap gesture.
200
+ * @platform ios
201
+ */
202
+ onAccessibilityTap?: (() => void) | undefined
203
+
204
+ /**
205
+ * When accessible is true, the system will invoke this function when the user performs the magic tap gesture.
206
+ * @platform ios
207
+ */
208
+ onMagicTap?: (() => void) | undefined
209
+
210
+ /**
211
+ * https://reactnative.dev/docs/accessibility#accessibilityignoresinvertcolorsios
212
+ * @platform ios
213
+ */
214
+ accessibilityIgnoresInvertColors?: boolean | undefined
215
+ }
216
+ export interface AccessibilityProps extends AccessibilityPropsAndroid, AccessibilityPropsIOS {
217
+ /**
218
+ * When true, indicates that the view is an accessibility element.
219
+ * By default, all the touchable elements are accessible.
220
+ */
221
+ accessible?: boolean | undefined
222
+
223
+ /**
224
+ * Provides an array of custom actions available for accessibility.
225
+ */
226
+ accessibilityActions?: ReadonlyArray<AccessibilityActionInfo> | undefined
227
+
228
+ /**
229
+ * Overrides the text that's read by the screen reader when the user interacts with the element. By default, the
230
+ * label is constructed by traversing all the children and accumulating all the Text nodes separated by space.
231
+ */
232
+ accessibilityLabel?: string | undefined
233
+
234
+ /**
235
+ * Accessibility Role tells a person using either VoiceOver on iOS or TalkBack on Android the type of element that is focused on.
236
+ */
237
+ accessibilityRole?: AccessibilityRole | undefined
238
+ /**
239
+ * Accessibility State tells a person using either VoiceOver on iOS or TalkBack on Android the state of the element currently focused on.
240
+ */
241
+ accessibilityState?: AccessibilityState | undefined
242
+ /**
243
+ * An accessibility hint helps users understand what will happen when they perform an action on the accessibility element when that result is not obvious from the accessibility label.
244
+ */
245
+ accessibilityHint?: string | undefined
246
+ /**
247
+ * Represents the current value of a component. It can be a textual description of a component's value, or for range-based components, such as sliders and progress bars,
248
+ * it contains range information (minimum, current, and maximum).
249
+ */
250
+ accessibilityValue?: AccessibilityValue | undefined
251
+
252
+ /**
253
+ * When `accessible` is true, the system will try to invoke this function when the user performs an accessibility custom action.
254
+ */
255
+ onAccessibilityAction?: ((event: AccessibilityActionEvent) => void) | undefined
256
+ }
@@ -0,0 +1,17 @@
1
+ import { ComponentType, ReactNode } from 'react'
2
+ import type { A11yProps, CopyLang, PressableState, Tokens, Variant, ViewProps } from './common'
3
+
4
+ type TooltipPosition = 'auto' | 'above' | 'right' | 'below' | 'left'
5
+
6
+ export interface TooltipProps extends A11yProps, ViewProps {
7
+ children?: ReactNode | ((state: PressableState) => React.ReactNode)
8
+ content?: ReactNode
9
+ copy?: CopyLang
10
+ position?: TooltipPosition
11
+ tokens?: Tokens
12
+ variant?: Variant
13
+ }
14
+
15
+ declare const Tooltip: ComponentType<TooltipProps>
16
+
17
+ export default Tooltip
@@ -0,0 +1,12 @@
1
+ import { ComponentType } from 'react'
2
+ import type { A11yProps, PressableState, Tokens, Variant, ViewProps } from './common'
3
+
4
+ export interface TooltipButtonProps extends A11yProps, ViewProps {
5
+ pressableState?: Partial<PressableState>
6
+ tokens?: Tokens
7
+ variant?: Variant
8
+ }
9
+
10
+ declare const TooltipButton: ComponentType<TooltipButtonProps>
11
+
12
+ export default TooltipButton
@@ -0,0 +1,27 @@
1
+ import { ComponentType, ReactNode } from 'react'
2
+ import type {
3
+ A11yProps,
4
+ SkeletonProps,
5
+ TextAlign,
6
+ TextProps,
7
+ Tokens,
8
+ Variant,
9
+ ViewProps
10
+ } from './common'
11
+
12
+ type HeadingTag = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
13
+
14
+ export interface TypographyProps extends A11yProps, TextProps, ViewProps {
15
+ tokens?: Tokens
16
+ variant?: Variant
17
+ heading?: HeadingTag | true
18
+ tag?: 'blockquote' | 'code' | 'del' | 'em' | 'ins' | 'li' | 'strong' | 'label' | HeadingTag
19
+ block?: boolean
20
+ align?: TextAlign
21
+ children?: ReactNode
22
+ skeleton?: SkeletonProps
23
+ }
24
+
25
+ declare const Typography: ComponentType<TypographyProps>
26
+
27
+ export default Typography
@@ -0,0 +1,17 @@
1
+ import type { ComponentType } from 'react'
2
+ import type { HTMLAttrs } from './common'
3
+
4
+ export interface WebVideoProps extends HTMLAttrs {
5
+ videoId: string
6
+ posterSrc: string
7
+ aspectRatio?: '16:9' | '4:3' | '1:1'
8
+ defaultVolume?: number
9
+ beginMuted?: boolean
10
+ videoLength: number
11
+ copy: 'en' | 'fr'
12
+ onStart: () => void
13
+ }
14
+
15
+ declare const WebVideo: ComponentType<WebVideoProps>
16
+
17
+ export default WebVideo
package/types/common.d.ts CHANGED
@@ -1,4 +1,22 @@
1
1
  import type { AriaRole, AriaAttributes } from 'react'
2
+ import type {
3
+ AccessibilityProps,
4
+ LayoutChangeEvent,
5
+ NativeSyntheticEvent,
6
+ TextLayoutEventData
7
+ } from './ReactNative'
8
+
9
+ export interface A11yProps extends AccessibilityProps {}
10
+
11
+ export interface InputSupportsProps {
12
+ copy?: CopyLang
13
+ label?: string
14
+ hint?: string
15
+ hintPosition?: 'inline' | 'below'
16
+ feedback?: string
17
+ tooltip?: string
18
+ validation?: 'error' | 'success'
19
+ }
2
20
 
3
21
  export interface HTMLAttrs extends AriaAttributes {
4
22
  dataSet?: Record<string, any>
@@ -11,4 +29,148 @@ export interface HTMLAttrs extends AriaAttributes {
11
29
  title?: string
12
30
  }
13
31
 
32
+ export interface TextInputHandlerProps {
33
+ // TODO: Typing RN synthetic event for web is going to be tricky...
34
+ // Come back to this and fix later.
35
+ onChange?: (text: string, event: any) => void
36
+ onChangeText?: (text: string) => void
37
+ onClear?: (event: any) => void
38
+ onSubmit?: (event: any) => void
39
+ onSubmitEditing?: (event: any) => void
40
+ onContentSizeChange?: ((w: number, h: number) => void) | undefined
41
+ onEndEditing?: (event: any) => void
42
+ onScroll?: (event: any) => void
43
+ onSelectionChange?: (event: any) => void
44
+ onKeyPress?: (event: any) => void
45
+ onKeyUp?: (event: any) => void
46
+ onKeyDown?: (event: any) => void
47
+ }
48
+
49
+ export interface CrossPlatformTextInputProps {
50
+ // Text props
51
+ maxFontSizeMultiplier?: number
52
+ nativeId?: string
53
+ onLayout?: (event: LayoutChangeEvent) => void
54
+ // Input value props
55
+ value?: string
56
+ initialValue?: string
57
+ readOnly?: boolean
58
+ inactive?: boolean
59
+ // Text input props
60
+ autoComplete?: string
61
+ autoCorrect?: boolean | 'on' | 'off'
62
+ autoFocus?: boolean
63
+ blurOnSubmit?: boolean
64
+ clearTextOnFocus?: boolean
65
+ editable?: boolean
66
+ keyboardType?: string
67
+ maxLength?: number
68
+ multiline?: boolean
69
+ numberOfLines?: number
70
+ placeholder?: string
71
+ placeholderTextColor?: string
72
+ returnKeyType?: string
73
+ secureTextEntry?: boolean
74
+ selectTextOnFocus?: boolean
75
+ spellCheck?: boolean
76
+ }
77
+
78
+ export interface NativeTextInputProps {
79
+ caretHidden?: boolean
80
+ clearButtonMode?: string
81
+ contextMenuHidden?: boolean
82
+ dataDetectorTypes?: string
83
+ disableFullscreenUI?: boolean
84
+ enablesReturnKeyAutomatically?: boolean
85
+ importantForAutofill?: string
86
+ inlineImageLeft?: string
87
+ keyboardAppearance?: string
88
+ returnKeyLabel?: string
89
+ rejectResponderTermination?: boolean
90
+ scrollEnabled?: boolean
91
+ selection?: any
92
+ selectionColor?: string
93
+ showSoftInputOnFocus?: boolean
94
+ textAlign?: string
95
+ textContentType?: string
96
+ passwordRules?: string
97
+ textBreakStrategy?: string
98
+ underlineColorAndroid?: string
99
+ }
100
+
101
+ export interface WebTextInputProps {
102
+ disabled?: boolean
103
+ dir?: 'auto' | 'ltr' | 'rtl'
104
+ lang?: string
105
+ pattern?: string
106
+ }
107
+
108
+ export interface TextInputProps
109
+ extends CrossPlatformTextInputProps,
110
+ NativeTextInputProps,
111
+ WebTextInputProps {}
112
+
113
+ export interface ViewProps {
114
+ pointerEvents?: 'all' | 'none' | 'box-only' | 'box-none'
115
+ onLayout?: (event: LayoutChangeEvent) => void
116
+ nativeID?: string
117
+ testID?: string
118
+ dataSet?: Record<string, any>
119
+ }
120
+
121
+ export interface CrossPlatformTextProps {
122
+ numberOfLines?: number
123
+ selectable?: boolean
124
+ }
125
+
126
+ export interface NativeTextProps {
127
+ ellipsizeMode?: string
128
+ maxFontSizeMultiplier?: number
129
+ minimumFontScale?: number
130
+ onTextLayout?: (event: NativeSyntheticEvent<TextLayoutEventData>) => void
131
+ suppressHighlighting?: boolean
132
+ textBreakStrategy?: string
133
+ }
134
+
135
+ export interface WebTextProps {
136
+ dir?: 'auto' | 'ltr' | 'rtl'
137
+ lang?: string
138
+ }
139
+
140
+ export interface TextProps extends CrossPlatformTextProps, NativeTextProps, WebTextProps {}
141
+
142
+ export type TextAlign = 'auto' | 'left' | 'right' | 'center' | 'justify'
143
+
144
+ export type Tokens = Record<string, any>
145
+
146
+ export type CopyLang = 'en' | 'fr'
147
+
14
148
  export type Variant = Record<string, string | number | boolean>
149
+
150
+ export interface PressableState {
151
+ pressed: boolean
152
+ hover: boolean
153
+ focus: boolean
154
+ }
155
+
156
+ // TODO: Make this more specific:
157
+ // https://telus.github.io/universal-design-system/components/allium/skeleton/#props
158
+ export type SkeletonProps = Record<string, any>
159
+
160
+ export type HeadingTag = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
161
+
162
+ export type LayoutTag =
163
+ | HeadingTag
164
+ | 'article'
165
+ | 'aside'
166
+ | 'blockquote'
167
+ | 'footer'
168
+ | 'figure'
169
+ | 'form'
170
+ | 'header'
171
+ | 'ul'
172
+ | 'li'
173
+ | 'main'
174
+ | 'nav'
175
+ | 'section'
176
+ | 'label'