import { type BorderOptions, BorderStyle, BorderType } from "@ironcalc/wasm"; import Popover, { type PopoverOrigin } from "@mui/material/Popover"; import { styled } from "@mui/material/styles"; import { Grid2X2 as BorderAllIcon, ChevronRight, PencilLine, } from "lucide-react"; import type React from "react"; import { useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { BorderBottomIcon, BorderCenterHIcon, BorderCenterVIcon, BorderInnerIcon, BorderLeftIcon, BorderNoneIcon, BorderOuterIcon, BorderRightIcon, BorderStyleIcon, BorderTopIcon, } from "../icons"; import { theme } from "../theme"; import ColorPicker from "./colorPicker"; type BorderPickerProps = { className?: string; onChange: (border: BorderOptions) => void; onClose: () => void; anchorEl: React.RefObject; anchorOrigin?: PopoverOrigin; transformOrigin?: PopoverOrigin; open: boolean; }; const BorderPicker = (properties: BorderPickerProps) => { const { t } = useTranslation(); const [borderSelected, setBorderSelected] = useState(null); const [borderColor, setBorderColor] = useState("#000000"); const [borderStyle, setBorderStyle] = useState(BorderStyle.Thin); const [colorPickerOpen, setColorPickerOpen] = useState(false); const [stylePickerOpen, setStylePickerOpen] = useState(false); // biome-ignore lint/correctness/useExhaustiveDependencies: useEffect(() => { if (!borderSelected) { return; } properties.onChange({ color: borderColor, style: borderStyle, border: borderSelected, }); }, [borderColor, borderStyle, borderSelected]); const onClose = properties.onClose; const borderColorButton = useRef(null); const borderStyleButton = useRef(null); return ( <> setColorPickerOpen(true)}>
Border color
setStylePickerOpen(true)} ref={borderStyleButton} >
Border style
{ setBorderColor(color); setColorPickerOpen(false); }} onClose={() => { setColorPickerOpen(false); }} anchorEl={borderColorButton} open={colorPickerOpen} /> { setStylePickerOpen(false); }} anchorEl={borderStyleButton.current} anchorOrigin={{ vertical: "bottom", horizontal: "right" }} transformOrigin={{ vertical: 38, horizontal: -6 }} > { setBorderStyle(BorderStyle.Dashed); setStylePickerOpen(false); }} $checked={borderStyle === BorderStyle.None} > None { setBorderStyle(BorderStyle.Thin); setStylePickerOpen(false); }} $checked={borderStyle === BorderStyle.Thin} > Thin { setBorderStyle(BorderStyle.Medium); setStylePickerOpen(false); }} $checked={borderStyle === BorderStyle.Medium} > Medium { setBorderStyle(BorderStyle.Thick); setStylePickerOpen(false); }} $checked={borderStyle === BorderStyle.Thick} > Thick { setBorderStyle(BorderStyle.Dotted); setStylePickerOpen(false); }} $checked={borderStyle === BorderStyle.Dotted} > Dotted { setBorderStyle(BorderStyle.Dashed); setStylePickerOpen(false); }} $checked={borderStyle === BorderStyle.Dashed} > Dashed { setBorderStyle(BorderStyle.Dashed); setStylePickerOpen(false); }} $checked={borderStyle === BorderStyle.Double} > Double
); }; type LineWrapperProperties = { $checked: boolean }; const LineWrapper = styled("div")` display: flex; flex-direction: row; align-items: center; background-color: ${({ $checked }): string => { if ($checked) { return "#EEEEEE;"; } return "inherit;"; }}; &:hover { border: 1px solid #eeeeee; } padding: 8px; cursor: pointer; border-radius: 4px; border: 1px solid white; `; const NoneLine = styled("div")` width: 68px; border-top: 1px solid #e0e0e0; `; const SolidLine = styled("div")` width: 68px; border-top: 1px solid #333333; `; const MediumLine = styled("div")` width: 68px; border-top: 2px solid #333333; `; const ThickLine = styled("div")` width: 68px; border-top: 3px solid #333333; `; const DashedLine = styled("div")` width: 68px; border-top: 1px dashed #333333; `; const DottedLine = styled("div")` width: 68px; border-top: 1px dotted #333333; `; const DoubleLine = styled("div")` width: 68px; border-top: 3px double #333333; `; const Divider = styled("div")` display: inline-flex; heigh: 1px; border-bottom: 1px solid #eee; margin-left: 0px; margin-right: 0px; `; const Borders = styled("div")` display: flex; flex-direction: column; padding-bottom: 4px; `; const Styles = styled("div")` display: flex; flex-direction: column; `; const Line = styled("div")` display: flex; flex-direction: row; align-items: center; `; const ButtonWrapper = styled("div")` display: flex; flex-direction: row; align-items: center; &:hover { background-color: #eee; border-top-color: ${(): string => theme.palette.grey["400"]}; } cursor: pointer; padding: 8px; `; const BorderStyleDialog = styled("div")` background: ${({ theme }): string => theme.palette.background.default}; padding: 4px; display: flex; flex-direction: column; align-items: center; `; const StyledPopover = styled(Popover)` .MuiPopover-paper { border-radius: 10px; border: 0px solid ${({ theme }): string => theme.palette.background.default}; box-shadow: 1px 2px 8px rgba(139, 143, 173, 0.5); } .MuiPopover-padding { padding: 0px; } .MuiList-padding { padding: 0px; } font-family: ${({ theme }) => theme.typography.fontFamily}; font-size: 12px; `; const BorderPickerDialog = styled("div")` background: ${({ theme }): string => theme.palette.background.default}; padding: 4px; display: flex; flex-direction: column; `; const BorderDescription = styled("div")` width: 70px; `; type TypeButtonProperties = { $pressed: boolean; $underlinedColor?: string }; const Button = styled("button")( ({ disabled, $pressed, $underlinedColor }) => { const result = { width: "24px", height: "24px", display: "inline-flex", alignItems: "center", justifyContent: "center", // fontSize: "26px", border: "0px solid #fff", borderRadius: "4px", marginRight: "5px", transition: "all 0.2s", cursor: "pointer", padding: "0px", }; if (disabled) { return { ...result, color: theme.palette.grey["600"], cursor: "default", }; } return { ...result, borderTop: $underlinedColor ? "3px solid #FFF" : "none", borderBottom: $underlinedColor ? `3px solid ${$underlinedColor}` : "none", color: "#21243A", backgroundColor: $pressed ? theme.palette.grey["200"] : "inherit", "&:hover": { backgroundColor: "#F1F2F8", borderTopColor: "#F1F2F8", }, svg: { width: "16px", height: "16px", }, }; }, ); const ChevronRightStyled = styled(ChevronRight)` width: 16px; height: 16px; `; export default BorderPicker;