Skip to content

Commit 4cf3796

Browse files
committed
feat: style improvements to chip input
1 parent e38de06 commit 4cf3796

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

src/components/chip-input.tsx

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from 'solid-js';
77
import { IconX } from '@tabler/icons-solidjs';
88

9-
import type { WithOverride } from '~/utils';
9+
import { cn, type WithOverride } from '~/utils';
1010
import {
1111
FORM_INPUT_PROP_NAMES,
1212
makeFieldComponent,
@@ -96,38 +96,40 @@ export function ChipInput(props: ChipInputProps) {
9696
}
9797

9898
return (
99-
<div {...rest} class="w-full">
100-
<div
101-
onClick={() => inputRef()?.focus()}
102-
class="flex flex-wrap items-center gap-2 p-2 border border-gray-300 rounded-md focus-within:ring-2 focus-within:ring-primary-500 focus-within:border-primary-500 min-h-12"
103-
>
104-
<Show when={props.value?.length}>
105-
{props.value?.map(chip => (
106-
<Badge
107-
variant="secondary"
108-
class="flex items-center gap-1 px-2 py-1"
109-
>
110-
{chip}
111-
{!props.disabled && (
112-
<IconX
113-
onClick={() => removeChip(chip)}
114-
class="h-3 w-3 cursor-pointer"
115-
/>
116-
)}
117-
</Badge>
118-
))}
119-
</Show>
120-
99+
<div
100+
onClick={() => inputRef()?.focus()}
101+
class={cn(
102+
'w-full min-h-9 flex flex-wrap items-center gap-2 px-3 py-1 border border-input rounded-md shadow-sm transition-shadow focus-within:outline-none focus-within:ring-[1.5px] focus-within:ring-ring',
103+
props.disabled && 'cursor-not-allowed opacity-50',
104+
props.class,
105+
)}
106+
{...rest}
107+
>
108+
<Show when={props.value?.length}>
109+
{props.value?.map(chip => (
110+
<Badge variant="secondary" class="flex items-center gap-1">
111+
{chip}
112+
{!props.disabled && (
113+
<IconX
114+
onClick={() => removeChip(chip)}
115+
class="h-3 w-3 cursor-pointer"
116+
/>
117+
)}
118+
</Badge>
119+
))}
120+
</Show>
121+
122+
<Show when={!props.disabled}>
121123
<TextInput
122124
ref={setInputRef}
123125
disabled={props.disabled}
124126
onBlur={() => props.onBlur?.()}
125127
onKeyDown={onKeyDown}
126128
onPaste={onPaste}
127129
placeholder={props.value?.length ? '' : props.placeholder}
128-
class="flex-grow !border-0 !ring-0 !shadow-none !p-0 min-w-20"
130+
class="flex-grow !border-0 !ring-0 !shadow-none !p-0"
129131
/>
130-
</div>
132+
</Show>
131133
</div>
132134
);
133135
}

0 commit comments

Comments
 (0)