Skip to content

Commit

Permalink
RSC - patches (#1075)
Browse files Browse the repository at this point in the history
* fix: add `'use client'` to `Banner.CollapseButton` due to having event handlers

* fix: add `'use client'` to `Sidebar` due to having context

* fix: add `'use client'` to `SidebarItemGroup` due to having context

* fix: add support for individual import since compound components do not work in server components

* fix: tests + imports of deprecated `Tabs.Group` compound component; update docs

---------

Co-authored-by: Sebastian Sutu <[email protected]>
  • Loading branch information
SutuSebastian and Sebastian Sutu authored Oct 19, 2023
1 parent cac6148 commit 2e1202c
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 70 deletions.
36 changes: 18 additions & 18 deletions app/docs/components/tabs/tabs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Tabs } from 'flowbite-react';

## Default tabs

Add the `<Tabs.Item>` child component to the `<Tabs.Group>` component to create a tab item and you can add any type of markup and React components inside of it and it will be shown when clicking on the associated tab item.
Add the `<Tabs.Item>` child component to the `<Tabs>` component to create a tab item and you can add any type of markup and React components inside of it and it will be shown when clicking on the associated tab item.

You can also choose to add the `active` prop to the `<Tabs.Item>` component to make it active by default and set the title of the tab item using the `title` prop.

Expand All @@ -33,7 +33,7 @@ import { MdDashboard } from 'react-icons/md';"
importFlowbiteReact="Tabs"
title="Default tabs"
>
<Tabs.Group aria-label="Default tabs" style="default">
<Tabs aria-label="Default tabs" style="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 All @@ -57,12 +57,12 @@ import { MdDashboard } from 'react-icons/md';"
<Tabs.Item disabled title="Disabled">
Disabled content
</Tabs.Item>
</Tabs.Group>
</Tabs>
</CodePreview>

## Tabs with underline

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

<CodePreview
githubPage="Tab/Tabs"
Expand All @@ -71,7 +71,7 @@ import { MdDashboard } from 'react-icons/md';"
importFlowbiteReact="Tabs"
title="Tabs with underline"
>
<Tabs.Group aria-label="Tabs with underline" style="underline">
<Tabs aria-label="Tabs with underline" style="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 All @@ -95,7 +95,7 @@ import { MdDashboard } from 'react-icons/md';"
<Tabs.Item disabled title="Disabled">
Disabled content
</Tabs.Item>
</Tabs.Group>
</Tabs>
</CodePreview>

## Tabs with icons
Expand All @@ -109,7 +109,7 @@ import { MdDashboard } from 'react-icons/md';"
importFlowbiteReact="Tabs"
title="Tabs with icons"
>
<Tabs.Group aria-label="Tabs with icons" style="underline">
<Tabs aria-label="Tabs with icons" style="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 All @@ -133,15 +133,15 @@ import { MdDashboard } from 'react-icons/md';"
<Tabs.Item disabled title="Disabled">
Disabled content
</Tabs.Item>
</Tabs.Group>
</Tabs>
</CodePreview>

## Tabs with pills

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

<CodePreview githubPage="Tab/Tabs" importFlowbiteReact="Tabs" title="Pills tabs">
<Tabs.Group aria-label="Pills" style="pills">
<Tabs aria-label="Pills" style="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 @@ -157,12 +157,12 @@ Add the `style="pills"` prop to the `<Tabs.Group>` component to make the tabs ha
<Tabs.Item disabled title="Tab 5">
<p className="text-sm text-gray-500 dark:text-gray-400">Content 5</p>
</Tabs.Item>
</Tabs.Group>
</Tabs>
</CodePreview>

## Full width tabs

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

