diff --git a/src/components/Connections/ConnectionFormModal.tsx b/src/components/Connections/ConnectionFormModal.tsx index 66eb9c9b7..edf303444 100644 --- a/src/components/Connections/ConnectionFormModal.tsx +++ b/src/components/Connections/ConnectionFormModal.tsx @@ -1,4 +1,4 @@ -import { Tab, Tabs } from "@flanksource-ui/ui/Tabs/Tabs"; +import FlatTabs from "@flanksource-ui/ui/Tabs/FlatTabs"; import React, { useEffect, useState } from "react"; import { Icon } from "../../ui/Icons/Icon"; import { Modal } from "../../ui/Modal"; @@ -128,44 +128,46 @@ export default function ConnectionFormModal({ > {type ? ( formValue?.id ? ( - setActiveTab(label)} - > - - setConnectionType(undefined)} - connectionType={type} - onConnectionSubmit={onConnectionSubmit} - onConnectionDelete={onConnectionDelete} - formValue={formValue} - className={className} - isSubmitting={isSubmitting} - isDeleting={isDeleting} - /> - - - - - - + setActiveTab={(label) => setActiveTab(label)} + tabs={[ + { + label: "Edit", + key: "form", + current: activeTab === "form", + content: ( + setConnectionType(undefined)} + connectionType={type} + onConnectionSubmit={onConnectionSubmit} + onConnectionDelete={onConnectionDelete} + formValue={formValue} + className={className} + isSubmitting={isSubmitting} + isDeleting={isDeleting} + /> + ) + }, + { + label: "Permissions", + key: "permissions", + current: activeTab === "permissions", + content: ( + + ) + } + ]} + /> ) : ( setConnectionType(undefined)} diff --git a/src/components/Playbooks/Settings/PlaybookSpecFormModal.tsx b/src/components/Playbooks/Settings/PlaybookSpecFormModal.tsx index 92f49b47a..c139b9b03 100644 --- a/src/components/Playbooks/Settings/PlaybookSpecFormModal.tsx +++ b/src/components/Playbooks/Settings/PlaybookSpecFormModal.tsx @@ -1,7 +1,7 @@ import { PlaybookSpec } from "@flanksource-ui/api/types/playbooks"; import PermissionsView from "@flanksource-ui/components/Permissions/PermissionsView"; import { Modal } from "@flanksource-ui/ui/Modal"; -import { Tab, Tabs } from "@flanksource-ui/ui/Tabs/Tabs"; +import FlatTabs from "@flanksource-ui/ui/Tabs/FlatTabs"; import { useState } from "react"; import PlaybookSpecModalTitle from "../PlaybookSpecModalTitle"; import PlaybookSpecsForm from "./PlaybookSpecsForm"; @@ -37,35 +37,41 @@ export default function PlaybookSpecFormModal({ helpLink="playbooks" > {playbook?.id ? ( - setActiveTab(label)} - > - - - - - - - - + setActiveTab={(label) => setActiveTab(label)} + tabs={[ + { + label: "Edit Playbook Spec", + key: "form", + current: activeTab === "form", + content: ( + + ) + }, + { + label: "Permissions", + key: "permissions", + current: activeTab === "permissions", + content: ( + + ) + } + ]} + /> ) : ( )} diff --git a/src/ui/Tabs/FlatTabs.stories.tsx b/src/ui/Tabs/FlatTabs.stories.tsx new file mode 100644 index 000000000..bffa058d0 --- /dev/null +++ b/src/ui/Tabs/FlatTabs.stories.tsx @@ -0,0 +1,36 @@ +import { Meta, StoryFn } from "@storybook/react"; +import { useState } from "react"; +import FlatTabs from "./FlatTabs"; + +export default { + title: "ui/FlatTabs", + component: FlatTabs +} satisfies Meta; + +const Template: StoryFn = () => { + const [activeTab, setActiveTab] = useState<"tab1" | "tab2">("tab1"); + + return ( + Tab 1 content + }, + { + label: "Tab 2", + key: "tab2", + current: activeTab === "tab2", + content:
Tab 2 content
+ } + ]} + activeTab={activeTab} + setActiveTab={(t) => setActiveTab(t)} + /> + ); +}; + +export const Default = Template.bind({}); +Default.args = {}; diff --git a/src/ui/Tabs/FlatTabs.tsx b/src/ui/Tabs/FlatTabs.tsx new file mode 100644 index 000000000..1e5c7f433 --- /dev/null +++ b/src/ui/Tabs/FlatTabs.tsx @@ -0,0 +1,61 @@ +import clsx from "clsx"; + +type FlatTabsProps = { + tabs: { + label: string; + key: T; + current: boolean; + content: React.ReactNode; + }[]; + activeTab: string; + setActiveTab: (tab: T) => void; +}; + +export default function FlatTabs({ + tabs, + activeTab, + setActiveTab +}: FlatTabsProps) { + return ( +
+
+ + {/* Use an "onChange" listener to redirect the user to the selected tab URL. */} + +
+
+
+ +
+ {tabs.find((tab) => tab.current)?.content} +
+
+ ); +}