From 642428f8962c95a49dd5d2b2d4ba5aa9966926ab Mon Sep 17 00:00:00 2001 From: Red Adaya Date: Mon, 21 Oct 2024 20:46:37 +0800 Subject: [PATCH] Rename palette to popover --- frontend/app/element/emojipalette.tsx | 16 +++---- .../element/{palette.less => popover.less} | 0 ...alette.stories.tsx => popover.stories.tsx} | 30 ++++++------- .../app/element/{palette.tsx => popover.tsx} | 44 +++++++++---------- 4 files changed, 45 insertions(+), 45 deletions(-) rename frontend/app/element/{palette.less => popover.less} (100%) rename frontend/app/element/{palette.stories.tsx => popover.stories.tsx} (65%) rename frontend/app/element/{palette.tsx => popover.tsx} (69%) diff --git a/frontend/app/element/emojipalette.tsx b/frontend/app/element/emojipalette.tsx index c012285f5..f0bf45bc0 100644 --- a/frontend/app/element/emojipalette.tsx +++ b/frontend/app/element/emojipalette.tsx @@ -6,9 +6,9 @@ import clsx from "clsx"; import { memo, useState } from "react"; import { Button } from "./button"; import { Input, InputGroup, InputLeftElement } from "./input"; -import { Palette, PaletteButton, PaletteContent } from "./palette"; +import { Popover, PopoverButton, PopoverContent } from "./popover"; -import "./emojiPalette.less"; +import "./emojipalette.less"; type EmojiItem = { emoji: string; name: string }; @@ -234,11 +234,11 @@ const EmojiPalette = memo(({ className, placement, onSelect }: EmojiPaletteProps return (
- - + + - - + + @@ -256,8 +256,8 @@ const EmojiPalette = memo(({ className, placement, onSelect }: EmojiPaletteProps
No emojis found
)}
- - + + ); }); diff --git a/frontend/app/element/palette.less b/frontend/app/element/popover.less similarity index 100% rename from frontend/app/element/palette.less rename to frontend/app/element/popover.less diff --git a/frontend/app/element/palette.stories.tsx b/frontend/app/element/popover.stories.tsx similarity index 65% rename from frontend/app/element/palette.stories.tsx rename to frontend/app/element/popover.stories.tsx index deb20b4f7..62f3eee3e 100644 --- a/frontend/app/element/palette.stories.tsx +++ b/frontend/app/element/popover.stories.tsx @@ -2,33 +2,33 @@ // SPDX-License-Identifier: Apache-2.0 import type { Meta, StoryObj } from "@storybook/react"; -import { Palette, PaletteButton, PaletteContent } from "./palette"; +import { Popover, PopoverButton, PopoverContent } from "./popover"; -const meta: Meta = { - title: "Elements/Palette", - component: Palette, +const meta: Meta = { + title: "Elements/Popover", + component: Popover, args: { - className: "custom-palette-class", + className: "custom-popover-class", }, argTypes: { className: { - description: "Custom class for palette styling", + description: "Custom class for popover styling", }, }, }; export default meta; -type Story = StoryObj; +type Story = StoryObj; -export const DefaultPalette: Story = { +export const DefaultPopover: Story = { render: (args) => { return (
- - + + - - + +
Empty
-
-
+ +
); }, args: { - className: "custom-palette-class", + className: "custom-popover-class", }, }; diff --git a/frontend/app/element/palette.tsx b/frontend/app/element/popover.tsx similarity index 69% rename from frontend/app/element/palette.tsx rename to frontend/app/element/popover.tsx index 9c5fe5306..47fdb03cc 100644 --- a/frontend/app/element/palette.tsx +++ b/frontend/app/element/popover.tsx @@ -16,28 +16,28 @@ import { } from "react"; import { Button } from "./button"; -import "./palette.less"; +import "./popover.less"; -interface PaletteProps { +interface PopoverProps { children: ReactNode; className?: string; placement?: Placement; onOpenChange?: (isOpen: boolean) => void; } -const isPaletteButton = ( +const isPopoverButton = ( element: ReactElement -): element is ReactElement> => { - return element.type === PaletteButton; +): element is ReactElement> => { + return element.type === PopoverButton; }; -const isPaletteContent = ( +const isPopoverContent = ( element: ReactElement -): element is ReactElement> => { - return element.type === PaletteContent; +): element is ReactElement> => { + return element.type === PopoverContent; }; -const Palette = memo(({ children, className, placement, onOpenChange }: PaletteProps) => { +const Popover = memo(({ children, className, placement, onOpenChange }: PopoverProps) => { const [isOpen, setIsOpen] = useState(false); const toggleOpen = () => { @@ -56,7 +56,7 @@ const Palette = memo(({ children, className, placement, onOpenChange }: PaletteP const renderChildren = Children.map(children, (child) => { if (isValidElement(child)) { - if (isPaletteButton(child)) { + if (isPopoverButton(child)) { return cloneElement(child as any, { isActive: isOpen, ref: refs.setReference, @@ -65,7 +65,7 @@ const Palette = memo(({ children, className, placement, onOpenChange }: PaletteP }); } - if (isPaletteContent(child)) { + if (isPopoverContent(child)) { return isOpen ? cloneElement(child as any, { ref: refs.setFloating, @@ -81,19 +81,19 @@ const Palette = memo(({ children, className, placement, onOpenChange }: PaletteP return <>{renderChildren}; }); -interface PaletteButtonProps extends React.ButtonHTMLAttributes { +interface PopoverButtonProps extends React.ButtonHTMLAttributes { isActive?: boolean; children: React.ReactNode; onClick?: () => void; getReferenceProps?: () => any; } -const PaletteButton = forwardRef( +const PopoverButton = forwardRef( ({ isActive, children, onClick, getReferenceProps, className, ...props }, ref) => { return (