mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-18 22:11:43 +01:00
feat(InputTags): new component (#4261)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -24,6 +24,7 @@ export { default as formField } from './form-field'
|
||||
export { default as input } from './input'
|
||||
export { default as inputMenu } from './input-menu'
|
||||
export { default as inputNumber } from './input-number'
|
||||
export { default as inputTags } from './input-tags'
|
||||
export { default as kbd } from './kbd'
|
||||
export { default as link } from './link'
|
||||
export { default as modal } from './modal'
|
||||
|
||||
@@ -26,14 +26,13 @@ export default (options: Required<ModuleOptions>) => {
|
||||
tagsItem: 'px-1.5 py-0.5 rounded-sm font-medium inline-flex items-center gap-0.5 ring ring-inset ring-accented bg-elevated text-default data-disabled:cursor-not-allowed data-disabled:opacity-75',
|
||||
tagsItemText: 'truncate',
|
||||
tagsItemDelete: ['inline-flex items-center rounded-xs text-dimmed hover:text-default hover:bg-accented/75 disabled:pointer-events-none', options.theme.transitions && 'transition-colors'],
|
||||
tagsItemDeleteIcon: '',
|
||||
tagsInput: ''
|
||||
tagsItemDeleteIcon: 'shrink-0',
|
||||
tagsInput: 'flex-1 border-0 bg-transparent placeholder:text-dimmed focus:outline-none disabled:cursor-not-allowed disabled:opacity-75'
|
||||
},
|
||||
variants: {
|
||||
multiple: {
|
||||
true: {
|
||||
root: 'flex-wrap',
|
||||
tagsInput: 'border-0 bg-transparent placeholder:text-dimmed focus:outline-none disabled:cursor-not-allowed disabled:opacity-75'
|
||||
root: 'flex-wrap'
|
||||
},
|
||||
false: {
|
||||
base: 'w-full border-0 placeholder:text-dimmed focus:outline-none disabled:cursor-not-allowed disabled:opacity-75'
|
||||
@@ -97,7 +96,15 @@ export default (options: Required<ModuleOptions>) => {
|
||||
}
|
||||
}
|
||||
},
|
||||
compoundVariants: [...(options.theme.colors || []).map((color: string) => ({
|
||||
compoundVariants: [{
|
||||
variant: 'soft',
|
||||
multiple: true,
|
||||
class: 'has-focus:bg-elevated'
|
||||
}, {
|
||||
variant: 'ghost',
|
||||
multiple: true,
|
||||
class: 'has-focus:bg-elevated'
|
||||
}, ...(options.theme.colors || []).map((color: string) => ({
|
||||
color,
|
||||
multiple: true,
|
||||
variant: ['outline', 'subtle'],
|
||||
|
||||
54
src/theme/input-tags.ts
Normal file
54
src/theme/input-tags.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { defuFn } from 'defu'
|
||||
import type { ModuleOptions } from '../module'
|
||||
import input from './input'
|
||||
|
||||
export default (options: Required<ModuleOptions>) => {
|
||||
return defuFn({
|
||||
slots: {
|
||||
root: (prev: string) => [prev, 'flex-wrap'],
|
||||
base: () => ['rounded-md', options.theme.transitions && 'transition-colors'],
|
||||
item: 'px-1.5 py-0.5 rounded-sm font-medium inline-flex items-center gap-0.5 ring ring-inset ring-accented bg-elevated text-default data-disabled:cursor-not-allowed data-disabled:opacity-75 wrap-anywhere data-[state="active"]:bg-accented',
|
||||
itemText: '',
|
||||
itemDelete: ['inline-flex items-center rounded-xs text-dimmed hover:text-default hover:bg-accented/75 disabled:pointer-events-none', options.theme.transitions && 'transition-colors'],
|
||||
itemDeleteIcon: 'shrink-0',
|
||||
input: 'flex-1 border-0 bg-transparent placeholder:text-dimmed focus:outline-none disabled:cursor-not-allowed disabled:opacity-75'
|
||||
},
|
||||
variants: {
|
||||
size: {
|
||||
xs: {
|
||||
item: 'text-[10px]/3',
|
||||
itemDeleteIcon: 'size-3'
|
||||
},
|
||||
sm: {
|
||||
item: 'text-[10px]/3',
|
||||
itemDeleteIcon: 'size-3'
|
||||
},
|
||||
md: {
|
||||
item: 'text-xs',
|
||||
itemDeleteIcon: 'size-3.5'
|
||||
},
|
||||
lg: {
|
||||
item: 'text-xs',
|
||||
itemDeleteIcon: 'size-3.5'
|
||||
},
|
||||
xl: {
|
||||
item: 'text-sm',
|
||||
itemDeleteIcon: 'size-4'
|
||||
}
|
||||
},
|
||||
variant: (prev: Record<string, string>) => Object.fromEntries(
|
||||
Object.entries(prev).map(([key, value]) => [key, replaceFocus(value)])
|
||||
)
|
||||
},
|
||||
compoundVariants: (prev: Record<string, any>[]) => prev.map(item => ({
|
||||
...item,
|
||||
class: typeof item.class === 'string' ? replaceFocus(item.class) : item.class
|
||||
}))
|
||||
}, input(options))
|
||||
}
|
||||
|
||||
function replaceFocus(str: string): string {
|
||||
return str
|
||||
.replace(/focus:/g, 'has-focus:')
|
||||
.replace(/focus-visible:/g, 'has-focus-visible:')
|
||||
}
|
||||
Reference in New Issue
Block a user