From eadf6e715579e7f0827f7c053b88987966515cfd Mon Sep 17 00:00:00 2001 From: Bishal Shrestha Date: Fri, 20 Jun 2025 15:47:01 +0545 Subject: [PATCH 01/18] feat: add toolbar actions --- .../demo/src/Views/Ui/components/PageDemo.tsx | 24 +++++++++ packages/ui/src/Page/Header.tsx | 15 +++++- packages/ui/src/Page/ToolbarActions.tsx | 54 +++++++++++++++++++ packages/ui/src/Page/index.tsx | 19 +++++-- packages/ui/src/assets/css/page.css | 3 +- 5 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 packages/ui/src/Page/ToolbarActions.tsx diff --git a/apps/demo/src/Views/Ui/components/PageDemo.tsx b/apps/demo/src/Views/Ui/components/PageDemo.tsx index 7f632fe2c..fd608ff21 100644 --- a/apps/demo/src/Views/Ui/components/PageDemo.tsx +++ b/apps/demo/src/Views/Ui/components/PageDemo.tsx @@ -69,6 +69,30 @@ export const PageDemo = () => { subtitle={} children={PageContent} breadcrumb={breadcrumb} + toolbarActionMenu={{ + actions: [ + { + label: "View", + onClick: () => { + console.log("view action"); + }, + }, + { + label: "Edit", + disabled: true, + onClick: () => { + console.log("edit action"); + }, + }, + { + label: "Delete", + className: "danger", + onClick: () => { + console.log("delete action"); + }, + }, + ], + }} /> ); diff --git a/packages/ui/src/Page/Header.tsx b/packages/ui/src/Page/Header.tsx index 33ec9468c..91b6c1518 100644 --- a/packages/ui/src/Page/Header.tsx +++ b/packages/ui/src/Page/Header.tsx @@ -1,9 +1,14 @@ +import { ToolbarActions } from "./ToolbarActions"; + +import type { ToolbarActionsMenuProperties } from "./ToolbarActions"; + interface IHeaderProperties { breadcrumb?: React.ReactNode; - titleTag?: string | React.ReactNode; subtitle?: React.ReactNode | string; - toolbar?: React.ReactNode; title?: string | React.ReactNode; + titleTag?: string | React.ReactNode; + toolbar?: React.ReactNode; + toolbarActionMenu?: ToolbarActionsMenuProperties; } export const PageHeader = ({ @@ -12,6 +17,7 @@ export const PageHeader = ({ subtitle, toolbar, title, + toolbarActionMenu, }: IHeaderProperties) => { const renderTitle = () => { if (!title) return null; @@ -48,6 +54,11 @@ export const PageHeader = ({ {toolbar} )} + {toolbarActionMenu && ( +
+ +
+ )} ); }; diff --git a/packages/ui/src/Page/ToolbarActions.tsx b/packages/ui/src/Page/ToolbarActions.tsx new file mode 100644 index 000000000..996988092 --- /dev/null +++ b/packages/ui/src/Page/ToolbarActions.tsx @@ -0,0 +1,54 @@ +import React, { useState } from "react"; + +import { Button, DropdownMenu, MenuItem } from ".."; +import { ConfirmationModal, IModalProperties } from "../ConfirmationModal"; + +export interface ActionsMenuItem extends MenuItem { + requireConfirmationModal?: boolean; +} + +export interface ToolbarActionsMenuProperties { + actions?: ActionsMenuItem[]; +} + +export const ToolbarActions = ({ actions }: ToolbarActionsMenuProperties) => { + const [confirmation, setConfirmation] = useState(); + + const renderActions = () => { + if (!actions || !actions.length) { + return null; + } + + const { icon, label, onClick, disabled, ...rest } = actions[0]; + + if (actions.length == 1 && icon) { + return ( +