Skip to content

Commit

Permalink
add withoutPadding prop to Tab, allow to set padding to 0 when Tab ha…
Browse files Browse the repository at this point in the history
…s Table
  • Loading branch information
JeanMarcMilletScality committed Jun 25, 2024
1 parent a2cc750 commit 472f4a4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/lib/components/tabsv2/StyledTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ export const TabsContainer = styled.div<{
margin-right: -1px;
}
`;
export const TabContent = styled.div<{ tabContentColor?: string }>`
export const TabContent = styled.div<{
tabContentColor?: string;
withoutPadding?: boolean;
}>`
margin: 0;
padding: 0;
padding: ${(props) => (props.withoutPadding ? '0' : spacing.r16)};
display: block;
width: 100%;
height: 100%;
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/tabsv2/Tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type TabProps = {
exact?: boolean;
strict?: boolean;
sensitive?: boolean;
withoutPadding?: boolean;
};

function Tab(_: TabProps) {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/components/tabsv2/Tabsv2.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function Tabs({
const [selectedTabIndex, setSelectedTabIndex] = useState<
number | null | undefined
>(null);
const [withoutPadding, setWithoutPadding] = useState();
const queryURL = new URLSearchParams(location.search);
const filteredTabsChildren = React.Children.toArray(children).filter(
(child) => React.isValidElement(child) && child.type === Tab,
Expand Down Expand Up @@ -115,6 +116,7 @@ function Tabs({

if (isSelected) {
setSelectedTabIndex(index);
setWithoutPadding(child.props.withoutPadding);
hasSelectedTab = true;
}
});
Expand Down Expand Up @@ -216,6 +218,7 @@ function Tabs({
<TabContent
className="sc-tabs-item-content"
tabContentColor={tabContentColor}
withoutPadding={withoutPadding}
>
{filteredTabsChildren.map((tab: Element<typeof Tab>, index) => (
<Route
Expand Down
3 changes: 2 additions & 1 deletion stories/tabsv2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const DefaultTabsDetails = (props) => {
{location.pathname} / {location.search}
</Title>
<Tabs {...props}>
<Tab path="/iframe.html" label="Users">
<Tab path="/iframe.html" label="Users" withoutPadding>
<Content>Users Content</Content>
</Tab>
<Tab
Expand All @@ -98,6 +98,7 @@ const DefaultTabsDetails = (props) => {
tab: 'role @',
}}
label="Roles"
withoutPadding
>
{details()}
</Tab>
Expand Down

0 comments on commit 472f4a4

Please sign in to comment.