| 17 | export const CoverInput: FC<{ |
| 18 | accessor: [any, (value: any) => void] |
| 19 | }> = ({ accessor }) => { |
| 20 | const [meta, setMeta] = accessor |
| 21 | |
| 22 | const value = meta?.cover || '' |
| 23 | const reset = () => { |
| 24 | const nextValue = { |
| 25 | ...meta, |
| 26 | } |
| 27 | delete nextValue.cover |
| 28 | setMeta(nextValue) |
| 29 | } |
| 30 | return ( |
| 31 | <SidebarSection label="Cover"> |
| 32 | <div className="relative"> |
| 33 | <Input |
| 34 | className={clsx('w-full', !!value && 'pr-8')} |
| 35 | value={value} |
| 36 | onChange={(e) => { |
| 37 | const { value } = e.target |
| 38 | |
| 39 | if (value === '') { |
| 40 | reset() |
| 41 | return |
| 42 | } |
| 43 | if (!isUrl(value)) { |
| 44 | toast.error('只能粘贴一个图片链接') |
| 45 | return |
| 46 | } |
| 47 | setMeta({ |
| 48 | ...meta, |
| 49 | cover: value, |
| 50 | }) |
| 51 | }} |
| 52 | /> |
| 53 | {!!value && ( |
| 54 | <button className="cursor-default" onClick={reset}> |
| 55 | <CloseIcon className="absolute right-2 top-1/2 -translate-y-1/2 rounded-full bg-gray-200 p-1 duration-200 hover:opacity-90 dark:bg-zinc-800" /> |
| 56 | </button> |
| 57 | )} |
| 58 | </div> |
| 59 | </SidebarSection> |
| 60 | ) |
| 61 | } |