@web-canvas-ui/react 0.0.0-stage → 0.1.1
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/Canvas.tsx +142 -0
- package/README.md +988 -2
- package/__tests__/pure-logic.test.ts +153 -0
- package/__tests__/scene-and-node.test.ts +131 -0
- package/__tests__/scratch-space.test.ts +30 -0
- package/__tests__/textarea-caret.test.ts +96 -0
- package/__tests__/utils.test.ts +114 -0
- package/canvas-handle.ts +114 -0
- package/components/Button/button.ts +57 -0
- package/components/Button/index.ts +3 -0
- package/components/Button/logic.ts +11 -0
- package/components/CanvasView/canvasView.ts +103 -0
- package/components/CanvasView/index.ts +7 -0
- package/components/Carousel/carousel.ts +107 -0
- package/components/Carousel/index.ts +3 -0
- package/components/Carousel/logic.ts +36 -0
- package/components/Checkbox/checkbox.ts +14 -0
- package/components/Checkbox/index.ts +2 -0
- package/components/ChoiceGroup/choiceGroup.ts +172 -0
- package/components/ChoiceGroup/index.ts +3 -0
- package/components/ChoiceGroup/logic.ts +14 -0
- package/components/Circle/circle.ts +31 -0
- package/components/Circle/index.ts +2 -0
- package/components/Collapse/collapse.ts +69 -0
- package/components/Collapse/index.ts +3 -0
- package/components/Collapse/logic.ts +14 -0
- package/components/CustomDraw/customDraw.ts +50 -0
- package/components/CustomDraw/index.ts +7 -0
- package/components/DatePicker/datePicker.ts +70 -0
- package/components/DatePicker/index.ts +2 -0
- package/components/Dialog/dialog.ts +102 -0
- package/components/Dialog/index.ts +2 -0
- package/components/Dropdown/dropdown.ts +125 -0
- package/components/Dropdown/index.ts +3 -0
- package/components/Dropdown/logic.ts +29 -0
- package/components/Grid/grid.ts +15 -0
- package/components/Grid/index.ts +2 -0
- package/components/GridItem/gridItem.ts +11 -0
- package/components/GridItem/index.ts +2 -0
- package/components/Group/group.ts +8 -0
- package/components/Group/index.ts +2 -0
- package/components/Icon/icon.ts +669 -0
- package/components/Icon/index.ts +2 -0
- package/components/Image/image.ts +69 -0
- package/components/Image/index.ts +2 -0
- package/components/Input/index.ts +2 -0
- package/components/Input/input.ts +139 -0
- package/components/Progress/index.ts +2 -0
- package/components/Progress/progress.ts +59 -0
- package/components/Radio/index.ts +2 -0
- package/components/Radio/radio.ts +14 -0
- package/components/Rect/index.ts +2 -0
- package/components/Rect/rect.ts +35 -0
- package/components/Slider/index.ts +3 -0
- package/components/Slider/logic.ts +19 -0
- package/components/Slider/slider.ts +58 -0
- package/components/Switch/index.ts +3 -0
- package/components/Switch/logic.ts +8 -0
- package/components/Switch/switch.ts +37 -0
- package/components/Tabs/index.ts +3 -0
- package/components/Tabs/logic.ts +14 -0
- package/components/Tabs/tabs.ts +78 -0
- package/components/Text/index.ts +2 -0
- package/components/Text/text.ts +95 -0
- package/components/Textarea/index.ts +2 -0
- package/components/Textarea/textarea.ts +16 -0
- package/components/Upload/index.ts +2 -0
- package/components/Upload/upload.ts +66 -0
- package/components/draw-utils.ts +230 -0
- package/components/shared.ts +15 -0
- package/components/size.ts +20 -0
- package/components/types.ts +37 -0
- package/components.ts +98 -0
- package/engine/__tests__/carousel.test.ts +218 -0
- package/engine/__tests__/hit-test.test.ts +282 -0
- package/engine/__tests__/layout.test.ts +474 -0
- package/engine/carousel.ts +150 -0
- package/engine/events.ts +73 -0
- package/engine/hit-test.ts +321 -0
- package/engine/images.ts +41 -0
- package/engine/interaction.ts +442 -0
- package/engine/layout.ts +355 -0
- package/engine/nodes.ts +166 -0
- package/engine/state.ts +75 -0
- package/engine/text-controls.ts +122 -0
- package/engine/transform.ts +61 -0
- package/engine/vnodes.ts +204 -0
- package/engine.ts +162 -0
- package/image-assets.ts +37 -0
- package/index.ts +78 -0
- package/input-bridge.ts +285 -0
- package/package.json +27 -4
- package/renderer.ts +303 -0
- package/scene.ts +122 -0
- package/theme.css +327 -0
- package/theme.scss +234 -0
- package/types.ts +256 -0
- package/web-canvas-ui-react-0.1.1.tgz +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { TransformProps } from '../../types';
|
|
2
|
+
import { createComponent } from '../shared';
|
|
3
|
+
|
|
4
|
+
export interface CustomDrawSize {
|
|
5
|
+
readonly width: number;
|
|
6
|
+
readonly height: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CustomDrawClickEvent extends CustomDrawSize {
|
|
10
|
+
readonly x: number;
|
|
11
|
+
readonly y: number;
|
|
12
|
+
readonly canvasX: number;
|
|
13
|
+
readonly canvasY: number;
|
|
14
|
+
readonly pointerId: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type CustomDrawHitTest = (x: number, y: number, size: CustomDrawSize) => boolean;
|
|
18
|
+
|
|
19
|
+
export interface CustomDrawProps extends TransformProps {
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
draw: (context: CanvasRenderingContext2D, size: CustomDrawSize) => void;
|
|
23
|
+
onClick?: (event: CustomDrawClickEvent) => void;
|
|
24
|
+
hitTest?: CustomDrawHitTest;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const CustomDraw = createComponent<CustomDrawProps>('customDraw');
|
|
28
|
+
|
|
29
|
+
export function drawCustomDraw(context: CanvasRenderingContext2D, props: CustomDrawProps): void {
|
|
30
|
+
const draw = props.draw;
|
|
31
|
+
if (typeof draw !== 'function') {
|
|
32
|
+
throw new TypeError('<CustomDraw> requires a draw(context, size) function.');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const width = finiteDimension(props.width, 'width');
|
|
36
|
+
const height = finiteDimension(props.height, 'height');
|
|
37
|
+
context.save();
|
|
38
|
+
try {
|
|
39
|
+
draw(context, { width, height });
|
|
40
|
+
} finally {
|
|
41
|
+
context.restore();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function finiteDimension(value: unknown, name: string): number {
|
|
46
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
|
|
47
|
+
throw new RangeError(`<CustomDraw> ${name} must be a non-negative finite number.`);
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { TransformProps } from '../../types';
|
|
2
|
+
import { number, string, themeColor } from '../draw-utils';
|
|
3
|
+
import { createComponent } from '../shared';
|
|
4
|
+
|
|
5
|
+
export interface DatePickerProps extends TransformProps {
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
value?: string;
|
|
9
|
+
defaultValue?: string;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
fontSize?: number;
|
|
12
|
+
color?: string;
|
|
13
|
+
bgColor?: string;
|
|
14
|
+
borderColor?: string;
|
|
15
|
+
focusBorderColor?: string;
|
|
16
|
+
borderRadius?: number;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
onChange?: (value: string) => void;
|
|
19
|
+
onFocus?: () => void;
|
|
20
|
+
onBlur?: () => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const DatePicker = createComponent<DatePickerProps>('datePicker');
|
|
24
|
+
|
|
25
|
+
/** Public props plus the engine-injected focus state consumed by the draw layer. */
|
|
26
|
+
export type DatePickerDrawProps = DatePickerProps & { focused?: boolean };
|
|
27
|
+
|
|
28
|
+
export function drawDatePicker(
|
|
29
|
+
context: CanvasRenderingContext2D,
|
|
30
|
+
props: DatePickerDrawProps,
|
|
31
|
+
): void {
|
|
32
|
+
const width = number(props.width, 200);
|
|
33
|
+
const height = number(props.height, 36);
|
|
34
|
+
const radius = Math.max(0, Math.min(number(props.borderRadius, 4), width / 2, height / 2));
|
|
35
|
+
const value = String(props.value ?? '');
|
|
36
|
+
context.beginPath();
|
|
37
|
+
context.roundRect(0, 0, width, height, radius);
|
|
38
|
+
context.fillStyle = string(
|
|
39
|
+
props.bgColor,
|
|
40
|
+
themeColor(context, '--canvas-ui-input-background', '#fff'),
|
|
41
|
+
);
|
|
42
|
+
context.fill();
|
|
43
|
+
context.strokeStyle = props.focused
|
|
44
|
+
? string(
|
|
45
|
+
props.focusBorderColor,
|
|
46
|
+
themeColor(context, '--canvas-ui-input-focus-border', '#1677ff'),
|
|
47
|
+
)
|
|
48
|
+
: string(props.borderColor, themeColor(context, '--canvas-ui-input-border', '#d9d9d9'));
|
|
49
|
+
context.stroke();
|
|
50
|
+
context.font = `${number(props.fontSize, 14)}px sans-serif`;
|
|
51
|
+
context.textBaseline = 'middle';
|
|
52
|
+
context.fillStyle = value
|
|
53
|
+
? string(props.color, themeColor(context, '--canvas-ui-input-color', '#333'))
|
|
54
|
+
: themeColor(context, '--canvas-ui-input-placeholder-color', '#999');
|
|
55
|
+
context.fillText(value || string(props.placeholder, 'Select date'), 8, height / 2);
|
|
56
|
+
context.fillStyle = string(props.color, themeColor(context, '--canvas-ui-input-color', '#666'));
|
|
57
|
+
context.strokeStyle = context.fillStyle;
|
|
58
|
+
context.lineWidth = 1.4;
|
|
59
|
+
const iconX = width - 20;
|
|
60
|
+
const iconY = height / 2 - 7;
|
|
61
|
+
context.strokeRect(iconX, iconY + 2, 13, 12);
|
|
62
|
+
context.beginPath();
|
|
63
|
+
context.moveTo(iconX, iconY + 5);
|
|
64
|
+
context.lineTo(iconX + 13, iconY + 5);
|
|
65
|
+
context.moveTo(iconX + 3, iconY);
|
|
66
|
+
context.lineTo(iconX + 3, iconY + 4);
|
|
67
|
+
context.moveTo(iconX + 10, iconY);
|
|
68
|
+
context.lineTo(iconX + 10, iconY + 4);
|
|
69
|
+
context.stroke();
|
|
70
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { TransformProps } from '../../types';
|
|
2
|
+
import { fitText, number, themeColor } from '../draw-utils';
|
|
3
|
+
import { createComponent } from '../shared';
|
|
4
|
+
|
|
5
|
+
export interface DialogProps extends TransformProps {
|
|
6
|
+
open: boolean;
|
|
7
|
+
width?: number;
|
|
8
|
+
height?: number;
|
|
9
|
+
title?: string;
|
|
10
|
+
confirmText?: string;
|
|
11
|
+
cancelText?: string;
|
|
12
|
+
closeOnBackdrop?: boolean;
|
|
13
|
+
children?: unknown;
|
|
14
|
+
onConfirm?: () => void;
|
|
15
|
+
onCancel?: () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const Dialog = createComponent<DialogProps>('dialog');
|
|
19
|
+
|
|
20
|
+
/** Public props plus the engine-injected viewport size consumed by the draw layer. */
|
|
21
|
+
export type DialogDrawProps = DialogProps & { _viewportWidth?: number; _viewportHeight?: number };
|
|
22
|
+
|
|
23
|
+
export function drawDialog(context: CanvasRenderingContext2D, props: DialogDrawProps): void {
|
|
24
|
+
const viewportWidth = number(props._viewportWidth, context.canvas.width);
|
|
25
|
+
const viewportHeight = number(props._viewportHeight, context.canvas.height);
|
|
26
|
+
const width = number(props.width, 420);
|
|
27
|
+
const height = number(props.height, 240);
|
|
28
|
+
const x = (viewportWidth - width) / 2;
|
|
29
|
+
const y = (viewportHeight - height) / 2;
|
|
30
|
+
context.fillStyle = themeColor(context, '--canvas-ui-dialog-mask', 'rgba(0, 0, 0, 0.45)');
|
|
31
|
+
context.fillRect(0, 0, viewportWidth, viewportHeight);
|
|
32
|
+
context.fillStyle = themeColor(context, '--canvas-ui-dialog-background', '#fff');
|
|
33
|
+
context.beginPath();
|
|
34
|
+
context.roundRect(x, y, width, height, 8);
|
|
35
|
+
context.fill();
|
|
36
|
+
context.fillStyle = themeColor(context, '--canvas-ui-dialog-title-color', '#1f1f1f');
|
|
37
|
+
context.font = '600 16px sans-serif';
|
|
38
|
+
context.textBaseline = 'middle';
|
|
39
|
+
context.fillText(
|
|
40
|
+
fitText(context, String(props.title ?? 'Confirm'), Math.max(0, width - 48)),
|
|
41
|
+
x + 24,
|
|
42
|
+
y + 28,
|
|
43
|
+
);
|
|
44
|
+
context.strokeStyle = themeColor(context, '--canvas-ui-dialog-border', '#f0f0f0');
|
|
45
|
+
context.beginPath();
|
|
46
|
+
context.moveTo(x, y + 56);
|
|
47
|
+
context.lineTo(x + width, y + 56);
|
|
48
|
+
context.moveTo(x, y + height - 56);
|
|
49
|
+
context.lineTo(x + width, y + height - 56);
|
|
50
|
+
context.stroke();
|
|
51
|
+
drawDialogButton(
|
|
52
|
+
context,
|
|
53
|
+
x + width - 196,
|
|
54
|
+
y + height - 44,
|
|
55
|
+
80,
|
|
56
|
+
32,
|
|
57
|
+
String(props.cancelText ?? 'Cancel'),
|
|
58
|
+
false,
|
|
59
|
+
);
|
|
60
|
+
drawDialogButton(
|
|
61
|
+
context,
|
|
62
|
+
x + width - 104,
|
|
63
|
+
y + height - 44,
|
|
64
|
+
80,
|
|
65
|
+
32,
|
|
66
|
+
String(props.confirmText ?? 'OK'),
|
|
67
|
+
true,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function drawDialogButton(
|
|
72
|
+
context: CanvasRenderingContext2D,
|
|
73
|
+
x: number,
|
|
74
|
+
y: number,
|
|
75
|
+
width: number,
|
|
76
|
+
height: number,
|
|
77
|
+
label: string,
|
|
78
|
+
primary: boolean,
|
|
79
|
+
): void {
|
|
80
|
+
context.beginPath();
|
|
81
|
+
context.roundRect(x, y, width, height, 6);
|
|
82
|
+
context.fillStyle = primary
|
|
83
|
+
? themeColor(context, '--canvas-ui-dialog-confirm-background', '#1677ff')
|
|
84
|
+
: themeColor(context, '--canvas-ui-dialog-cancel-background', '#fff');
|
|
85
|
+
context.fill();
|
|
86
|
+
context.strokeStyle = primary
|
|
87
|
+
? themeColor(context, '--canvas-ui-dialog-confirm-background', '#1677ff')
|
|
88
|
+
: themeColor(context, '--canvas-ui-dialog-border', '#d9d9d9');
|
|
89
|
+
context.stroke();
|
|
90
|
+
context.fillStyle = primary
|
|
91
|
+
? themeColor(context, '--canvas-ui-dialog-confirm-color', '#fff')
|
|
92
|
+
: themeColor(context, '--canvas-ui-dialog-cancel-color', '#333');
|
|
93
|
+
context.font = '14px sans-serif';
|
|
94
|
+
context.textAlign = 'center';
|
|
95
|
+
context.textBaseline = 'middle';
|
|
96
|
+
context.fillText(
|
|
97
|
+
fitText(context, label, Math.max(0, width - 16)),
|
|
98
|
+
x + width / 2,
|
|
99
|
+
y + height / 2,
|
|
100
|
+
);
|
|
101
|
+
context.textAlign = 'left';
|
|
102
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { TransformProps } from '../../types';
|
|
2
|
+
import { fitText, number, string, themeColor } from '../draw-utils';
|
|
3
|
+
import { createComponent } from '../shared';
|
|
4
|
+
|
|
5
|
+
export interface DropdownOption {
|
|
6
|
+
label: string;
|
|
7
|
+
value: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface DropdownProps extends TransformProps {
|
|
12
|
+
width?: number;
|
|
13
|
+
height?: number;
|
|
14
|
+
value?: string;
|
|
15
|
+
defaultValue?: string;
|
|
16
|
+
options: Array<string | DropdownOption>;
|
|
17
|
+
placeholder?: string;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
fontSize?: number;
|
|
20
|
+
color?: string;
|
|
21
|
+
bgColor?: string;
|
|
22
|
+
borderColor?: string;
|
|
23
|
+
focusBorderColor?: string;
|
|
24
|
+
borderRadius?: number;
|
|
25
|
+
onChange?: (value: string) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const Dropdown = createComponent<DropdownProps>('dropdown');
|
|
29
|
+
|
|
30
|
+
/** Public props plus the engine-injected focus/open state consumed by the draw layer. */
|
|
31
|
+
export type DropdownDrawProps = DropdownProps & { focused?: boolean; open?: boolean };
|
|
32
|
+
|
|
33
|
+
export function drawDropdown(context: CanvasRenderingContext2D, props: DropdownDrawProps): void {
|
|
34
|
+
const width = number(props.width, 200);
|
|
35
|
+
const height = number(props.height, 36);
|
|
36
|
+
const options = optionsList(props.options);
|
|
37
|
+
const selected = options.find((option) => option.value === String(props.value ?? ''));
|
|
38
|
+
drawControlBox(
|
|
39
|
+
context,
|
|
40
|
+
width,
|
|
41
|
+
height,
|
|
42
|
+
number(props.borderRadius, 4),
|
|
43
|
+
props,
|
|
44
|
+
Boolean(props.focused || props.open),
|
|
45
|
+
);
|
|
46
|
+
context.font = `${number(props.fontSize, 14)}px sans-serif`;
|
|
47
|
+
context.textBaseline = 'middle';
|
|
48
|
+
context.fillStyle = selected
|
|
49
|
+
? string(props.color, themeColor(context, '--canvas-ui-dropdown-color', '#333'))
|
|
50
|
+
: themeColor(context, '--canvas-ui-dropdown-placeholder-color', '#999');
|
|
51
|
+
context.fillText(
|
|
52
|
+
fitText(
|
|
53
|
+
context,
|
|
54
|
+
selected?.label ?? string(props.placeholder, 'Select...'),
|
|
55
|
+
Math.max(0, width - 34),
|
|
56
|
+
),
|
|
57
|
+
8,
|
|
58
|
+
height / 2,
|
|
59
|
+
);
|
|
60
|
+
context.fillStyle = string(
|
|
61
|
+
props.color,
|
|
62
|
+
themeColor(context, '--canvas-ui-dropdown-color', '#555'),
|
|
63
|
+
);
|
|
64
|
+
context.beginPath();
|
|
65
|
+
context.moveTo(width - 18, height / 2 - 3);
|
|
66
|
+
context.lineTo(width - 12, height / 2 + 3);
|
|
67
|
+
context.lineTo(width - 6, height / 2 - 3);
|
|
68
|
+
context.stroke();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function drawDropdownOptions(
|
|
72
|
+
context: CanvasRenderingContext2D,
|
|
73
|
+
props: DropdownDrawProps,
|
|
74
|
+
): void {
|
|
75
|
+
const width = number(props.width, 200);
|
|
76
|
+
const height = number(props.height, 36);
|
|
77
|
+
context.font = `${number(props.fontSize, 14)}px sans-serif`;
|
|
78
|
+
context.textBaseline = 'middle';
|
|
79
|
+
optionsList(props.options).forEach((option, index) => {
|
|
80
|
+
const y = height * (index + 1);
|
|
81
|
+
context.fillStyle = themeColor(context, '--canvas-ui-dropdown-option-background', '#fff');
|
|
82
|
+
context.fillRect(0, y, width, height);
|
|
83
|
+
context.strokeStyle = themeColor(context, '--canvas-ui-dropdown-option-border', '#e3e7ed');
|
|
84
|
+
context.strokeRect(0, y, width, height);
|
|
85
|
+
context.fillStyle = option.disabled
|
|
86
|
+
? themeColor(context, '--canvas-ui-dropdown-disabled-color', '#aaa')
|
|
87
|
+
: string(props.color, themeColor(context, '--canvas-ui-dropdown-color', '#333'));
|
|
88
|
+
context.fillText(
|
|
89
|
+
fitText(context, option.label, Math.max(0, width - 16)),
|
|
90
|
+
8,
|
|
91
|
+
y + height / 2,
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function drawControlBox(
|
|
97
|
+
context: CanvasRenderingContext2D,
|
|
98
|
+
width: number,
|
|
99
|
+
height: number,
|
|
100
|
+
radius: number,
|
|
101
|
+
props: DropdownProps,
|
|
102
|
+
focused: boolean,
|
|
103
|
+
): void {
|
|
104
|
+
context.beginPath();
|
|
105
|
+
context.roundRect(0, 0, width, height, radius);
|
|
106
|
+
context.fillStyle = string(
|
|
107
|
+
props.bgColor,
|
|
108
|
+
themeColor(context, '--canvas-ui-dropdown-background', '#fff'),
|
|
109
|
+
);
|
|
110
|
+
context.fill();
|
|
111
|
+
context.strokeStyle = focused
|
|
112
|
+
? string(
|
|
113
|
+
props.focusBorderColor,
|
|
114
|
+
themeColor(context, '--canvas-ui-dropdown-focus-border', '#1677ff'),
|
|
115
|
+
)
|
|
116
|
+
: string(props.borderColor, themeColor(context, '--canvas-ui-dropdown-border', '#d9d9d9'));
|
|
117
|
+
context.stroke();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function optionsList(value: unknown): DropdownOption[] {
|
|
121
|
+
if (!Array.isArray(value)) return [];
|
|
122
|
+
return value.map((option) =>
|
|
123
|
+
typeof option === 'string' ? { label: option, value: option } : (option as DropdownOption),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DropdownOption } from './dropdown';
|
|
2
|
+
import type { SceneNode } from '../../scene';
|
|
3
|
+
|
|
4
|
+
export function normalizeDropdownOptions(value: unknown): DropdownOption[] {
|
|
5
|
+
if (!Array.isArray(value)) return [];
|
|
6
|
+
return value.flatMap((option): DropdownOption[] => {
|
|
7
|
+
if (typeof option === 'string') return [{ label: option, value: option }];
|
|
8
|
+
if (!option || typeof option !== 'object') return [];
|
|
9
|
+
const candidate = option as Partial<DropdownOption>;
|
|
10
|
+
if (typeof candidate.label !== 'string' || typeof candidate.value !== 'string') return [];
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
label: candidate.label,
|
|
14
|
+
value: candidate.value,
|
|
15
|
+
disabled: candidate.disabled === true,
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function dropdownOptionAt(value: unknown, index: number): DropdownOption | undefined {
|
|
22
|
+
return normalizeDropdownOptions(value)[index];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function selectDropdownOption(node: SceneNode, option: DropdownOption): void {
|
|
26
|
+
node.setProps({ value: option.value, open: false });
|
|
27
|
+
const onChange = node.props.onChange;
|
|
28
|
+
if (typeof onChange === 'function') onChange(option.value);
|
|
29
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TransformProps } from '../../types';
|
|
2
|
+
import { createComponent } from '../shared';
|
|
3
|
+
|
|
4
|
+
export interface GridProps extends TransformProps {
|
|
5
|
+
columns: number;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
cellWidth?: number;
|
|
9
|
+
cellHeight: number;
|
|
10
|
+
gap?: number;
|
|
11
|
+
children?: unknown;
|
|
12
|
+
onScroll?: (scrollTop: number) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const Grid = createComponent<GridProps>('grid');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TransformProps } from '../../types';
|
|
2
|
+
import { createComponent } from '../shared';
|
|
3
|
+
|
|
4
|
+
export interface GridItemProps extends TransformProps {
|
|
5
|
+
columnSpan?: number;
|
|
6
|
+
rowSpan?: number;
|
|
7
|
+
backgroundColor?: string;
|
|
8
|
+
children?: unknown;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const GridItem = createComponent<GridItemProps>('gridItem');
|