Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed the Tabs attribute from style to variant #1405

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/web/content/docs/components/tabs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Additionally, if you pass the `disabled` prop to the `<Tabs.Item>` component, it

## Tabs with underline

Pass the `style="underline"` prop to the `<Tabs>` component to make the tabs have an underline style.
Pass the `variant="underline"` prop to the `<Tabs>` component to make the tabs have an underline style.

<Example name="tabs.withUnderline" />

Expand All @@ -37,13 +37,13 @@ Pass the `icon` prop to the `<Tabs.Item>` component to add an icon to the tab it

## Tabs with pills

Add the `style="pills"` prop to the `<Tabs>` component to make the tabs have a pills style with rounded corners as an alternative style.
Add the `variant="pills"` prop to the `<Tabs>` component to make the tabs have a pills style with rounded corners as an alternative style.

<Example name="tabs.withPills" />

## Full width tabs

Make the tabs span the full width of their container, pass the `style="fullWidth"` prop to the `<Tabs>`
Make the tabs span the full width of their container, pass the `variant="fullWidth"` prop to the `<Tabs>`

<Example name="tabs.fullWidth" />

Expand Down
4 changes: 2 additions & 2 deletions apps/web/examples/tabs/tabs.fullWidth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { MdDashboard } from "react-icons/md";
export function Component() {
return (
<div className="overflow-x-auto">
<Tabs aria-label="Full width tabs" style="fullWidth">
<Tabs aria-label="Full width tabs" variant="fullWidth">
<Tabs.Item active title="Profile" icon={HiUserCircle}>
This is <span className="font-medium text-gray-800 dark:text-white">Profile tab's associated content</span>.
Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to
Expand Down Expand Up @@ -46,7 +46,7 @@ export function Component() {
export function Component() {
return (
<div className="overflow-x-auto">
<Tabs aria-label="Full width tabs" style="fullWidth">
<Tabs aria-label="Full width tabs" variant="fullWidth">
<Tabs.Item active title="Profile" icon={HiUserCircle}>
This is <span className="font-medium text-gray-800 dark:text-white">Profile tab's associated content</span>.
Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to
Expand Down
4 changes: 2 additions & 2 deletions apps/web/examples/tabs/tabs.root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MdDashboard } from "react-icons/md";

export function Component() {
return (
<Tabs aria-label="Default tabs" style="default">
<Tabs aria-label="Default tabs" variant="default">
<Tabs.Item active title="Profile" icon={HiUserCircle}>
This is <span className="font-medium text-gray-800 dark:text-white">Profile tab's associated content</span>.
Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to
Expand Down Expand Up @@ -43,7 +43,7 @@ export function Component() {

export function Component() {
return (
<Tabs aria-label="Default tabs" style="default">
<Tabs aria-label="Default tabs" variant="default">
<Tabs.Item active title="Profile" icon={HiUserCircle}>
This is <span className="font-medium text-gray-800 dark:text-white">Profile tab's associated content</span>.
Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to
Expand Down
4 changes: 2 additions & 2 deletions apps/web/examples/tabs/tabs.stateOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function Component() {

return (
<div className="flex flex-col gap-3">
<Tabs aria-label="Default tabs" style="default" ref={tabsRef} onActiveTabChange={(tab) => setActiveTab(tab)}>
<Tabs aria-label="Default tabs" variant="default" ref={tabsRef} onActiveTabChange={(tab) => setActiveTab(tab)}>
<Tabs.Item active title="Profile" icon={HiUserCircle}>
This is <span className="font-medium text-gray-800 dark:text-white">Profile tab's associated content</span>.
Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to
Expand Down Expand Up @@ -71,7 +71,7 @@ export function Component() {

return (
<div className="flex flex-col gap-3">
<Tabs aria-label="Default tabs" style="default" ref={tabsRef} onActiveTabChange={(tab) => setActiveTab(tab)}>
<Tabs aria-label="Default tabs" variant="default" ref={tabsRef} onActiveTabChange={(tab) => setActiveTab(tab)}>
<Tabs.Item active title="Profile" icon={HiUserCircle}>
This is <span className="font-medium text-gray-800 dark:text-white">Profile tab's associated content</span>.
Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to
Expand Down
4 changes: 2 additions & 2 deletions apps/web/examples/tabs/tabs.withIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MdDashboard } from "react-icons/md";

export function Component() {
return (
<Tabs aria-label="Tabs with icons" style="underline">
<Tabs aria-label="Tabs with icons" variant="underline">
<Tabs.Item active title="Profile" icon={HiUserCircle}>
This is <span className="font-medium text-gray-800 dark:text-white">Profile tab's associated content</span>.
Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to
Expand Down Expand Up @@ -43,7 +43,7 @@ export function Component() {

export function Component() {
return (
<Tabs aria-label="Tabs with icons" style="underline">
<Tabs aria-label="Tabs with icons" variant="underline">
<Tabs.Item active title="Profile" icon={HiUserCircle}>
This is <span className="font-medium text-gray-800 dark:text-white">Profile tab's associated content</span>.
Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to
Expand Down
4 changes: 2 additions & 2 deletions apps/web/examples/tabs/tabs.withPills.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Tabs } from "flowbite-react";

export function Component() {
return (
<Tabs aria-label="Pills" style="pills">
<Tabs aria-label="Pills" variant="pills">
<Tabs.Item active title="Tab 1">
<p className="text-sm text-gray-500 dark:text-gray-400">Content 1</p>
</Tabs.Item>
Expand All @@ -31,7 +31,7 @@ export function Component() {

export function Component() {
return (
<Tabs aria-label="Pills" style="pills">
<Tabs aria-label="Pills" variant="pills">
<Tabs.Item active title="Tab 1">
<p className="text-sm text-gray-500 dark:text-gray-400">Content 1</p>
</Tabs.Item>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/examples/tabs/tabs.withUnderline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MdDashboard } from "react-icons/md";

export function Component() {
return (
<Tabs aria-label="Tabs with underline" style="underline">
<Tabs aria-label="Tabs with underline" variant="underline">
<Tabs.Item active title="Profile" icon={HiUserCircle}>
This is <span className="font-medium text-gray-800 dark:text-white">Profile tab's associated content</span>.
Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to
Expand Down Expand Up @@ -43,7 +43,7 @@ export function Component() {

export function Component() {
return (
<Tabs aria-label="Tabs with underline" style="underline">
<Tabs aria-label="Tabs with underline" variant="underline">
<Tabs.Item active title="Profile" icon={HiUserCircle}>
This is <span className="font-medium text-gray-800 dark:text-white">Profile tab's associated content</span>.
Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to
Expand Down
10 changes: 5 additions & 5 deletions packages/ui/src/components/Tabs/Tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
className: {
control: "text",
},
style: {
variant: {
control: "radio",
options: ["default", "underline", "pills", "fullWidth"],
},
Expand Down Expand Up @@ -45,7 +45,7 @@ export const WithUnderline = (args: TabsProps): JSX.Element => (
</Tabs>
);
WithUnderline.args = {
style: "underline",
variant: "underline",
};
WithUnderline.storyName = "With underline";

Expand All @@ -69,7 +69,7 @@ export const WithIcons = (args: TabsProps): JSX.Element => (
</Tabs>
);
WithIcons.args = {
style: "underline",
variant: "underline",
};
WithIcons.storyName = "With icons";

Expand All @@ -85,7 +85,7 @@ export const Pills = (args: TabsProps): JSX.Element => (
</Tabs>
);
Pills.args = {
style: "pills",
variant: "pills",
};

export const FullWidth = (args: TabsProps): JSX.Element => (
Expand All @@ -100,6 +100,6 @@ export const FullWidth = (args: TabsProps): JSX.Element => (
</Tabs>
);
FullWidth.args = {
style: "fullWidth",
variant: "fullWidth",
};
FullWidth.storyName = "Full width";
18 changes: 9 additions & 9 deletions packages/ui/src/components/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ export interface FlowbiteTabsTheme {
base: string;
tablist: {
base: string;
styles: TabStyles;
variant: TabStyles;
tabitem: {
base: string;
styles: TabStyleItem<TabStyles>;
variant: TabStyleItem<TabStyles>;
icon: string;
};
};
tabitemcontainer: {
base: string;
styles: TabStyles;
variant: TabStyles;
};
tabpanel: string;
}
Expand Down Expand Up @@ -54,9 +54,9 @@ interface TabKeyboardEventProps extends TabEventProps {
event: KeyboardEvent<HTMLButtonElement>;
}

export interface TabsProps extends Omit<ComponentProps<"div">, "ref" | "style"> {
export interface TabsProps extends Omit<ComponentProps<"div">, "ref"> {
onActiveTabChange?: (activeTab: number) => void;
style?: keyof TabStyles;
variant?: keyof TabStyles;
theme?: DeepPartial<FlowbiteTabsTheme>;
}

Expand All @@ -66,7 +66,7 @@ export interface TabsRef {

const TabsComponent = forwardRef<TabsRef, TabsProps>(
(
{ children, className, onActiveTabChange, style = "default", theme: customTheme = {}, ...props },
{ children, className, onActiveTabChange, variant = "default", theme: customTheme = {}, ...props },
ref: ForwardedRef<TabsRef>,
) => {
const theme = mergeDeep(getTheme().tabs, customTheme);
Expand Down Expand Up @@ -114,8 +114,8 @@ const TabsComponent = forwardRef<TabsRef, TabsProps>(
}
};

const tabItemStyle = theme.tablist.tabitem.styles[style];
const tabItemContainerStyle = theme.tabitemcontainer.styles[style];
const tabItemStyle = theme.tablist.tabitem.variant[variant];
const tabItemContainerStyle = theme.tabitemcontainer.variant[variant];

useEffect(() => {
tabRefs.current[focusedTab]?.focus();
Expand All @@ -130,7 +130,7 @@ const TabsComponent = forwardRef<TabsRef, TabsProps>(
<div
aria-label="Tabs"
role="tablist"
className={twMerge(theme.tablist.base, theme.tablist.styles[style], className)}
className={twMerge(theme.tablist.base, theme.tablist.variant[variant], className)}
{...props}
>
{tabs.map((tab, index) => (
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/components/Tabs/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const tabTheme: FlowbiteTabsTheme = createTheme({
base: "flex flex-col gap-2",
tablist: {
base: "flex text-center",
styles: {
variant: {
default: "flex-wrap border-b border-gray-200 dark:border-gray-700",
underline: "-mb-px flex-wrap border-b border-gray-200 dark:border-gray-700",
pills: "flex-wrap space-x-2 text-sm font-medium text-gray-500 dark:text-gray-400",
Expand All @@ -14,7 +14,7 @@ export const tabTheme: FlowbiteTabsTheme = createTheme({
},
tabitem: {
base: "flex items-center justify-center rounded-t-lg p-4 text-sm font-medium first:ml-0 focus:outline-none focus:ring-4 focus:ring-cyan-300 disabled:cursor-not-allowed disabled:text-gray-400 disabled:dark:text-gray-500",
styles: {
variant: {
default: {
base: "rounded-t-lg",
active: {
Expand Down Expand Up @@ -49,7 +49,7 @@ export const tabTheme: FlowbiteTabsTheme = createTheme({
},
tabitemcontainer: {
base: "",
styles: {
variant: {
default: "",
underline: "",
pills: "",
Expand Down
Loading