refactor(components): 优化复选框组件并引入 Dynamic 组件
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
ParentProps,
|
||||
Show,
|
||||
} from 'solid-js';
|
||||
import { Dynamic } from 'solid-js/web';
|
||||
|
||||
interface CheckBoxProps {
|
||||
name?: string;
|
||||
@@ -17,6 +18,11 @@ interface CheckBoxProps {
|
||||
onChange?: (checked?: boolean) => void;
|
||||
}
|
||||
|
||||
const CheckIcon = [
|
||||
() => <Icon icon="hugeicons:square" class="text-[14px] stroke-1" />,
|
||||
() => <Icon icon="hugeicons:checkmark-square-03" class="text-[14px] stroke-1 text-primary" />,
|
||||
];
|
||||
|
||||
const Check: ParentComponent<CheckBoxProps> = (props) => {
|
||||
const mProps = mergeProps<ParentProps<CheckBoxProps>[]>(
|
||||
{
|
||||
@@ -38,19 +44,13 @@ const Check: ParentComponent<CheckBoxProps> = (props) => {
|
||||
if (mProps.disabled) {
|
||||
return;
|
||||
}
|
||||
console.debug('[Check]before', internalChecked());
|
||||
setInternalChecked((prev) => !prev);
|
||||
console.debug('[Check]after', internalChecked());
|
||||
mProps.onChange?.(internalChecked());
|
||||
};
|
||||
|
||||
return (
|
||||
<div class="flex flex-row items-center gap-2 cursor-pointer" onClick={handleClick}>
|
||||
<Icon
|
||||
icon={internalChecked() ? 'hugeicons:checkmark-square-03' : 'hugeicons:square'}
|
||||
class="text-[14px] stroke-1"
|
||||
classList={{ 'text-primary': internalChecked() }}
|
||||
/>
|
||||
<Dynamic component={CheckIcon[internalChecked() ? 1 : 0]} />
|
||||
<div>{mProps.children}</div>
|
||||
<Show when={isNotNil(mProps.name)}>
|
||||
<input type="hidden" name={mProps.name} value={internalChecked()} />
|
||||
|
Reference in New Issue
Block a user