From ee0eaac8855ba4ad6ec5d6e7fd09977378dbe37f Mon Sep 17 00:00:00 2001 From: Rohit <120627552+Rohitgautam02@users.noreply.github.com> Date: Mon, 9 Feb 2026 08:01:42 +0000 Subject: [PATCH] [CommandPalette] Add Storybook stories --- .../commandPalette/commandPalette.stories.tsx | 344 ++++++++++++++++++ 1 file changed, 344 insertions(+) create mode 100644 packages/frappe-ui-react/src/components/commandPalette/commandPalette.stories.tsx diff --git a/packages/frappe-ui-react/src/components/commandPalette/commandPalette.stories.tsx b/packages/frappe-ui-react/src/components/commandPalette/commandPalette.stories.tsx new file mode 100644 index 00000000..6749f128 --- /dev/null +++ b/packages/frappe-ui-react/src/components/commandPalette/commandPalette.stories.tsx @@ -0,0 +1,344 @@ +import { useState } from "react"; +import type { Meta, StoryObj } from "@storybook/react-vite"; +import { action } from "storybook/actions"; +import { + Home, + Settings, + Users, + FileText, + Search, + Mail, + Calendar, + BarChart, +} from "lucide-react"; + +import { CommandPalette } from "./commandPalette"; +import { Button } from "../button"; +import type { CommandPaletteGroup } from "./types"; + +const filterGroups = ( + groups: CommandPaletteGroup[], + query: string +): CommandPaletteGroup[] => + groups + .map((group) => ({ + ...group, + items: group.items.filter((item) => + item.title.toLowerCase().includes(query.toLowerCase()) + ), + })) + .filter((group) => group.items.length > 0); + +const handleSelect = action("onSelect"); + +const meta: Meta = { + title: "Components/CommandPalette", + component: CommandPalette, + parameters: { + docs: { source: { type: "dynamic" } }, + layout: "centered", + }, + tags: ["autodocs"], + argTypes: { + show: { + control: "boolean", + description: "Controls whether the command palette is visible.", + }, + onShowChange: { + description: + "Callback function called when the visibility state changes.", + }, + searchQuery: { + control: "text", + description: "The current search query string.", + }, + onSearchQueryChange: { + description: "Callback function called when the search query changes.", + }, + groups: { + control: "object", + description: + "Array of groups, each containing a title and an array of items to display.", + }, + onSelect: { + description: + "Callback function called when an item is selected from the palette.", + }, + }, +}; + +export default meta; +type Story = StoryObj; + +const navigationItems: CommandPaletteGroup[] = [ + { + title: "Navigation", + items: [ + { + name: "home", + title: "Home", + description: "Go to homepage", + icon: Home, + }, + { + name: "settings", + title: "Settings", + description: "App settings", + icon: Settings, + }, + { + name: "users", + title: "Users", + description: "Manage users", + icon: Users, + }, + { + name: "documents", + title: "Documents", + description: "View documents", + icon: FileText, + }, + ], + }, +]; + +const multiGroupItems: CommandPaletteGroup[] = [ + { + title: "Pages", + items: [ + { + name: "home", + title: "Home", + description: "Go to homepage", + icon: Home, + }, + { + name: "reports", + title: "Reports", + description: "View reports", + icon: BarChart, + }, + ], + }, + { + title: "Actions", + items: [ + { + name: "search", + title: "Search", + description: "Search everything", + icon: Search, + }, + { + name: "send-email", + title: "Send Email", + description: "Compose new email", + icon: Mail, + }, + { + name: "calendar", + title: "Open Calendar", + description: "View calendar", + icon: Calendar, + }, + ], + }, + { + title: "Settings", + items: [ + { + name: "settings", + title: "Settings", + description: "App settings", + icon: Settings, + }, + { + name: "users", + title: "Users", + description: "Manage users", + icon: Users, + }, + ], + }, +]; + +const itemsWithDisabled: CommandPaletteGroup[] = [ + { + title: "Actions", + items: [ + { + name: "home", + title: "Home", + description: "Go to homepage", + icon: Home, + }, + { + name: "settings", + title: "Settings", + description: "Requires admin access", + icon: Settings, + disabled: true, + }, + { + name: "users", + title: "Users", + description: "Manage users", + icon: Users, + }, + { + name: "reports", + title: "Reports", + description: "Feature coming soon", + icon: BarChart, + disabled: true, + }, + ], + }, +]; + +export const Default: Story = { + render: () => { + const [show, setShow] = useState(false); + const [searchQuery, setSearchQuery] = useState(""); + + return ( +
+ + +
+ ); + }, +}; + +export const MultipleGroups: Story = { + render: () => { + const [show, setShow] = useState(false); + const [searchQuery, setSearchQuery] = useState(""); + + return ( +
+ + +
+ ); + }, +}; + +export const WithDisabledItems: Story = { + render: () => { + const [show, setShow] = useState(false); + const [searchQuery, setSearchQuery] = useState(""); + + return ( +
+ + +
+ ); + }, +}; + +const hiddenTitleGroups: CommandPaletteGroup[] = [ + { + title: "Quick Actions", + hideTitle: true, + items: [ + { + name: "home", + title: "Home", + description: "Go to homepage", + icon: Home, + }, + { + name: "search", + title: "Search", + description: "Search everything", + icon: Search, + }, + { + name: "settings", + title: "Settings", + description: "App settings", + icon: Settings, + }, + ], + }, +]; + +export const HiddenGroupTitle: Story = { + render: () => { + const [show, setShow] = useState(false); + const [searchQuery, setSearchQuery] = useState(""); + + return ( +
+ + +
+ ); + }, +}; + +export const KeyboardShortcut: Story = { + render: () => { + const [show, setShow] = useState(false); + const [searchQuery, setSearchQuery] = useState(""); + + return ( +
+

+ Press{" "} + + Ctrl/Cmd + {" "} + +{" "} + + K + {" "} + to open the command palette +

+ + +
+ ); + }, +};