@utilitywarehouse/hearth-react-native 0.15.3 → 0.16.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.
- package/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-lint.log +1 -3
- package/CHANGELOG.md +67 -6
- package/build/components/Checkbox/CheckboxGroup.d.ts +1 -1
- package/build/components/Checkbox/CheckboxGroup.js +2 -2
- package/build/components/Checkbox/CheckboxGroup.props.d.ts +2 -1
- package/build/components/CurrencyInput/CurrencyInput.d.ts +1 -1
- package/build/components/CurrencyInput/CurrencyInput.js +2 -6
- package/build/components/CurrencyInput/CurrencyInput.props.d.ts +6 -0
- package/build/components/DateInput/DateInputSegment.js +0 -1
- package/build/components/DatePickerInput/DatePickerInput.d.ts +1 -1
- package/build/components/DatePickerInput/DatePickerInput.js +2 -2
- package/build/components/DatePickerInput/DatePickerInput.props.d.ts +6 -0
- package/build/components/FormField/FormField.context.d.ts +8 -2
- package/build/components/FormField/FormField.d.ts +1 -1
- package/build/components/FormField/FormField.js +24 -4
- package/build/components/FormField/FormField.props.d.ts +2 -0
- package/build/components/FormField/FormFieldLabel.d.ts +1 -1
- package/build/components/FormField/FormFieldLabel.js +3 -3
- package/build/components/FormField/FormFieldValid.js +2 -2
- package/build/components/Input/Input.js +48 -10
- package/build/components/Input/Input.props.d.ts +7 -1
- package/build/components/Label/Label.d.ts +1 -1
- package/build/components/Label/Label.js +5 -1
- package/build/components/Label/Label.props.d.ts +3 -2
- package/build/components/Radio/RadioGroup.d.ts +1 -1
- package/build/components/Radio/RadioGroup.js +2 -2
- package/build/components/Radio/RadioGroup.props.d.ts +1 -0
- package/build/components/RadioCard/RadioCard.d.ts +1 -1
- package/build/components/RadioCard/RadioCard.js +2 -2
- package/build/components/RadioCard/RadioCard.props.d.ts +1 -0
- package/build/components/Select/Select.d.ts +1 -1
- package/build/components/Select/Select.js +2 -2
- package/build/components/Select/Select.props.d.ts +10 -0
- package/build/components/Textarea/Textarea.d.ts +1 -1
- package/build/components/Textarea/Textarea.js +43 -6
- package/build/components/Textarea/Textarea.props.d.ts +8 -0
- package/build/components/VerificationInput/VerificationInput.d.ts +1 -1
- package/build/components/VerificationInput/VerificationInput.js +2 -2
- package/build/components/VerificationInput/VerificationInput.props.d.ts +4 -0
- package/docs/components/AllComponents.web.tsx +3 -2
- package/docs/theme-tokens.mdx +390 -2
- package/package.json +3 -3
- package/src/components/Checkbox/Checkbox.docs.mdx +32 -31
- package/src/components/Checkbox/CheckboxGroup.props.ts +2 -1
- package/src/components/Checkbox/CheckboxGroup.tsx +6 -1
- package/src/components/CurrencyInput/CurrencyInput.docs.mdx +52 -9
- package/src/components/CurrencyInput/CurrencyInput.props.ts +6 -0
- package/src/components/CurrencyInput/CurrencyInput.stories.tsx +30 -1
- package/src/components/CurrencyInput/CurrencyInput.tsx +16 -8
- package/src/components/DateInput/DateInputSegment.tsx +0 -1
- package/src/components/DatePickerInput/DatePickerInput.docs.mdx +22 -0
- package/src/components/DatePickerInput/DatePickerInput.props.ts +6 -0
- package/src/components/DatePickerInput/DatePickerInput.tsx +17 -3
- package/src/components/FormField/FormField.context.ts +6 -1
- package/src/components/FormField/FormField.docs.mdx +30 -30
- package/src/components/FormField/FormField.props.ts +2 -0
- package/src/components/FormField/FormField.stories.tsx +8 -2
- package/src/components/FormField/FormField.tsx +38 -4
- package/src/components/FormField/FormFieldLabel.tsx +7 -3
- package/src/components/FormField/FormFieldValid.tsx +2 -2
- package/src/components/Input/Input.docs.mdx +67 -22
- package/src/components/Input/Input.props.ts +7 -1
- package/src/components/Input/Input.stories.tsx +9 -1
- package/src/components/Input/Input.tsx +124 -59
- package/src/components/Label/Label.props.ts +3 -2
- package/src/components/Label/Label.tsx +11 -1
- package/src/components/Radio/Radio.docs.mdx +31 -30
- package/src/components/Radio/RadioGroup.props.ts +1 -0
- package/src/components/Radio/RadioGroup.stories.tsx +6 -0
- package/src/components/Radio/RadioGroup.tsx +6 -1
- package/src/components/RadioCard/RadioCard.docs.mdx +31 -30
- package/src/components/RadioCard/RadioCard.props.ts +1 -0
- package/src/components/RadioCard/RadioCard.tsx +8 -2
- package/src/components/Select/Select.props.ts +10 -0
- package/src/components/Select/Select.tsx +3 -2
- package/src/components/Textarea/Textarea.docs.mdx +65 -17
- package/src/components/Textarea/Textarea.props.ts +8 -0
- package/src/components/Textarea/Textarea.stories.tsx +23 -2
- package/src/components/Textarea/Textarea.tsx +84 -19
- package/src/components/VerificationInput/VerificationInput.docs.mdx +1 -0
- package/src/components/VerificationInput/VerificationInput.props.ts +4 -1
- package/src/components/VerificationInput/VerificationInput.tsx +2 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createFormControl } from '@gluestack-ui/form-control';
|
|
2
|
-
import { useMemo } from 'react';
|
|
2
|
+
import { useMemo, useState } from 'react';
|
|
3
3
|
import { View } from 'react-native';
|
|
4
4
|
import { HelperIcon, HelperText } from '../Helper';
|
|
5
5
|
import { FormFieldContext } from './FormField.context';
|
|
@@ -46,16 +46,40 @@ const FormField = ({
|
|
|
46
46
|
validText,
|
|
47
47
|
invalidText,
|
|
48
48
|
required = true,
|
|
49
|
+
labelVariant = 'body',
|
|
50
|
+
accessibilityHandledByChildren = false,
|
|
49
51
|
...props
|
|
50
52
|
}: FormFieldProps) => {
|
|
53
|
+
const [shouldHandleAccessibility, setShouldHandleAccessibility] = useState<boolean>(
|
|
54
|
+
accessibilityHandledByChildren
|
|
55
|
+
);
|
|
51
56
|
const value = useMemo(
|
|
52
57
|
() => ({
|
|
53
58
|
validationStatus,
|
|
54
59
|
disabled,
|
|
55
60
|
readonly,
|
|
56
61
|
required,
|
|
62
|
+
label,
|
|
63
|
+
helperText,
|
|
64
|
+
helperIcon,
|
|
65
|
+
validText,
|
|
66
|
+
invalidText,
|
|
67
|
+
setShouldHandleAccessibility,
|
|
68
|
+
shouldHandleAccessibility,
|
|
57
69
|
}),
|
|
58
|
-
[
|
|
70
|
+
[
|
|
71
|
+
validationStatus,
|
|
72
|
+
disabled,
|
|
73
|
+
readonly,
|
|
74
|
+
required,
|
|
75
|
+
label,
|
|
76
|
+
helperText,
|
|
77
|
+
helperIcon,
|
|
78
|
+
validText,
|
|
79
|
+
invalidText,
|
|
80
|
+
setShouldHandleAccessibility,
|
|
81
|
+
shouldHandleAccessibility,
|
|
82
|
+
]
|
|
59
83
|
);
|
|
60
84
|
|
|
61
85
|
return (
|
|
@@ -64,13 +88,23 @@ const FormField = ({
|
|
|
64
88
|
{(!!label || !!helperText) && (
|
|
65
89
|
<FormFieldTextContent>
|
|
66
90
|
{!!label && (
|
|
67
|
-
<FormFieldLabelText
|
|
91
|
+
<FormFieldLabelText
|
|
92
|
+
variant={labelVariant}
|
|
93
|
+
importantForAccessibility={shouldHandleAccessibility ? 'no' : undefined}
|
|
94
|
+
accessibilityElementsHidden={shouldHandleAccessibility}
|
|
95
|
+
>
|
|
68
96
|
{label}
|
|
69
97
|
{!required ? ` (Optional)` : ''}
|
|
70
98
|
</FormFieldLabelText>
|
|
71
99
|
)}
|
|
72
100
|
{!!helperText && (
|
|
73
|
-
<FormFieldHelper
|
|
101
|
+
<FormFieldHelper
|
|
102
|
+
text={helperText}
|
|
103
|
+
icon={helperIcon}
|
|
104
|
+
showIcon={!!helperIcon}
|
|
105
|
+
importantForAccessibility={shouldHandleAccessibility ? 'no' : undefined}
|
|
106
|
+
accessibilityElementsHidden={shouldHandleAccessibility}
|
|
107
|
+
/>
|
|
74
108
|
)}
|
|
75
109
|
</FormFieldTextContent>
|
|
76
110
|
)}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { useFormFieldContext } from './FormField.context';
|
|
2
1
|
import { Label } from '../Label';
|
|
3
2
|
import LabelProps from '../Label/Label.props';
|
|
3
|
+
import { useFormFieldContext } from './FormField.context';
|
|
4
4
|
|
|
5
|
-
const FormFieldLabel = ({ children }: Omit<LabelProps, 'disabled'>) => {
|
|
5
|
+
const FormFieldLabel = ({ children, ...props }: Omit<LabelProps, 'disabled'>) => {
|
|
6
6
|
const { disabled } = useFormFieldContext();
|
|
7
|
-
return
|
|
7
|
+
return (
|
|
8
|
+
<Label disabled={disabled} {...props}>
|
|
9
|
+
{children}
|
|
10
|
+
</Label>
|
|
11
|
+
);
|
|
8
12
|
};
|
|
9
13
|
|
|
10
14
|
FormFieldLabel.displayName = 'FormFieldLabel';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TickCircleSmallIcon } from '@utilitywarehouse/hearth-react-native-icons';
|
|
2
2
|
import { Helper } from '../Helper';
|
|
3
3
|
import HelperProps from '../Helper/Helper.props';
|
|
4
|
-
import {
|
|
4
|
+
import { useFormFieldContext } from './FormField.context';
|
|
5
5
|
|
|
6
6
|
const FormFieldValid = ({
|
|
7
7
|
children,
|
|
@@ -83,18 +83,25 @@ all of the React Native [`View` props](https://reactnative.dev/docs/view).
|
|
|
83
83
|
| ---------------- | ---------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
84
84
|
| type | `'text' \| 'password'` | `'text'` | The type of the input. |
|
|
85
85
|
| validationStatus | `'initial' \| 'valid' \| 'invalid` | `'initial'` | The validation status of the input. |
|
|
86
|
-
| disabled | boolean
|
|
87
|
-
| readonly | boolean
|
|
88
|
-
| focused | boolean
|
|
89
|
-
|
|
|
90
|
-
|
|
|
91
|
-
|
|
|
92
|
-
|
|
|
93
|
-
|
|
|
94
|
-
|
|
|
95
|
-
|
|
|
96
|
-
|
|
|
97
|
-
|
|
|
86
|
+
| disabled | `boolean` | `false` | Disables the input. |
|
|
87
|
+
| readonly | `boolean` | `false` | Makes the input read-only. |
|
|
88
|
+
| focused | `boolean` | `false` | Sets focus on the input. |
|
|
89
|
+
| label | `string` | `-` | The label for the input. **(Only to be used if the input has no children)** |
|
|
90
|
+
| labelVariant | `'heading' \| 'body'` | `'body'` | The variant of the label text. **(Only to be used if the input has no children)** |
|
|
91
|
+
| helperText | `string` | `-` | Helper text to display below the input. **(Only to be used if the input has no children)** |
|
|
92
|
+
| helperIcon | `React.ComponentType` | `-` | Icon to display alongside the helper text. **(Only to be used if the input has no children)** |
|
|
93
|
+
| validText | `string` | `-` | Text to display when validation status is 'valid'. **(Only to be used if the input has no children)** |
|
|
94
|
+
| invalidText | `string` | `-` | Text to display when validation status is 'invalid'. **(Only to be used if the input has no children)** |
|
|
95
|
+
| required | `boolean` | `true` | Indicates that the input is required. **(Only to be used if the input has no children)** |
|
|
96
|
+
| leadingIcon | `React.ComponentType` | `-` | The leading icon of the input. **(Only to be used if the input has no children)** |
|
|
97
|
+
| trailingIcon | `React.ComponentType` | `-` | The trailing icon of the input. **(Only to be used if the input has no children)** |
|
|
98
|
+
| value | `string` | `-` | The value of the input. **(Only to be used if the input has no children)** |
|
|
99
|
+
| onChange | `function` | `-` | Callback function that is triggered when the input value changes. **(Only to be used if the input has no children)** **(Only to be used if the input has no children)** |
|
|
100
|
+
| onBlur | `function` | `-` | Callback function that is triggered when the input loses focus. **(Only to be used if the input has no children)** |
|
|
101
|
+
| onFocus | `function` | `-` | Callback function that is triggered when the input gains focus. **(Only to be used if the input has no children)** |
|
|
102
|
+
| placeholder | `string` | `-` | The placeholder text for the input. **(Only to be used if the input has no children)** |
|
|
103
|
+
| required | `boolean` | `true` | Indicates that the input is required. **(Only to be used if the input has no children)** |
|
|
104
|
+
| inBottomSheet | `boolean` | `false` | Indicates if the input is within a bottom sheet. |
|
|
98
105
|
|
|
99
106
|
If the `leadingIcon` or `trailingIcon` props are used, the `Input` component should not have any children.
|
|
100
107
|
|
|
@@ -105,19 +112,19 @@ The `InputField` inherits all of the React Native [`TextInput` props](https://re
|
|
|
105
112
|
| Prop | Type | Default | Description |
|
|
106
113
|
| ------------- | ---------------------- | -------- | ----------------------------------------------------------------- |
|
|
107
114
|
| type | `'text' \| 'password'` | `'text'` | The type of the input. |
|
|
108
|
-
| value | string
|
|
109
|
-
| onChange | function
|
|
110
|
-
| onBlur | function
|
|
111
|
-
| onFocus | function
|
|
112
|
-
| placeholder | string
|
|
113
|
-
| required | boolean
|
|
114
|
-
| inBottomSheet | boolean
|
|
115
|
+
| value | `string` | `-` | The value of the input. |
|
|
116
|
+
| onChange | `function` | `-` | Callback function that is triggered when the input value changes. |
|
|
117
|
+
| onBlur | `function` | `-` | Callback function that is triggered when the input loses focus. |
|
|
118
|
+
| onFocus | `function` | `-` | Callback function that is triggered when the input gains focus. |
|
|
119
|
+
| placeholder | `string` | `-` | The placeholder text for the input. |
|
|
120
|
+
| required | `boolean` | `true` | Indicates that the input is required. |
|
|
121
|
+
| inBottomSheet | `boolean` | `false` | Indicates if the input is within a bottom sheet. |
|
|
115
122
|
|
|
116
123
|
### `InputIcon`
|
|
117
124
|
|
|
118
|
-
| Prop | Type
|
|
119
|
-
| ---- |
|
|
120
|
-
| as | string | | The icon component. |
|
|
125
|
+
| Prop | Type | Default | Description |
|
|
126
|
+
| ---- | -------- | ------- | ------------------- |
|
|
127
|
+
| as | `string` | | The icon component. |
|
|
121
128
|
|
|
122
129
|
### `InputSlot`
|
|
123
130
|
|
|
@@ -191,6 +198,41 @@ The `Input` component has the following variants:
|
|
|
191
198
|
|
|
192
199
|
## Examples
|
|
193
200
|
|
|
201
|
+
## With Label and Helper Text
|
|
202
|
+
|
|
203
|
+
The `Input` component can be used with a label and helper text by passing the `label` and `helperText` props.
|
|
204
|
+
|
|
205
|
+
<UsageWrap>
|
|
206
|
+
<Center>
|
|
207
|
+
<Input
|
|
208
|
+
label="Label"
|
|
209
|
+
helperText="Helper text"
|
|
210
|
+
onChange={() => console.log('###')}
|
|
211
|
+
placeholder="Placeholder"
|
|
212
|
+
/>
|
|
213
|
+
</Center>
|
|
214
|
+
</UsageWrap>
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
import { Input } from '@utilitywarehouse/hearth-react-native';
|
|
218
|
+
|
|
219
|
+
const MyComponent = () => {
|
|
220
|
+
const [value, setValue] = useState('');
|
|
221
|
+
const handleChange = e => {
|
|
222
|
+
setValue(e.target.value);
|
|
223
|
+
};
|
|
224
|
+
return (
|
|
225
|
+
<Input
|
|
226
|
+
label="Label"
|
|
227
|
+
helperText="Helper text"
|
|
228
|
+
onChange={handleChange}
|
|
229
|
+
value={value}
|
|
230
|
+
placeholder="Placeholder"
|
|
231
|
+
/>
|
|
232
|
+
);
|
|
233
|
+
};
|
|
234
|
+
```
|
|
235
|
+
|
|
194
236
|
### With `FormField`
|
|
195
237
|
|
|
196
238
|
The `Input` component can be used with the `FormField` component to create a custom input field.
|
|
@@ -230,6 +272,9 @@ We have outlined the various features that ensure the Input component is accessi
|
|
|
230
272
|
|
|
231
273
|
### Screen Reader
|
|
232
274
|
|
|
275
|
+
- When setting the label prop, it is associated with the Input using aria-label.
|
|
276
|
+
- When setting the helperText prop, it is associated with the Input using aria-describedby.
|
|
277
|
+
- The required prop to indicate if the Input is required or optional and is read out by screen readers.
|
|
233
278
|
- Compatible with screen readers such as VoiceOver and Talk-back.
|
|
234
279
|
- The accessible and aria-label props to provide descriptive information about the Input
|
|
235
280
|
- Setting aria-traits and aria-hint to provide contextual information about the various states of the Input, such as "double tap to edit".
|
|
@@ -27,6 +27,13 @@ export interface InputBaseProps {
|
|
|
27
27
|
focused?: boolean;
|
|
28
28
|
placeholder?: string;
|
|
29
29
|
inBottomSheet?: boolean;
|
|
30
|
+
label?: string;
|
|
31
|
+
labelVariant?: 'heading' | 'body';
|
|
32
|
+
helperText?: string;
|
|
33
|
+
helperIcon?: ComponentType;
|
|
34
|
+
validText?: string;
|
|
35
|
+
invalidText?: string;
|
|
36
|
+
required?: boolean;
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
// For inputs that have children
|
|
@@ -40,7 +47,6 @@ export interface InputWithChildrenProps extends InputBaseProps, ViewProps {
|
|
|
40
47
|
onClear?: never;
|
|
41
48
|
leadingIcon?: never;
|
|
42
49
|
trailingIcon?: never;
|
|
43
|
-
required?: never;
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
// Base for inputs without children
|
|
@@ -82,7 +82,15 @@ export const Playground: Story = {
|
|
|
82
82
|
const leadingIcon = leading === 'none' ? undefined : Icons[leading];
|
|
83
83
|
// @ts-expect-error - This is a playground
|
|
84
84
|
const trailingIcon = trailing === 'none' ? undefined : Icons[trailing];
|
|
85
|
-
return
|
|
85
|
+
return (
|
|
86
|
+
<Input
|
|
87
|
+
{...args}
|
|
88
|
+
leadingIcon={leadingIcon}
|
|
89
|
+
trailingIcon={trailingIcon}
|
|
90
|
+
label="First Name"
|
|
91
|
+
helperText="Only enter your first name, not your full name"
|
|
92
|
+
/>
|
|
93
|
+
);
|
|
86
94
|
},
|
|
87
95
|
};
|
|
88
96
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createInput } from '@gluestack-ui/input';
|
|
2
|
-
import { ComponentType, forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
|
2
|
+
import { ComponentType, forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
3
3
|
import { TextInput } from 'react-native';
|
|
4
4
|
import type InputProps from './Input.props';
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
SearchMediumIcon,
|
|
11
11
|
} from '@utilitywarehouse/hearth-react-native-icons';
|
|
12
12
|
import { useTheme } from '../../hooks';
|
|
13
|
-
import { useFormFieldContext } from '../FormField';
|
|
13
|
+
import { FormField, useFormFieldContext } from '../FormField';
|
|
14
14
|
import { Spinner } from '../Spinner';
|
|
15
15
|
import { UnstyledIconButton } from '../UnstyledIconButton';
|
|
16
16
|
import { InputWithoutChildrenProps } from './Input.props';
|
|
@@ -46,17 +46,35 @@ const Input = forwardRef<TextInput, InputProps>(
|
|
|
46
46
|
format,
|
|
47
47
|
loading,
|
|
48
48
|
clearable = false,
|
|
49
|
-
required,
|
|
49
|
+
required = true,
|
|
50
50
|
inBottomSheet = false,
|
|
51
51
|
style,
|
|
52
|
+
label,
|
|
53
|
+
labelVariant,
|
|
54
|
+
helperText,
|
|
55
|
+
helperIcon,
|
|
56
|
+
validText,
|
|
57
|
+
invalidText,
|
|
52
58
|
...props
|
|
53
59
|
},
|
|
54
60
|
ref
|
|
55
61
|
) => {
|
|
56
62
|
const formFieldContext = useFormFieldContext();
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
63
|
+
const inputLabel = label ?? formFieldContext?.label;
|
|
64
|
+
const inputHelperText = helperText ?? formFieldContext?.helperText;
|
|
65
|
+
const inputValidText = validText ?? formFieldContext?.validText;
|
|
66
|
+
const inputInvalidText = invalidText ?? formFieldContext?.invalidText;
|
|
67
|
+
const inputRequired = required ?? formFieldContext?.required;
|
|
68
|
+
const inputDisabled = disabled ?? formFieldContext?.disabled;
|
|
69
|
+
const inputReadonly = readonly ?? formFieldContext?.readonly;
|
|
70
|
+
const inputValidationStatus = formFieldContext?.validationStatus ?? validationStatus;
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (formFieldContext?.setShouldHandleAccessibility) {
|
|
74
|
+
formFieldContext.setShouldHandleAccessibility(true);
|
|
75
|
+
}
|
|
76
|
+
}, []);
|
|
77
|
+
|
|
60
78
|
const [fieldType, setFieldType] = useState<'password' | 'text'>(
|
|
61
79
|
type === 'password' ? 'password' : 'text'
|
|
62
80
|
);
|
|
@@ -87,61 +105,108 @@ const Input = forwardRef<TextInput, InputProps>(
|
|
|
87
105
|
return undefined;
|
|
88
106
|
})();
|
|
89
107
|
|
|
108
|
+
const getAccessibilityLabel = () => {
|
|
109
|
+
let accessibilityLabel = '';
|
|
110
|
+
if (inputLabel) {
|
|
111
|
+
accessibilityLabel = accessibilityLabel + inputLabel;
|
|
112
|
+
}
|
|
113
|
+
if (inputRequired) {
|
|
114
|
+
accessibilityLabel = accessibilityLabel + ', required';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return accessibilityLabel || props.accessibilityLabel;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const getAccessibilityHint = () => {
|
|
121
|
+
let accessibilityHint = '';
|
|
122
|
+
if (inputHelperText) {
|
|
123
|
+
accessibilityHint = accessibilityHint + inputHelperText;
|
|
124
|
+
}
|
|
125
|
+
if (inputValidationStatus !== 'initial') {
|
|
126
|
+
if (accessibilityHint.length > 0) {
|
|
127
|
+
accessibilityHint = accessibilityHint + ', ';
|
|
128
|
+
}
|
|
129
|
+
if (inputValidationStatus === 'invalid' && inputInvalidText) {
|
|
130
|
+
accessibilityHint = accessibilityHint + inputInvalidText;
|
|
131
|
+
}
|
|
132
|
+
if (inputValidationStatus === 'valid' && inputValidText) {
|
|
133
|
+
accessibilityHint = accessibilityHint + inputValidText;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return accessibilityHint || props.accessibilityHint;
|
|
137
|
+
};
|
|
138
|
+
|
|
90
139
|
return (
|
|
91
|
-
<
|
|
92
|
-
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
140
|
+
<FormField
|
|
141
|
+
label={label}
|
|
142
|
+
labelVariant={labelVariant}
|
|
143
|
+
helperText={helperText}
|
|
144
|
+
helperIcon={helperIcon}
|
|
145
|
+
validText={validText}
|
|
146
|
+
invalidText={invalidText}
|
|
147
|
+
required={required}
|
|
148
|
+
validationStatus={validationStatus}
|
|
149
|
+
disabled={disabled}
|
|
150
|
+
readonly={readonly}
|
|
151
|
+
accessibilityHandledByChildren
|
|
101
152
|
>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
{
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
153
|
+
<InputComponent
|
|
154
|
+
{...(children ? props : {})}
|
|
155
|
+
validationStatus={inputValidationStatus}
|
|
156
|
+
isInvalid={inputValidationStatus === 'invalid'}
|
|
157
|
+
isReadOnly={inputReadonly}
|
|
158
|
+
isDisabled={inputDisabled}
|
|
159
|
+
isFocused={focused}
|
|
160
|
+
type={type as undefined}
|
|
161
|
+
isRequired={inputRequired}
|
|
162
|
+
style={style}
|
|
163
|
+
>
|
|
164
|
+
{children ? (
|
|
165
|
+
<>{children}</>
|
|
166
|
+
) : (
|
|
167
|
+
<>
|
|
168
|
+
{!!leadingIconComponent && (
|
|
169
|
+
<InputSlot>
|
|
170
|
+
<InputIcon as={leadingIconComponent} />
|
|
171
|
+
</InputSlot>
|
|
172
|
+
)}
|
|
173
|
+
<InputField
|
|
174
|
+
// @ts-expect-error - ref forwarding issue
|
|
175
|
+
ref={inputRef}
|
|
176
|
+
type={fieldType}
|
|
177
|
+
inputMode={getInputMode}
|
|
178
|
+
inBottomSheet={inBottomSheet}
|
|
179
|
+
{...props}
|
|
180
|
+
aria-label={getAccessibilityLabel()}
|
|
181
|
+
accessibilityHint={getAccessibilityHint()}
|
|
182
|
+
/>
|
|
183
|
+
{shouldShowClear && (
|
|
184
|
+
<InputSlot>
|
|
185
|
+
<UnstyledIconButton onPress={onClear} icon={CloseSmallIcon} />
|
|
186
|
+
</InputSlot>
|
|
187
|
+
)}
|
|
188
|
+
{loading && (
|
|
189
|
+
<InputSlot>
|
|
190
|
+
<Spinner size="xs" color={color.icon.primary} />
|
|
191
|
+
</InputSlot>
|
|
192
|
+
)}
|
|
193
|
+
{shouldShowPasswordToggle && (
|
|
194
|
+
<InputSlot>
|
|
195
|
+
<UnstyledIconButton
|
|
196
|
+
onPress={toggleFieldType}
|
|
197
|
+
icon={fieldType === 'password' ? EyeSmallIcon : EyeOffSmallIcon}
|
|
198
|
+
/>
|
|
199
|
+
</InputSlot>
|
|
200
|
+
)}
|
|
201
|
+
{!!trailingIcon && (
|
|
202
|
+
<InputSlot>
|
|
203
|
+
<InputIcon as={trailingIcon} />
|
|
204
|
+
</InputSlot>
|
|
205
|
+
)}
|
|
206
|
+
</>
|
|
207
|
+
)}
|
|
208
|
+
</InputComponent>
|
|
209
|
+
</FormField>
|
|
145
210
|
);
|
|
146
211
|
}
|
|
147
212
|
);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BodyTextProps } from '../BodyText';
|
|
2
2
|
|
|
3
|
-
interface LabelProps extends
|
|
3
|
+
interface LabelProps extends Omit<BodyTextProps, 'size' | 'weight'> {
|
|
4
4
|
nested?: boolean;
|
|
5
5
|
disabled?: boolean;
|
|
6
|
+
variant?: 'heading' | 'body';
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
export default LabelProps;
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { StyleSheet } from 'react-native-unistyles';
|
|
2
2
|
import { BodyText } from '../BodyText';
|
|
3
|
+
import { Heading } from '../Heading';
|
|
3
4
|
import LabelProps from './Label.props';
|
|
4
5
|
|
|
5
|
-
const Label = ({ children, nested, disabled, style, ...props }: LabelProps) => {
|
|
6
|
+
const Label = ({ children, nested, disabled, style, variant = 'body', ...props }: LabelProps) => {
|
|
6
7
|
styles.useVariants({ disabled });
|
|
8
|
+
|
|
9
|
+
if (variant === 'heading') {
|
|
10
|
+
return (
|
|
11
|
+
<Heading size="md" style={[styles.text, style]} {...props}>
|
|
12
|
+
{children}
|
|
13
|
+
</Heading>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
return (
|
|
8
18
|
<BodyText
|
|
9
19
|
size="md"
|
|
@@ -90,21 +90,21 @@ const MyComponent = () => {
|
|
|
90
90
|
|
|
91
91
|
## Props
|
|
92
92
|
|
|
93
|
-
| Property | Type | Default
|
|
94
|
-
| -------------------- | ----------------------------------- |
|
|
95
|
-
| `value` | string | -
|
|
96
|
-
| `onChange` | function | -
|
|
97
|
-
| `disabled` | bool | false
|
|
98
|
-
| `validationStatus` | `'valid' \| 'invalid' \| 'initial'` | -
|
|
99
|
-
| `disabled` | `bool` | `false`
|
|
100
|
-
| `label` | `string` | -
|
|
101
|
-
| `helperText` | `string` | -
|
|
102
|
-
| `helperIcon` | `React.ComponentType` | -
|
|
103
|
-
| `invalidText` | `string` | -
|
|
104
|
-
| `validText` | `string` | -
|
|
105
|
-
| `showValidationIcon` | `boolean` | `true`
|
|
106
|
-
| `type` | `'default' \| 'tile'` | `default` | The type of the radio. |
|
|
107
|
-
| `image` | `ReactNode` | -
|
|
93
|
+
| Property | Type | Default | Description |
|
|
94
|
+
| -------------------- | ----------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------- |
|
|
95
|
+
| `value` | string | - | The value to be used in the radio input. This is the value that will be returned on form submission. |
|
|
96
|
+
| `onChange` | function | - | Function called when the state of the radio changes. |
|
|
97
|
+
| `disabled` | bool | false | To manually set disable to the radio. |
|
|
98
|
+
| `validationStatus` | `'valid' \| 'invalid' \| 'initial'` | - | The validation status of the radio. |
|
|
99
|
+
| `disabled` | `bool` | `false` | To manually set disable to the radio. |
|
|
100
|
+
| `label` | `string` | - | The label to be displayed next to the radio. |
|
|
101
|
+
| `helperText` | `string` | - | The helper text to be displayed below the radio. |
|
|
102
|
+
| `helperIcon` | `React.ComponentType` | - | The icon to be displayed next to the helper text. |
|
|
103
|
+
| `invalidText` | `string` | - | The invalid text to be displayed below the radio. |
|
|
104
|
+
| `validText` | `string` | - | The valid text to be displayed below the radio. |
|
|
105
|
+
| `showValidationIcon` | `boolean` | `true` | Whether to show the validation icon. |
|
|
106
|
+
| `type` | `'default' \| 'tile'` | `'default'` | The type of the radio. |
|
|
107
|
+
| `image` | `ReactNode` | - | The image to be displayed next to the label. |
|
|
108
108
|
|
|
109
109
|
## Components
|
|
110
110
|
|
|
@@ -132,21 +132,22 @@ Contains all Label related layout style props and actions. It inherits all the p
|
|
|
132
132
|
|
|
133
133
|
Contains all Group related layout style props and actions. It inherits all the properties of React Native's [View component](https://reactnative.dev/docs/view).
|
|
134
134
|
|
|
135
|
-
| Property | Type | Default
|
|
136
|
-
| -------------------- | ----------------------------------- |
|
|
137
|
-
| `value` | string | -
|
|
138
|
-
| `onChange` | function | -
|
|
139
|
-
| `disabled` | bool | -
|
|
140
|
-
| `validationStatus` | `'valid' \| 'invalid' \| 'initial'` | -
|
|
141
|
-
| `label` | `string` | -
|
|
142
|
-
| `
|
|
143
|
-
| `
|
|
144
|
-
| `
|
|
145
|
-
| `
|
|
146
|
-
| `
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
149
|
-
| `
|
|
135
|
+
| Property | Type | Default | Description |
|
|
136
|
+
| -------------------- | ----------------------------------- | ----------- | ------------------------------------------------------------------- |
|
|
137
|
+
| `value` | string | - | The value of the radio group. |
|
|
138
|
+
| `onChange` | function | - | The callback fired when any children Radio is checked or unchecked. |
|
|
139
|
+
| `disabled` | bool | - | To manually set disable to the radio group. |
|
|
140
|
+
| `validationStatus` | `'valid' \| 'invalid' \| 'initial'` | - | The validation status of the radio group. |
|
|
141
|
+
| `label` | `string` | - | The label to be displayed above the radio group. |
|
|
142
|
+
| `labelVariant` | `'heading' \| 'body'` | `'body'` | The variant of the label text. |
|
|
143
|
+
| `helperText` | `string` | - | The helper text to be displayed below the radio group. |
|
|
144
|
+
| `helperIcon` | `React.ComponentType` | - | The icon to be displayed next to the helper text. |
|
|
145
|
+
| `invalidText` | `string` | - | The invalid text to be displayed below the radio group. |
|
|
146
|
+
| `validText` | `string` | - | The valid text to be displayed below the radio group. |
|
|
147
|
+
| `showValidationIcon` | `boolean` | `true` | Whether to show the validation icon. |
|
|
148
|
+
| `type` | `'default' \| 'tile'` | `'default'` | The type of the radio group. |
|
|
149
|
+
| `direction` | `'row' \| 'column'` | `'column'` | The direction of the radio group. |
|
|
150
|
+
| `gap` | `string` | - | The gap between the radio group items. |
|
|
150
151
|
|
|
151
152
|
### `RadioImage`
|
|
152
153
|
|
|
@@ -19,6 +19,11 @@ const meta = {
|
|
|
19
19
|
control: 'text',
|
|
20
20
|
description: 'The label component for the radio group.',
|
|
21
21
|
},
|
|
22
|
+
labelVariant: {
|
|
23
|
+
control: 'radio',
|
|
24
|
+
options: ['heading', 'body'],
|
|
25
|
+
description: 'The variant of the label text.',
|
|
26
|
+
},
|
|
22
27
|
helperText: {
|
|
23
28
|
type: 'string',
|
|
24
29
|
control: 'text',
|
|
@@ -51,6 +56,7 @@ const meta = {
|
|
|
51
56
|
args: {
|
|
52
57
|
disabled: false,
|
|
53
58
|
label: 'Group label',
|
|
59
|
+
labelVariant: 'body',
|
|
54
60
|
helperText: 'Supporting text',
|
|
55
61
|
validationStatus: 'initial',
|
|
56
62
|
showValidationIcon: true,
|