|
|
@ -1,23 +1,27 @@ |
|
|
|
import { Popover, PopoverProps } from 'antd' |
|
|
|
import { FC, useEffect } from 'react' |
|
|
|
import { FC, memo, useEffect } from 'react' |
|
|
|
import Display from './Display.tsx' |
|
|
|
import PickerPanel from './PickerPanel' |
|
|
|
import { PickerContextProvider, usePickerContext } from './context.tsx' |
|
|
|
|
|
|
|
import { ICON_RESET, PickerContextProvider, usePickerContext } from './context.tsx' |
|
|
|
import { IconUnit } from '@/components/icon/types.ts' |
|
|
|
|
|
|
|
interface PickerProps extends Partial<PopoverProps> { |
|
|
|
value?: string, |
|
|
|
onChange?: (value: string) => void, |
|
|
|
} |
|
|
|
|
|
|
|
const IconPicker: FC = (props: PickerProps) => { |
|
|
|
const IconPicker: FC = memo((props: PickerProps) => { |
|
|
|
|
|
|
|
const { state, actions: { selectIcon, togglePanel } } = usePickerContext() |
|
|
|
const { value, onChange } = props |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (onChange) { |
|
|
|
onChange(state.icon ? `${state.icon.type}:${state.icon.componentName}` : '') |
|
|
|
if (onChange && state.icon) { |
|
|
|
if (state.icon === ICON_RESET) { |
|
|
|
return onChange('') |
|
|
|
} |
|
|
|
const icon = state.icon as IconUnit |
|
|
|
onChange(state.icon ? `${icon.type}:${icon.componentName}` : '') |
|
|
|
} |
|
|
|
}, [ state.icon ]) |
|
|
|
|
|
|
@ -47,10 +51,10 @@ const IconPicker: FC = (props: PickerProps) => { |
|
|
|
<Display/> |
|
|
|
</Popover> |
|
|
|
) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
export default (props: PickerProps) => { |
|
|
|
export default memo((props: PickerProps) => { |
|
|
|
return <PickerContextProvider value={{} as any}> |
|
|
|
<IconPicker {...props as any}/> |
|
|
|
</PickerContextProvider> |
|
|
|
} |
|
|
|
}) |