From fa2704a9d3f49657463812ed8657d97be87e2a61 Mon Sep 17 00:00:00 2001 From: Bruno Henriques Date: Thu, 9 Jan 2025 12:25:07 +0000 Subject: [PATCH] fix(Tabs): support for scrollable tabs --- apps/docs/next-env.d.ts | 2 +- apps/docs/src/pages/components/tabs.mdx | 65 +++++++++++++++++-------- packages/core/src/Tabs/Tabs.stories.tsx | 55 +++++++++++++++++---- packages/core/src/Tabs/Tabs.styles.tsx | 5 +- 4 files changed, 93 insertions(+), 34 deletions(-) diff --git a/apps/docs/next-env.d.ts b/apps/docs/next-env.d.ts index a4a7b3f5cf..52e831b434 100644 --- a/apps/docs/next-env.d.ts +++ b/apps/docs/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. +// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information. diff --git a/apps/docs/src/pages/components/tabs.mdx b/apps/docs/src/pages/components/tabs.mdx index 65369792bb..34852b3545 100644 --- a/apps/docs/src/pages/components/tabs.mdx +++ b/apps/docs/src/pages/components/tabs.mdx @@ -17,6 +17,9 @@ export const getStaticProps = async ({ params }) => { ### Usage +The `HvTabs` is controlled via the `value` and `onChange` props. +The `value` prop contains the `value` of the `HvTab`, which is its index by default. + ```tsx live import { useState } from "react"; @@ -30,9 +33,42 @@ export default function Demo() { - {`Page ${value + 1} content`} + + {`Page ${value + 1} content`} + + + ); +} +``` + +### Variants + +The tabs supports `fullWidth` and `scrollable` variants, based on the [MUI Tabs](https://mui.com/material-ui/api/tabs/#tabs-prop-variant) component. + +```tsx live +import { useState } from "react"; + +export default function Demo() { + const [value, setValue] = useState(0); + + const handleChange: HvTabsProps["onChange"] = (evt, newValue) => { + setValue(newValue); + }; + + return ( +
+ + + + + +
+ + {[...Array(12).keys()].map((i) => ( + + ))} + +
); } @@ -51,19 +87,15 @@ export default function Demo() { const [showLabels, setShowLabels] = useState(true); const [iconPosition, setIconPosition] = useState("start"); - const handleChange: HvTabsProps["onChange"] = (_, newValue) => { - setValue(newValue); - }; - return ( -
-
+
+
setShowLabels((p) => !p)} label="Show labels" /> -
+
Icon position:
- + setValue(val)}> {tabs.map((tab, index) => ( , - iconPosition: "start", }, { label: "Clickable tab 2", icon: , - iconPosition: "start", }, { label: "Clickable tab 3", icon: , - iconPosition: "start", }, ]; ``` @@ -164,13 +193,9 @@ import { useState } from "react"; export default function Demo() { const [value, setValue] = useState(0); - const handleChange: HvTabsProps["onChange"] = (_, newValue) => { - setValue(newValue); - }; - return ( -
- +
+ setValue(val)}> } iconPosition="start" /> } iconPosition="start" /> } iconPosition="start" /> diff --git a/packages/core/src/Tabs/Tabs.stories.tsx b/packages/core/src/Tabs/Tabs.stories.tsx index 0ae5096c2c..f1fa5ac277 100644 --- a/packages/core/src/Tabs/Tabs.stories.tsx +++ b/packages/core/src/Tabs/Tabs.stories.tsx @@ -72,6 +72,34 @@ export const FullWidth: StoryObj = { }, }; +export const Scrollable: StoryObj = { + parameters: { + docs: { + description: { + story: "Tabs with scroll buttons.", + }, + }, + }, + render: () => { + const [value, setValue] = useState(0); + + return ( +
+ setValue(newValue)} + > + {[...Array(12).keys()].map((i) => ( + + ))} + +
+ ); + }, +}; + export const ContentChanging: StoryObj = { parameters: { docs: { @@ -281,15 +309,24 @@ export const Test: StoryObj = { iconPosition="top" />
- - } aria-label="Alert" /> - } aria-label="Reload" /> - } aria-label="Calendar" /> - - - } /> - } /> - +
+ + {[...Array(12).keys()].map((i) => ( + + ))} + +
+
+ + } aria-label="Alert" /> + } aria-label="Reload" /> + } aria-label="Calendar" /> + + + } /> + } /> + +
), }; diff --git a/packages/core/src/Tabs/Tabs.styles.tsx b/packages/core/src/Tabs/Tabs.styles.tsx index f2f482ba85..e16ff10573 100644 --- a/packages/core/src/Tabs/Tabs.styles.tsx +++ b/packages/core/src/Tabs/Tabs.styles.tsx @@ -3,12 +3,9 @@ import { createClasses } from "@hitachivantara/uikit-react-utils"; export const { staticClasses, useClasses } = createClasses("HvTabs", { root: { minHeight: 0, - overflow: "visible", }, indicator: {}, - scroller: { - overflow: "visible !important", - }, + scroller: {}, flexContainer: { marginLeft: "3px", },