@wso2/oxygen-ui 0.21.0 → 0.22.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.
@@ -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,9 @@ 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. Add validation with `error` and `helperText` props
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. Add validation with `error` and `helperText` props
14
16
 
15
17
  ## Critical Rules
16
18
 
@@ -18,6 +20,8 @@ description: Generate forms with Form.* components and validation. Use when crea
18
20
  - Use controlled components with state
19
21
  - Show validation errors with `error` and `helperText` props
20
22
  - Use theme tokens for spacing
23
+ - Use `labelPlacement="top"` on every `TextField` in a form; never use the floating label in forms
24
+ - Set `required` on every required field; never use the `optional` prop or write "(Optional)" in a label
21
25
  - Write all UI text in sentence case (see below)
22
26
 
23
27
  ## UI Text
@@ -32,11 +36,57 @@ Write all titles, action text, and content in sentence case. Capitalize only the
32
36
  - Applies to section headers, labels, placeholders, helper text, error messages, and buttons
33
37
  - Write the text in sentence case in the source; never change case with `textTransform: 'uppercase'` or `'capitalize'`
34
38
 
39
+ ## Field Labels
40
+
41
+ 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.
42
+
43
+ ```tsx
44
+ <TextField labelPlacement="top" label="Display name" required /> // required: label shows a themed *
45
+ <TextField labelPlacement="top" label="Description" /> // optional: no marker
46
+ ```
47
+
48
+ ### Required fields
49
+
50
+ - The developer marks each required field with the `required` prop. Nothing is required by default
51
+ - `required` draws a `*` after the label, colored by the theme, and sets `required` on the native input, so screen readers announce it
52
+ - Do not add a `*` to the label text yourself, and do not color labels red; the theme handles it
53
+ - Keep `required` in sync with validation: every field the form rejects when empty is `required`, and no other field is
54
+
55
+ ### Optional fields
56
+
57
+ - Leave optional fields unmarked. Do not pass the `optional` prop and do not write "(Optional)" in the label, placeholder, or helper text
58
+ - Do not describe a section as optional in its header or subheader; unmarked fields already read as optional
59
+
60
+ ### Select and Autocomplete
61
+
62
+ The same rules apply. Use `TextField` with `select`, or pass `labelPlacement="top"` and `required` to the `TextField` in `renderInput`:
63
+
64
+ ```tsx
65
+ <TextField select labelPlacement="top" label="Role" required value={role} onChange={...}>
66
+ <MenuItem value="developer">Developer</MenuItem>
67
+ </TextField>
68
+
69
+ <Autocomplete
70
+ options={countries}
71
+ renderInput={(params) => <TextField {...params} labelPlacement="top" label="Country" required />}
72
+ />
73
+ ```
74
+
75
+ ### Do and don't
76
+
77
+ ```text
78
+ ✓ <TextField labelPlacement="top" label="Email" required />
79
+ ✗ <TextField label="Email" required /> floating label in a form
80
+ ✗ <TextField labelPlacement="top" label="Email *" /> hand-written asterisk
81
+ ✗ <TextField labelPlacement="top" label="Phone" optional /> optional marker
82
+ ✗ <TextField labelPlacement="top" label="Phone (Optional)" />
83
+ ```
84
+
35
85
  ## Basic Form
36
86
 
