@web-canvas-ui/react 0.1.2 → 0.3.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/README.md +415 -205
- package/index.js +3660 -0
- package/package.json +36 -27
- package/types/canvas-handle.d.ts +22 -0
- package/types/components/Button/button.d.ts +22 -0
- package/types/components/Button/logic.d.ts +3 -0
- package/types/components/CanvasView/canvasView.d.ts +28 -0
- package/types/components/CanvasView/index.d.ts +2 -0
- package/types/components/Carousel/carousel.d.ts +31 -0
- package/types/components/Carousel/logic.d.ts +2 -0
- package/types/components/Checkbox/checkbox.d.ts +8 -0
- package/types/components/ChoiceGroup/choiceGroup.d.ts +38 -0
- package/{components/ChoiceGroup/index.ts → types/components/ChoiceGroup/index.d.ts} +1 -1
- package/types/components/ChoiceGroup/logic.d.ts +3 -0
- package/types/components/Circle/circle.d.ts +9 -0
- package/types/components/Collapse/collapse.d.ts +32 -0
- package/types/components/Collapse/logic.d.ts +1 -0
- package/types/components/CustomDraw/customDraw.d.ts +22 -0
- package/types/components/CustomDraw/index.d.ts +2 -0
- package/types/components/DatePicker/datePicker.d.ts +24 -0
- package/types/components/Dialog/dialog.d.ts +20 -0
- package/types/components/Dropdown/dropdown.d.ts +30 -0
- package/types/components/Dropdown/logic.d.ts +5 -0
- package/types/components/Form/form.d.ts +42 -0
- package/types/components/Form/index.d.ts +2 -0
- package/{components/Grid/grid.ts → types/components/Grid/grid.d.ts} +3 -4
- package/{components/GridItem/gridItem.ts → types/components/GridItem/gridItem.d.ts} +1 -4
- package/{components/Group/group.ts → types/components/Group/group.d.ts} +1 -4
- package/types/components/Icon/icon.d.ts +14 -0
- package/types/components/Image/image.d.ts +12 -0
- package/types/components/Input/input.d.ts +32 -0
- package/types/components/Progress/progress.d.ts +15 -0
- package/types/components/Radio/radio.d.ts +8 -0
- package/types/components/Rect/rect.d.ts +11 -0
- package/types/components/Slider/logic.d.ts +1 -0
- package/types/components/Slider/slider.d.ts +17 -0
- package/types/components/Switch/logic.d.ts +2 -0
- package/types/components/Switch/switch.d.ts +14 -0
- package/types/components/Tabs/logic.d.ts +2 -0
- package/types/components/Tabs/tabs.d.ts +35 -0
- package/types/components/Text/text.d.ts +39 -0
- package/types/components/Textarea/textarea.d.ts +10 -0
- package/types/components/Upload/index.d.ts +2 -0
- package/types/components/Upload/upload.d.ts +30 -0
- package/types/components/Video/index.d.ts +4 -0
- package/types/components/Video/logic.d.ts +56 -0
- package/types/components/Video/video.d.ts +54 -0
- package/types/components/draw-utils.d.ts +48 -0
- package/types/components/shared.d.ts +7 -0
- package/types/components/size.d.ts +6 -0
- package/{components/types.ts → types/components/types.d.ts} +5 -13
- package/types/engine/accessibility.d.ts +5 -0
- package/types/engine/carousel.d.ts +10 -0
- package/types/engine/events.d.ts +14 -0
- package/types/engine/forms.d.ts +21 -0
- package/types/engine/hit-test.d.ts +31 -0
- package/types/engine/images.d.ts +8 -0
- package/types/engine/interaction.d.ts +12 -0
- package/types/engine/layout.d.ts +6 -0
- package/types/engine/nodes.d.ts +19 -0
- package/types/engine/state.d.ts +91 -0
- package/types/engine/text-controls.d.ts +10 -0
- package/types/engine/transform.d.ts +13 -0
- package/types/engine/uploads.d.ts +5 -0
- package/types/engine/videos.d.ts +28 -0
- package/types/engine/vnodes.d.ts +36 -0
- package/types/engine.d.ts +38 -0
- package/types/image-assets.d.ts +2 -0
- package/types/input-bridge.d.ts +54 -0
- package/types/react/Canvas.d.ts +4 -0
- package/types/react/components.d.ts +31 -0
- package/types/react/index.d.ts +5 -0
- package/types/renderer.d.ts +20 -0
- package/types/scene.d.ts +15 -0
- package/{types.ts → types/types.d.ts} +48 -142
- package/types/video-assets.d.ts +28 -0
- package/Canvas.tsx +0 -142
- package/__tests__/pure-logic.test.ts +0 -153
- package/__tests__/scene-and-node.test.ts +0 -131
- package/__tests__/scratch-space.test.ts +0 -30
- package/__tests__/textarea-caret.test.ts +0 -96
- package/__tests__/utils.test.ts +0 -114
- package/canvas-handle.ts +0 -114
- package/components/Button/button.ts +0 -57
- package/components/Button/logic.ts +0 -11
- package/components/CanvasView/canvasView.ts +0 -103
- package/components/CanvasView/index.ts +0 -7
- package/components/Carousel/carousel.ts +0 -107
- package/components/Carousel/logic.ts +0 -36
- package/components/Checkbox/checkbox.ts +0 -14
- package/components/ChoiceGroup/choiceGroup.ts +0 -172
- package/components/ChoiceGroup/logic.ts +0 -14
- package/components/Circle/circle.ts +0 -31
- package/components/Collapse/collapse.ts +0 -69
- package/components/Collapse/logic.ts +0 -14
- package/components/CustomDraw/customDraw.ts +0 -50
- package/components/CustomDraw/index.ts +0 -7
- package/components/DatePicker/datePicker.ts +0 -70
- package/components/Dialog/dialog.ts +0 -102
- package/components/Dropdown/dropdown.ts +0 -125
- package/components/Dropdown/logic.ts +0 -29
- package/components/Icon/icon.ts +0 -669
- package/components/Image/image.ts +0 -69
- package/components/Input/input.ts +0 -139
- package/components/Progress/progress.ts +0 -59
- package/components/Radio/radio.ts +0 -14
- package/components/Rect/rect.ts +0 -35
- package/components/Slider/logic.ts +0 -19
- package/components/Slider/slider.ts +0 -58
- package/components/Switch/logic.ts +0 -8
- package/components/Switch/switch.ts +0 -37
- package/components/Tabs/logic.ts +0 -14
- package/components/Tabs/tabs.ts +0 -78
- package/components/Text/text.ts +0 -95
- package/components/Textarea/textarea.ts +0 -16
- package/components/Upload/index.ts +0 -2
- package/components/Upload/upload.ts +0 -66
- package/components/draw-utils.ts +0 -230
- package/components/shared.ts +0 -15
- package/components/size.ts +0 -20
- package/components.ts +0 -98
- package/engine/__tests__/carousel.test.ts +0 -218
- package/engine/__tests__/hit-test.test.ts +0 -282
- package/engine/__tests__/layout.test.ts +0 -474
- package/engine/carousel.ts +0 -150
- package/engine/events.ts +0 -73
- package/engine/hit-test.ts +0 -321
- package/engine/images.ts +0 -41
- package/engine/interaction.ts +0 -442
- package/engine/layout.ts +0 -355
- package/engine/nodes.ts +0 -166
- package/engine/state.ts +0 -75
- package/engine/text-controls.ts +0 -122
- package/engine/transform.ts +0 -61
- package/engine/vnodes.ts +0 -204
- package/engine.ts +0 -162
- package/image-assets.ts +0 -37
- package/index.ts +0 -78
- package/input-bridge.ts +0 -285
- package/renderer.ts +0 -303
- package/scene.ts +0 -122
- package/theme.scss +0 -234
- package/web-canvas-ui-react-0.1.1.tgz +0 -0
- /package/{components/Button/index.ts → types/components/Button/index.d.ts} +0 -0
- /package/{components/Carousel/index.ts → types/components/Carousel/index.d.ts} +0 -0
- /package/{components/Checkbox/index.ts → types/components/Checkbox/index.d.ts} +0 -0
- /package/{components/Circle/index.ts → types/components/Circle/index.d.ts} +0 -0
- /package/{components/Collapse/index.ts → types/components/Collapse/index.d.ts} +0 -0
- /package/{components/DatePicker/index.ts → types/components/DatePicker/index.d.ts} +0 -0
- /package/{components/Dialog/index.ts → types/components/Dialog/index.d.ts} +0 -0
- /package/{components/Dropdown/index.ts → types/components/Dropdown/index.d.ts} +0 -0
- /package/{components/Grid/index.ts → types/components/Grid/index.d.ts} +0 -0
- /package/{components/GridItem/index.ts → types/components/GridItem/index.d.ts} +0 -0
- /package/{components/Group/index.ts → types/components/Group/index.d.ts} +0 -0
- /package/{components/Icon/index.ts → types/components/Icon/index.d.ts} +0 -0
- /package/{components/Image/index.ts → types/components/Image/index.d.ts} +0 -0
- /package/{components/Input/index.ts → types/components/Input/index.d.ts} +0 -0
- /package/{components/Progress/index.ts → types/components/Progress/index.d.ts} +0 -0
- /package/{components/Radio/index.ts → types/components/Radio/index.d.ts} +0 -0
- /package/{components/Rect/index.ts → types/components/Rect/index.d.ts} +0 -0
- /package/{components/Slider/index.ts → types/components/Slider/index.d.ts} +0 -0
- /package/{components/Switch/index.ts → types/components/Switch/index.d.ts} +0 -0
- /package/{components/Tabs/index.ts → types/components/Tabs/index.d.ts} +0 -0
- /package/{components/Text/index.ts → types/components/Text/index.d.ts} +0 -0
- /package/{components/Textarea/index.ts → types/components/Textarea/index.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -10,20 +10,34 @@ A declarative component library built on Canvas 2D, with **React**, **Vue 3**, *
|
|
|
10
10
|
|
|
11
11
|
> **Adapters:** React, Vue, Svelte, and Angular import from `@web-canvas-ui/react`, `@web-canvas-ui/vue`, `@web-canvas-ui/svelte`, and `@web-canvas-ui/angular` respectively. Pick the entry that matches your host Canvas framework and do not mix components across adapters — they all reuse the same engine and control drawing implementation.
|
|
12
12
|
|
|
13
|
-
> **Shared component contract:** Each control lives under `components/<Component>/`.
|
|
13
|
+
> **Shared component contract:** Each control lives under `src/canvas-ui/components/<Component>/`. `<component>.ts` defines the Props type and Canvas drawing function, and `logic.ts` (when needed) holds control-specific interaction and business logic. Public types are aggregated in `components/types.ts` and re-exported through `src/canvas-ui/types.ts` and each framework entry. The React, Vue, Svelte, and Angular adapters share this type contract. See the [component development guide](./COMPONENT-DEVELOPMENT.zh-CN.md) (in Chinese) for the full procedure.
|
|
14
14
|
|
|
15
|
-
###
|
|
16
|
-
|
|
15
|
+
### Clone the Repository
|
|
16
|
+
|
|
17
|
+
Clone the project to your local machine and navigate into the directory:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
git clone https://github.com/web-canvas-ui/web-canvas-ui.git
|
|
21
|
+
cd web-canvas-ui
|
|
22
|
+
npm install
|
|
23
|
+
npm run dev
|
|
24
|
+
|
|
25
|
+
OR
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
[▶️ ui-demo](https://codesandbox.io/p/sandbox/web-canvas-ui-demo-2jhwsn)
|
|
29
|
+
|
|
30
|
+
[▶️ form-demo](https://codesandbox.io/p/sandbox/form-demo-drvqqk)
|
|
17
31
|
|
|
18
32
|
## Global Theme Colors
|
|
19
33
|
|
|
20
34
|
Theme colors are centralized in [`theme.scss`](src/canvas-ui/theme.scss) as `$primary: #1668dc`. Changing this single variable updates the accent color for buttons, selected states, focus borders, progress bars, and more. Light variants are mixed with white, and pressed variants darken the primary; the shared scales are also emitted as `--canvas-ui-primary*` CSS variables. `theme.css` is a build artifact — import it as global CSS and do not edit the generated file directly:
|
|
21
35
|
|
|
22
36
|
```css
|
|
23
|
-
@import 'web-canvas-ui/theme.css';
|
|
37
|
+
@import '@web-canvas-ui/react/theme.css';
|
|
24
38
|
```
|
|
25
39
|
|
|
26
|
-
After editing `theme.scss`, run `npm run build:theme` to regenerate the CSS. The compiled CSS custom properties apply to React, Vue, Svelte, and Angular, and provide `.dark` and `[data-theme="dark"]` dark themes. Colors passed explicitly to a component take precedence over theme variables.
|
|
40
|
+
Replace `react` with `vue`, `svelte`, or `angular` for the other packages. After editing `theme.scss`, run `npm run build:theme` to regenerate the CSS. The compiled CSS custom properties apply to React, Vue, Svelte, and Angular, and provide `.dark` and `[data-theme="dark"]` dark themes. Colors passed explicitly to a component take precedence over theme variables.
|
|
27
41
|
|
|
28
42
|
Five built-in primary palettes are provided: blue, green, purple, orange, and red. Add the corresponding class to the outer Canvas container to switch palettes; they also combine with the dark theme:
|
|
29
43
|
|
|
@@ -68,12 +82,8 @@ To customize the theme for a specific application, override only the variables y
|
|
|
68
82
|
|
|
69
83
|
## Environment and Imports
|
|
70
84
|
|
|
71
|
-
|
|
85
|
+
Install the package for your framework: React 19+, Vue 3, Svelte 5+, or Angular 17+. Framework dependencies are supplied by the host project.
|
|
72
86
|
|
|
73
|
-
```
|
|
74
|
-
npm install web-canvas-ui
|
|
75
|
-
```
|
|
76
|
-
OR
|
|
77
87
|
```
|
|
78
88
|
npm install @web-canvas-ui/react
|
|
79
89
|
|
|
@@ -84,12 +94,12 @@ npm install @web-canvas-ui/svelte
|
|
|
84
94
|
npm install @web-canvas-ui/angular
|
|
85
95
|
```
|
|
86
96
|
|
|
87
|
-
| Framework | Entry
|
|
88
|
-
| -----------
|
|
89
|
-
| React |
|
|
90
|
-
| Vue 3 |
|
|
91
|
-
| Svelte 5+ |
|
|
92
|
-
| Angular 17+ |
|
|
97
|
+
| Framework | Entry |
|
|
98
|
+
| ----------- | ------------------------ |
|
|
99
|
+
| React | `@web-canvas-ui/react` |
|
|
100
|
+
| Vue 3 | `@web-canvas-ui/vue` |
|
|
101
|
+
| Svelte 5+ | `@web-canvas-ui/svelte` |
|
|
102
|
+
| Angular 17+ | `@web-canvas-ui/angular` |
|
|
93
103
|
|
|
94
104
|
Components must be placed inside the corresponding adapter's Canvas container and use the scene components exported by that framework's entry. Do not place plain DOM elements inside a Canvas scene.
|
|
95
105
|
|
|
@@ -123,9 +133,7 @@ export function ProfileCanvas() {
|
|
|
123
133
|
<Canvas ref={canvasRef} width={420} height={220}>
|
|
124
134
|
<Group x={24} y={24}>
|
|
125
135
|
<Rect width={340} height={170} color="#f5f8fc" radius={12} />
|
|
126
|
-
<Text x={16} y={16} fontSize={20} color="#222"
|
|
127
|
-
Profile
|
|
128
|
-
</Text>
|
|
136
|
+
<Text x={16} y={16} fontSize={20} color="#222" text="Profile" />
|
|
129
137
|
<Input
|
|
130
138
|
x={16}
|
|
131
139
|
y={54}
|
|
@@ -135,9 +143,13 @@ export function ProfileCanvas() {
|
|
|
135
143
|
placeholder="Your name"
|
|
136
144
|
onChange={setName}
|
|
137
145
|
/>
|
|
138
|
-
<Text
|
|
139
|
-
{
|
|
140
|
-
|
|
146
|
+
<Text
|
|
147
|
+
x={16}
|
|
148
|
+
y={108}
|
|
149
|
+
width={280}
|
|
150
|
+
fontSize={16}
|
|
151
|
+
text={name ? `Hello, ${name}` : 'Type your name'}
|
|
152
|
+
/>
|
|
141
153
|
<Button
|
|
142
154
|
x={16}
|
|
143
155
|
y={136}
|
|
@@ -160,7 +172,7 @@ export function ProfileCanvas() {
|
|
|
160
172
|
|
|
161
173
|
## Quick Start (Vue 3 Single-File Component)
|
|
162
174
|
|
|
163
|
-
The Vue adapter lives
|
|
175
|
+
The Vue adapter lives in `@web-canvas-ui/vue`. Nest Canvas UI components directly in a `.vue` template — no TSX, no JSX plugin, no manual Canvas node arrays:
|
|
164
176
|
|
|
165
177
|
```vue
|
|
166
178
|
<script setup lang="ts">
|
|
@@ -190,7 +202,7 @@ function exportPng() {
|
|
|
190
202
|
<Canvas ref="canvasRef" :width="420" :height="220">
|
|
191
203
|
<Group :x="24" :y="24">
|
|
192
204
|
<Rect :width="340" :height="170" color="#f5f8fc" :radius="12" />
|
|
193
|
-
<Text :x="16" :y="16" :font-size="20"
|
|
205
|
+
<Text :x="16" :y="16" :font-size="20" text="Vue 3 Canvas" />
|
|
194
206
|
<Input
|
|
195
207
|
:x="16"
|
|
196
208
|
:y="54"
|
|
@@ -200,9 +212,12 @@ function exportPng() {
|
|
|
200
212
|
placeholder="Your name"
|
|
201
213
|
@change="name = $event"
|
|
202
214
|
/>
|
|
203
|
-
<Text
|
|
204
|
-
|
|
205
|
-
|
|
215
|
+
<Text
|
|
216
|
+
:x="16"
|
|
217
|
+
:y="104"
|
|
218
|
+
:width="280"
|
|
219
|
+
:text="name ? `Hello, ${name}` : 'Type your name'"
|
|
220
|
+
/>
|
|
206
221
|
<Button :x="16" :y="142" :width="120" :height="36" @click="exportPng">
|
|
207
222
|
Export Image
|
|
208
223
|
</Button>
|
|
@@ -262,10 +277,10 @@ The Angular entry provides a standalone `Canvas` component and scene directives.
|
|
|
262
277
|
```ts
|
|
263
278
|
import { Component, ViewChild } from '@angular/core';
|
|
264
279
|
import { Button, Canvas, Group, Input, Rect, Text } from '@web-canvas-ui/angular';
|
|
265
|
-
import './theme.css';
|
|
266
280
|
|
|
267
281
|
@Component({
|
|
268
|
-
selector: '
|
|
282
|
+
selector: 'app-root',
|
|
283
|
+
styleUrl: './theme.css',
|
|
269
284
|
standalone: true,
|
|
270
285
|
imports: [Canvas, Group, Rect, Text, Input, Button],
|
|
271
286
|
template: `
|
|
@@ -283,7 +298,7 @@ import './theme.css';
|
|
|
283
298
|
[y]="48"
|
|
284
299
|
[value]="name"
|
|
285
300
|
placeholder="Your name"
|
|
286
|
-
(valueChange)="
|
|
301
|
+
(valueChange)="onInputChange($event)"
|
|
287
302
|
></canvas-input>
|
|
288
303
|
<canvas-text
|
|
289
304
|
[x]="16"
|
|
@@ -312,6 +327,9 @@ export class ProfileCanvas {
|
|
|
312
327
|
link.download = 'profile.png';
|
|
313
328
|
link.click();
|
|
314
329
|
}
|
|
330
|
+
onInputChange(e: any) {
|
|
331
|
+
this.name = e;
|
|
332
|
+
}
|
|
315
333
|
}
|
|
316
334
|
```
|
|
317
335
|
|
|
@@ -332,6 +350,12 @@ Every visible component except `<Canvas>` supports the following transform props
|
|
|
332
350
|
| `scaleY` | `number` | `1` | Vertical transform scale. |
|
|
333
351
|
| `visible` | `boolean` | `true` | Whether the component is drawn; when `false`, its children are also hidden and do not respond to clicks. |
|
|
334
352
|
|
|
353
|
+
### Keyboard and accessibility
|
|
354
|
+
|
|
355
|
+
`Input`, `Textarea`, `DatePicker`, `Button`, `Upload`, `Switch`, `Radio`, `Checkbox`, `Slider`, and `Dropdown` support keyboard focus and native accessibility semantics. Use Tab to move between controls, Enter/Space for buttons and switches, and the browser's native keys for choices and sliders. Keyboard operation of Dropdown uses a native selection list. Set `ariaLabel` on interactive components for a meaningful name, for example `<Switch ariaLabel="Notifications" />`; text inputs fall back to their placeholder. Form errors are associated with their fields for assistive technology.
|
|
356
|
+
|
|
357
|
+
Keyboard support for Tabs, Collapse, Carousel, Video, and custom-drawn controls is not yet included. Test keyboard and screen-reader behavior in your application.
|
|
358
|
+
|
|
335
359
|
### Sizing Rules
|
|
336
360
|
|
|
337
361
|
- `Rect`, `Input`, `Textarea`, `Upload`, `Dropdown`, `DatePicker`, `Slider`, `Switch`, and `Button` use `width` and `height` to set their size.
|
|
@@ -449,7 +473,7 @@ import { Canvas, CustomDraw } from '@web-canvas-ui/react';
|
|
|
449
473
|
</Canvas>;
|
|
450
474
|
```
|
|
451
475
|
|
|
452
|
-
Each invocation is isolated from the rest of the Canvas drawing state — colors, line widths, and transforms set inside the callback do not leak to other components. Only draw inside the callback; do not update UI state or perform side effects.
|
|
476
|
+
Each invocation is isolated from the rest of the Canvas drawing state — colors, line widths, and transforms set inside the callback do not leak to other components. Only draw inside the callback; do not update UI state or perform side effects. The renderer logs drawing errors to the console, skips the affected node, and continues drawing other nodes.
|
|
453
477
|
|
|
454
478
|
### `<Group>`
|
|
455
479
|
|
|
@@ -461,12 +485,83 @@ Used to group, position, and transform children. Supports [Common Props](#common
|
|
|
461
485
|
|
|
462
486
|
```tsx
|
|
463
487
|
<Group x={20} y={30} scaleX={1.2}>
|
|
464
|
-
<Text x={10} y={10}
|
|
465
|
-
Text inside a group
|
|
466
|
-
</Text>
|
|
488
|
+
<Text x={10} y={10} text="Text inside a group" />
|
|
467
489
|
</Group>
|
|
468
490
|
```
|
|
469
491
|
|
|
492
|
+
### `<Form>` and `<FormItem>`
|
|
493
|
+
|
|
494
|
+
`Form` manages field values, validation, and submission. Each `FormItem` needs a unique `name` and exactly one direct `Input`, `Textarea`, `DatePicker`, `Radio`, `Checkbox`, `Dropdown`, `Slider`, `Switch`, or `Upload`. Child positions are relative to the item; nested forms are not supported.
|
|
495
|
+
|
|
496
|
+
```tsx
|
|
497
|
+
<Form
|
|
498
|
+
initialValues={{ email: '', role: 'Individual' }}
|
|
499
|
+
onSubmit={(values) => console.log(values)}
|
|
500
|
+
onInvalid={(errors) => console.log(errors)}
|
|
501
|
+
>
|
|
502
|
+
<FormItem
|
|
503
|
+
x={20}
|
|
504
|
+
y={20}
|
|
505
|
+
name="email"
|
|
506
|
+
rules={[
|
|
507
|
+
{ required: true, message: 'Enter an email' },
|
|
508
|
+
{ pattern: /^[^\s@]+@[^\s@]+\.[^\s@]+$/, message: 'Invalid email' },
|
|
509
|
+
]}
|
|
510
|
+
>
|
|
511
|
+
<Input placeholder="Email" />
|
|
512
|
+
</FormItem>
|
|
513
|
+
<FormItem x={20} y={90} name="role">
|
|
514
|
+
<Radio options={['Individual', 'Team']} />
|
|
515
|
+
</FormItem>
|
|
516
|
+
<Button x={20} y={140} text="Submit" formAction="submit" />
|
|
517
|
+
<Button x={160} y={140} text="Reset" formAction="reset" />
|
|
518
|
+
</Form>
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
`Form` and `FormItem` also support [Common Props](#common-props). Field value types depend on the control: `Checkbox` uses `string[]`, `Upload` uses `File[]`, `Switch` uses `boolean`, `Slider` uses `number`, and the other supported controls use `string`. The exported types include `FormValue`, `FormValues` (field names to values), and `FormErrors` (field names to error messages).
|
|
522
|
+
|
|
523
|
+
**Form props**
|
|
524
|
+
|
|
525
|
+
| Prop | Type | Required | Description |
|
|
526
|
+
| ---------------- | ------------------------------------------------- | -------- | ----------- |
|
|
527
|
+
| `children` | Child components | No | Form items, buttons, and layout components. |
|
|
528
|
+
| `initialValues` | `FormValues` | No | Initial values by field name; takes precedence over control initial values. |
|
|
529
|
+
| `controller` | `FormController` | No | Created by `createFormController()` to read or set fields. |
|
|
530
|
+
| `onSubmit` | `(values: FormValues) => void` | No | Called when submission passes validation. |
|
|
531
|
+
| `onInvalid` | `(errors: FormErrors, values: FormValues) => void` | No | Called when submission fails validation. |
|
|
532
|
+
| `onValuesChange` | `(values: FormValues) => void` | No | Called with all current field values when a field changes. |
|
|
533
|
+
| `onReset` | `() => void` | No | Called after a reset. |
|
|
534
|
+
|
|
535
|
+
**FormItem props**
|
|
536
|
+
|
|
537
|
+
| Prop | Type | Required | Default | Description |
|
|
538
|
+
| --------------- | ------------ | -------- | ----------- | ----------- |
|
|
539
|
+
| `children` | Child component | Yes | — | Must contain exactly one direct supported form control. |
|
|
540
|
+
| `name` | `string` | Yes | — | Nonempty field name, unique within the form. |
|
|
541
|
+
| `rules` | `FormRule[]` | No | `[]` | Validation rules evaluated in order. |
|
|
542
|
+
| `errorY` | `number` | No | control height + 4 | Error text's vertical position relative to the item; its horizontal position is `0`. |
|
|
543
|
+
| `errorColor` | `string` | No | `'#d93025'` | Error text color. |
|
|
544
|
+
| `errorFontSize` | `number` | No | `12` | Error text font size. |
|
|
545
|
+
|
|
546
|
+
**FormRule properties**
|
|
547
|
+
|
|
548
|
+
| Property | Type | Description |
|
|
549
|
+
| ----------- | ----------------------------------------------------------------------- | ----------- |
|
|
550
|
+
| `required` | `boolean` | When `true`, whitespace-only strings, empty arrays, and `false` fail validation; `0` is not empty. |
|
|
551
|
+
| `minLength` | `number` | Minimum length for nonempty strings or arrays. |
|
|
552
|
+
| `maxLength` | `number` | Maximum length for nonempty strings or arrays. |
|
|
553
|
+
| `pattern` | `RegExp` | Pattern that a nonempty string must match. |
|
|
554
|
+
| `validator` | `(value: FormValue, values: Readonly<FormValues>) => string \| undefined \| Promise<string \| undefined>` | Synchronous or asynchronous validation; return an error string to fail, or `undefined` or an empty string to pass. |
|
|
555
|
+
| `message` | `string` | Overrides the rule's default or custom validation error message. |
|
|
556
|
+
|
|
557
|
+
- `initialValues` supplies initial field values; otherwise the control's `value` / `defaultValue` (or `checked` / `defaultChecked` for Switch) or its default is used. Form owns these values, but the control's original `onChange` still fires.
|
|
558
|
+
- Rules run in order; validators may return a Promise, and rejections appear as `Validation failed: ...`. Required treats whitespace-only strings, empty arrays and `false` as empty. Length applies to strings and arrays; patterns apply to strings.
|
|
559
|
+
- Text inputs validate on blur, other controls when their keyboard focus leaves, and all fields on submit. After the first submit, edits revalidate the form. Submission waits for async validation; stale results after edits, reset or unmount are ignored. Errors default to 4 pixels below the control; reserve room for errors and upload lists or override `errorY`.
|
|
560
|
+
- `onValuesChange(values)` fires for field edits. A reset button restores the current `initialValues` / control defaults, clears errors and calls `onReset()`. Removed fields are omitted from submission.
|
|
561
|
+
- All four adapters export `Form`, `FormItem`, and their types. Angular uses `<canvas-form>` and `<canvas-form-item>` with `(formSubmit)`, `(formInvalid)`, `(valuesChange)`, and `(formReset)` events.
|
|
562
|
+
|
|
563
|
+
Create a controller with `createFormController()` from the framework entry point and pass it as `controller`. Once mounted, use `controller.getValues()`, `controller.getFieldValue('email')`, or `controller.setFieldValue('email', 'a@example.com')`. Setting a field fires `onValuesChange` and revalidates after a submit, but does not fire the control's `onChange`; arrays returned by the getters are copies. Unknown fields, invalid types, use while unmounted, and sharing a controller between mounted forms throw errors. Angular uses `[controller]`.
|
|
564
|
+
|
|
470
565
|
### `<Grid>`
|
|
471
566
|
|
|
472
567
|
Places children in order into fixed-size cells, wrapping to the next row once a row fills the specified column count. `Grid` does not draw a background; it is a layout container and can use transform props like `Group`.
|
|
@@ -479,6 +574,7 @@ Places children in order into fixed-size cells, wrapping to the next row once a
|
|
|
479
574
|
| `cellWidth` | `number` | No | — | Fixed logical cell width; takes precedence over `width` auto-distribution. Must be positive. |
|
|
480
575
|
| `cellHeight` | `number` | Yes | — | Logical cell height; must be positive. |
|
|
481
576
|
| `gap` | `number` | No | `0` | Equal row and column spacing; must not be negative. |
|
|
577
|
+
| `virtual` | `boolean` | No | `false` | Mount only items near the viewport; requires `height`. |
|
|
482
578
|
| `onScroll` | `(scrollTop: number) => void` | No | — | Scroll position change callback, in logical pixels. |
|
|
483
579
|
|
|
484
580
|
Direct children keep their own `x` and `y`, plus the offset of the cell they fall into. When `cellWidth` is not passed, columns are equal-width: `(width - gap * (columns - 1)) / columns`. A child's own size is not automatically stretched.
|
|
@@ -511,12 +607,31 @@ Once a Grid has a `height`, content beyond the visible area is scrollable via th
|
|
|
511
607
|
<Grid columns={1} width={280} height={180} cellHeight={44} gap={4}>
|
|
512
608
|
{items.map((item) => (
|
|
513
609
|
<GridItem key={item.id}>
|
|
514
|
-
<Text
|
|
610
|
+
<Text text={item.label} />
|
|
515
611
|
</GridItem>
|
|
516
612
|
))}
|
|
517
613
|
</Grid>
|
|
518
614
|
```
|
|
519
615
|
|
|
616
|
+
For large data sets, use `<Grid ... height={180} virtual>` (Angular: `[virtual]="true"`). Only items within the viewport and approximately one row above and below it are mounted; the window updates as you scroll, and row and column spans still affect layout. Offscreen items are unmounted, so store uncontrolled input and other state externally using controlled values and stable keys. Visibility is based on the cell area, not overflow caused by drawing, rotation, or scaling. Initial layout and framework child creation still process all supplied items.
|
|
617
|
+
|
|
618
|
+
Where possible, unchanged static virtual grids reuse their drawing when other components repaint. Scrolling, content changes, and theme changes invalidate it. Grids containing videos, images, `CustomDraw`, or `CanvasView` are drawn normally to keep dynamic content current. In React, memoize the whole Grid element with `useMemo` to avoid recreating and compiling its children when unrelated state changes; include the data and all values affecting the list in the dependency array:
|
|
619
|
+
|
|
620
|
+
```tsx
|
|
621
|
+
const grid = useMemo(
|
|
622
|
+
() => (
|
|
623
|
+
<Grid columns={1} width={280} height={180} cellHeight={44} virtual>
|
|
624
|
+
{items.map((item) => (
|
|
625
|
+
<GridItem key={item.id}>
|
|
626
|
+
<Text text={item.label} />
|
|
627
|
+
</GridItem>
|
|
628
|
+
))}
|
|
629
|
+
</Grid>
|
|
630
|
+
),
|
|
631
|
+
[items],
|
|
632
|
+
);
|
|
633
|
+
```
|
|
634
|
+
|
|
520
635
|
### `<GridItem>`
|
|
521
636
|
|
|
522
637
|
`GridItem` is a grouping/layout node inside a Grid and does not draw anything itself. It can contain multiple controls, positioning them together as one grid entry; children inside the group still use their own sizes and local coordinates. Placing ordinary controls directly under `Grid` also works — they each occupy one cell by default.
|
|
@@ -535,9 +650,7 @@ Grid places items row by row, skipping cells already occupied by spanning items:
|
|
|
535
650
|
<Grid columns={3} width={316} cellHeight={50} gap={8}>
|
|
536
651
|
<GridItem columnSpan={2}>
|
|
537
652
|
<Rect width={180} height={40} color="#f5f8fc" />
|
|
538
|
-
<Text x={8} y={8}
|
|
539
|
-
Group spanning two columns
|
|
540
|
-
</Text>
|
|
653
|
+
<Text x={8} y={8} text="Group spanning two columns" />
|
|
541
654
|
</GridItem>
|
|
542
655
|
<Rect width={80} height={40} color="#e5efff" />
|
|
543
656
|
</Grid>
|
|
@@ -547,6 +660,8 @@ Vue and Svelte use the same `<GridItem>`; Angular uses `<canvas-grid-item [colum
|
|
|
547
660
|
|
|
548
661
|
### `<Image>`
|
|
549
662
|
|
|
663
|
+
`Image`, `Text`, and `Icon` accept an optional `onClick: () => void`. Only nodes with a click listener participate in hit testing; the clickable area is the component's bounding box. Angular uses `(click)`; Vue uses `@click`; React and Svelte use `onClick`.
|
|
664
|
+
|
|
550
665
|
Loads an image from `src` and draws it into the Canvas at the specified size. `objectFit` supports `contain` (default), `cover`, `fill`, `none`, and `scale-down`; `onError(error)` fires on load failure. Angular uses the `(imageError)` event binding for the error callback.
|
|
551
666
|
|
|
552
667
|
| Prop | Type | Required | Default | Description |
|
|
@@ -555,6 +670,7 @@ Loads an image from `src` and draws it into the Canvas at the specified size. `o
|
|
|
555
670
|
| `width` / `height` | `number` | Yes | — | Canvas logical size. |
|
|
556
671
|
| `objectFit` | `"contain" \| "cover" \| "fill" \| "none" \| "scale-down"` | No | `"contain"` | Image scaling and cropping mode. |
|
|
557
672
|
| `onError` | `(error: Error) => void` | No | — | Fires when the image fails to load. |
|
|
673
|
+
| `onClick` | `() => void` | No | — | Click callback. |
|
|
558
674
|
|
|
559
675
|
```tsx
|
|
560
676
|
<Image x={16} y={16} src="/avatar.png" width={96} height={96} objectFit="cover" />
|
|
@@ -562,6 +678,53 @@ Loads an image from `src` and draws it into the Canvas at the specified size. `o
|
|
|
562
678
|
|
|
563
679
|
Remote images draw correctly, but browser CORS rules still apply to Canvas export: if the image server does not authorize cross-origin reads, a Canvas containing that image may fail to export as PNG.
|
|
564
680
|
|
|
681
|
+
### `<Video>`
|
|
682
|
+
|
|
683
|
+
Loads a video from `src` and paints its frames into the Canvas through the engine's render loop — no extra animation loop is created. Every `<Video>` node owns a dedicated `<video>` element: nodes sharing the same `src` can still be played, paused and seeked independently, and the element is released automatically when the node leaves the scene. `objectFit` supports the same modes as `<Image>`. Set `controls` to draw the built-in controls bar — a play/pause toggle, a seekable progress track and the time text — and to make the bar's regions pointer-interactive.
|
|
684
|
+
|
|
685
|
+
| Prop | Type | Required | Default | Description |
|
|
686
|
+
| -------------------- | ---------------------------------------------------------- | -------: | -------------------------- | ------------------------------------------------------------------------------------------- |
|
|
687
|
+
| `src` | `string` | Yes | — | Video URL. |
|
|
688
|
+
| `width` / `height` | `number` | No | Video's native | Canvas logical size; defaults to the video's intrinsic size. |
|
|
689
|
+
| `objectFit` | `"contain" \| "cover" \| "fill" \| "none" \| "scale-down"` | No | `"contain"` | Video scaling and cropping mode, identical to `<Image>`. |
|
|
690
|
+
| `autoplay` | `boolean` | No | `false` | Start playback automatically; browsers require `muted` for autoplay to succeed. |
|
|
691
|
+
| `loop` | `boolean` | No | `false` | Restart from the beginning when playback ends. |
|
|
692
|
+
| `muted` | `boolean` | No | `false` | Mute the audio track. |
|
|
693
|
+
| `paused` | `boolean` | No | — | Declarative play/pause: `false` plays, `true` pauses; omitted leaves control to `autoplay`. |
|
|
694
|
+
| `currentTime` | `number` | No | — | Seek target in seconds; set it once to jump, not on every frame. |
|
|
695
|
+
| `controls` | `boolean` | No | `false` | Show the built-in controls bar and accept pointer input on its toggle and track. |
|
|
696
|
+
| `controlsOnHover` | `boolean` | No | `false` | Show controls on hover; on touch devices, tap the video to show or hide them. |
|
|
697
|
+
| `controlsBarColor` | `string` | No | `"rgba(0,0,0,0.55)"` | Background of the controls bar. |
|
|
698
|
+
| `controlsColor` | `string` | No | `"#fff"` | Play/pause icon, played track, thumb and time text color. |
|
|
699
|
+
| `controlsTrackColor` | `string` | No | `"rgba(255,255,255,0.35)"` | Idle part of the seek track. |
|
|
700
|
+
| `onError` | `(error: Error) => void` | No | — | Fires when the video fails to load. |
|
|
701
|
+
| `onTimeUpdate` | `(currentTime: number, duration: number) => void` | No | — | Fires on playback progress, driven by the video's native `timeupdate` event. |
|
|
702
|
+
| `onPausedChange` | `(paused: boolean) => void` | No | — | Fires when the user toggles playback through the controls bar. |
|
|
703
|
+
| `onSeek` | `(currentTime: number) => void` | No | — | Fires when the user seeks through the controls bar (press or drag on the track). |
|
|
704
|
+
|
|
705
|
+
```tsx
|
|
706
|
+
<Video
|
|
707
|
+
x={16}
|
|
708
|
+
y={16}
|
|
709
|
+
src="/clip.mp4"
|
|
710
|
+
width={320}
|
|
711
|
+
height={180}
|
|
712
|
+
objectFit="cover"
|
|
713
|
+
muted
|
|
714
|
+
autoplay
|
|
715
|
+
loop
|
|
716
|
+
controls
|
|
717
|
+
controlsOnHover
|
|
718
|
+
onSeek={(currentTime) => console.log(currentTime)}
|
|
719
|
+
/>
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
During a seek, the previous frame stays visible until the target frame can be drawn. Seeking to unbuffered content may still require the browser to load data. When controlling `paused`, update its state in `onPausedChange` so the next update does not undo a controls-bar action.
|
|
723
|
+
|
|
724
|
+
The fullscreen button opens the current video in the browser's native fullscreen player. Native play, pause, and seek actions also trigger `onPausedChange` and `onSeek`. Native controls take precedence while fullscreen is active: `paused`, `autoplay`, and `currentTime` are not applied to the player until fullscreen exits. Fullscreen errors are reported through `onError`, or logged if no handler is provided.
|
|
725
|
+
|
|
726
|
+
Browser autoplay policies apply: without `muted`, playback only starts after a user gesture. Videos are first loaded with CORS; on failure, loading is retried without CORS, although the browser may still report the initial error in its console. A cross-origin video loaded without CORS can play, but drawing it taints the Canvas and prevents pixel reads and PNG export. For export, use a same-origin video or configure the video server to return an `Access-Control-Allow-Origin` header permitting the current site. Angular uses `<canvas-video>`, with `(videoError)`, `(timeUpdate)`, `(pausedChange)` and `(seek)` event bindings.
|
|
727
|
+
|
|
565
728
|
### `<Progress>`
|
|
566
729
|
|
|
567
730
|
Draws a non-interactive progress bar. `value` is clamped between `min` and `max`.
|
|
@@ -579,18 +742,20 @@ Draws a non-interactive progress bar. `value` is clamped between `min` and `max`
|
|
|
579
742
|
|
|
580
743
|
`Carousel` shows one `CarouselItem` at a time in child order, with optional autoplay, looping, prev/next arrows, and bottom indicator dots. Item content supports any Canvas UI component; when `activeIndex` is not passed explicitly, the carousel runs uncontrolled starting at index 0.
|
|
581
744
|
|
|
582
|
-
| Component | Prop
|
|
583
|
-
| -------------- |
|
|
584
|
-
| `Carousel` | `width` / `height`
|
|
585
|
-
| `Carousel` | `activeIndex`
|
|
586
|
-
| `Carousel` | `defaultActiveIndex`
|
|
587
|
-
| `Carousel` | `autoplay`
|
|
588
|
-
| `Carousel` | `interval`
|
|
589
|
-
| `Carousel` | `transitionDuration`
|
|
590
|
-
| `Carousel` | `loop`
|
|
591
|
-
| `Carousel` | `showArrows` / `showDots`
|
|
592
|
-
| `Carousel` | `
|
|
593
|
-
| `
|
|
745
|
+
| Component | Prop | Type | Default | Description |
|
|
746
|
+
| -------------- | -------------------------------------------- | ------------------------- | ----------------------------------------------------------- | --------------------------------------------------------------------------- |
|
|
747
|
+
| `Carousel` | `width` / `height` | `number` | Required | Viewport size; content overflowing the bounds is clipped. |
|
|
748
|
+
| `Carousel` | `activeIndex` | `number` | — | Controlled current index; combine with `onChange` to update. |
|
|
749
|
+
| `Carousel` | `defaultActiveIndex` | `number` | `0` | Uncontrolled initial index. |
|
|
750
|
+
| `Carousel` | `autoplay` | `boolean` | `true` | Whether to auto-advance; disabled when there are fewer than two items. |
|
|
751
|
+
| `Carousel` | `interval` | `number` | `3000` | Autoplay interval in ms; treated as a minimum of `250`. |
|
|
752
|
+
| `Carousel` | `transitionDuration` | `number` | `450` | Horizontal slide transition duration in ms; set `0` to switch instantly. |
|
|
753
|
+
| `Carousel` | `loop` | `boolean` | `true` | Whether to loop back to the first item at the end. |
|
|
754
|
+
| `Carousel` | `showArrows` / `showDots` | `boolean` | `true` | Whether to show the prev/next arrows and bottom indicator dots. |
|
|
755
|
+
| `Carousel` | `backgroundColor` | `string` | `"transparent"` | Viewport background color. |
|
|
756
|
+
| `Carousel` | `arrowColor` / `dotColor` / `activeDotColor` | `string` | theme / `"#fff"` / `"rgba(255,255,255,0.65)"` / `"#1677ff"` | Arrow, inactive dot and active dot colors; the listed colors are fallbacks. |
|
|
757
|
+
| `Carousel` | `onChange` | `(index: number) => void` | — | Fires when the active index changes. |
|
|
758
|
+
| `CarouselItem` | Children | Canvas UI components | — | Content shown for this slide. |
|
|
594
759
|
|
|
595
760
|
```tsx
|
|
596
761
|
<Carousel width={320} height={180} interval={4000} onChange={setActiveIndex}>
|
|
@@ -609,28 +774,25 @@ Angular uses `<canvas-carousel>` and `<canvas-carousel-item>`; controlled index
|
|
|
609
774
|
|
|
610
775
|
`Tabs` uses `TabItem` to declare tabs and their corresponding Canvas subtrees. The first `TabItem` is selected by default.
|
|
611
776
|
|
|
612
|
-
| Component | Prop | Type
|
|
613
|
-
| --------- | ------------------------------------------------------------------ |
|
|
614
|
-
| `Tabs` | `width` / `height` | `number`
|
|
615
|
-
| `Tabs` | `activeKey` / `defaultActiveKey` | `string`
|
|
616
|
-
| `Tabs` | `headerHeight` | `number`
|
|
617
|
-
| `Tabs` | `backgroundColor` / `textColor` / `activeColor` / `indicatorColor` | `string`
|
|
618
|
-
| `Tabs` | `onChange` | `(key: string) => void`
|
|
619
|
-
| `TabItem` | `id` / `title` | `string`
|
|
620
|
-
| `TabItem` | `disabled` | `boolean`
|
|
621
|
-
| `TabItem` |
|
|
777
|
+
| Component | Prop | Type | Description |
|
|
778
|
+
| --------- | ------------------------------------------------------------------ | ------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
779
|
+
| `Tabs` | `width` / `height` | `number` | Size of the tab container; required. Content is drawn below the header and clipped to the content area. |
|
|
780
|
+
| `Tabs` | `activeKey` / `defaultActiveKey` | `string` | Controlled selected key / uncontrolled initial key. |
|
|
781
|
+
| `Tabs` | `headerHeight` | `number` | Header bar height; default `40`. |
|
|
782
|
+
| `Tabs` | `backgroundColor` / `textColor` / `activeColor` / `indicatorColor` | `string` | Colors for the tab bar, text, active state, and indicator line. |
|
|
783
|
+
| `Tabs` | `onChange` | `(key: string) => void` | Fires when the selected tab changes. |
|
|
784
|
+
| `TabItem` | `id` / `title` | `string` | Unique identifier and label; required. |
|
|
785
|
+
| `TabItem` | `disabled` | `boolean` | Disables clicking on this tab. |
|
|
786
|
+
| `TabItem` | `size` | `{ width?: number; height?: number }` | Optional in the public type; currently does not determine the header or content area size. |
|
|
787
|
+
| `TabItem` | Children | Canvas UI components | Canvas content for this tab. |
|
|
622
788
|
|
|
623
789
|
```tsx
|
|
624
790
|
<Tabs width={320} height={180} defaultActiveKey="profile">
|
|
625
791
|
<TabItem id="profile" title="Profile">
|
|
626
|
-
<Text x={12} y={12}
|
|
627
|
-
Profile content
|
|
628
|
-
</Text>
|
|
792
|
+
<Text x={12} y={12} text="Profile content" />
|
|
629
793
|
</TabItem>
|
|
630
794
|
<TabItem id="settings" title="Settings">
|
|
631
|
-
<Text x={12} y={12}
|
|
632
|
-
Settings content
|
|
633
|
-
</Text>
|
|
795
|
+
<Text x={12} y={12} text="Settings content" />
|
|
634
796
|
</TabItem>
|
|
635
797
|
</Tabs>
|
|
636
798
|
```
|
|
@@ -657,14 +819,10 @@ Each `CollapseItem` header toggles its panel; children serve as panel content.
|
|
|
657
819
|
```tsx
|
|
658
820
|
<Collapse width={320} defaultActiveKeys={['details']} accordion>
|
|
659
821
|
<CollapseItem id="details" title="Details" height={72}>
|
|
660
|
-
<Text x={12} y={8}
|
|
661
|
-
Panel content
|
|
662
|
-
</Text>
|
|
822
|
+
<Text x={12} y={8} text="Panel content" />
|
|
663
823
|
</CollapseItem>
|
|
664
824
|
<CollapseItem id="more" title="More">
|
|
665
|
-
<Text x={12} y={8}
|
|
666
|
-
Another panel
|
|
667
|
-
</Text>
|
|
825
|
+
<Text x={12} y={8} text="Another panel" />
|
|
668
826
|
</CollapseItem>
|
|
669
827
|
</Collapse>
|
|
670
828
|
```
|
|
@@ -673,7 +831,7 @@ Angular counterparts are `<canvas-collapse>` and `<canvas-collapse-item>`; expan
|
|
|
673
831
|
|
|
674
832
|
### `<Dialog>`
|
|
675
833
|
|
|
676
|
-
The confirmation dialog overlays the Canvas centered by default, painting a mask, title, content area, and built-in Cancel/Confirm buttons.
|
|
834
|
+
The confirmation dialog overlays the Canvas centered by default, painting a mask, title, content area, and built-in Cancel/Confirm buttons. Only inputs in the topmost dialog are editable while it is open; background inputs are blocked and dialog inputs are clipped to the content area. Focus cycles within the dialog, Escape invokes `onCancel`, and closing restores the previous focus. The mask and focus restriction apply to this Canvas; applications must manage page content outside it.
|
|
677
835
|
|
|
678
836
|
| Prop | Type | Default | Description |
|
|
679
837
|
| ---------------------------- | -------------------- | ------------------: | -------------------------------------------------------- |
|
|
@@ -695,7 +853,7 @@ The confirmation dialog overlays the Canvas centered by default, painting a mask
|
|
|
695
853
|
}}
|
|
696
854
|
onCancel={() => setOpen(false)}
|
|
697
855
|
>
|
|
698
|
-
<Text width={340}
|
|
856
|
+
<Text width={340} text="This action cannot be undone." />
|
|
699
857
|
</Dialog>
|
|
700
858
|
```
|
|
701
859
|
|
|
@@ -705,53 +863,54 @@ Angular uses `<canvas-dialog>`, with the `open` input and `(confirm)` / `(cancel
|
|
|
705
863
|
|
|
706
864
|
Draws a rectangle. Supports [Common Props](#common-props).
|
|
707
865
|
|
|
708
|
-
| Prop | Type |
|
|
709
|
-
| ------------- | -------- |
|
|
710
|
-
| `width` | `number` |
|
|
711
|
-
| `height` | `number` |
|
|
712
|
-
| `color` | `string` | `"transparent"` | Fill color. |
|
|
713
|
-
| `radius` | `number` |
|
|
714
|
-
| `stroke` | `string` |
|
|
715
|
-
| `strokeWidth` | `number` |
|
|
866
|
+
| Prop | Type | Default | Description |
|
|
867
|
+
| ------------- | -------- | ----------------------: | -------------------------------------- |
|
|
868
|
+
| `width` | `number` | `100` | Width. |
|
|
869
|
+
| `height` | `number` | `40` | Height. |
|
|
870
|
+
| `color` | `string` | theme / `"transparent"` | Fill color. |
|
|
871
|
+
| `radius` | `number` | `0` | Corner radius. |
|
|
872
|
+
| `stroke` | `string` | — | Stroke color; omitted means no stroke. |
|
|
873
|
+
| `strokeWidth` | `number` | `1` | Stroke width. |
|
|
716
874
|
|
|
717
875
|
### `<Circle>`
|
|
718
876
|
|
|
719
877
|
Draws a circle. Supports [Common Props](#common-props).
|
|
720
878
|
|
|
721
|
-
| Prop | Type |
|
|
722
|
-
| ------------- | -------- |
|
|
723
|
-
| `radius` | `number` |
|
|
724
|
-
| `color` | `string` | `"#e74c3c"` | Fill color. |
|
|
725
|
-
| `stroke` | `string` |
|
|
726
|
-
| `strokeWidth` | `number` |
|
|
879
|
+
| Prop | Type | Default | Description |
|
|
880
|
+
| ------------- | -------- | ------------------: | -------------------------------------- |
|
|
881
|
+
| `radius` | `number` | `10` | Circle radius. |
|
|
882
|
+
| `color` | `string` | theme / `"#e74c3c"` | Fill color. |
|
|
883
|
+
| `stroke` | `string` | — | Stroke color; omitted means no stroke. |
|
|
884
|
+
| `strokeWidth` | `number` | `1` | Stroke width. |
|
|
727
885
|
|
|
728
886
|
### `<Text>`
|
|
729
887
|
|
|
730
|
-
Draws single-line or auto-wrapped text. The node reports the box its rendered lines actually need, so containers such as `<CollapseItem>` can size themselves to it. Supports [Common Props](#common-props).
|
|
888
|
+
Draws single-line or auto-wrapped text. Pass content through `text`; `<Text>` does not accept children. Other non-container components also reject child components; `<Button>` accepts plain text children only. The node reports the box its rendered lines actually need, so containers such as `<CollapseItem>` can size themselves to it. Supports [Common Props](#common-props).
|
|
731
889
|
|
|
732
|
-
| Prop | Type
|
|
733
|
-
| ------------ |
|
|
734
|
-
| `text` | `string`
|
|
735
|
-
|
|
|
736
|
-
| `
|
|
737
|
-
| `
|
|
738
|
-
| `
|
|
739
|
-
| `
|
|
740
|
-
| `
|
|
741
|
-
| `
|
|
742
|
-
| `
|
|
890
|
+
| Prop | Type | Default | Description |
|
|
891
|
+
| ------------ | -------------------- | ---------------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
892
|
+
| `text` | `string` | — | Text content. |
|
|
893
|
+
| `fontSize` | `number` | `16` | Font size, in logical pixels. |
|
|
894
|
+
| `width` | `number` | — | Max line width; content wraps beyond it. Monospaced CJK characters also wrap based on measured width. Inside a `<Grid>`, defaults to the cell's width. |
|
|
895
|
+
| `maxLines` | `number` | — | Maximum lines to show; the last visible line is cut with an ellipsis. Inside a `<Grid>`, defaults to the lines that fit the cell; unlimited when neither is set. |
|
|
896
|
+
| `fontFamily` | `string` | `"sans-serif"` | Font family. |
|
|
897
|
+
| `color` | `string` | theme / `"#333"` | Font color. |
|
|
898
|
+
| `baseline` | `CanvasTextBaseline` | `"top"` | Canvas text baseline. |
|
|
899
|
+
| `textAlign` | `CanvasTextAlign` | `"left"` | Horizontal alignment within the text box; only `center` and `right` are special, other values render as `left`. |
|
|
900
|
+
| `onClick` | `() => void` | — | Click callback. |
|
|
743
901
|
|
|
744
902
|
### `<Icon>`
|
|
745
903
|
|
|
746
904
|
Original vector icons with no dependency on icon fonts or external images. Supports [Common Props](#common-props).
|
|
747
905
|
|
|
748
|
-
| Prop | Type |
|
|
749
|
-
| ------------- | ---------------------- |
|
|
750
|
-
| `name` | `IconName` |
|
|
751
|
-
| `size` | `number` |
|
|
752
|
-
| `color` | `string` |
|
|
753
|
-
| `variant` | `"outline" \| "solid"` |
|
|
754
|
-
| `strokeWidth` | `number` |
|
|
906
|
+
| Prop | Type | Default | Description |
|
|
907
|
+
| ------------- | ---------------------- | ---------------: | ---------------------------------------------------------------------------------------- |
|
|
908
|
+
| `name` | `IconName` | Required | Icon name; see the list below. |
|
|
909
|
+
| `size` | `number` | `24` | Icon width and height. |
|
|
910
|
+
| `color` | `string` | theme / `"#333"` | Icon color; can be set via `--canvas-ui-icon-color`. |
|
|
911
|
+
| `variant` | `"outline" \| "solid"` | `"outline"` | `outline` for stroked shapes; `solid` uses thicker strokes and fills the primary shapes. |
|
|
912
|
+
| `strokeWidth` | `number` | `2` | Outline stroke width; solid style uses at least `4`. |
|
|
913
|
+
| `onClick` | `() => void` | — | Click callback. |
|
|
755
914
|
|
|
756
915
|
Supported: `home`, `house`, `building`, `apartment`, `store`, `mapPin`, `map`, `globe`, `compass`, `navigation`, `flag`, `mountain`, `tree`, `leaf`, `flower`, `sun`, `moon`, `cloud`, `rain`, `snow`, `fire`, `water`, `wind`, `car`, `bus`, `train`, `plane`, `bicycle`, `ship`, `rocket`, `truck`, `walk`, `phone`, `message`, `mail`, `bell`, `calendar`, `clock`, `alarm`, `camera`, `image`, `video`, `music`, `microphone`, `headphones`, `play`, `pause`, `stop`, `record`, `volume`, `wifi`, `bluetooth`, `battery`, `signal`, `power`, `monitor`, `laptop`, `tablet`, `keyboard`, `mouse`, `printer`, `folder`, `file`, `document`, `download`, `upload`, `share`, `link`, `search`, `settings`, `sliders`, `menu`, `close`, `check`, `plus`, `minus`, `edit`, `trash`, `copy`, `save`, `lock`, `unlock`, `key`, `user`, `users`, `heart`, `star`, `bookmark`, `cart`, `bag`, `gift`, `creditCard`, `wallet`, `chart`, `pieChart`, `barChart`, `analytics`, `shield`, `warning`, `info`, `help`, `question`, `tag`, `puzzle`, `code`, `database`, and `cloudDownload`.
|
|
757
916
|
|
|
@@ -764,26 +923,26 @@ Supported: `home`, `house`, `building`, `apartment`, `store`, `mapPin`, `map`, `
|
|
|
764
923
|
|
|
765
924
|
Single-line input. The control's appearance is painted onto the Canvas; a transparent HTML input handles keyboard, IME, and selection.
|
|
766
925
|
|
|
767
|
-
| Prop | Type |
|
|
768
|
-
| ------------------ | ---------------------------------- |
|
|
769
|
-
| `width` / `height` | `number` |
|
|
770
|
-
| `value` | `string` |
|
|
771
|
-
| `defaultValue` | `string` |
|
|
772
|
-
| `placeholder` | `string` |
|
|
773
|
-
| `type` | `"text" \| "password" \| "number"` |
|
|
774
|
-
| `fontSize` | `number` |
|
|
775
|
-
| `fontFamily` | `string` |
|
|
776
|
-
| `color` | `string` |
|
|
777
|
-
| `bgColor` | `string` |
|
|
778
|
-
| `borderColor` | `string` |
|
|
779
|
-
| `focusBorderColor` | `string` |
|
|
780
|
-
| `borderRadius` | `number` |
|
|
781
|
-
| `padding` | `number` |
|
|
782
|
-
| `disabled` | `boolean` |
|
|
783
|
-
| `maxLength` | `number` |
|
|
784
|
-
| `onChange` | `(value: string) => void` |
|
|
785
|
-
| `onFocus` | `() => void` |
|
|
786
|
-
| `onBlur` | `() => void` |
|
|
926
|
+
| Prop | Type | Default | Description |
|
|
927
|
+
| ------------------ | ---------------------------------- | ------------------: | ------------------------------------------------------------ |
|
|
928
|
+
| `width` / `height` | `number` | `200` / `36` | Control size. |
|
|
929
|
+
| `value` | `string` | — | Controlled input value; pair with `onChange` to update. |
|
|
930
|
+
| `defaultValue` | `string` | `""` | Uncontrolled initial value. |
|
|
931
|
+
| `placeholder` | `string` | `""` | Placeholder text. |
|
|
932
|
+
| `type` | `"text" \| "password" \| "number"` | `"text"` | Input type. Password content is shown as dots on the Canvas. |
|
|
933
|
+
| `fontSize` | `number` | `14` | Font size. |
|
|
934
|
+
| `fontFamily` | `string` | `"sans-serif"` | Font family. |
|
|
935
|
+
| `color` | `string` | theme / `"#333"` | Input text color. |
|
|
936
|
+
| `bgColor` | `string` | theme / `"#fff"` | Background color. |
|
|
937
|
+
| `borderColor` | `string` | theme / `"#d9d9d9"` | Normal border color. |
|
|
938
|
+
| `focusBorderColor` | `string` | theme / `"#1677ff"` | Focused border color. |
|
|
939
|
+
| `borderRadius` | `number` | `4` | Corner radius. |
|
|
940
|
+
| `padding` | `number` | `8` | Text padding. |
|
|
941
|
+
| `disabled` | `boolean` | `false` | Disables input. |
|
|
942
|
+
| `maxLength` | `number` | — | Max character count; a non-negative integer takes effect. |
|
|
943
|
+
| `onChange` | `(value: string) => void` | — | Fires when the input changes. |
|
|
944
|
+
| `onFocus` | `() => void` | — | Fires when focused. |
|
|
945
|
+
| `onBlur` | `() => void` | — | Fires when blurred. |
|
|
787
946
|
|
|
788
947
|
### `<Textarea>`
|
|
789
948
|
|
|
@@ -805,45 +964,53 @@ Multi-line text input; inherits value, size, style, and callback props from `<In
|
|
|
805
964
|
|
|
806
965
|
### `<Upload>`
|
|
807
966
|
|
|
808
|
-
Draws a file-picker button. A built-in vector icon and the label are drawn together as one horizontally centered group. Clicking opens the browser's native file picker; this component does not upload to a server.
|
|
809
|
-
|
|
810
|
-
| Prop | Type |
|
|
811
|
-
| ------------------ | ------------------------- |
|
|
812
|
-
| `width` / `height` | `number` |
|
|
813
|
-
| `text` | `string` |
|
|
814
|
-
| `icon` | `IconName` |
|
|
815
|
-
| `iconSize` | `number` | `fontSize × 1.1` | Icon size. |
|
|
816
|
-
| `accept` | `string` |
|
|
817
|
-
| `multiple` | `boolean` |
|
|
818
|
-
| `
|
|
819
|
-
| `
|
|
967
|
+
Draws a file-picker button. A built-in vector icon and the label are drawn together as one horizontally centered group. Clicking opens the browser's native file picker; this component does not upload to a server. Supports [Common Props](#common-props).
|
|
968
|
+
|
|
969
|
+
| Prop | Type | Default | Description |
|
|
970
|
+
| ------------------ | ------------------------- | ----------------------: | -------------------------------------------------------------------------- |
|
|
971
|
+
| `width` / `height` | `number` | `120` / `40` | Button size. |
|
|
972
|
+
| `text` | `string` | `"Choose File"` | Button label. |
|
|
973
|
+
| `icon` | `IconName` | `"upload"` | Built-in icon drawn before the label; use any name from [`<Icon>`](#icon). |
|
|
974
|
+
| `iconSize` | `number` | `round(fontSize × 1.1)` | Icon size. |
|
|
975
|
+
| `accept` | `string` | — | File type filter, e.g. `"image/*,.pdf"`. |
|
|
976
|
+
| `multiple` | `boolean` | `false` | Allow multi-selection. |
|
|
977
|
+
| `value` / `defaultValue` | `File[]` | `[]` | Controlled file list / uncontrolled initial list. |
|
|
978
|
+
| `maxSize` | `number` | — | Maximum size per file, in bytes. |
|
|
979
|
+
| `disabled` | `boolean` | `false` | Disables file selection. |
|
|
980
|
+
| `backgroundColor` | `string` | theme / `"#1677ff"` | Button background color. |
|
|
981
|
+
| `textColor` | `string` | theme / `"#fff"` | Label and icon color. |
|
|
982
|
+
| `borderColor` | `string` | — | Border color; omitted means no border. |
|
|
983
|
+
| `borderRadius` | `number` | `6` | Corner radius. |
|
|
984
|
+
| `fontSize` | `number` | `15` | Label font size. |
|
|
985
|
+
| `onChange` | `(files: File[]) => void` | — | Receives the complete list after selection or removal; canceled picks do not fire. |
|
|
986
|
+
| `onReject` | `(files: UploadRejection[]) => void` | — | Rejected files and their reasons (`type` or `size`). |
|
|
820
987
|
|
|
821
988
|
```tsx
|
|
822
989
|
<Upload accept="image/*" multiple onChange={(files) => console.log(files)} />
|
|
823
990
|
<Upload icon="cloud" text="Upload Photos" />
|
|
824
991
|
```
|
|
825
992
|
|
|
826
|
-
Angular uses `<canvas-upload
|
|
993
|
+
Files and removal buttons appear below the picker. Single selection replaces the file; multiple selection appends. `accept` and `maxSize` are checked locally; validate files on the server too. Angular uses `<canvas-upload>`, `(change)` and `(reject)`.
|
|
827
994
|
|
|
828
995
|
### `<Dropdown>`
|
|
829
996
|
|
|
830
997
|
Canvas-drawn dropdown select. Supports [Common Props](#common-props).
|
|
831
998
|
|
|
832
|
-
| Prop | Type |
|
|
833
|
-
| ------------------ | --------------------------------- |
|
|
834
|
-
| `width` / `height` | `number` |
|
|
835
|
-
| `options` | `Array<string \| DropdownOption>` |
|
|
836
|
-
| `value` | `string` |
|
|
837
|
-
| `defaultValue` | `string` |
|
|
838
|
-
| `placeholder` | `string` |
|
|
839
|
-
| `disabled` | `boolean` |
|
|
840
|
-
| `fontSize` | `number` |
|
|
841
|
-
| `color` | `string` |
|
|
842
|
-
| `bgColor` | `string` |
|
|
843
|
-
| `borderColor` | `string` |
|
|
844
|
-
| `focusBorderColor` | `string` |
|
|
845
|
-
| `borderRadius` | `number` |
|
|
846
|
-
| `onChange` | `(value: string) => void` |
|
|
999
|
+
| Prop | Type | Default | Description |
|
|
1000
|
+
| ------------------ | --------------------------------- | ------------------: | ------------------------------------------------------------------- |
|
|
1001
|
+
| `width` / `height` | `number` | `200` / `36` | Control size. |
|
|
1002
|
+
| `options` | `Array<string \| DropdownOption>` | Required | Option list; string options use the same value for label and value. |
|
|
1003
|
+
| `value` | `string` | — | Controlled selected value. |
|
|
1004
|
+
| `defaultValue` | `string` | — | Uncontrolled initial value. |
|
|
1005
|
+
| `placeholder` | `string` | `"Select..."` | Text shown when nothing is selected. |
|
|
1006
|
+
| `disabled` | `boolean` | `false` | Disables interaction. |
|
|
1007
|
+
| `fontSize` | `number` | `14` | Font size. |
|
|
1008
|
+
| `color` | `string` | theme / `"#333"` | Text color; the arrow fallback is `"#555"`. |
|
|
1009
|
+
| `bgColor` | `string` | theme / `"#fff"` | Control background. |
|
|
1010
|
+
| `borderColor` | `string` | theme / `"#d9d9d9"` | Normal border color. |
|
|
1011
|
+
| `focusBorderColor` | `string` | theme / `"#1677ff"` | Opened border color. |
|
|
1012
|
+
| `borderRadius` | `number` | `4` | Corner radius. |
|
|
1013
|
+
| `onChange` | `(value: string) => void` | — | Selection change callback. |
|
|
847
1014
|
|
|
848
1015
|
`DropdownOption` type:
|
|
849
1016
|
|
|
@@ -865,27 +1032,38 @@ Canvas-drawn dropdown select. Supports [Common Props](#common-props).
|
|
|
865
1032
|
|
|
866
1033
|
Canvas-drawn date input; clicking opens the browser's native date picker.
|
|
867
1034
|
|
|
868
|
-
| Prop
|
|
869
|
-
|
|
|
870
|
-
| `width` / `height`
|
|
871
|
-
| `value`
|
|
872
|
-
| `defaultValue`
|
|
873
|
-
| `placeholder`
|
|
874
|
-
| `disabled`
|
|
875
|
-
| `
|
|
1035
|
+
| Prop | Type | Default | Description |
|
|
1036
|
+
| ---------------------------------- | ------------------------- | --------------------------------: | -------------------------------------------------------------- |
|
|
1037
|
+
| `width` / `height` | `number` | `200` / `36` | Control size. |
|
|
1038
|
+
| `value` | `string` | — | Controlled date value, format `YYYY-MM-DD`. |
|
|
1039
|
+
| `defaultValue` | `string` | `""` | Uncontrolled initial date value. |
|
|
1040
|
+
| `placeholder` | `string` | `"Select date"` | Text shown when nothing is selected. |
|
|
1041
|
+
| `disabled` | `boolean` | `false` | Disables date selection. |
|
|
1042
|
+
| `fontSize` | `number` | `14` | Text font size. |
|
|
1043
|
+
| `color` | `string` | theme / `"#333"` | Date text color; icon fallback is `"#666"`. |
|
|
1044
|
+
| `bgColor` | `string` | theme / `"#fff"` | Background color. |
|
|
1045
|
+
| `borderColor` / `focusBorderColor` | `string` | theme / `"#d9d9d9"` / `"#1677ff"` | Normal and focused border colors; listed colors are fallbacks. |
|
|
1046
|
+
| `borderRadius` | `number` | `4` | Corner radius. |
|
|
1047
|
+
| `onChange` | `(value: string) => void` | — | Fires when the date changes. |
|
|
1048
|
+
| `onFocus` / `onBlur` | `() => void` | — | Called when focus is gained / lost. |
|
|
876
1049
|
|
|
877
1050
|
### `<Radio>` and `<Checkbox>`
|
|
878
1051
|
|
|
879
1052
|
Both accept an `options` array; Radio is single-select and Checkbox is multi-select. String options use the same value for label and value; you may also pass `{ label, value, disabled }` objects.
|
|
880
1053
|
|
|
881
|
-
| Prop
|
|
882
|
-
|
|
|
883
|
-
| `options`
|
|
884
|
-
| `value`
|
|
885
|
-
| `defaultValue`
|
|
886
|
-
| `direction`
|
|
887
|
-
| `width` / `height`
|
|
888
|
-
| `
|
|
1054
|
+
| Prop | Type | Default | Description |
|
|
1055
|
+
| --------------------------------------------------------- | ----------------------------------------------------------------------- | ---------------------------------------------------------: | -------------------------------------------------------------------------------- |
|
|
1056
|
+
| `options` | `Array<string \| ChoiceOption>` | Required | Option list. |
|
|
1057
|
+
| `value` | Radio: `string`; Checkbox: `string[]` | — | Controlled selected value. |
|
|
1058
|
+
| `defaultValue` | Radio: `string`; Checkbox: `string[]` | — | Uncontrolled initial value. |
|
|
1059
|
+
| `direction` | `"horizontal" \| "vertical"` | `"horizontal"` | Option layout direction. |
|
|
1060
|
+
| `width` / `height` | `number` | Auto | Control size. |
|
|
1061
|
+
| `size` | `{ width?: number; height?: number }` | — | Each dimension takes precedence over `width` / `height`. |
|
|
1062
|
+
| `disabled` | `boolean` | `false` | Disables the whole group. |
|
|
1063
|
+
| `gap` / `optionHeight` | `number` | `12` / `28` | Spacing between options and option height. |
|
|
1064
|
+
| `fontSize` | `number` | `14` | Option label font size. |
|
|
1065
|
+
| `color` / `activeColor` / `disabledColor` / `borderColor` | `string` | theme / `"#333"` / `"#1677ff"` / `"#bfbfbf"` / `"#d9d9d9"` | Label, selected, disabled option and border colors; listed colors are fallbacks. |
|
|
1066
|
+
| `onChange` | Radio: `(value: string) => void`; Checkbox: `(value: string[]) => void` | — | Fires when the selection changes. |
|
|
889
1067
|
|
|
890
1068
|
```tsx
|
|
891
1069
|
<Radio options={['Small', 'Medium', 'Large']} value={size} onChange={setSize} />
|
|
@@ -898,50 +1076,50 @@ Angular uses `<canvas-date-picker>`, `<canvas-radio>`, and `<canvas-checkbox>`;
|
|
|
898
1076
|
|
|
899
1077
|
Draggable slider. Supports [Common Props](#common-props).
|
|
900
1078
|
|
|
901
|
-
| Prop | Type |
|
|
902
|
-
| ------------------ | ------------------------- |
|
|
903
|
-
| `width` / `height` | `number` |
|
|
904
|
-
| `min` / `max` | `number` |
|
|
905
|
-
| `step` | `number` |
|
|
906
|
-
| `value` | `number` |
|
|
907
|
-
| `defaultValue` | `number` |
|
|
908
|
-
| `disabled` | `boolean` |
|
|
909
|
-
| `trackColor` | `string` |
|
|
910
|
-
| `activeColor` | `string` |
|
|
911
|
-
| `thumbColor` | `string` |
|
|
912
|
-
| `onChange` | `(value: number) => void` |
|
|
1079
|
+
| Prop | Type | Default | Description |
|
|
1080
|
+
| ------------------ | ------------------------- | ------------------: | ------------------------------ |
|
|
1081
|
+
| `width` / `height` | `number` | `160` / `32` | Slider size. |
|
|
1082
|
+
| `min` / `max` | `number` | `0` / `100` | Min and max values. |
|
|
1083
|
+
| `step` | `number` | `1` | Step size. |
|
|
1084
|
+
| `value` | `number` | — | Controlled value. |
|
|
1085
|
+
| `defaultValue` | `number` | `min` | Uncontrolled initial value. |
|
|
1086
|
+
| `disabled` | `boolean` | `false` | Disables dragging. |
|
|
1087
|
+
| `trackColor` | `string` | theme / `"#f0f0f0"` | Track color. |
|
|
1088
|
+
| `activeColor` | `string` | theme / `"#1677ff"` | Filled track and border color. |
|
|
1089
|
+
| `thumbColor` | `string` | theme / `"#fff"` | Thumb color. |
|
|
1090
|
+
| `onChange` | `(value: number) => void` | — | Fires when the value changes. |
|
|
913
1091
|
|
|
914
1092
|
### `<Switch>`
|
|
915
1093
|
|
|
916
1094
|
Toggle switch. Supports [Common Props](#common-props).
|
|
917
1095
|
|
|
918
|
-
| Prop | Type |
|
|
919
|
-
| ------------------ | ---------------------------- |
|
|
920
|
-
| `width` / `height` | `number` |
|
|
921
|
-
| `checked` | `boolean` |
|
|
922
|
-
| `defaultChecked` | `boolean` |
|
|
923
|
-
| `disabled` | `boolean` |
|
|
924
|
-
| `onColor` | `string` | `"#
|
|
925
|
-
| `offColor` | `string` | `"#
|
|
926
|
-
| `thumbColor` | `string` | `"#fff"` | Thumb color. |
|
|
927
|
-
| `onChange` | `(checked: boolean) => void` |
|
|
1096
|
+
| Prop | Type | Default | Description |
|
|
1097
|
+
| ------------------ | ---------------------------- | ------------------: | ----------------------------- |
|
|
1098
|
+
| `width` / `height` | `number` | `44` / `24` | Switch size. |
|
|
1099
|
+
| `checked` | `boolean` | — | Controlled checked state. |
|
|
1100
|
+
| `defaultChecked` | `boolean` | `false` | Uncontrolled initial state. |
|
|
1101
|
+
| `disabled` | `boolean` | `false` | Blocks toggling. |
|
|
1102
|
+
| `onColor` | `string` | theme / `"#1677ff"` | Track color when on. |
|
|
1103
|
+
| `offColor` | `string` | theme / `"#d9d9d9"` | Track color when off. |
|
|
1104
|
+
| `thumbColor` | `string` | theme / `"#fff"` | Thumb color. |
|
|
1105
|
+
| `onChange` | `(checked: boolean) => void` | — | Fires when the state changes. |
|
|
928
1106
|
|
|
929
1107
|
### `<Button>`
|
|
930
1108
|
|
|
931
1109
|
Canvas-drawn button. Supports [Common Props](#common-props).
|
|
932
1110
|
|
|
933
|
-
| Prop | Type |
|
|
934
|
-
| ------------------ | ------------------ |
|
|
935
|
-
| `width` / `height` | `number` |
|
|
936
|
-
| Children | `string \| number` |
|
|
937
|
-
| `text` | `string` |
|
|
938
|
-
| `fontSize` | `number` |
|
|
939
|
-
| `fontColor` | `string` |
|
|
940
|
-
| `backgroundColor` | `string` |
|
|
941
|
-
| `borderColor` | `string` |
|
|
942
|
-
| `borderRadius` | `number` |
|
|
943
|
-
| `disabled` | `boolean` |
|
|
944
|
-
| `onClick` | `() => void` |
|
|
1111
|
+
| Prop | Type | Default | Description |
|
|
1112
|
+
| ------------------ | ------------------ | ------------------: | ---------------------------------------------------------- |
|
|
1113
|
+
| `width` / `height` | `number` | `120` / `40` | Button size. |
|
|
1114
|
+
| Children | `string \| number` | — | Button label; can be replaced by `text`. |
|
|
1115
|
+
| `text` | `string` | — | Button label; wins over `children` when both are provided. |
|
|
1116
|
+
| `fontSize` | `number` | `15` | Font size. |
|
|
1117
|
+
| `fontColor` | `string` | theme / `"#fff"` | Text color. |
|
|
1118
|
+
| `backgroundColor` | `string` | theme / `"#1677ff"` | Background color. |
|
|
1119
|
+
| `borderColor` | `string` | — | Stroke color. |
|
|
1120
|
+
| `borderRadius` | `number` | `6` | Corner radius. |
|
|
1121
|
+
| `disabled` | `boolean` | `false` | Disables the button. |
|
|
1122
|
+
| `onClick` | `() => void` | — | Click callback. |
|
|
945
1123
|
|
|
946
1124
|
## Image Export
|
|
947
1125
|
|
|
@@ -987,3 +1165,35 @@ const jpegBlob = await canvasRef.current?.toBlob('image/jpeg', 0.9);
|
|
|
987
1165
|
```
|
|
988
1166
|
|
|
989
1167
|
Export size and pixel ratio must be positive numbers. If the scene contains a cross-origin image without server-side CORS authorization, `toDataURL()` throws an error explaining the reason and `toBlob()` rejects with the same error. Configure the image server to return an `Access-Control-Allow-Origin` header that permits the current site, or remove the image before exporting.
|
|
1168
|
+
|
|
1169
|
+
## File Structure
|
|
1170
|
+
|
|
1171
|
+
Paths below are relative to `src/canvas-ui/`.
|
|
1172
|
+
|
|
1173
|
+
| File | Purpose |
|
|
1174
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
1175
|
+
| `react/` | React components and Canvas container adapter. |
|
|
1176
|
+
| `vue/` | Vue 3 components and Canvas container adapter. |
|
|
1177
|
+
| `svelte/` | Svelte 5+ adapter and template components. |
|
|
1178
|
+
| `angular/` | Angular standalone Canvas component and scene directives. |
|
|
1179
|
+
| `components/` | Shared implementations, each with its own directory, entry, Props and drawing code, and optional interaction logic. |
|
|
1180
|
+
| `components/types.ts` | Aggregates public component Props types. |
|
|
1181
|
+
| `theme.css` | Light and dark CSS theme variables for Canvas components. |
|
|
1182
|
+
| `types.ts` | Component Props, scene, Canvas, and input-bridge types. |
|
|
1183
|
+
| `renderer.ts` | Drawing registration, scene traversal, and Canvas rendering. |
|
|
1184
|
+
| `scene.ts` | Scene nodes and child reconciliation. |
|
|
1185
|
+
| `input-bridge.ts` | Transparent HTML input bridge for Input and Textarea. |
|
|
1186
|
+
| `engine.ts` | Orchestrates scene updates, rendering, input, and interaction. |
|
|
1187
|
+
| `engine/transform.ts` | Pure matrix math. |
|
|
1188
|
+
| `engine/interaction.ts` | Pointer and wheel interactions and state changes. |
|
|
1189
|
+
| `engine/layout.ts` | Declarative tree preparation and layout. |
|
|
1190
|
+
| `engine/carousel.ts` | Carousel state and animation timing. |
|
|
1191
|
+
| `engine/images.ts` | Image subscription lifecycle. |
|
|
1192
|
+
| `engine/text-controls.ts` | DOM input bridge synchronization. |
|
|
1193
|
+
| `engine/events.ts` | Public and CanvasView event dispatch. |
|
|
1194
|
+
| `engine/hit-test.ts` | Coordinate resolution and hit testing. |
|
|
1195
|
+
| `engine/vnodes.ts` | VNode tree and Grid layout helpers. |
|
|
1196
|
+
| `engine/nodes.ts` | SceneNode predicates and derived values. |
|
|
1197
|
+
| `engine/state.ts` | Internal types, EngineCore interface, and EngineState container. |
|
|
1198
|
+
|
|
1199
|
+
For appearance changes, edit the drawing function in `components/<Component>/<component>.ts`; place component-specific interaction logic in `logic.ts` in the same directory. For shared layout, event, or export behavior, edit the relevant adapter, `engine.ts`, or `renderer.ts`.
|