|
6 | 6 | } from 'solid-js'; |
7 | 7 | import { IconX } from '@tabler/icons-solidjs'; |
8 | 8 |
|
9 | | -import type { WithOverride } from '~/utils'; |
| 9 | +import { cn, type WithOverride } from '~/utils'; |
10 | 10 | import { |
11 | 11 | FORM_INPUT_PROP_NAMES, |
12 | 12 | makeFieldComponent, |
@@ -96,38 +96,40 @@ export function ChipInput(props: ChipInputProps) { |
96 | 96 | } |
97 | 97 |
|
98 | 98 | 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}> |
121 | 123 | <TextInput |
122 | 124 | ref={setInputRef} |
123 | 125 | disabled={props.disabled} |
124 | 126 | onBlur={() => props.onBlur?.()} |
125 | 127 | onKeyDown={onKeyDown} |
126 | 128 | onPaste={onPaste} |
127 | 129 | 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" |
129 | 131 | /> |
130 | | - </div> |
| 132 | + </Show> |
131 | 133 | </div> |
132 | 134 | ); |
133 | 135 | } |
0 commit comments