37
87
  ```tsx
38
88
  import { useState } from 'react';
39
- import { Box, TextField, Button, Alert } from '@wso2/oxygen-ui';
89
+ import { Box, Form, TextField, Button } from '@wso2/oxygen-ui';
40
90
 
41
91
  function BasicForm() {
42
92
  const [formData, setFormData] = useState({ name: '', email: '' });
@@ -67,31 +117,34 @@ function BasicForm() {
67
117
  };
68
118
 
69
119
  return (
70
- <Box component="form" onSubmit={handleSubmit} sx={{ maxWidth: 400 }}>
71
- <TextField
72
- fullWidth
73
- label="Name"
74
- value={formData.name}
75
- onChange={(e) => setFormData({ ...formData, name: e.target.value })}
76
- error={!!errors.name}
77
- helperText={errors.name}
78
- margin="normal"
79
- required
80
- />
81
-
82
- <TextField
83
- fullWidth
84
- label="Email"
85
- type="email"
86
- value={formData.email}
87
- onChange={(e) => setFormData({ ...formData, email: e.target.value })}
88
- error={!!errors.email}
89
- helperText={errors.email}
90
- margin="normal"
91
- required
92
- />
93
-
94
- <Button type="submit" variant="contained" sx={{ mt: 2 }}>
120
+ // noValidate lets validate() show inline errors instead of the browser's required bubbles
121
+ <Box component="form" onSubmit={handleSubmit} noValidate sx={{ maxWidth: 400 }}>
122
+ <Form.Stack spacing={2}>
123
+ <TextField
124
+ fullWidth
125
+ labelPlacement="top"
126
+ label="Name"
127
+ value={formData.name}
128
+ onChange={(e) => setFormData({ ...formData, name: e.target.value })}
129
+ error={!!errors.name}
130
+ helperText={errors.name}
131
+ required
132
+ />
133
+
134
+ <TextField
135
+ fullWidth
136
+ labelPlacement="top"
137
+ label="Email"
138
+ type="email"
139
+ value={formData.email}
140
+ onChange={(e) => setFormData({ ...formData, email: e.target.value })}
141
+ error={!!errors.email}
142
+ helperText={errors.email}
143
+ required
144
+ />
145
+ </Form.Stack>
146
+
147
+ <Button type="submit" variant="contained" sx={{ mt: 3 }}>
95
148
  Submit
96
149
  </Button>
97
150
  </Box>
@@ -102,7 +155,7 @@ function BasicForm() {
102
155
  ## Form with Sections
103
156
 
104
157
  ```tsx
105
- import { Form, TextField, Button, Box } from '@wso2/oxygen-ui';
158
+ import { Form, TextField, MenuItem, Button, Box } from '@wso2/oxygen-ui';
106
159
 
