From 481402e09fe760634b826b09e302e2e1bfec88b1 Mon Sep 17 00:00:00 2001 From: shu Date: Mon, 7 Sep 2026 15:48:36 +0800 Subject: feat: initialize React Spectrum template with layouts and showcases --- src/components/form-examples/color-file-fields.tsx | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/components/form-examples/color-file-fields.tsx (limited to 'src/components/form-examples/color-file-fields.tsx') diff --git a/src/components/form-examples/color-file-fields.tsx b/src/components/form-examples/color-file-fields.tsx new file mode 100644 index 0000000..e9d0e74 --- /dev/null +++ b/src/components/form-examples/color-file-fields.tsx @@ -0,0 +1,69 @@ +import FieldGrid from './field-grid' +import { useState } from 'react' +import { ColorArea, parseColor } from '@react-spectrum/s2/ColorArea' +import { ColorField } from '@react-spectrum/s2/ColorField' +import { ColorSlider } from '@react-spectrum/s2/ColorSlider' +import { ColorWheel } from '@react-spectrum/s2/ColorWheel' +import { ColorSwatch, ColorSwatchPicker } from '@react-spectrum/s2/ColorSwatchPicker' +import { DropZone } from '@react-spectrum/s2/DropZone' +import { FileTrigger } from '@react-spectrum/s2/FileTrigger' +import { Button } from '@react-spectrum/s2/Button' +import styles from './form-examples.module.css' + +export default function ColorFileFields({ disabled }: { disabled: boolean }) { + const [color, setColor] = useState(() => parseColor('hsl(265, 75%, 60%)')) + const [files, setFiles] = useState([]) + const [fileError, setFileError] = useState('') + return ( + <> +
+

颜色选择

+

输入框、色板、色轮和滑块共享同一个颜色值。

+ + { if (next) setColor(next) }} /> + + +
+ 预设色板 + + + +
+
+
+
二维颜色面板
+
色轮
+
+ + {color.toString('hexa')} +
+
+

文件选择与拖放

+ !disabled && types.has('Files') ? 'copy' : 'cancel'} + onDrop={async (event) => { + try { + const next = await Promise.all(event.items.filter((item) => item.kind === 'file').map((item) => item.getFile())) + setFiles(next) + setFileError('') + } catch { + setFileError('无法读取文件,请重新选择。') + } + }}> +
+

将文件拖放到这里,或从设备中选择。

+ { if (selected) { setFiles(Array.from(selected)); setFileError('') } }}> + + +

仅在本页预览文件信息,不上传。

+
+
+ {fileError &&

{fileError}

} +
+ {files.length ?
    {files.map((file, index) =>
  • {file.name} · {Math.ceil(file.size / 1024)} KB
  • )}
:

尚未选择文件。

} +
+ {files.length > 0 && } + ({ name, size, type })))} /> +
+ + ) +} -- cgit v1.2.3