import { JSXElement, Match, Show, Switch } from "solid-js"; import { Icon } from "../Icon"; import { TagConfig, TagGroup } from "../TagGroup"; import { InnerInput } from "../FormElements/Input/input"; export interface ValueProps { onClear?: Function prepend?: any text?: string | Array clearable?: boolean icon?: JSXElement disabled?: boolean size?: 'small'|'large' multi?: boolean showMax?: number placeholder?: string valueClosable?: boolean, onClose?(item: TagConfig, e: any): void, onInput?(e: any): void, filter?: boolean, query?: [Function, Function] showMore?: boolean, onDeleteLastValue?: Function } export function Value (props: ValueProps) { const [query, setQuery] = props.query ?? [() => {}, () => {}]; let filterInput: any; const onClear = (e: any) => { e.stopImmediatePropagation && e.stopImmediatePropagation(); e.preventDefault && e.preventDefault(); e.stopPropagation && e.stopPropagation(); props.onClear && props.onClear(); } const classList = () => ({ 'cm-field-value': true, 'cm-field-clearable': props.clearable && !!props.text && !!props.text.length, 'cm-field-disabled': props.disabled, [`cm-field-value-${props.size}`]: !!props.size, }) const text = () => { Promise.resolve().then(() => { if (props.filter && filterInput) { filterInput.focus(); } }) if (props.multi && props.text && props.text instanceof Array) { return props.text.map((item: any, index: number) => { return {id: item.id, title: item.title}; }) } return []; }; const inputStyle = () => { const str = props.filter ? query() : ''; return { width: str !== undefined ? str.length * 12 + 20 + 'px' : '100%', } } const onValueClick = () => { if (props.filter && filterInput) { filterInput.focus(); } } const onFilterKeyDown = (e: any) => { const queryStr = query(); if (e.key === 'Backspace' || e.code === 'Backspace' || e.key === 'Delete' || e.code === 'Delete') { if (queryStr.length === 0) { props.onDeleteLastValue && props.onDeleteLastValue(); } } } return
{/* 文字对齐辅助 */} A
{props.prepend}
{ props.filter ? : null }
{props.text ? props.text : {props.placeholder??''}}
{props.icon}
}