Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add extra to tabs #136

Merged
merged 6 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ const tabListCSS = css`
--tab-hover-color: ${transparentize(0.2, theme.colors.arizeBlue)};
--tab-selected-border-color: ${theme.colors.arizeBlue};

button {
button[role='tab'] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

it might be worth figuring out a way to keep a specificity of 1 here. Having a specificity higher makes customization a bit harder

box-sizing: border-box; /* place the border inside */
background-color: inherit;
border: none;
outline: none;
cursor: pointer;
padding: 0 ${theme.spacing.padding16}px;
height: 30px;
min-height: 30px;
transition: 0.3s;
font-weight: bold;
border-color: var(--tab-border-color);
Expand All @@ -50,14 +50,14 @@ const tabListCSS = css`
gap: var(--ac-global-dimension-static-size-65);
}

button[data-is-hidden='true'] {
button[role='tab'][data-is-hidden='true'] {
display: none;
}

&[data-orientation='horizontal'] {
flex-direction: row;
border-bottom: 1px solid var(--tab-border-color);
button {
button[role='tab'] {
border-bottom: 2px solid transparent;
&:hover {
border-color: var(--tab-hover-color);
Expand All @@ -66,11 +66,17 @@ const tabListCSS = css`
border-color: var(--tab-selected-border-color);
}
}
.ac-tabs__extra-content {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is the extra wrap right? probably worth not naming it content.

className="ac-field-label__label-extra"

display: flex;
align-items: center;
justify-content: flex-end;
flex-grow: 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this means the extra takes up the entire width on the right-hand side - I think it's probably worth just having the content aligned left and let it form it's own layout rather than forcing flex.

}
}
&[data-orientation='vertical'] {
flex-direction: column;
border-right: 1px solid var(--tab-border-color);
button {
button[role='tab'] {
border-right: 2px solid transparent;
&:hover {
border-color: var(--tab-hover-color);
Expand All @@ -79,6 +85,12 @@ const tabListCSS = css`
border-color: var(--tab-selected-border-color);
}
}
.ac-tabs__extra-content {
display: flex;
align-items: center;
justify-content: center;
flex-grow: 1;
}
}
`;

Expand Down Expand Up @@ -106,6 +118,7 @@ export type TabsProps = {
* @default horizontal
*/
orientation?: Orientation;
extra?: ReactNode; // Extra controls on the tablist
};

/**
Expand All @@ -116,6 +129,7 @@ export function Tabs({
className,
onChange,
orientation = 'horizontal',
extra,
}: TabsProps) {
const tabs = parseTabList(children);
const [selectedIndex, setSelectedIndex] = useState<number>(0);
Expand Down Expand Up @@ -154,6 +168,7 @@ export function Tabs({
</button>
);
})}
{extra && <div className="ac-tabs__extra-content">{extra}</div>}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
{extra && <div className="ac-tabs__extra-content">{extra}</div>}
{extra && <div className="ac-tabs__extra">{extra}</div>}

</div>
<div className="ac-tabs__pane-container">
{Children.map(children, (child, index) => {
Expand Down
13 changes: 11 additions & 2 deletions stories/Tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Meta, Story } from '@storybook/react';
import { withDesign } from 'storybook-addon-designs';
import { Tabs, TabsProps } from '../src/tabs/Tabs';
import { Heading } from '../src/content';
import { Counter, Provider } from '../src';
import { Button, CloseOutline, Counter, Icon, Provider } from '../src';

const { TabPane } = Tabs;

Expand Down Expand Up @@ -79,7 +79,16 @@ export const LazyLoading: Story<TabsProps> = args => (
export const WithExtra: Story<TabsProps> = args => (
<Provider>
<div style={{ width: 500 }} css={tabContentCSS}>
<Tabs {...args}>
<Tabs
{...args}
extra={
<Button
variant="default"
size="compact"
icon={<Icon svg={<CloseOutline />} />}
/>
}
>
<TabPane name="Tab 1" extra={<Counter>12</Counter>}>
{({ isSelected }) => (
<LazyLoadingTabContents isSelected={isSelected} />
Expand Down