Skip to content

Commit 24b1ad8

Browse files
feat(Tabs): Support icon-only tab (#2496)
* feat: support icon-only-tab * fix: alignment of icon * chore: update borderRadius to medium * chore: remove divider from tablist according to design * chore: update background color * fix: update padding for tab horizontal bordered and filled * chore: update types * chore: update snap * Revert "fix: update padding for tab horizontal bordered and filled" This reverts commit 4f76377. * chore: update snaps * chore: unused code --------- Co-authored-by: tewarig <[email protected]>
1 parent ba66b34 commit 24b1ad8

File tree

5 files changed

+132
-116
lines changed

5 files changed

+132
-116
lines changed

packages/blade/src/components/Tabs/TabItem.web.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,17 @@ const TabItem = ({
165165
{Leading ? (
166166
<Leading size={iconSizeMap[size!]} color={iconColor[selectedState][interaction]} />
167167
) : null}
168-
<Text
169-
color={textColor[selectedState][interaction]}
170-
size={size === 'medium' ? 'medium' : 'large'}
171-
weight="semibold"
172-
>
173-
{children}
174-
</Text>
168+
169+
{children ? (
170+
<Text
171+
color={textColor[selectedState][interaction]}
172+
size={size === 'medium' ? 'medium' : 'large'}
173+
weight="semibold"
174+
>
175+
{children}
176+
</Text>
177+
) : null}
178+
175179
{validatedTrailingComponent}
176180
</StyledTabButton>
177181
}

packages/blade/src/components/Tabs/TabList.web.tsx

+3-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { TabIndicator } from './TabIndicator';
66
import { trackColor } from './tabTokens';
77
import BaseBox from '~components/Box/BaseBox';
88
import { useIsomorphicLayoutEffect } from '~utils/useIsomorphicLayoutEffect';
9-
import { Divider } from '~components/Divider';
109
import { Box } from '~components/Box';
1110
import type { StyledPropsBlade } from '~components/Box/styledProps';
1211
import { getStyledProps } from '~components/Box/styledProps';
@@ -84,9 +83,9 @@ const TabList = ({
8483
overflow={isVertical ? 'hidden' : undefined}
8584
{...(isFilled
8685
? {
87-
borderRadius: 'small',
86+
borderRadius: 'medium',
8887
borderWidth: 'thin',
89-
borderColor: 'interactive.border.gray.faded',
88+
borderColor: 'interactive.border.gray.default',
9089
padding: 'spacing.2',
9190
gap: isVertical ? 'spacing.0' : 'spacing.1',
9291
backgroundColor: 'surface.background.gray.intense',
@@ -96,23 +95,7 @@ const TabList = ({
9695
gap: isVertical ? 'spacing.0' : { base: 'spacing.7', m: 'spacing.8' },
9796
})}
9897
>
99-
{variant === 'filled' && !isVertical
100-
? React.Children.map(children, (child, index) => {
101-
return (
102-
<>
103-
{index > 0 ? (
104-
<Divider
105-
margin="auto"
106-
height="20px"
107-
variant="subtle"
108-
orientation="vertical"
109-
/>
110-
) : null}
111-
{child}
112-
</>
113-
);
114-
})
115-
: children}
98+
{children}
11699
</BaseBox>
117100
</BaseBox>
118101
);

packages/blade/src/components/Tabs/Tabs.stories.tsx

+64
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
BankIcon,
1717
CreditCardIcon,
1818
ZapIcon,
19+
MonitorIcon,
20+
SmartphoneIcon,
1921
} from '~components/Icons';
2022
import { Counter } from '~components/Counter';
2123
import { Box } from '~components/Box';
@@ -911,3 +913,65 @@ const ProductUseCase3Template: StoryFn<(props: StoryControlProps) => React.React
911913

912914
export const ProductUseCase3 = ProductUseCase3Template.bind({});
913915
ProductUseCase3.storyName = 'Product Usecase: React Router';
916+
917+
const ProductUseCase4Template: StoryFn<(props: StoryControlProps) => React.ReactElement> = () => {
918+
return (
919+
<Box height={isReactNative() ? '100%' : undefined}>
920+
<Card marginTop="spacing.6" elevation="none" padding="spacing.0">
921+
<CardBody height="100%">
922+
<Tabs isFullWidthTabItem={false} variant="filled" defaultValue="desktop">
923+
<Box
924+
padding="spacing.6"
925+
minHeight="300px"
926+
display="flex"
927+
alignItems="center"
928+
justifyContent="center"
929+
paddingBottom="spacing.6"
930+
>
931+
<TabPanel value="desktop">
932+
<Box
933+
elevation="midRaised"
934+
display="flex"
935+
alignItems="center"
936+
justifyContent="center"
937+
width="400px"
938+
height="200px"
939+
borderRadius="large"
940+
borderColor="surface.border.gray.muted"
941+
borderWidth="thin"
942+
>
943+
<Text>Desktop Preview</Text>
944+
</Box>
945+
</TabPanel>
946+
<TabPanel value="mobile">
947+
<Box
948+
elevation="midRaised"
949+
display="flex"
950+
alignItems="center"
951+
justifyContent="center"
952+
width="140px"
953+
height="200px"
954+
borderRadius="large"
955+
borderColor="surface.border.gray.muted"
956+
borderWidth="thin"
957+
>
958+
<Text>Mobile Preview</Text>
959+
</Box>
960+
</TabPanel>
961+
</Box>
962+
963+
<Box width="200px" padding="spacing.6">
964+
<TabList>
965+
<TabItem value="desktop" leading={MonitorIcon} />
966+
<TabItem value="mobile" leading={SmartphoneIcon} />
967+
</TabList>
968+
</Box>
969+
</Tabs>
970+
</CardBody>
971+
</Card>
972+
</Box>
973+
);
974+
};
975+
976+
export const ProductUseCase4 = ProductUseCase4Template.bind({});
977+
ProductUseCase4.storyName = 'Product Usecase: Icon only tabs';

0 commit comments

Comments
 (0)