Skip to content

Commit

Permalink
TabView: add end element to tab item
Browse files Browse the repository at this point in the history
  • Loading branch information
sandrine-ds committed Jan 27, 2025
1 parent cf3376b commit 3d2bf5b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/lake/__stories__/TabView.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Meta } from "@storybook/react";
import { TabView } from "../src/components/TabView";
import { Tag } from "../src/components/Tag";
import { StoryBlock } from "./_StoriesComponents";

export default {
Expand All @@ -20,6 +21,15 @@ export const Default = () => {
url: "/simulator/sct",
count: 2,
},
{
label: "Physical card",
url: "/simulator/endElement",
endElement: (
<Tag size="small" color="shakespear">
Expiring soon
</Tag>
),
},
{
label: "SEPA Direct Debits",
url: "/simulator/sdd",
Expand Down
19 changes: 17 additions & 2 deletions packages/lake/src/components/TabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const tabsViewHeight = TABS_HEIGHT + 1;
type Tab = ({ id: string } | { url: string }) & {
count?: number;
icon?: IconName;
endElement?: ReactNode;
label: string;
withSeparator?: boolean;
};
Expand Down Expand Up @@ -691,7 +692,7 @@ export const TabView = ({
>
<View style={styles.placeholder} aria-hidden={true} ref={placeholderRef} onLayout={onLayout}>
{tabs.map(tab => {
const { label, icon, count } = tab;
const { label, icon, count, endElement } = tab;
const tabId = getTabId(tab);

return (
Expand Down Expand Up @@ -719,6 +720,13 @@ export const TabView = ({

<Text>{label}</Text>

{isNotNullish(endElement) && (
<>
<Space width={8} />
{endElement}
</>
)}

{count != null ? (
<>
<Space width={8} />
Expand All @@ -742,7 +750,7 @@ export const TabView = ({
</View>

{kept.map(tab => {
const { label, icon, withSeparator, count } = tab;
const { label, icon, withSeparator, count, endElement } = tab;
const tabId = getTabId(tab);

return (
Expand Down Expand Up @@ -773,6 +781,13 @@ export const TabView = ({

<Text>{label}</Text>

{isNotNullish(endElement) && (
<>
<Space width={8} />
{endElement}
</>
)}

{count != null ? (
<>
<Space width={8} />
Expand Down

0 comments on commit 3d2bf5b

Please sign in to comment.