<CodePreview
githubPage="Tab/Tabs"
Expand All @@ -171,7 +171,7 @@ import { MdDashboard } from 'react-icons/md';"
importFlowbiteReact="Tabs"
title="Full width tabs"
>
<Tabs.Group aria-label="Full width tabs" style="fullWidth">
<Tabs aria-label="Full width tabs" style="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 All @@ -195,15 +195,15 @@ import { MdDashboard } from 'react-icons/md';"
<Tabs.Item disabled title="Disabled">
Disabled content
</Tabs.Item>
</Tabs.Group>
</Tabs>
</CodePreview>

## React state options

Here's an example on how you can set the activate tab programatically using the React state variables and functions of `activateTab` and `setActivateTab`.

<CodePreview
code={`<Tabs.Group
code={`<Tabs
aria-label="Default tabs"
style="default"
ref={props.tabsRef}
Expand Down Expand Up @@ -232,7 +232,7 @@ Here's an example on how you can set the activate tab programatically using the
<Tabs.Item disabled title="Disabled">
Disabled content
</Tabs.Item>
</Tabs.Group>
</Tabs>
<div className="pb-4 pt-2 text-sm text-gray-500 dark:text-gray-400">Active tab: {props.activeTab}</div>
<Button.Group>
<Button color="gray" onClick={() => props.tabsRef.current?.setActiveTab(0)}>
Expand All @@ -259,7 +259,7 @@ import { MdDashboard } from 'react-icons/md';"
importFlowbiteReact="Button, Tabs, type TabsRef"
title="Set active tab programmatically"
>
<Tabs.Group
<Tabs
aria-label="Default tabs"
style="default"
ref={props.tabsRef}
Expand Down Expand Up @@ -288,7 +288,7 @@ import { MdDashboard } from 'react-icons/md';"
<Tabs.Item disabled title="Disabled">
Disabled content
</Tabs.Item>
</Tabs.Group>
</Tabs>
<div className="pb-4 pt-2 text-sm text-gray-500 dark:text-gray-400">Active tab: {props.activeTab}</div>
<Button.Group>
<Button color="gray" onClick={() => props.tabsRef.current?.setActiveTab(0)}>
Expand Down
5 changes: 3 additions & 2 deletions src/components/Accordion/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './Accordion';
export type { AccordionPanelProps } from './AccordionPanel';
export type { AccordionTitleProps } from './AccordionTitle';
export * from './AccordionContent';
export * from './AccordionPanel';
export * from './AccordionTitle';
2 changes: 2 additions & 0 deletions src/components/Banner/BannerCollapseButton.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import type { FC, MouseEventHandler } from 'react';
import type { ButtonProps } from '../Button';
import { Button } from '../Button';
Expand Down
4 changes: 1 addition & 3 deletions src/components/Datepicker/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import { WeekStart } from './helpers';

export * from './Datepicker';
export { WeekStart };
export { WeekStart } from './helpers';
4 changes: 3 additions & 1 deletion src/components/Dropdown/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './Dropdown';
export type { DropdownItemProps } from './DropdownItem';
export * from './DropdownDivider';
export * from './DropdownHeader';
export * from './DropdownItem';
8 changes: 4 additions & 4 deletions src/components/Navbar/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './Navbar';
export type { NavbarBrandProps } from './NavbarBrand';
export type { NavbarCollapseProps } from './NavbarCollapse';
export type { NavbarLinkProps } from './NavbarLink';
export type { NavbarToggleProps } from './NavbarToggle';
export * from './NavbarBrand';
export * from './NavbarCollapse';
export * from './NavbarLink';
export * from './NavbarToggle';
4 changes: 2 additions & 2 deletions src/components/Rating/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './Rating';
export type { RatingAdvancedProps } from './RatingAdvanced';
export type { RatingStarProps } from './RatingStar';
export * from './RatingAdvanced';
export * from './RatingStar';
2 changes: 2 additions & 0 deletions src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import type { ComponentProps, ElementType, FC, PropsWithChildren } from 'react';
import { twMerge } from 'tailwind-merge';
import { mergeDeep } from '../../helpers/merge-deep';
Expand Down
2 changes: 2 additions & 0 deletions src/components/Sidebar/SidebarItemGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import type { ComponentProps, FC, PropsWithChildren } from 'react';
import { twMerge } from 'tailwind-merge';
import { getTheme } from '../../theme-store';
Expand Down
10 changes: 6 additions & 4 deletions src/components/Sidebar/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export * from './Sidebar';
export type { SidebarCTAProps } from './SidebarCTA';
export type { SidebarCollapseProps } from './SidebarCollapse';
export type { SidebarItemProps } from './SidebarItem';
export type { SidebarLogoProps } from './SidebarLogo';
export * from './SidebarCTA';
export * from './SidebarCollapse';
export * from './SidebarItem';
export * from './SidebarItemGroup';
export * from './SidebarItems';
export * from './SidebarLogo';
16 changes: 8 additions & 8 deletions src/components/Tab/Tabs.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ interface TestTabsProps {

// eslint-disable-next-line react/display-name
const TestTabs = forwardRef<TabsRef, TestTabsProps>(({ onActiveTabChange }, ref) => (
<Tabs.Group aria-label="Test tabs" onActiveTabChange={onActiveTabChange} ref={ref}>
<Tabs aria-label="Test tabs" onActiveTabChange={onActiveTabChange} ref={ref}>
<Tabs.Item title="Profile" icon={HiUserCircle}>
Profile content
</Tabs.Item>
Expand All @@ -171,22 +171,22 @@ const TestTabs = forwardRef<TabsRef, TestTabsProps>(({ onActiveTabChange }, ref)
<Tabs.Item disabled title="Disabled">
Disabled content
</Tabs.Item>
</Tabs.Group>
</Tabs>
));

// eslint-disable-next-line react/display-name
const TestConditionalTabs = forwardRef<TabsRef, TestTabsProps>(({ condition }) => (
<Tabs.Group aria-label="Test tabs">
<Tabs aria-label="Test tabs">
{condition && (
<Tabs.Item title="Profile" icon={HiUserCircle}>
Profile content
</Tabs.Item>
)}
</Tabs.Group>
</Tabs>
));

const TestTabsDifferentActiveItem: FC = () => (
<Tabs.Group aria-label="Test tabs">
<Tabs aria-label="Test tabs">
<Tabs.Item title="Profile" icon={HiUserCircle}>
Profile content
</Tabs.Item>
Expand All @@ -202,11 +202,11 @@ const TestTabsDifferentActiveItem: FC = () => (
<Tabs.Item disabled title="Disabled">
Disabled content
</Tabs.Item>
</Tabs.Group>
</Tabs>
);

const TestTabsLastActiveItem: FC = () => (
<Tabs.Group aria-label="Test tabs">
<Tabs aria-label="Test tabs">
<Tabs.Item title="Profile" icon={HiUserCircle}>
Profile content
</Tabs.Item>
Expand All @@ -222,7 +222,7 @@ const TestTabsLastActiveItem: FC = () => (
<Tabs.Item active title="Still working">
Completely functional content
</Tabs.Item>
</Tabs.Group>
</Tabs>
);

const tabs = () => screen.queryAllByRole('tab');
Expand Down
24 changes: 12 additions & 12 deletions src/components/Tab/Tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import type { Meta } from '@storybook/react';
import { HiAdjustments, HiClipboardList, HiUserCircle } from 'react-icons/hi';
import { MdDashboard } from 'react-icons/md';
import type { TabsProps } from './Tabs';
import { Tabs, TabsComponent } from './Tabs';
import { Tabs } from './Tabs';

export default {
title: 'Components/Tabs',
component: TabsComponent,
component: Tabs,
args: {
className: 'bg-white rounded-lg dark:bg-gray-800 dark:text-white',
},
Expand All @@ -22,35 +22,35 @@ export default {
} as Meta;

export const Default = (args: TabsProps): JSX.Element => (
<Tabs.Group {...args}>
<Tabs {...args}>
<Tabs.Item title="Profile">Profile content</Tabs.Item>
<Tabs.Item title="Dashboard">Dashboard content</Tabs.Item>
<Tabs.Item title="Settings">Settings content</Tabs.Item>
<Tabs.Item title="Contacts">Contacts content</Tabs.Item>
<Tabs.Item disabled title="Disabled">
Disabled content
</Tabs.Item>
</Tabs.Group>
</Tabs>
);

export const WithUnderline = (args: TabsProps): JSX.Element => (
<Tabs.Group {...args}>
<Tabs {...args}>
<Tabs.Item title="Profile">Profile content</Tabs.Item>
<Tabs.Item title="Dashboard">Dashboard content</Tabs.Item>
<Tabs.Item title="Settings">Settings content</Tabs.Item>
<Tabs.Item title="Contacts">Contacts content</Tabs.Item>
<Tabs.Item disabled title="Disabled">
Disabled content
</Tabs.Item>
</Tabs.Group>
</Tabs>
);
WithUnderline.args = {
style: 'underline',
};
WithUnderline.storyName = 'With underline';

export const WithIcons = (args: TabsProps): JSX.Element => (
<Tabs.Group {...args}>
<Tabs {...args}>
<Tabs.Item title="Profile" icon={HiUserCircle}>
Profile content
</Tabs.Item>
Expand All @@ -66,38 +66,38 @@ export const WithIcons = (args: TabsProps): JSX.Element => (
<Tabs.Item disabled={true} title="Disabled">
Disabled content
</Tabs.Item>
</Tabs.Group>
</Tabs>
);
WithIcons.args = {
style: 'underline',
};
WithIcons.storyName = 'With icons';

export const Pills = (args: TabsProps): JSX.Element => (
<Tabs.Group {...args}>
<Tabs {...args}>
<Tabs.Item title="Profile">Profile content</Tabs.Item>
<Tabs.Item title="Dashboard">Dashboard content</Tabs.Item>
<Tabs.Item title="Settings">Settings content</Tabs.Item>
<Tabs.Item title="Contacts">Contacts content</Tabs.Item>
<Tabs.Item disabled title="Disabled">
Disabled content
</Tabs.Item>
</Tabs.Group>
</Tabs>
);
Pills.args = {
style: 'pills',
};

export const FullWidth = (args: TabsProps): JSX.Element => (
<Tabs.Group {...args}>
<Tabs {...args}>
<Tabs.Item title="Profile">Profile content</Tabs.Item>
<Tabs.Item title="Dashboard">Dashboard content</Tabs.Item>
<Tabs.Item title="Settings">Settings content</Tabs.Item>
<Tabs.Item title="Contacts">Contacts content</Tabs.Item>
<Tabs.Item disabled title="Disabled">
Disabled content
</Tabs.Item>
</Tabs.Group>
</Tabs>
);
FullWidth.args = {
style: 'fullWidth',
Expand Down
9 changes: 6 additions & 3 deletions src/components/Tab/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface TabsRef {
setActiveTab: (activeTab: number) => void;
}

export const TabsComponent = forwardRef<TabsRef, TabsProps>(
const TabsComponent = forwardRef<TabsRef, TabsProps>(
(
{ children, className, onActiveTabChange, style = 'default', theme: customTheme = {}, ...props },
ref: ForwardedRef<TabsRef>,
Expand Down Expand Up @@ -179,5 +179,8 @@ export const TabsComponent = forwardRef<TabsRef, TabsProps>(
},
);

TabsComponent.displayName = 'Tabs.Group';
export const Tabs = { Group: TabsComponent, Item: TabItem };
TabsComponent.displayName = 'Tabs';

export const Tabs = Object.assign(TabsComponent, {
Item: TabItem,
});
2 changes: 1 addition & 1 deletion src/components/Tab/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export type { TabItemProps } from './TabItem';
export * from './TabItem';
export * from './Tabs';
Loading

1 comment on commit 2e1202c

@vercel
Copy link

@vercel vercel bot commented on 2e1202c Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.