import React, { useCallback } from 'react'; import { SilkeBox } from '../../silke-box'; import { SilkeIcon, SilkeIcons } from '../../silke-icon'; import { SilkeText } from '../../silke-text'; import { SilkeTextFieldOutline } from '../../silke-text-field/silke-text-field-outline'; import { EmojiType, IconField as IconFieldType, SchemaFieldProps } from '@vev/utils'; import { useSchemaContext } from '../silke-schema-context'; import { getTitle } from './utils/schema-util'; const IconField = ({ value, schema, disabled, readonly, onChange, }: SchemaFieldProps) => { const { actions } = useSchemaContext(); const handleDeleteIcon = useCallback( (e: React.MouseEvent) => { e.stopPropagation(); onChange(null); }, [onChange], ); const handleSelectIcon = useCallback(() => { if (!actions) return; actions.shapeLibraryOpen((shape: any) => { if (!shape || !shape.path) return; onChange({ key: shape.key, name: shape.name, path: shape.path }); actions.shapeLibraryClose(); }); }, [onChange, actions]); const hasIcon = !!value?.path; return ( { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); handleSelectIcon(); } }} > {hasIcon ? ( ) : ( )} {hasIcon ? 'Change icon' : 'Select icon'} ); }; export default IconField;