import React, { ForwardedRef, forwardRef, useImperativeHandle, useState, useRef } from "react"; import "./index.less"; interface ComponentStyle { mainColor?: string; subColor?: string; } export interface ComponentProps { style?: ComponentStyle; base?: { width?: number, height?: number, id: string } } export interface ComponentRef { updateConfig: (config: ComponentProps) => void; } const Index = forwardRef((props: ComponentProps, ref: ForwardedRef) => { const { style: defStyle, base: defBase } = props; const [style, setStyle] = useState({ ...defStyle }); const [width, setWidth] = useState(defBase?.width || 300); const [height, setHeight] = useState(defBase?.height || 100); const { mainColor = "#83BFF6", subColor = "#00CED1" } = style || {}; const { animationId1, animationId2, animationId3, animationId4, animationId5, animationId6, animationId7 } = useRef({ animationId1: `d9ani1${defBase?.id}`, animationId2: `d9ani2${defBase?.id}`, animationId3: `d9ani3${defBase?.id}`, animationId4: `d9ani4${defBase?.id}`, animationId5: `d9ani5${defBase?.id}`, animationId6: `d9ani6${defBase?.id}`, animationId7: `d9ani7${defBase?.id}` }).current useImperativeHandle(ref, () => ({ updateConfig: (newConfig) => { setStyle({ ...newConfig.style }); setWidth(newConfig.base.width); setHeight(newConfig.base.height); }, })); return
; }); export default Index;