-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ #19 - feat: Implemented the Tabs component
- Loading branch information
Showing
7 changed files
with
185 additions
and
4 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 @@ | ||
export * from "./tabs"; |
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,49 @@ | ||
@use "../../settings/constants"; | ||
|
||
.mykn-tabs { | ||
&__buttons { | ||
background-color: var(--theme-shade-50); | ||
border: 1px solid var(--theme-shade-100); | ||
width: fit-content; | ||
display: flex; | ||
align-items: center; | ||
gap: 17px; | ||
padding: 6px 40px; | ||
border-radius: var(--border-radus-s); | ||
flex-wrap: wrap; | ||
} | ||
|
||
&__button { | ||
&--active { | ||
background-color: var(--theme-color-primary-100); | ||
color: var(--theme-color-primary-800); | ||
} | ||
} | ||
|
||
.mykn-button { | ||
&--variant-transparent { | ||
&:hover { | ||
background-color: var(--theme-color-primary-100); | ||
color: var(--theme-color-primary-800); | ||
} | ||
} | ||
} | ||
|
||
.mykn-p { | ||
color: var(--theme-shade-200); | ||
} | ||
|
||
&__content { | ||
margin-top: 16px; | ||
} | ||
|
||
@media screen and (max-width: constants.$breakpoint-desktop) { | ||
&__buttons { | ||
justify-content: center; | ||
} | ||
|
||
.mykn-p { | ||
display: none; | ||
} | ||
} | ||
} |
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,54 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import React from "react"; | ||
|
||
import { Card } from "../card"; | ||
import { Page } from "../page"; | ||
import { Tabs } from "./tabs"; | ||
|
||
const meta = { | ||
title: "Controls/Tabs", | ||
component: Tabs, | ||
decorators: [ | ||
(Story) => ( | ||
<Page> | ||
<Story /> | ||
</Page> | ||
), | ||
], | ||
} satisfies Meta<typeof Tabs>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
const defaultArgs: Story = { | ||
args: { | ||
tabs: [ | ||
{ | ||
label: "Structuur", | ||
content: <span>Content for tab one</span>, | ||
}, | ||
{ label: "Basis", content: "Tab 2 content" }, | ||
{ label: "Statussen", content: "Tab 3 content" }, | ||
{ label: "Documenten", content: "Tab 4 content" }, | ||
{ label: "Rollen", content: "Tab 5 content" }, | ||
{ label: "Eigenschappen", content: "Tab 6 content" }, | ||
], | ||
}, | ||
}; | ||
|
||
export const TabsComponent: Story = { | ||
...defaultArgs, | ||
}; | ||
|
||
export const TabsComponentInCard: Story = { | ||
...defaultArgs, | ||
decorators: [ | ||
(Story) => ( | ||
<Page> | ||
<Card> | ||
<Story /> | ||
</Card> | ||
</Page> | ||
), | ||
], | ||
}; |
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,62 @@ | ||
import clsx from "clsx"; | ||
import React, { useState } from "react"; | ||
|
||
import { Button } from "../button"; | ||
import { Toolbar, ToolbarProps } from "../toolbar"; | ||
import { P } from "../typography"; | ||
import "./tabs.scss"; | ||
|
||
export type TabProps = { | ||
label: string; | ||
content: React.ReactNode; | ||
}; | ||
|
||
export type TabsProps = React.PropsWithChildren< | ||
{ | ||
tabs: TabProps[]; | ||
onTabChange?: (activeTabIndex: number) => void; | ||
} & ToolbarProps | ||
>; | ||
|
||
/** | ||
* A tabs component meant to allow for cycling through different content sections. Allows for passing custom react nodes as content for each tab. | ||
* @param tabs | ||
* @param onTabChange | ||
* @param props | ||
* @constructor | ||
*/ | ||
export const Tabs: React.FC<TabsProps> = ({ | ||
onTabChange, | ||
tabs, | ||
className, | ||
...props | ||
}) => { | ||
const [activeTab, setActiveTab] = useState(0); | ||
|
||
const handleTabClick = (index: number) => { | ||
setActiveTab(index); | ||
onTabChange && onTabChange(index); | ||
}; | ||
|
||
return ( | ||
<Toolbar className={clsx("mykn-tabs", className)} {...props}> | ||
<div className="mykn-tabs__buttons"> | ||
{tabs.map((tab, index) => ( | ||
<React.Fragment key={index}> | ||
<Button | ||
variant="transparent" | ||
className={clsx("mykn-tabs__button", { | ||
"mykn-tabs__button--active": activeTab === index, | ||
})} | ||
onClick={() => handleTabClick(index)} | ||
> | ||
{tab.label} | ||
</Button> | ||
{index < tabs.length - 1 && <P>|</P>} | ||
</React.Fragment> | ||
))} | ||
</div> | ||
<div className="mykn-tabs__content">{tabs[activeTab].content}</div> | ||
</Toolbar> | ||
); | ||
}; |
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