107
160
  function SectionedForm() {
108
161
  return (
@@ -112,23 +165,25 @@ function SectionedForm() {
112
165
  <Form.Subheader>Enter your basic details</Form.Subheader>
113
166
 
114
167
  <Form.Stack spacing={2}>
115
- <Form.TextInput label="First name" required />
116
- <Form.TextInput label="Last name" required />
117
- <Form.TextInput label="Email" type="email" required />
168
+ <TextField fullWidth labelPlacement="top" label="First name" required />
169
+ <TextField fullWidth labelPlacement="top" label="Last name" required />
170
+ <TextField fullWidth labelPlacement="top" label="Email" type="email" required />
118
171
  </Form.Stack>
119
172
  </Form.Section>
120
173
 
121
174
  <Form.Section>
122
175
  <Form.Header>Company details</Form.Header>
123
- <Form.Subheader>Optional information about your organization</Form.Subheader>
176
+ <Form.Subheader>Tell us about your organization</Form.Subheader>
124
177
 
125
178
  <Form.Stack spacing={2}>
126
- <Form.TextInput label="Company name" />
127
- <Form.SelectInput label="Role">
128
- <Form.MenuItem value="developer">Developer</Form.MenuItem>
129
- <Form.MenuItem value="designer">Designer</Form.MenuItem>
130
- <Form.MenuItem value="manager">Manager</Form.MenuItem>
131
- </Form.SelectInput>
179
+ {/* Optional fields: no marker */}
180
+ <TextField fullWidth labelPlacement="top" label="Company name" />
181
+ <TextField fullWidth select labelPlacement="top" label="Role" defaultValue="">
182
+ <MenuItem value="">None</MenuItem>
183
+ <MenuItem value="developer">Developer</MenuItem>
184
+ <MenuItem value="designer">Designer</MenuItem>
185
+ <MenuItem value="manager">Manager</MenuItem>
186
+ </TextField>
132
187
  </Form.Stack>
133
188
  </Form.Section>
134
189
 
@@ -152,8 +207,8 @@ import {
152
207
  TextField,
153
208
  Button,
154
209
  Link,
155
- Divider,
156
210
  Alert,
211
+ Form,
157
212
  } from '@wso2/oxygen-ui';
158
213
 
159
214
  function LoginForm() {
@@ -189,7 +244,7 @@ function LoginForm() {
189
244
  >
190
245
  <Paper sx={{ p: 4, maxWidth: 400, width: '100%' }}>
191
246
  <Typography variant="h5" gutterBottom align="center">
192
- Sign In
247
+ Sign in
193
248
  </Typography>
194
249
 
195
250
  {error && (
@@ -199,25 +254,27 @@ function LoginForm() {
199
254
  )}
200
255
 
201
256
  <Box component="form" onSubmit={handleSubmit}>
202
- <TextField
203
- fullWidth
204
- label="Email"
205
- type="email"
206
- value={email}
207
- onChange={(e) => setEmail(e.target.value)}
208
- margin="normal"
209
- required
210
- />
211
-
212
- <TextField
213
- fullWidth
214
- label="Password"
215
- type="password"
216
- value={password}
217
- onChange={(e) => setPassword(e.target.value)}
218
- margin="normal"
219
- required
220
- />
257
+ <Form.Stack spacing={2}>
258
+ <TextField
259
+ fullWidth
260
+ labelPlacement="top"
261
+ label="Email"
262
+ type="email"
263
+ value={email}
264
+ onChange={(e) => setEmail(e.target.value)}
265
+ required
266
+ />
267
+
268
+ <TextField
269
+ fullWidth
270
+ labelPlacement="top"
271
+ label="Password"
272
+ type="password"
273
+ value={password}
274
+ onChange={(e) => setPassword(e.target.value)}
275
+ required
276
+ />
277
+ </Form.Stack>
221
278
 
222
279
  <Button
223
280
  fullWidth
@@ -265,6 +322,7 @@ import {
265
322
  Button,
266
323
  Typography,
267
324
  TextField,
325
+ Form,
268
326
  } from '@wso2/oxygen-ui';
269
327
 
270
328
  const steps = ['Account', 'Profile', 'Review'];
@@ -289,43 +347,46 @@ function RegistrationWizard() {
289
347
  switch (step) {
290
348
  case 0:
291
349
  return (
292
- <>
350
+ <Form.Stack spacing={2}>
293
351
  <TextField
294
352
  fullWidth
353
+ labelPlacement="top"
295
354
  label="Email"
296
355
  type="email"
297
356
  value={formData.email}
298
357
  onChange={(e) => setFormData({ ...formData, email: e.target.value })}
299
- margin="normal"
358
+ required
300
359
  />
301
360
  <TextField
302
361
  fullWidth
362
+ labelPlacement="top"
303
363
  label="Password"
304
364
  type="password"
305
365
  value={formData.password}
306
366
  onChange={(e) => setFormData({ ...formData, password: e.target.value })}
307
- margin="normal"
367
+ required
308
368
  />
309
- </>
369
+ </Form.Stack>
310
370
  );
311
371
  case 1:
312
372
  return (
313
- <>
373
+ <Form.Stack spacing={2}>
314
374
  <TextField
315
375
  fullWidth
376
+ labelPlacement="top"
316
377
  label="Full name"
317
378
  value={formData.name}
318
379
  onChange={(e) => setFormData({ ...formData, name: e.target.value })}
319
- margin="normal"
380
+ required
320
381
  />
321
382
  <TextField
322
383
  fullWidth
384
+ labelPlacement="top"
323
385
  label="Company"
324
386
  value={formData.company}
325
387
  onChange={(e) => setFormData({ ...formData, company: e.target.value })}
326
- margin="normal"
327
388
  />
328
- </>
389
+ </Form.Stack>
329
390
  );
330
391
  case 2:
331
392
  return (
@@ -381,7 +442,7 @@ function RegistrationWizard() {
381
442
 
382
443
  ```tsx
383
444
  import { useState } from 'react';
384
- import { Box, TextField, Button, MenuItem, Autocomplete } from '@wso2/oxygen-ui';
445
+ import { Box, Form, TextField, Button, Autocomplete } from '@wso2/oxygen-ui';
385
446
 
386
447
  const countries = [
387
448
  { label: 'United States', code: 'US' },
@@ -392,38 +453,41 @@ const countries = [
392
453
 
393
454
  function AddressForm() {
394
455
  const [country, setCountry] = useState<typeof countries[0] | null>(null);
395
- const [state, setState] = useState('');
456
+ const [region, setRegion] = useState('');
396
457
 
397
458
  return (
398
459
  <Box sx={{ maxWidth: 400 }}>
399
- <Autocomplete
400
- options={countries}
401
- value={country}
402
- onChange={(_, newValue) => setCountry(newValue)}
403
- renderInput={(params) => (
404
- <TextField {...params} label="Country" margin="normal" />
405
- )}
406
- />
407
-
408
- <TextField
409
- fullWidth
410
- select
411
- label="State"
412
- value={state}
413
- onChange={(e) => setState(e.target.value)}
414
- margin="normal"
415
- >
416
- <MenuItem value="ca">California</MenuItem>
417
- <MenuItem value="ny">New York</MenuItem>
418
- <MenuItem value="tx">Texas</MenuItem>
419
- </TextField>
420
-
421
- <TextField fullWidth label="City" margin="normal" />
422
- <TextField fullWidth label="Address" margin="normal" multiline rows={2} />
423
- <TextField fullWidth label="ZIP code" margin="normal" />
424
-
425
- <Button variant="contained" sx={{ mt: 2 }}>
426
- Save Address
460
+ <Form.Stack spacing={2}>
461
+ <Autocomplete
462
+ options={countries}
463
+ value={country}
464
+ onChange={(_, newValue) => {
465
+ setCountry(newValue);
466
+ setRegion('');
467
+ }}
468
+ renderInput={(params) => (
469
+ <TextField {...params} labelPlacement="top" label="Country" required />
470
+ )}
471
+ />
472
+
473
+ {/* Free text, so it works for any country */}
474
+ <TextField
475
+ fullWidth
476
+ labelPlacement="top"
477
+ label="State, province, or region"
478
+ value={region}
479
+ onChange={(e) => setRegion(e.target.value)}
480
+ required
481
+ />
482
+
483
+ <TextField fullWidth labelPlacement="top" label="City" required />
484
+ <TextField fullWidth labelPlacement="top" label="Address" required multiline rows={2} />
485
+ {/* Optional field: no marker */}
486
+ <TextField fullWidth labelPlacement="top" label="Postal code" />
487
+ </Form.Stack>
488
+
489
+ <Button variant="contained" sx={{ mt: 3 }}>
490
+ Save address
427
491
  </Button>
428
492
  </Box>
429
493
  );
@@ -61,8 +61,8 @@ export interface AppSwitcherProps {
61
61
  * ```tsx
62
62
  * <AppSwitcher currentAppId="agent-manager">
63
63
  * <AppSwitcher.Trigger label="Switch platforms" />
64
- * <AppSwitcher.Section label="Platforms" apps={platforms} loading={isLoading} />
65
- * <AppSwitcher.Footer label="Manage" links={manage} loading={isLoading} />
64
+ * <AppSwitcher.Section label="Categories" apps={platforms} loading={isLoading} />
65
+ * <AppSwitcher.Footer columns={2} links={cloudLinks} loading={isLoading} />
66
66
  * </AppSwitcher>
67
67
  * ```
68
68
  *
@@ -71,14 +71,14 @@ export interface AppSwitcherProps {
71
71
  * <Header.Actions>
72
72
  * <AppSwitcher>
73
73
  * <AppSwitcher.Trigger />
74
- * <AppSwitcher.Section label="Platforms">
74
+ * <AppSwitcher.Section label="Categories">
75
75
  * <AppSwitcher.App name="Agent Manager" url="https://agent.wso2.com" />
76
76
  * <AppSwitcher.App name="API Platform" url="https://api.wso2.com" />
77
77
  * <AppSwitcher.App name="Analytics" disabled tooltip="Coming soon" />
78
78
  * </AppSwitcher.Section>
79
- * <AppSwitcher.Footer label="Manage">
80
- * <AppSwitcher.App name="Organizations" url="https://console.wso2.com/organizations" />
81
- * <AppSwitcher.App name="Billing" url="https://console.wso2.com/billing" />
79
+ * <AppSwitcher.Footer columns={2}>
80
+ * <AppSwitcher.App name="Cloud home" url="https://console.wso2.com" icon={<Home size={16} />} />
81
+ * <AppSwitcher.App name="Settings" url="https://console.wso2.com/settings" icon={<Settings size={16} />} />
82
82
  * </AppSwitcher.Footer>
83
83
  * </AppSwitcher>
84
84
  * </Header.Actions>
@@ -46,8 +46,16 @@ export interface AppSwitcherFooterProps {
46
46
  children?: React.ReactNode;
47
47
  /** WSO2 Cloud destinations rendered as cards, as an alternative to `children` */
48
48
  links?: AppSwitcherFooterLink[];
49
- /** Heading above the links (default: `"Manage"`) */
49
+ /**
50
+ * Heading above the links. Omit it to show the links under the divider alone,
51
+ * as in the WSO2 Cloud design.
52
+ */
50
53
  label?: string;
54
+ /**
55
+ * Accessible name for the links when there is no visible `label`
56
+ * (default: `"Manage"`)
57
+ */
58
+ 'aria-label'?: string;
51
59
  /** Number of grid columns from the `sm` breakpoint up (default: 3) */
52
60
  columns?: number;
53
61
  /** Shows placeholder cards, e.g. while the links are fetched */
@@ -58,8 +66,8 @@ export interface AppSwitcherFooterProps {
58
66
  /**
59
67
  * AppSwitcher.Footer - Bottom section of the app switcher popover.
60
68
  *
61
- * Holds the WSO2 Cloud destinations (organizations, users, billing) as a
62
- * labelled grid of cards, using the same card as the platform grid so both rows
69
+ * Holds the WSO2 Cloud destinations (e.g. Cloud home and Settings) below a
70
+ * divider, as a grid of cards, using the same card as the platform grid so both rows
63
71
  * behave identically. The neutral mark and lighter type keep them visually
64
72
  * secondary to the platforms above.
65
73
  *
@@ -68,9 +76,9 @@ export interface AppSwitcherFooterProps {
68
76
  *
69
77
  * @example
70
78
  * ```tsx
71
- * <AppSwitcher.Footer label="Manage">
72
- * <AppSwitcher.App name="Organizations" url="https://console.wso2.com/organizations" />
73
- * <AppSwitcher.App name="Billing" url="https://console.wso2.com/billing" />
79
+ * <AppSwitcher.Footer columns={2}>
80
+ * <AppSwitcher.App name="Cloud home" url="https://console.wso2.com" icon={<Home size={16} />} />
81
+ * <AppSwitcher.App name="Settings" url="https://console.wso2.com/settings" icon={<Settings size={16} />} />
74
82
  * </AppSwitcher.Footer>
75
83
  * ```
76
84
  */
@@ -42,8 +42,13 @@ export interface AppSwitcherSectionProps {
42
42
  * `url`, `onClick` or `component` renders disabled.
43
43
  */
44
44
  apps?: AppSwitcherAppItem[];
45
- /** Section heading, rendered as an uppercase label (e.g. `"Platforms"`) */
45
+ /** Section heading, rendered as an uppercase label (e.g. `"Categories"`) */
46
46
  label?: string;
47
+ /**
48
+ * Accessible name for the grid when there is no visible `label`. Ignored
49
+ * when `label` is set, since the heading already names the grid.
50
+ */
51
+ 'aria-label'?: string;
47
52
  /** Number of grid columns from the `sm` breakpoint up (default: 3) */
48
53
  columns?: number;
49
54
  /** Shows placeholder cards, e.g. while the apps are fetched */
@@ -60,12 +65,12 @@ export interface AppSwitcherSectionProps {
60
65
  *
61
66
  * @example
62
67
  * ```tsx
63
- * <AppSwitcher.Section label="Platforms">
68
+ * <AppSwitcher.Section label="Categories">
64
69
  * <AppSwitcher.App name="Agent Manager" url="https://agent.wso2.com" />
65
70
  * <AppSwitcher.App name="API Platform" url="https://api.wso2.com" />
66
71
  * </AppSwitcher.Section>
67
72
  *
68
- * <AppSwitcher.Section label="Platforms" apps={platforms} loading={isLoading} />
73
+ * <AppSwitcher.Section label="Categories" apps={platforms} loading={isLoading} />
69
74
  * ```
70
75
  */
71
76
  export declare const AppSwitcherSection: React.FC<AppSwitcherSectionProps>;