@wso2/oxygen-ui 0.21.0 → 0.23.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/.ai/AGENTS.md +2 -0
- package/.claude/skills/oxygen-form/SKILL.md +165 -98
- package/.claude/skills/oxygen-select/SKILL.md +139 -0
- package/.claude/skills/oxygen-textfield/SKILL.md +91 -0
- package/README.md +2 -0
- package/bin/cli.js +4 -0
- package/dist/components/AppBreadcrumbs/AppBreadcrumbs.d.ts +3 -2
- package/dist/components/AppSwitcher/AppSwitcher.d.ts +6 -6
- package/dist/components/AppSwitcher/AppSwitcherFooter.d.ts +14 -6
- package/dist/components/AppSwitcher/AppSwitcherSection.d.ts +8 -3
- package/dist/components/Select/Select.d.ts +23 -0
- package/dist/components/Select/index.d.ts +2 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1583 -960
- package/dist/index.js.map +4 -4
- package/dist/styles/Themes/ChoreoLabsTheme.d.ts +70 -0
- package/package.json +2 -2
package/.ai/AGENTS.md
CHANGED
|
@@ -23,6 +23,8 @@ function App() {
|
|
|
23
23
|
3. **Icons from `@wso2/oxygen-ui-icons-react`** - Separate package for icons
|
|
24
24
|
4. **MUI X uses namespaces** - `DataGrid.DataGrid`, `DatePickers.DatePicker`, `TreeView.TreeView`
|
|
25
25
|
5. **Use theme tokens** - Use `sx` prop with theme values, not hardcoded colors/spacing
|
|
26
|
+
6. **Fixed labels on inputs** - Give every labelled `TextField` and `Select` `labelPlacement="top"`; never use MUI's floating label (`InputLabel` inside `FormControl`) in new code
|
|
27
|
+
7. **Select placeholders come from the developer** - Give every `Select` and `TextField select` a `placeholder`; ask the developer for the text instead of inventing it. Native selects (`native` or `SelectProps={{ native: true }}`) ignore `placeholder`, so put that same text in the empty option instead: `<option value="">Select a role</option>`
|
|
26
28
|
|
|
27
29
|
## Import Patterns
|
|
28
30
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: oxygen-form
|
|
3
|
-
description: Generate forms with Form.* components and validation. Use when creating input forms, multi-step wizards, or form validation.
|
|
3
|
+
description: Generate forms with Form.* components and validation. Use when creating input forms, multi-step wizards, or form validation. Covers field labels and required-field marking.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Generate Oxygen UI Form
|
|
@@ -10,7 +10,10 @@ description: Generate forms with Form.* components and validation. Use when crea
|
|
|
10
10
|
1. Read `.claude/oxygen-ui/components.md` for Form.* API
|
|
11
11
|
2. Use `Form.Section` for grouping fields
|
|
12
12
|
3. Use `Form.Stack` for field layout
|
|
13
|
-
4.
|
|
13
|
+
4. Give every field a fixed label on top with `labelPlacement="top"` (see Field Labels)
|
|
14
|
+
5. Mark each required field with `required`; leave optional fields unmarked
|
|
15
|
+
6. Give every select a `placeholder`; ask the developer for the text (see Select and Autocomplete)
|
|
16
|
+
7. Add validation with `error` and `helperText` props. Plain `Select` has no `helperText`, so use `TextField select` for any select that shows validation messages
|
|
14
17
|
|
|
15
18
|
## Critical Rules
|
|
16
19
|
|
|
@@ -18,6 +21,8 @@ description: Generate forms with Form.* components and validation. Use when crea
|
|
|
18
21
|
- Use controlled components with state
|
|
19
22
|
- Show validation errors with `error` and `helperText` props
|
|
20
23
|
- Use theme tokens for spacing
|
|
24
|
+
- Use `labelPlacement="top"` on every `TextField` in a form; never use the floating label in forms
|
|
25
|
+
- Set `required` on every required field; never use the `optional` prop or write "(Optional)" in a label
|
|
21
26
|
- Write all UI text in sentence case (see below)
|
|
22
27
|
|
|
23
28
|
## UI Text
|
|
@@ -32,11 +37,57 @@ Write all titles, action text, and content in sentence case. Capitalize only the
|
|
|
32
37
|
- Applies to section headers, labels, placeholders, helper text, error messages, and buttons
|
|
33
38
|
- Write the text in sentence case in the source; never change case with `textTransform: 'uppercase'` or `'capitalize'`
|
|
34
39
|
|
|
40
|
+
## Field Labels
|
|
41
|
+
|
|
42
|
+
Forms use a fixed label above the input, not MUI's floating label. `labelPlacement` is an Oxygen UI prop, so import `TextField` from `@wso2/oxygen-ui`; the MUI `TextField` ignores it.
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
<TextField labelPlacement="top" label="Display name" required /> // required: label shows a themed *
|
|
46
|
+
<TextField labelPlacement="top" label="Description" /> // optional: no marker
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Required fields
|
|
50
|
+
|
|
51
|
+
- The developer marks each required field with the `required` prop. Nothing is required by default
|
|
52
|
+
- `required` draws a `*` after the label, colored by the theme, and sets `required` on the native input, so screen readers announce it
|
|
53
|
+
- Do not add a `*` to the label text yourself, and do not color labels red; the theme handles it
|
|
54
|
+
- Keep `required` in sync with validation: every field the form rejects when empty is `required`, and no other field is
|
|
55
|
+
|
|
56
|
+
### Optional fields
|
|
57
|
+
|
|
58
|
+
- Leave optional fields unmarked. Do not pass the `optional` prop and do not write "(Optional)" in the label, placeholder, or helper text
|
|
59
|
+
- Do not describe a section as optional in its header or subheader; unmarked fields already read as optional
|
|
60
|
+
|
|
61
|
+
### Select and Autocomplete
|
|
62
|
+
|
|
63
|
+
The same rules apply. Use `TextField` with `select` (it supports `helperText` for validation messages), or `Select` with `labelPlacement="top"` (see the `oxygen-select` skill). Every select needs a `placeholder`; ask the developer for the text before writing the form, listing each select with a suggestion such as "Select a role", and never invent it. Native selects ignore `placeholder`, so use that text as the empty option's label instead. A select in error keeps its label colour; the error shows on the border and in `helperText`. For Autocomplete, pass `labelPlacement="top"` and `required` to the `TextField` in `renderInput`:
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
<TextField select labelPlacement="top" label="Role" placeholder="Select a role" required value={role} onChange={...}>
|
|
67
|
+
<MenuItem value="developer">Developer</MenuItem>
|
|
68
|
+
</TextField>
|
|
69
|
+
|
|
70
|
+
<Autocomplete
|
|
71
|
+
options={countries}
|
|
72
|
+
renderInput={(params) => <TextField {...params} labelPlacement="top" label="Country" required />}
|
|
73
|
+
/>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Do and don't
|
|
77
|
+
|
|
78
|
+
```text
|
|
79
|
+
✓ <TextField labelPlacement="top" label="Email" required />
|
|
80
|
+
✗ <TextField label="Email" required /> floating label in a form
|
|
81
|
+
✗ <TextField labelPlacement="top" label="Email *" /> hand-written asterisk
|
|
82
|
+
✗ <TextField labelPlacement="top" label="Phone" optional /> optional marker
|
|
83
|
+
✗ <TextField labelPlacement="top" label="Phone (Optional)" />
|
|
84
|
+
```
|
|
85
|
+
|
|
35
86
|
## Basic Form
|
|
36
87
|
|
|
37
88
|
```tsx
|
|
38
89
|
import { useState } from 'react';
|
|
39
|
-
import { Box, TextField, Button
|
|
90
|
+
import { Box, Form, TextField, Button } from '@wso2/oxygen-ui';
|
|
40
91
|
|
|
41
92
|
function BasicForm() {
|
|
42
93
|
const [formData, setFormData] = useState({ name: '', email: '' });
|
|
@@ -67,31 +118,34 @@ function BasicForm() {
|
|
|
67
118
|
};
|
|
68
119
|
|
|
69
120
|
return (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
121
|
+
// noValidate lets validate() show inline errors instead of the browser's required bubbles
|
|
122
|
+
<Box component="form" onSubmit={handleSubmit} noValidate sx={{ maxWidth: 400 }}>
|
|
123
|
+
<Form.Stack spacing={2}>
|
|
124
|
+
<TextField
|
|
125
|
+
fullWidth
|
|
126
|
+
labelPlacement="top"
|
|
127
|
+
label="Name"
|
|
128
|
+
value={formData.name}
|
|
129
|
+
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
|
|
130
|
+
error={!!errors.name}
|
|
131
|
+
helperText={errors.name}
|
|
132
|
+
required
|
|
133
|
+
/>
|
|
134
|
+
|
|
135
|
+
<TextField
|
|
136
|
+
fullWidth
|
|
137
|
+
labelPlacement="top"
|
|
138
|
+
label="Email"
|
|
139
|
+
type="email"
|
|
140
|
+
value={formData.email}
|
|
141
|
+
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
|
|
142
|
+
error={!!errors.email}
|
|
143
|
+
helperText={errors.email}
|
|
144
|
+
required
|
|
145
|
+
/>
|
|
146
|
+
</Form.Stack>
|
|
147
|
+
|
|
148
|
+
<Button type="submit" variant="contained" sx={{ mt: 3 }}>
|
|
95
149
|
Submit
|
|
96
150
|
</Button>
|
|
97
151
|
</Box>
|
|
@@ -102,7 +156,7 @@ function BasicForm() {
|
|
|
102
156
|
## Form with Sections
|
|
103
157
|
|
|
104
158
|
```tsx
|
|
105
|
-
import { Form, TextField, Button, Box } from '@wso2/oxygen-ui';
|
|
159
|
+
import { Form, TextField, MenuItem, Button, Box } from '@wso2/oxygen-ui';
|
|
106
160
|
|
|
107
161
|
function SectionedForm() {
|
|
108
162
|
return (
|
|
@@ -112,23 +166,27 @@ function SectionedForm() {
|
|
|
112
166
|
<Form.Subheader>Enter your basic details</Form.Subheader>
|
|
113
167
|
|
|
114
168
|
<Form.Stack spacing={2}>
|
|
115
|
-
<
|
|
116
|
-
<
|
|
117
|
-
<
|
|
169
|
+
<TextField fullWidth labelPlacement="top" label="First name" required />
|
|
170
|
+
<TextField fullWidth labelPlacement="top" label="Last name" required />
|
|
171
|
+
<TextField fullWidth labelPlacement="top" label="Email" type="email" required />
|
|
118
172
|
</Form.Stack>
|
|
119
173
|
</Form.Section>
|
|
120
174
|
|
|
121
175
|
<Form.Section>
|
|
122
176
|
<Form.Header>Company details</Form.Header>
|
|
123
|
-
<Form.Subheader>
|
|
177
|
+
<Form.Subheader>Tell us about your organization</Form.Subheader>
|
|
124
178
|
|
|
125
179
|
<Form.Stack spacing={2}>
|
|
126
|
-
|
|
127
|
-
<
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
180
|
+
{/* Optional fields: no marker */}
|
|
181
|
+
<TextField fullWidth labelPlacement="top" label="Company name" />
|
|
182
|
+
{/* Placeholder text comes from the developer */}
|
|
183
|
+
<TextField fullWidth select labelPlacement="top" label="Role" placeholder="Select a role" defaultValue="">
|
|
184
|
+
{/* Optional select: an empty option lets users clear it */}
|
|
185
|
+
<MenuItem value="">None</MenuItem>
|
|
186
|
+
<MenuItem value="developer">Developer</MenuItem>
|
|
187
|
+
<MenuItem value="designer">Designer</MenuItem>
|
|
188
|
+
<MenuItem value="manager">Manager</MenuItem>
|
|
189
|
+
</TextField>
|
|
132
190
|
</Form.Stack>
|
|
133
191
|
</Form.Section>
|
|
134
192
|
|
|
@@ -152,8 +210,8 @@ import {
|
|
|
152
210
|
TextField,
|
|
153
211
|
Button,
|
|
154
212
|
Link,
|
|
155
|
-
Divider,
|
|
156
213
|
Alert,
|
|
214
|
+
Form,
|
|
157
215
|
} from '@wso2/oxygen-ui';
|
|
158
216
|
|
|
159
217
|
function LoginForm() {
|
|
@@ -189,7 +247,7 @@ function LoginForm() {
|
|
|
189
247
|
>
|
|
190
248
|
<Paper sx={{ p: 4, maxWidth: 400, width: '100%' }}>
|
|
191
249
|
<Typography variant="h5" gutterBottom align="center">
|
|
192
|
-
Sign
|
|
250
|
+
Sign in
|
|
193
251
|
</Typography>
|
|
194
252
|
|
|
195
253
|
{error && (
|
|
@@ -199,25 +257,27 @@ function LoginForm() {
|
|
|
199
257
|
)}
|
|
200
258
|
|
|
201
259
|
<Box component="form" onSubmit={handleSubmit}>
|
|
202
|
-
<
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
260
|
+
<Form.Stack spacing={2}>
|
|
261
|
+
<TextField
|
|
262
|
+
fullWidth
|
|
263
|
+
labelPlacement="top"
|
|
264
|
+
label="Email"
|
|
265
|
+
type="email"
|
|
266
|
+
value={email}
|
|
267
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
268
|
+
required
|
|
269
|
+
/>
|
|
270
|
+
|
|
271
|
+
<TextField
|
|
272
|
+
fullWidth
|
|
273
|
+
labelPlacement="top"
|
|
274
|
+
label="Password"
|
|
275
|
+
type="password"
|
|
276
|
+
value={password}
|
|
277
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
278
|
+
required
|
|
279
|
+
/>
|
|
280
|
+
</Form.Stack>
|
|
221
281
|
|
|
222
282
|
<Button
|
|
223
283
|
fullWidth
|
|
@@ -265,6 +325,7 @@ import {
|
|
|
265
325
|
Button,
|
|
266
326
|
Typography,
|
|
267
327
|
TextField,
|
|
328
|
+
Form,
|
|
268
329
|
} from '@wso2/oxygen-ui';
|
|
269
330
|
|
|
270
331
|
const steps = ['Account', 'Profile', 'Review'];
|
|
@@ -289,43 +350,46 @@ function RegistrationWizard() {
|
|
|
289
350
|
switch (step) {
|
|
290
351
|
case 0:
|
|
291
352
|
return (
|
|
292
|
-
|
|
353
|
+
<Form.Stack spacing={2}>
|
|
293
354
|
<TextField
|
|
294
355
|
fullWidth
|
|
356
|
+
labelPlacement="top"
|
|
295
357
|
label="Email"
|
|
296
358
|
type="email"
|
|
297
359
|
value={formData.email}
|
|
298
360
|
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
|
|
299
|
-
|
|
361
|
+
required
|
|
300
362
|
/>
|
|
301
363
|
<TextField
|
|
302
364
|
fullWidth
|
|
365
|
+
labelPlacement="top"
|
|
303
366
|
label="Password"
|
|
304
367
|
type="password"
|
|
305
368
|
value={formData.password}
|
|
306
369
|
onChange={(e) => setFormData({ ...formData, password: e.target.value })}
|
|
307
|
-
|
|
370
|
+
required
|
|
308
371
|
/>
|
|
309
|
-
|
|
372
|
+
</Form.Stack>
|
|
310
373
|
);
|
|
311
374
|
case 1:
|
|
312
375
|
return (
|
|
313
|
-
|
|
376
|
+
<Form.Stack spacing={2}>
|
|
314
377
|
<TextField
|
|
315
378
|
fullWidth
|
|
379
|
+
labelPlacement="top"
|
|
316
380
|
label="Full name"
|
|
317
381
|
value={formData.name}
|
|
318
382
|
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
|
|
319
|
-
|
|
383
|
+
required
|
|
320
384
|
/>
|
|
321
385
|
<TextField
|
|
322
386
|
fullWidth
|
|
387
|
+
labelPlacement="top"
|
|
323
388
|
label="Company"
|
|
324
389
|
value={formData.company}
|
|
325
390
|
onChange={(e) => setFormData({ ...formData, company: e.target.value })}
|
|
326
|
-
margin="normal"
|
|
327
391
|
/>
|
|
328
|
-
|
|
392
|
+
</Form.Stack>
|
|
329
393
|
);
|
|
330
394
|
case 2:
|
|
331
395
|
return (
|
|
@@ -381,7 +445,7 @@ function RegistrationWizard() {
|
|
|
381
445
|
|
|
382
446
|
```tsx
|
|
383
447
|
import { useState } from 'react';
|
|
384
|
-
import { Box, TextField, Button,
|
|
448
|
+
import { Box, Form, TextField, Button, Autocomplete } from '@wso2/oxygen-ui';
|
|
385
449
|
|
|
386
450
|
const countries = [
|
|
387
451
|
{ label: 'United States', code: 'US' },
|
|
@@ -392,38 +456,41 @@ const countries = [
|
|
|
392
456
|
|
|
393
457
|
function AddressForm() {
|
|
394
458
|
const [country, setCountry] = useState<typeof countries[0] | null>(null);
|
|
395
|
-
const [
|
|
459
|
+
const [region, setRegion] = useState('');
|
|
396
460
|
|
|
397
461
|
return (
|
|
398
462
|
<Box sx={{ maxWidth: 400 }}>
|
|
399
|
-
<
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
463
|
+
<Form.Stack spacing={2}>
|
|
464
|
+
<Autocomplete
|
|
465
|
+
options={countries}
|
|
466
|
+
value={country}
|
|
467
|
+
onChange={(_, newValue) => {
|
|
468
|
+
setCountry(newValue);
|
|
469
|
+
setRegion('');
|
|
470
|
+
}}
|
|
471
|
+
renderInput={(params) => (
|
|
472
|
+
<TextField {...params} labelPlacement="top" label="Country" required />
|
|
473
|
+
)}
|
|
474
|
+
/>
|
|
475
|
+
|
|
476
|
+
{/* Free text, so it works for any country */}
|
|
477
|
+
<TextField
|
|
478
|
+
fullWidth
|
|
479
|
+
labelPlacement="top"
|
|
480
|
+
label="State, province, or region"
|
|
481
|
+
value={region}
|
|
482
|
+
onChange={(e) => setRegion(e.target.value)}
|
|
483
|
+
required
|
|
484
|
+
/>
|
|
485
|
+
|
|
486
|
+
<TextField fullWidth labelPlacement="top" label="City" required />
|
|
487
|
+
<TextField fullWidth labelPlacement="top" label="Address" required multiline rows={2} />
|
|
488
|
+
{/* Optional field: no marker */}
|
|
489
|
+
<TextField fullWidth labelPlacement="top" label="Postal code" />
|
|
490
|
+
</Form.Stack>
|
|
491
|
+
|
|
492
|
+
<Button variant="contained" sx={{ mt: 3 }}>
|
|
493
|
+
Save address
|
|
427
494
|
</Button>
|
|
428
495
|
</Box>
|
|
429
496
|
);
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: oxygen-select
|
|
3
|
+
description: Use the Oxygen UI Select with a fixed label above the field instead of MUI's floating label, and a placeholder the developer provides. Use when adding or editing any Select, dropdown, or picker built on Select, or when converting FormControl + InputLabel + Select code to fixed labels.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Fixed-Label Select
|
|
7
|
+
|
|
8
|
+
Oxygen UI selects use a fixed label that sits above the field and never moves. Do not use MUI's floating label, which starts inside the field and shrinks into the border on focus. The floating variant still works, but only for existing screens; never write new code with it.
|
|
9
|
+
|
|
10
|
+
```text
|
|
11
|
+
Fixed label (use) Floating label (don't use)
|
|
12
|
+
Environment ┌─ Environment ───────┐
|
|
13
|
+
┌─────────────────────┐ │ Production ▾ │
|
|
14
|
+
│ Production ▾ │ └─────────────────────┘
|
|
15
|
+
└─────────────────────┘
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Instructions
|
|
19
|
+
|
|
20
|
+
1. Import `Select` from `@wso2/oxygen-ui`, never from `@mui/material`. `labelPlacement` is an Oxygen UI prop, and the MUI `Select` ignores it.
|
|
21
|
+
2. Add `labelPlacement="top"` and `label` to every `Select`. Do not wrap it in `FormControl` or add an `InputLabel`; the component draws its own.
|
|
22
|
+
3. Give every `Select` a `placeholder`. Get the text from the developer; never make it up (see Placeholder text).
|
|
23
|
+
4. Mark required selects with `required`; the theme draws the `*`.
|
|
24
|
+
5. When the select needs helper text or validation messages, use `TextField select labelPlacement="top"` instead (see the `oxygen-textfield` skill). It has the same fixed label, supports `helperText`, and takes the same `placeholder`.
|
|
25
|
+
6. For forms (validation, sections, wizards), also follow the `oxygen-form` skill.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { Select, MenuItem } from '@wso2/oxygen-ui';
|
|
31
|
+
|
|
32
|
+
<Select
|
|
33
|
+
labelPlacement="top"
|
|
34
|
+
label="Environment"
|
|
35
|
+
placeholder="Select an environment"
|
|
36
|
+
required
|
|
37
|
+
value={env}
|
|
38
|
+
onChange={(e) => setEnv(e.target.value)}
|
|
39
|
+
>
|
|
40
|
+
<MenuItem value="dev">Development</MenuItem>
|
|
41
|
+
<MenuItem value="prod">Production</MenuItem>
|
|
42
|
+
</Select>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
With helper text:
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { TextField, MenuItem } from '@wso2/oxygen-ui';
|
|
49
|
+
|
|
50
|
+
<TextField
|
|
51
|
+
select
|
|
52
|
+
labelPlacement="top"
|
|
53
|
+
label="Environment"
|
|
54
|
+
placeholder="Select an environment"
|
|
55
|
+
helperText="Where the component is deployed."
|
|
56
|
+
value={env}
|
|
57
|
+
onChange={(e) => setEnv(e.target.value)}
|
|
58
|
+
>
|
|
59
|
+
<MenuItem value="dev">Development</MenuItem>
|
|
60
|
+
<MenuItem value="prod">Production</MenuItem>
|
|
61
|
+
</TextField>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Placeholder text
|
|
65
|
+
|
|
66
|
+
Every select shows a placeholder while nothing is selected. The developer owns this text, so ask for it.
|
|
67
|
+
|
|
68
|
+
1. Before writing the code, check whether the developer has given placeholder text for each select.
|
|
69
|
+
2. If any is missing, ask the developer once, listing every select that needs one by its label. Offer a suggestion for each so they can accept or change it, for example:
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
Placeholder text needed for these selects. Reply with your text, or "ok" to use the suggestions:
|
|
73
|
+
- Environment: "Select an environment"
|
|
74
|
+
- Region: "Select a region"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
3. Use the developer's text exactly as given. Do not write code with placeholder text the developer has not provided or accepted.
|
|
78
|
+
4. If you can't ask (for example, in a non-interactive run), use the suggestions and list them in your summary so the developer can review them.
|
|
79
|
+
|
|
80
|
+
Suggestions follow these rules:
|
|
81
|
+
|
|
82
|
+
- Start with "Select" and name the thing chosen, in sentence case: "Select a region", not "Select Region" or "Choose…"
|
|
83
|
+
- No trailing punctuation or ellipsis
|
|
84
|
+
- Don't repeat "(Optional)" or "*" from the label
|
|
85
|
+
- Never use the placeholder in place of a label
|
|
86
|
+
|
|
87
|
+
## How it behaves
|
|
88
|
+
|
|
89
|
+
- The label renders as a `FormLabel` above the select and keeps its colour on focus and in the error state; the error shows on the field's border and in helper text. Focus shows only on the field: in the Choreo Labs theme, a text-colour border with a Cobalt ring, the same as fixed-label text fields.
|
|
90
|
+
- The label names the combobox through `labelId` (or `htmlFor` with `native`), so screen readers announce it. Do not add your own `aria-label` when a label is set.
|
|
91
|
+
- `sx`, `className`, `style`, `fullWidth` and `ref` apply to the outer wrapper that holds the label and the select. `size`, `variant`, `required`, `error` and `disabled` apply to both.
|
|
92
|
+
- `placeholder` shows text in the field while nothing is selected (an empty value: `''`, `null`, `undefined` or `[]`), in the secondary text colour so it meets contrast requirements. It works with a custom `renderValue`. Native selects ignore it, so give them an empty option with the developer's placeholder text instead: `<option value="">Select a role</option>`.
|
|
93
|
+
- Without a `label`, the prop has no effect and the select renders as a plain MUI `Select`.
|
|
94
|
+
|
|
95
|
+
## Selects with no visible label
|
|
96
|
+
|
|
97
|
+
Some selects have no visible label, such as a sort or page-size picker in a toolbar. Omit `label`, give the select an accessible name, and still ask the developer for a placeholder if the select can be empty:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
<Select placeholder="Sort by" value={sort} onChange={(e) => setSort(e.target.value)} inputProps={{ 'aria-label': 'Sort by' }}>
|
|
101
|
+
<MenuItem value="name">Name</MenuItem>
|
|
102
|
+
<MenuItem value="date">Date</MenuItem>
|
|
103
|
+
</Select>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Never use a floating label to save vertical space.
|
|
107
|
+
|
|
108
|
+
## Converting floating labels
|
|
109
|
+
|
|
110
|
+
When you edit code that uses floating labels:
|
|
111
|
+
|
|
112
|
+
| Floating-label code | Fixed-label replacement |
|
|
113
|
+
| --- | --- |
|
|
114
|
+
| `import { Select } from '@mui/material'` | `import { Select } from '@wso2/oxygen-ui'` |
|
|
115
|
+
| `<FormControl><InputLabel id="x">Role</InputLabel><Select labelId="x" label="Role">…</Select></FormControl>` | `<Select labelPlacement="top" label="Role">…</Select>` |
|
|
116
|
+
| The same, plus a `FormHelperText` | `<TextField select labelPlacement="top" label="Role" helperText="…">…</TextField>` |
|
|
117
|
+
| `<FormControl sx={{ minWidth: 200 }}>` around the select | Move `sx` onto the `Select` |
|
|
118
|
+
| `<FormControl error required>` around the select | Move `error` and `required` onto the `Select` |
|
|
119
|
+
| A `Typography` or `FormLabel` placed above a label-less `Select` | Remove it; pass the text as `label` with `labelPlacement="top"` |
|
|
120
|
+
| `label="Role *"` | `label="Role" required` |
|
|
121
|
+
| `<MenuItem value="" disabled>Select a role</MenuItem>` used as a placeholder | Remove it; pass `placeholder="Select a role"` |
|
|
122
|
+
| `displayEmpty` with a `renderValue` that returns placeholder text | Remove both; pass `placeholder` (keep a `renderValue` that formats real values) |
|
|
123
|
+
| A select with no placeholder | Ask the developer for the text, then add `placeholder` |
|
|
124
|
+
|
|
125
|
+
## Do and don't
|
|
126
|
+
|
|
127
|
+
```text
|
|
128
|
+
✓ <Select labelPlacement="top" label="Role" placeholder="Select a role" required value={role} onChange={…}>…</Select>
|
|
129
|
+
✓ <TextField select labelPlacement="top" label="Role" placeholder="Select a role" helperText="…">…</TextField>
|
|
130
|
+
✗ <Select labelPlacement="top" label="Role" value={role}>…</Select> no placeholder; ask the developer for one
|
|
131
|
+
✗ <MenuItem value="" disabled>Select a role</MenuItem> fake placeholder option
|
|
132
|
+
✗ <FormControl><InputLabel>Role</InputLabel><Select label="Role"> floating label
|
|
133
|
+
✗ import { Select } from '@mui/material' labelPlacement is ignored
|
|
134
|
+
✗ <FormControl><Select labelPlacement="top" label="Role" /></FormControl> extra wrapper; the Select has its own
|
|
135
|
+
✗ <Typography>Role</Typography><Select /> label not linked to the select
|
|
136
|
+
✗ <Select labelPlacement="top" label="Role *" /> hand-written asterisk
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Write labels in sentence case, for example "Deployment region", not "Deployment Region".
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: oxygen-textfield
|
|
3
|
+
description: Use the Oxygen UI TextField with a fixed label above the field instead of MUI's floating label. Use when adding or editing any TextField, select, or Autocomplete input, or when converting floating-label fields to fixed labels.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Fixed-Label TextField
|
|
7
|
+
|
|
8
|
+
Oxygen UI text inputs use a fixed label that sits above the field and never moves. Do not use MUI's floating label, which starts inside the field and shrinks into the border on focus.
|
|
9
|
+
|
|
10
|
+
```text
|
|
11
|
+
Fixed label (use) Floating label (don't use)
|
|
12
|
+
Display name ┌─ Display name ──────┐
|
|
13
|
+
┌─────────────────────┐ │ my-app │
|
|
14
|
+
│ my-app │ └─────────────────────┘
|
|
15
|
+
└─────────────────────┘
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Instructions
|
|
19
|
+
|
|
20
|
+
1. Import `TextField` from `@wso2/oxygen-ui`, never from `@mui/material`. `labelPlacement` is an Oxygen UI prop, and the MUI `TextField` ignores it.
|
|
21
|
+
2. Add `labelPlacement="top"` to every `TextField` that has a `label`.
|
|
22
|
+
3. Apply the same rule to selects (`TextField select`) and to the `TextField` in an Autocomplete's `renderInput`. Every `TextField select` also needs a `placeholder` whose text the developer provides; follow the `oxygen-select` skill for selects. Native selects (`SelectProps={{ native: true }}`) ignore `placeholder`, so use that text as the empty `<option value="">` instead.
|
|
23
|
+
4. Mark required fields with `required`; the theme draws the `*`.
|
|
24
|
+
5. For forms (validation, sections, wizards), also follow the `oxygen-form` skill.
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { TextField, MenuItem, Autocomplete } from '@wso2/oxygen-ui';
|
|
30
|
+
|
|
31
|
+
<TextField labelPlacement="top" label="Display name" required />
|
|
32
|
+
|
|
33
|
+
<TextField select labelPlacement="top" label="Environment" placeholder="Select an environment" value={env} onChange={(e) => setEnv(e.target.value)}>
|
|
34
|
+
<MenuItem value="dev">Development</MenuItem>
|
|
35
|
+
<MenuItem value="prod">Production</MenuItem>
|
|
36
|
+
</TextField>
|
|
37
|
+
|
|
38
|
+
<Autocomplete
|
|
39
|
+
options={regions}
|
|
40
|
+
renderInput={(params) => <TextField {...params} labelPlacement="top" label="Region" />}
|
|
41
|
+
/>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## How it behaves
|
|
45
|
+
|
|
46
|
+
- The label renders as a `FormLabel` above the input and keeps its colour on focus. Focus shows only on the field's border.
|
|
47
|
+
- The label is linked to the input with `htmlFor`, and for selects through `labelId`, so screen readers announce it. Do not add your own `aria-label` when a label is set.
|
|
48
|
+
- `sx`, `className`, `style`, `fullWidth`, `margin` and `ref` apply to the outer wrapper that holds the label and the field.
|
|
49
|
+
- When `error` is set, an empty helper line is reserved so the layout doesn't shift when a message appears.
|
|
50
|
+
- Without a `label`, the prop has no effect and the field renders as a plain MUI `TextField`.
|
|
51
|
+
|
|
52
|
+
## Fields with no visible label
|
|
53
|
+
|
|
54
|
+
Some fields have no visible label, such as a search box in a toolbar or a table filter. Omit `label`, describe the field with a `placeholder`, and give it an accessible name:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
<TextField
|
|
58
|
+
placeholder="Search projects"
|
|
59
|
+
slotProps={{ htmlInput: { 'aria-label': 'Search projects' } }}
|
|
60
|
+
/>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Never use a floating label to save vertical space.
|
|
64
|
+
|
|
65
|
+
## Converting floating labels
|
|
66
|
+
|
|
67
|
+
When you edit code that uses floating labels:
|
|
68
|
+
|
|
69
|
+
| Floating-label code | Fixed-label replacement |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `import { TextField } from '@mui/material'` | `import { TextField } from '@wso2/oxygen-ui'` |
|
|
72
|
+
| `<TextField label="Name" />` | `<TextField labelPlacement="top" label="Name" />` |
|
|
73
|
+
| `InputLabelProps={{ shrink: true }}` or `slotProps={{ inputLabel: { shrink: true } }}` | Remove it; add `labelPlacement="top"` |
|
|
74
|
+
| `<FormControl><InputLabel>Role</InputLabel><Select label="Role">` | `<Select labelPlacement="top" label="Role" placeholder="Select a role">` or `<TextField select labelPlacement="top" label="Role" placeholder="Select a role">`, with placeholder text from the developer (see `oxygen-select`) |
|
|
75
|
+
| A `Typography` or `FormLabel` placed above a label-less `TextField` | Remove it; pass the text as `label` with `labelPlacement="top"` |
|
|
76
|
+
| `label="Email *"` | `label="Email" required` |
|
|
77
|
+
|
|
78
|
+
## Do and don't
|
|
79
|
+
|
|
80
|
+
```text
|
|
81
|
+
✓ <TextField labelPlacement="top" label="Email" required />
|
|
82
|
+
✓ <TextField select labelPlacement="top" label="Role" placeholder="Select a role">…</TextField>
|
|
83
|
+
✗ <TextField label="Email" /> floating label
|
|
84
|
+
✗ import { TextField } from '@mui/material' labelPlacement is ignored
|
|
85
|
+
✗ <TextField label="Email" slotProps={{ inputLabel: { shrink: true } }} />
|
|
86
|
+
✗ <InputLabel>Role</InputLabel><Select label="Role"> floating select label
|
|
87
|
+
✗ <Typography>Email</Typography><TextField /> label not linked to the input
|
|
88
|
+
✗ <TextField labelPlacement="top" label="Email *" /> hand-written asterisk
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Write labels in sentence case, for example "Display name", not "Display Name".
|
package/README.md
CHANGED
|
@@ -466,6 +466,8 @@ Creates:
|
|
|
466
466
|
- `/oxygen-component` - Generate Oxygen UI components
|
|
467
467
|
- `/oxygen-layout` - Generate app layouts
|
|
468
468
|
- `/oxygen-form` - Generate forms with validation
|
|
469
|
+
- `/oxygen-textfield` - Use fixed-label text fields instead of floating labels
|
|
470
|
+
- `/oxygen-select` - Use fixed-label selects instead of floating labels
|
|
469
471
|
- `/oxygen-migrate` - Migrate MUI code
|
|
470
472
|
- Updates root `CLAUDE.md` with reference
|
|
471
473
|
|