import { EditorProperty } from "@iplusplus/y-model" import { ColorPicker, IColor, useColor } from "react-color-palette" import "react-color-palette/css" import { GridCellEditStopReasons, useGridApiContext } from "@mui/x-data-grid" import { Box, Popper } from "@mui/material" import { useEffect, useRef, useState } from "react" import { CellRender, CellRenderBuilder2, CellRenderParam } from "../types" import ClearIcon from '@mui/icons-material/Clear'; import { CustomIcon } from "../../ui-utils" export function ColorSelectCell({ cellParams, property }: { cellParams: CellRenderParam, property: EditorProperty }) { const { id, value, field } = cellParams const divRef = useRef(null) const apiRef = useGridApiContext() const [showPops, setShowPops] = useState(false) // console.log(value); const [color, setColor] = useColor(value as unknown as string) const colorChange = (newColor: IColor) => { apiRef.current.setEditCellValue({ id, field, value: newColor.hex }) setColor(newColor) } useEffect(() => { // console.log(divRef.current) setShowPops(true) }, []) //const needShowPops = divRef.current != null && showPops // console.log(value) const enableClear = property.valueType.getAttach("canBeEmpty") const onClear = () => { apiRef.current.setEditCellValue({ id, field, value: "" }) setShowPops(false) apiRef.current.publishEvent("cellEditStop", { ...cellParams, reason: GridCellEditStopReasons.cellFocusOut, }) } const clearButton = enableClear ? } handler={onClear} /> : null return (
请选择 {clearButton}
) } // const colorEditRender: CellRender = params => { // return // } function renderColorEditRender(property: EditorProperty): CellRender { return params => { return } } const colorRender: CellRender = params => { // console.log(params.value) if (params.value) { return
[{params.value}]
} return
} export const colorRenderBuilder: CellRenderBuilder2 = (property: EditorProperty) => { if (property.editorType === "color") { return { editorCellRender: renderColorEditRender(property), cellRender: colorRender, } } return undefined }