-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: switch to flat tabs for permission view in modals
Update src/components/Connections/ConnectionFormModal.tsx Co-authored-by: Moshe Immerman <[email protected]>
- Loading branch information
1 parent
1349551
commit 4e131ea
Showing
4 changed files
with
172 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<typeof FlatTabs>; | ||
|
||
const Template: StoryFn<typeof FlatTabs> = () => { | ||
const [activeTab, setActiveTab] = useState<"tab1" | "tab2">("tab1"); | ||
|
||
return ( | ||
<FlatTabs | ||
tabs={[ | ||
{ | ||
label: "Tab 1", | ||
key: "tab1", | ||
current: activeTab === "tab1", | ||
content: <div>Tab 1 content</div> | ||
}, | ||
{ | ||
label: "Tab 2", | ||
key: "tab2", | ||
current: activeTab === "tab2", | ||
content: <div>Tab 2 content</div> | ||
} | ||
]} | ||
activeTab={activeTab} | ||
setActiveTab={(t) => setActiveTab(t)} | ||
/> | ||
); | ||
}; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import clsx from "clsx"; | ||
|
||
type FlatTabsProps<T extends string> = { | ||
tabs: { | ||
label: string; | ||
key: T; | ||
current: boolean; | ||
content: React.ReactNode; | ||
}[]; | ||
activeTab: string; | ||
setActiveTab: (tab: T) => void; | ||
}; | ||
|
||
export default function FlatTabs<T extends string>({ | ||
tabs, | ||
activeTab, | ||
setActiveTab | ||
}: FlatTabsProps<T>) { | ||
return ( | ||
<div className="flex flex-1 flex-col"> | ||
<div className="sm:hidden"> | ||
<label htmlFor="tabs" className="sr-only"> | ||
Select a tab | ||
</label> | ||
{/* Use an "onChange" listener to redirect the user to the selected tab URL. */} | ||
<select | ||
id="tabs" | ||
name="tabs" | ||
defaultValue={activeTab} | ||
className="block w-full rounded-md border-gray-300 focus:border-indigo-500 focus:ring-indigo-500" | ||
> | ||
{tabs.map((tab) => ( | ||
<option key={tab.label}>{tab.label}</option> | ||
))} | ||
</select> | ||
</div> | ||
<div className="hidden flex-1 flex-col sm:flex"> | ||
<div className="border-b border-gray-200"> | ||
<nav aria-label="Tabs" className="-mb-px flex space-x-8"> | ||
{tabs.map((tab) => ( | ||
<button | ||
key={tab.label} | ||
onClick={() => setActiveTab(tab.key)} | ||
aria-current={tab.current ? "page" : undefined} | ||
className={clsx( | ||
tab.current | ||
? "border-indigo-500 text-indigo-600" | ||
: "border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700", | ||
"group inline-flex items-center border-b-2 px-2 py-4 text-sm font-medium" | ||
)} | ||
> | ||
<span>{tab.label}</span> | ||
</button> | ||
))} | ||
</nav> | ||
</div> | ||
{tabs.find((tab) => tab.current)?.content} | ||
</div> | ||
</div> | ||
); | ||
} |