@jamesodwyer/gds-figma-vite 2.0.12 → 2.0.14
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/guidelines/Guidelines.md +109 -0
- package/package.json +1 -1
package/guidelines/Guidelines.md
CHANGED
|
@@ -194,6 +194,115 @@ import { Modal, Card, InputField, Accordion, TextStyle } from '@jamesodwyer/gds-
|
|
|
194
194
|
|
|
195
195
|
---
|
|
196
196
|
|
|
197
|
+
## 🚫 VALIDATION MESSAGES - ONLY SHOW ON ERROR
|
|
198
|
+
|
|
199
|
+
**`InputField.Validation` is for ERROR messages only. Do NOT show it by default.**
|
|
200
|
+
|
|
201
|
+
```tsx
|
|
202
|
+
// ❌ WRONG - Validation always visible (even without error)
|
|
203
|
+
<InputField id="email">
|
|
204
|
+
<InputField.Label>Email</InputField.Label>
|
|
205
|
+
<InputField.Row style={{ marginTop: '8px' }}>
|
|
206
|
+
<InputField.Input type="email" />
|
|
207
|
+
</InputField.Row>
|
|
208
|
+
<InputField.Validation type="error" screenReaderErrorPrefix="Error:">
|
|
209
|
+
We'll never share your email
|
|
210
|
+
</InputField.Validation>
|
|
211
|
+
</InputField>
|
|
212
|
+
|
|
213
|
+
// ✅ CORRECT - Only show validation when there IS an error
|
|
214
|
+
<InputField id="email">
|
|
215
|
+
<InputField.Label>Email</InputField.Label>
|
|
216
|
+
<InputField.Row style={{ marginTop: '8px' }}>
|
|
217
|
+
<InputField.Input type="email" isErrored={hasError} />
|
|
218
|
+
</InputField.Row>
|
|
219
|
+
{hasError && (
|
|
220
|
+
<InputField.Validation type="error" screenReaderErrorPrefix="Error:">
|
|
221
|
+
Please enter a valid email address
|
|
222
|
+
</InputField.Validation>
|
|
223
|
+
)}
|
|
224
|
+
</InputField>
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Helper Text vs Error Messages
|
|
228
|
+
|
|
229
|
+
- **Helper text** (like "We'll never share your email") = Use a regular `<p>` or `TextStyle.Snowdon`
|
|
230
|
+
- **Error messages** (like "Please enter a valid email") = Use `InputField.Validation` with conditional rendering
|
|
231
|
+
|
|
232
|
+
```tsx
|
|
233
|
+
// ✅ CORRECT - Helper text with regular element, error only when needed
|
|
234
|
+
<InputField id="email">
|
|
235
|
+
<InputField.Label>Email</InputField.Label>
|
|
236
|
+
<InputField.Row style={{ marginTop: "8px" }}>
|
|
237
|
+
<InputField.Input type="email" isErrored={hasError} />
|
|
238
|
+
</InputField.Row>
|
|
239
|
+
{hasError ? (
|
|
240
|
+
<InputField.Validation type="error" screenReaderErrorPrefix="Error:">
|
|
241
|
+
Please enter a valid email address
|
|
242
|
+
</InputField.Validation>
|
|
243
|
+
) : (
|
|
244
|
+
<p style={{ fontSize: "12px", color: "#666", marginTop: "4px" }}>
|
|
245
|
+
We'll never share your email with anyone else.
|
|
246
|
+
</p>
|
|
247
|
+
)}
|
|
248
|
+
</InputField>
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## 🎨 TEXT & BACKGROUND COLORS - CONTRAST RULES
|
|
254
|
+
|
|
255
|
+
**Always ensure text is readable against backgrounds:**
|
|
256
|
+
|
|
257
|
+
| Background | Text Color |
|
|
258
|
+
| ------------------------------------- | ------------------------------------------- |
|
|
259
|
+
| Light (white, `theme.base.bg`) | Dark text (`theme.text.primary` = #121212) |
|
|
260
|
+
| Dark (`theme.base.bgInverse`, cosmos) | Light text (`theme.text.inverse` = #ffffff) |
|
|
261
|
+
|
|
262
|
+
### Using Theme Colors for Contrast
|
|
263
|
+
|
|
264
|
+
```tsx
|
|
265
|
+
import styled from "styled-components";
|
|
266
|
+
|
|
267
|
+
// ✅ CORRECT - Light background with dark text
|
|
268
|
+
const LightSection = styled.div`
|
|
269
|
+
background: ${(props) => props.theme.base.bg};
|
|
270
|
+
color: ${(props) => props.theme.text.primary};
|
|
271
|
+
`;
|
|
272
|
+
|
|
273
|
+
// ✅ CORRECT - Dark background with light text
|
|
274
|
+
const DarkSection = styled.div`
|
|
275
|
+
background: ${(props) => props.theme.base.bgInverse};
|
|
276
|
+
color: ${(props) => props.theme.text.inverse};
|
|
277
|
+
`;
|
|
278
|
+
|
|
279
|
+
// ✅ CORRECT - Brand colored background with white text
|
|
280
|
+
const BrandSection = styled.div`
|
|
281
|
+
background: ${(props) => props.theme.base.primary};
|
|
282
|
+
color: #ffffff;
|
|
283
|
+
`;
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Default Text Colors
|
|
287
|
+
|
|
288
|
+
- **Light backgrounds**: Text is automatically dark (#121212)
|
|
289
|
+
- **GDS components**: Already have correct text colors built-in
|
|
290
|
+
- **Custom sections**: You must set the text color if you change the background
|
|
291
|
+
|
|
292
|
+
```tsx
|
|
293
|
+
// ❌ WRONG - Dark background but no text color set (text will be dark/invisible)
|
|
294
|
+
<div style={{ background: '#121212' }}>
|
|
295
|
+
<TitleHeading>Can't read this!</TitleHeading>
|
|
296
|
+
</div>
|
|
297
|
+
|
|
298
|
+
// ✅ CORRECT - Dark background with white text
|
|
299
|
+
<div style={{ background: '#121212', color: '#ffffff' }}>
|
|
300
|
+
<TitleHeading>Now visible!</TitleHeading>
|
|
301
|
+
</div>
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
197
306
|
## Package Information
|
|
198
307
|
|
|
199
308
|
- **Package Name**: `@jamesodwyer/gds-figma-vite`
|