import { selectDefined } from '@o/utils' import { gloss, useTheme } from 'gloss' import React from 'react' import { Button, ButtonProps } from '../buttons/Button' import { FilterToken } from '../tables/FilterToken' import { TableFilter } from '../tables/types' import { Stack } from '../View/Stack' import { Input, InputProps } from './Input' export type SearchInputProps = InputProps & { actions?: React.ReactNode // @ts-ignore filters?: TableFilter[] onClickClear?: InputProps['onClick'] focusedToken?: number filterProps?: Object clearable?: boolean } export function SearchInput({ width = '100%', before = null, placeholder = null, after = null, actions = null, filters = [], onClickClear = null, focusedToken = null, filterProps = null, value = null, flex = null, padding = 0, clearable, ...props }: SearchInputProps) { const clearVisible = typeof clearable === 'boolean' ? clearable : value && !!value.length const theme = useTheme({ subTheme: 'searchInput', }) return ( {filters.map((filter, i) => ( ))} } after={ <> {after} {!!actions && ( {actions} )} } elementProps={{ minWidth: 100, }} {...props} /> ) } export const ClearButton = gloss(Button, { icon: 'cross', circular: true, size: 0.75, sizeIcon: 1.5, coat: 'flat', glint: false, glintBottom: false, opacity: 1, pointerEvents: 'none', conditional: { invisible: { opacity: 0, pointerEvents: 'auto', }, }, }) const Actions = gloss(Stack, { marginLeft: 8, flexShrink: 0, })