@fvc/button 1.2.5 → 1.2.6-next-3607140332290efd627f3fac1cb34e4dcb36274e
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 +216 -0
- package/package.json +12 -2
package/README.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# @fvc/button
|
|
2
|
+
|
|
3
|
+
`@fvc/button` provides FE-VIS styled button primitives on top of Ant Design. It keeps the Ant Design button API familiar while adding the design-system behaviour used across FE-VIS applications: a full set of visual variants, shape and size controls, icon support, a loading state with optional loading text, and block layout.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @fvc/button
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Peer Dependencies
|
|
12
|
+
|
|
13
|
+
The package expects these dependencies to be available in the consuming application:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bun add react antd @fvc/icons
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Import
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { Button } from '@fvc/button';
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { Button } from '@fvc/button';
|
|
29
|
+
|
|
30
|
+
export function SaveAction() {
|
|
31
|
+
return (
|
|
32
|
+
<Button type="primary" onClick={() => handleSave()}>
|
|
33
|
+
Save
|
|
34
|
+
</Button>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Variants
|
|
40
|
+
|
|
41
|
+
| Value | Description |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `'default'` | Default styling. |
|
|
44
|
+
| `'primary'` | Primary action — green fill with shadow. |
|
|
45
|
+
| `'secondary'` | Secondary action — green outline. |
|
|
46
|
+
| `'white'` | White background variant. |
|
|
47
|
+
| `'dashed'` | Dashed border. |
|
|
48
|
+
| `'link'` | Inline link appearance. |
|
|
49
|
+
| `'text'` | No border or background. |
|
|
50
|
+
| `'text-black'` | No border or background, black text. |
|
|
51
|
+
| `'danger'` | Destructive action — red outline. |
|
|
52
|
+
| `'danger-light'` | Destructive action — light red fill. |
|
|
53
|
+
| `'transparent'` | Transparent background. |
|
|
54
|
+
| `'dropdown-button'` | Dropdown trigger variant. |
|
|
55
|
+
|
|
56
|
+
## Common Usage
|
|
57
|
+
|
|
58
|
+
### Primary and Secondary
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
<Button type="primary">Submit</Button>
|
|
62
|
+
<Button type="secondary">Cancel</Button>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Danger
|
|
66
|
+
|
|
67
|
+
Use `type="danger"` or the `danger` prop for destructive actions.
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
<Button type="danger">Delete</Button>
|
|
71
|
+
<Button danger type="secondary">Remove</Button>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Sizes
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
<Button size="small">Small</Button>
|
|
78
|
+
<Button size="middle">Middle</Button>
|
|
79
|
+
<Button size="large">Large</Button>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### With Icon
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import { Delete } from '@fvc/icons';
|
|
86
|
+
|
|
87
|
+
<Button icon={<Delete />} type="primary">Delete item</Button>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Icon-only buttons use `shape` to control the outline:
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
<Button icon={<Delete />} shape="circle" />
|
|
94
|
+
<Button icon={<Delete />} shape="round" type="secondary" />
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Loading State
|
|
98
|
+
|
|
99
|
+
`loading` shows a spinner and suppresses `onClick` until the operation completes. Use `loadingText` to replace the label during loading.
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
<Button loading type="primary">Saving…</Button>
|
|
103
|
+
<Button loading loadingText="Uploading…" icon={<Upload />} type="secondary" />
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Disabled
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
<Button disabled type="primary">Unavailable</Button>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Full-Width
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
<Button block type="primary">Submit form</Button>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Transparent Background
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
<Button bg="transparent" type="primary">Overlay action</Button>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Props
|
|
125
|
+
|
|
126
|
+
| Prop | Type | Description |
|
|
127
|
+
| --- | --- | --- |
|
|
128
|
+
| `type` | [`ButtonType`](#variants) | Visual variant. Defaults to `'default'`. |
|
|
129
|
+
| `shape` | `'round' \| 'circle'` | Button shape. |
|
|
130
|
+
| `bg` | `'transparent'` | Background override. |
|
|
131
|
+
| `size` | `'small' \| 'middle' \| 'large'` | Button size. Defaults to `'middle'`. |
|
|
132
|
+
| `danger` | `boolean` | Applies danger styling; equivalent to `type="danger"`. |
|
|
133
|
+
| `block` | `boolean` | Stretches the button to full container width. |
|
|
134
|
+
| `icon` | `ReactNode` | Icon element, typically from `@fvc/icons`. |
|
|
135
|
+
| `loading` | `boolean` | Shows a spinner and suppresses `onClick`. |
|
|
136
|
+
| `loadingText` | `ReactNode` | Text displayed while `loading` is `true`. |
|
|
137
|
+
| `disabled` | `boolean` | Disables the button and removes it from tab order. |
|
|
138
|
+
| `className` | `string` | Additional CSS class names. |
|
|
139
|
+
| `testId` | `string` | Maps to `data-testid`. |
|
|
140
|
+
| `children` | `ReactNode` | Button label. |
|
|
141
|
+
|
|
142
|
+
## Consumer Example
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
import { Button } from '@fvc/button';
|
|
146
|
+
import { Save, Trash } from '@fvc/icons';
|
|
147
|
+
|
|
148
|
+
export function RecordActions({ saving, onSave, onDelete }) {
|
|
149
|
+
return (
|
|
150
|
+
<div>
|
|
151
|
+
<Button
|
|
152
|
+
type="primary"
|
|
153
|
+
icon={<Save />}
|
|
154
|
+
loading={saving}
|
|
155
|
+
loadingText="Saving…"
|
|
156
|
+
onClick={onSave}
|
|
157
|
+
>
|
|
158
|
+
Save
|
|
159
|
+
</Button>
|
|
160
|
+
|
|
161
|
+
<Button
|
|
162
|
+
type="danger"
|
|
163
|
+
icon={<Trash />}
|
|
164
|
+
onClick={onDelete}
|
|
165
|
+
>
|
|
166
|
+
Delete
|
|
167
|
+
</Button>
|
|
168
|
+
</div>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Testing
|
|
174
|
+
|
|
175
|
+
Use `testId` when a stable test selector is needed.
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
<Button type="primary" testId="save-button">
|
|
179
|
+
Save
|
|
180
|
+
</Button>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
screen.getByTestId('save-button');
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## CSS Customisation
|
|
188
|
+
|
|
189
|
+
The component exposes CSS custom properties for theming. Override them in your global styles:
|
|
190
|
+
|
|
191
|
+
```css
|
|
192
|
+
:root {
|
|
193
|
+
--button-primary-text-color: #fff;
|
|
194
|
+
--button-primary-bg-color: #1a7a4c;
|
|
195
|
+
--button-primary-border-color: #1a7a4c;
|
|
196
|
+
--button-primary-hover-bg-color: #15623d;
|
|
197
|
+
|
|
198
|
+
--button-height-sm: 24px;
|
|
199
|
+
--button-height-md: 32px;
|
|
200
|
+
--button-height-lg: 48px;
|
|
201
|
+
--button-height-default: 40px;
|
|
202
|
+
|
|
203
|
+
--button-round-radius: 100px;
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
For the full variable list see [`src/variables.scss`](./src/variables.scss).
|
|
208
|
+
|
|
209
|
+
## Development
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
bun run lint
|
|
213
|
+
bun run type-check
|
|
214
|
+
bun run test
|
|
215
|
+
bun run build
|
|
216
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fvc/button",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6-next-3607140332290efd627f3fac1cb34e4dcb36274e",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"react",
|
|
6
|
+
"react-component",
|
|
7
|
+
"fvc",
|
|
8
|
+
"fe-vis-core",
|
|
9
|
+
"ui",
|
|
10
|
+
"button",
|
|
11
|
+
"design-system",
|
|
12
|
+
"antd"
|
|
13
|
+
],
|
|
4
14
|
"main": "./dist/lib/index.js",
|
|
5
15
|
"types": "./dist/lib/button/src/index.d.ts",
|
|
6
16
|
"files": [
|
|
@@ -27,7 +37,7 @@
|
|
|
27
37
|
"test": "bun test --preload ../../tests/happydom.ts --preload ../../tests/testing-library.tsx"
|
|
28
38
|
},
|
|
29
39
|
"peerDependencies": {
|
|
30
|
-
"@fvc/icons": "
|
|
40
|
+
"@fvc/icons": "1.1.4-next-3607140332290efd627f3fac1cb34e4dcb36274e",
|
|
31
41
|
"react": "^18.0.0",
|
|
32
42
|
"antd": "^5.0.0"
|
|
33
43
|
}
|