@fvc/label 1.0.1 → 1.0.2-next-ec65dfb844e6183b3d7f417eee613cfe5ecfd997

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.
Files changed (2) hide show
  1. package/README.md +163 -0
  2. package/package.json +14 -2
package/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # @fvc/label
2
+
3
+ `@fvc/label` provides a form label primitive for FE-VIS applications. It handles required indicators, disabled styling, inline error display, and rendering as any HTML element — covering the full range of label use cases in a form system without requiring additional wrapper components.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @fvc/label
9
+ ```
10
+
11
+ ## Peer Dependencies
12
+
13
+ ```bash
14
+ bun add react antd
15
+ ```
16
+
17
+ ## Import
18
+
19
+ ```tsx
20
+ import { Label } from '@fvc/label';
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ```tsx
26
+ import { Label } from '@fvc/label';
27
+
28
+ export function EmailField() {
29
+ return (
30
+ <>
31
+ <Label htmlFor="email" required>
32
+ Email address
33
+ </Label>
34
+ <input id="email" type="email" />
35
+ </>
36
+ );
37
+ }
38
+ ```
39
+
40
+ ## States
41
+
42
+ | State | Prop | Visual effect |
43
+ | --- | --- | --- |
44
+ | Default | — | Black text (`--black-1000`), 14px Roboto medium |
45
+ | Required | `required` | Appends `*` after the label text |
46
+ | Disabled | `disabled` | Muted colour (`--blue-gray-300`), `not-allowed` cursor |
47
+ | Error | `error="message"` | Replaces `children` with the error string; red text (`--warning-text-color-800`) |
48
+
49
+ ## Common Usage
50
+
51
+ ### Required field
52
+
53
+ ```tsx
54
+ <Label htmlFor="name" required>Full name</Label>
55
+ ```
56
+
57
+ ### Disabled
58
+
59
+ ```tsx
60
+ <Label htmlFor="name" disabled>Full name</Label>
61
+ ```
62
+
63
+ ### Error state
64
+
65
+ `error` replaces `children`. The same element serves as both the label and the inline error message — no separate error component needed.
66
+
67
+ ```tsx
68
+ <Label htmlFor="email" error="Enter a valid email address" />
69
+ ```
70
+
71
+ ### Combined required and error
72
+
73
+ ```tsx
74
+ <Label htmlFor="email" required error="This field is required" />
75
+ ```
76
+
77
+ ### Custom element type
78
+
79
+ When the label is not semantically a `<label>` element, pass `elementType`. The `htmlFor` attribute is omitted automatically when `elementType` is not `'label'`.
80
+
81
+ ```tsx
82
+ <Label elementType="span">Section heading</Label>
83
+ <Label elementType="p">Description text</Label>
84
+ ```
85
+
86
+ ## Props
87
+
88
+ | Prop | Type | Default | Description |
89
+ | --- | --- | --- | --- |
90
+ | `children` | `ReactNode` | — | Label text. Replaced by `error` when `error` is provided. |
91
+ | `htmlFor` | `string` | — | Native `htmlFor` attribute. Only applied when `elementType` is `'label'`. |
92
+ | `for` | `string` | — | Alias for `htmlFor`. |
93
+ | `required` | `boolean` | `false` | Appends a `*` indicator after the content. |
94
+ | `disabled` | `boolean` | `false` | Applies disabled styling. |
95
+ | `error` | `string` | — | Replaces `children` and applies error colour when set. |
96
+ | `elementType` | `ElementType` | `'label'` | Renders the label as any HTML or React element. |
97
+ | `testId` | `string` | — | Maps to `data-testid`. |
98
+ | `className` | `string` | — | Additional CSS class names. |
99
+
100
+ All standard `HTMLAttributes<HTMLElement>` are accepted and forwarded to the root element.
101
+
102
+ ## Consumer Example
103
+
104
+ ```tsx
105
+ import { Label } from '@fvc/label';
106
+ import { Input } from 'antd';
107
+ import { ReactNode } from 'react';
108
+
109
+ interface FormFieldProps {
110
+ id: string;
111
+ label: string;
112
+ required?: boolean;
113
+ disabled?: boolean;
114
+ error?: string;
115
+ children: ReactNode;
116
+ }
117
+
118
+ export function FormField({
119
+ id,
120
+ label,
121
+ required,
122
+ disabled,
123
+ error,
124
+ children,
125
+ }: FormFieldProps) {
126
+ return (
127
+ <div>
128
+ <Label htmlFor={id} required={required} disabled={disabled} error={error}>
129
+ {label}
130
+ </Label>
131
+ {children}
132
+ </div>
133
+ );
134
+ }
135
+ ```
136
+
137
+ ## Testing
138
+
139
+ Use `testId` when a stable test selector is needed.
140
+
141
+ ```tsx
142
+ <Label testId="email-label" htmlFor="email">Email address</Label>
143
+ ```
144
+
145
+ ```tsx
146
+ screen.getByTestId('email-label');
147
+ ```
148
+
149
+ ## CSS Classes
150
+
151
+ | Class | Applied when |
152
+ | --- | --- |
153
+ | `.fvc-label` | Always — base class |
154
+ | `.fvc-label-error` | `error` prop is a non-empty string |
155
+ | `.fvc-label-disabled` | `disabled` is `true` |
156
+
157
+ ## Development
158
+
159
+ ```bash
160
+ bun run lint
161
+ bun run type-check
162
+ bun run test
163
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fvc/label",
3
- "version": "1.0.1",
3
+ "version": "1.0.2-next-ec65dfb844e6183b3d7f417eee613cfe5ecfd997",
4
4
  "main": "./dist/lib/index.js",
5
5
  "types": "./dist/lib/label/src/index.d.ts",
6
6
  "files": [
@@ -29,5 +29,17 @@
29
29
  "peerDependencies": {
30
30
  "react": "^18.0.0",
31
31
  "antd": "^5.0.0"
32
- }
32
+ },
33
+ "keywords": [
34
+ "react",
35
+ "react-component",
36
+ "fvc",
37
+ "fe-vis-core",
38
+ "ui",
39
+ "label",
40
+ "form",
41
+ "form-label",
42
+ "design-system",
43
+ "antd"
44
+ ]
33
45
  }