From b864f62170f610aa7a73a86110bf0ad907db8f55 Mon Sep 17 00:00:00 2001 From: Vixalie Date: Tue, 12 Aug 2025 14:30:31 +0800 Subject: [PATCH] =?UTF-8?q?refactor(Radio):=20=E9=87=8D=E6=9E=84=20Radio?= =?UTF-8?q?=20=E7=BB=84=E4=BB=B6=E4=B8=AD=E7=9A=84=E5=9B=BE=E6=A0=87?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用 Dynamic 组件动态渲染 RadioIcon 数组中的图标组件 - 通过数组索引选择适当的图标,简化了图标切换逻辑 - 移除了原有的条件渲染代码,提高了组件的可读性和性能 --- src/components/Radio.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/Radio.tsx b/src/components/Radio.tsx index 5d6f19b..7b63498 100644 --- a/src/components/Radio.tsx +++ b/src/components/Radio.tsx @@ -9,6 +9,7 @@ import { ParentProps, Show, } from 'solid-js'; +import { Dynamic } from 'solid-js/web'; interface RadioProps { name?: string; @@ -17,6 +18,11 @@ interface RadioProps { onChange?: (value?: boolean) => void; } +const RadioIcon = [ + () => , + () => , +]; + const Radio: ParentComponent = (props) => { const mProps = mergeProps[]>( { @@ -44,11 +50,7 @@ const Radio: ParentComponent = (props) => { return (
- +
{mProps.children}