@xsolla/xui-supporting-text 0.148.0 → 0.148.2
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/README.md +243 -0
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# Supporting Text
|
|
2
|
+
|
|
3
|
+
A cross-platform React component for displaying supporting text around form fields, including labels, helper text, descriptions, and error messages with proper accessibility.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @xsolla/xui-supporting-text
|
|
9
|
+
# or
|
|
10
|
+
yarn add @xsolla/xui-supporting-text
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Demo
|
|
14
|
+
|
|
15
|
+
### All Variants
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import * as React from 'react';
|
|
19
|
+
import { SupportingText } from '@xsolla/xui-supporting-text';
|
|
20
|
+
|
|
21
|
+
export default function AllVariants() {
|
|
22
|
+
return (
|
|
23
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
|
24
|
+
<SupportingText variant="label">Label text</SupportingText>
|
|
25
|
+
<SupportingText variant="helper">Helper text with guidance</SupportingText>
|
|
26
|
+
<SupportingText variant="description">Description text for context</SupportingText>
|
|
27
|
+
<SupportingText variant="error">Error message</SupportingText>
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Different Sizes
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import * as React from 'react';
|
|
37
|
+
import { SupportingText } from '@xsolla/xui-supporting-text';
|
|
38
|
+
|
|
39
|
+
export default function Sizes() {
|
|
40
|
+
return (
|
|
41
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
|
42
|
+
<SupportingText size="xs">Extra small</SupportingText>
|
|
43
|
+
<SupportingText size="sm">Small</SupportingText>
|
|
44
|
+
<SupportingText size="md">Medium</SupportingText>
|
|
45
|
+
<SupportingText size="lg">Large</SupportingText>
|
|
46
|
+
<SupportingText size="xl">Extra large</SupportingText>
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### With Icon
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import * as React from 'react';
|
|
56
|
+
import { SupportingText } from '@xsolla/xui-supporting-text';
|
|
57
|
+
import { Info } from '@xsolla/xui-icons-base';
|
|
58
|
+
|
|
59
|
+
export default function WithIcon() {
|
|
60
|
+
return (
|
|
61
|
+
<SupportingText variant="helper" icon={<Info />} showIcon>
|
|
62
|
+
Click here for more information
|
|
63
|
+
</SupportingText>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Anatomy
|
|
69
|
+
|
|
70
|
+
```jsx
|
|
71
|
+
import { SupportingText } from '@xsolla/xui-supporting-text';
|
|
72
|
+
|
|
73
|
+
<SupportingText
|
|
74
|
+
variant="helper" // label, helper, description, error
|
|
75
|
+
size="md" // xs, s, m, l, xl
|
|
76
|
+
icon={<Icon />} // Optional icon
|
|
77
|
+
showIcon={true} // Show icon
|
|
78
|
+
id="field-hint" // ID for aria-describedby
|
|
79
|
+
aria-label="Hint" // Accessible label
|
|
80
|
+
>
|
|
81
|
+
Helper text content
|
|
82
|
+
</SupportingText>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Examples
|
|
86
|
+
|
|
87
|
+
### Form Field with Label and Error
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import * as React from 'react';
|
|
91
|
+
import { SupportingText } from '@xsolla/xui-supporting-text';
|
|
92
|
+
import { Input } from '@xsolla/xui-input';
|
|
93
|
+
|
|
94
|
+
export default function FormField() {
|
|
95
|
+
const [email, setEmail] = React.useState('');
|
|
96
|
+
const [error, setError] = React.useState('');
|
|
97
|
+
|
|
98
|
+
const validate = (value: string) => {
|
|
99
|
+
if (value && !value.includes('@')) {
|
|
100
|
+
setError('Please enter a valid email address');
|
|
101
|
+
} else {
|
|
102
|
+
setError('');
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
|
108
|
+
<SupportingText variant="label" id="email-label">
|
|
109
|
+
Email address
|
|
110
|
+
</SupportingText>
|
|
111
|
+
<Input
|
|
112
|
+
value={email}
|
|
113
|
+
onChangeText={(text) => {
|
|
114
|
+
setEmail(text);
|
|
115
|
+
validate(text);
|
|
116
|
+
}}
|
|
117
|
+
aria-labelledby="email-label"
|
|
118
|
+
aria-describedby={error ? 'email-error' : 'email-hint'}
|
|
119
|
+
error={!!error}
|
|
120
|
+
/>
|
|
121
|
+
{error ? (
|
|
122
|
+
<SupportingText variant="error" id="email-error">
|
|
123
|
+
{error}
|
|
124
|
+
</SupportingText>
|
|
125
|
+
) : (
|
|
126
|
+
<SupportingText variant="helper" id="email-hint">
|
|
127
|
+
We'll never share your email
|
|
128
|
+
</SupportingText>
|
|
129
|
+
)}
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Password Requirements
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
import * as React from 'react';
|
|
139
|
+
import { SupportingText } from '@xsolla/xui-supporting-text';
|
|
140
|
+
import { InputPassword } from '@xsolla/xui-input-password';
|
|
141
|
+
|
|
142
|
+
export default function PasswordField() {
|
|
143
|
+
return (
|
|
144
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
|
145
|
+
<SupportingText variant="label">Password</SupportingText>
|
|
146
|
+
<InputPassword extraSee />
|
|
147
|
+
<SupportingText variant="description" size="sm">
|
|
148
|
+
Password must contain at least 8 characters, including uppercase, lowercase, and numbers.
|
|
149
|
+
</SupportingText>
|
|
150
|
+
</div>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Character Count Helper
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
import * as React from 'react';
|
|
159
|
+
import { SupportingText } from '@xsolla/xui-supporting-text';
|
|
160
|
+
import { Textarea } from '@xsolla/xui-textarea';
|
|
161
|
+
|
|
162
|
+
export default function CharacterCount() {
|
|
163
|
+
const [text, setText] = React.useState('');
|
|
164
|
+
const maxLength = 280;
|
|
165
|
+
const isOverLimit = text.length > maxLength;
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
|
169
|
+
<SupportingText variant="label">Bio</SupportingText>
|
|
170
|
+
<Textarea
|
|
171
|
+
value={text}
|
|
172
|
+
onChangeText={setText}
|
|
173
|
+
placeholder="Tell us about yourself"
|
|
174
|
+
/>
|
|
175
|
+
<SupportingText
|
|
176
|
+
variant={isOverLimit ? 'error' : 'helper'}
|
|
177
|
+
size="sm"
|
|
178
|
+
>
|
|
179
|
+
{text.length}/{maxLength} characters
|
|
180
|
+
</SupportingText>
|
|
181
|
+
</div>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Field Group with Description
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import * as React from 'react';
|
|
190
|
+
import { SupportingText } from '@xsolla/xui-supporting-text';
|
|
191
|
+
import { Checkbox } from '@xsolla/xui-checkbox';
|
|
192
|
+
|
|
193
|
+
export default function FieldGroup() {
|
|
194
|
+
return (
|
|
195
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
|
196
|
+
<SupportingText variant="label">Notification preferences</SupportingText>
|
|
197
|
+
<SupportingText variant="description" size="sm">
|
|
198
|
+
Choose how you'd like to receive updates from us
|
|
199
|
+
</SupportingText>
|
|
200
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 4, marginTop: 8 }}>
|
|
201
|
+
<Checkbox label="Email notifications" />
|
|
202
|
+
<Checkbox label="Push notifications" />
|
|
203
|
+
<Checkbox label="SMS notifications" />
|
|
204
|
+
</div>
|
|
205
|
+
</div>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## API Reference
|
|
211
|
+
|
|
212
|
+
### SupportingText
|
|
213
|
+
|
|
214
|
+
**SupportingTextProps:**
|
|
215
|
+
|
|
216
|
+
| Prop | Type | Default | Description |
|
|
217
|
+
| :--- | :--- | :------ | :---------- |
|
|
218
|
+
| children | `ReactNode` | - | Text content to display. |
|
|
219
|
+
| variant | `"label" \| "helper" \| "description" \| "error"` | `"helper"` | Visual variant. |
|
|
220
|
+
| size | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"md"` | Text size. |
|
|
221
|
+
| icon | `ReactNode` | - | Icon to display after text. |
|
|
222
|
+
| showIcon | `boolean` | `false` | Whether to show the icon. |
|
|
223
|
+
| id | `string` | - | HTML id for accessibility linking. |
|
|
224
|
+
| aria-label | `string` | - | Accessible label. |
|
|
225
|
+
| aria-describedby | `string` | - | ID of element this text describes. |
|
|
226
|
+
| testID | `string` | - | Test identifier. |
|
|
227
|
+
|
|
228
|
+
## Variants
|
|
229
|
+
|
|
230
|
+
| Variant | Color | Use Case |
|
|
231
|
+
| :------ | :---- | :------- |
|
|
232
|
+
| `label` | Primary | Field labels |
|
|
233
|
+
| `helper` | Tertiary | Guidance and hints |
|
|
234
|
+
| `description` | Tertiary | Additional context |
|
|
235
|
+
| `error` | Alert | Validation errors |
|
|
236
|
+
|
|
237
|
+
## Accessibility Features
|
|
238
|
+
|
|
239
|
+
- **Error variant**: Uses `role="alert"` for immediate announcement
|
|
240
|
+
- **Live regions**: Error messages use `aria-live="polite"`
|
|
241
|
+
- **ID linking**: Use `id` with `aria-describedby` on form fields
|
|
242
|
+
- **Color contrast**: Appropriate colors for all variants
|
|
243
|
+
- **Icon handling**: Icons are hidden from screen readers
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsolla/xui-supporting-text",
|
|
3
|
-
"version": "0.148.
|
|
3
|
+
"version": "0.148.2",
|
|
4
4
|
"main": "./web/index.js",
|
|
5
5
|
"module": "./web/index.mjs",
|
|
6
6
|
"types": "./web/index.d.ts",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"build:native": "PLATFORM=native tsup"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xsolla/xui-core": "0.148.
|
|
14
|
-
"@xsolla/xui-icons": "0.148.
|
|
15
|
-
"@xsolla/xui-primitives-core": "0.148.
|
|
13
|
+
"@xsolla/xui-core": "0.148.2",
|
|
14
|
+
"@xsolla/xui-icons": "0.148.2",
|
|
15
|
+
"@xsolla/xui-primitives-core": "0.148.2"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"react": ">=16.8.0",
|