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(atomic): improve atomic-tab overflow behaviour #4725

Merged
merged 11 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
50 changes: 50 additions & 0 deletions packages/atomic/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3786,6 +3786,22 @@ export namespace Components {
}
interface TabBar {
}
interface TabButton {
/**
* Whether the tab button is active.
*/
"active": boolean;
/**
* The label to display on the tab button.
*/
"label": string;
/**
* Click handler for the tab button.
*/
"select": () => void;
}
interface TabManagerBar {
}
interface TabPopover {
"setButtonVisibility": (isVisible: boolean) => Promise<void>;
"togglePopover": () => Promise<void>;
Expand Down Expand Up @@ -6040,6 +6056,18 @@ declare global {
prototype: HTMLTabBarElement;
new (): HTMLTabBarElement;
};
interface HTMLTabButtonElement extends Components.TabButton, HTMLStencilElement {
}
var HTMLTabButtonElement: {
prototype: HTMLTabButtonElement;
new (): HTMLTabButtonElement;
};
interface HTMLTabManagerBarElement extends Components.TabManagerBar, HTMLStencilElement {
}
var HTMLTabManagerBarElement: {
prototype: HTMLTabManagerBarElement;
new (): HTMLTabManagerBarElement;
};
interface HTMLTabPopoverElement extends Components.TabPopover, HTMLStencilElement {
}
var HTMLTabPopoverElement: {
Expand Down Expand Up @@ -6244,6 +6272,8 @@ declare global {
"atomic-timeframe": HTMLAtomicTimeframeElement;
"atomic-timeframe-facet": HTMLAtomicTimeframeFacetElement;
"tab-bar": HTMLTabBarElement;
"tab-button": HTMLTabButtonElement;
"tab-manager-bar": HTMLTabManagerBarElement;
"tab-popover": HTMLTabPopoverElement;
}
}
Expand Down Expand Up @@ -9833,6 +9863,22 @@ declare namespace LocalJSX {
}
interface TabBar {
}
interface TabButton {
/**
* Whether the tab button is active.
*/
"active"?: boolean;
/**
* The label to display on the tab button.
*/
"label": string;
/**
* Click handler for the tab button.
*/
"select": () => void;
}
interface TabManagerBar {
}
interface TabPopover {
}
interface IntrinsicElements {
Expand Down Expand Up @@ -10033,6 +10079,8 @@ declare namespace LocalJSX {
"atomic-timeframe": AtomicTimeframe;
"atomic-timeframe-facet": AtomicTimeframeFacet;
"tab-bar": TabBar;
"tab-button": TabButton;
"tab-manager-bar": TabManagerBar;
"tab-popover": TabPopover;
}
}
Expand Down Expand Up @@ -10917,6 +10965,8 @@ declare module "@stencil/core" {
*/
"atomic-timeframe-facet": LocalJSX.AtomicTimeframeFacet & JSXBase.HTMLAttributes<HTMLAtomicTimeframeFacetElement>;
"tab-bar": LocalJSX.TabBar & JSXBase.HTMLAttributes<HTMLTabBarElement>;
"tab-button": LocalJSX.TabButton & JSXBase.HTMLAttributes<HTMLTabButtonElement>;
"tab-manager-bar": LocalJSX.TabManagerBar & JSXBase.HTMLAttributes<HTMLTabManagerBarElement>;
"tab-popover": LocalJSX.TabPopover & JSXBase.HTMLAttributes<HTMLTabPopoverElement>;
}
}
Expand Down
81 changes: 52 additions & 29 deletions packages/atomic/src/components/common/tab-manager/tab-button.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,54 @@
import {FunctionalComponent, h} from '@stencil/core';
import {Button} from '../button';
import {Component, Host, Prop, h} from '@stencil/core';

export interface TabButtonProps {
label: string | undefined;
handleClick: () => void;
isActive: boolean;
}
/**
* @internal
*/
@Component({
tag: 'tab-button',
})
export class TabButton {
/**
* The label to display on the tab button.
*/
@Prop() label!: string;

/**
* Whether the tab button is active.
*/
@Prop() active: boolean = false;

/**
* Click handler for the tab button.
*/
@Prop() select!: () => void;

export const TabButton: FunctionalComponent<TabButtonProps> = (props) => {
const activeTabClass = props.isActive
? "relative after:content-[''] after:block after:w-full after:h-1 after:absolute after:-bottom-0.5 after:bg-primary after:rounded"
: '';
const activeTabTextClass = props.isActive ? '' : 'text-neutral-dark';
return (
<li
aria-current={props.isActive ? 'true' : 'false'}
aria-label={'tab for ' + props.label}
part="button-container"
class={activeTabClass}
>
<Button
style="text-transparent"
class={`w-full px-6 pb-1 text-xl ${activeTabTextClass}`}
text={props.label}
part="tab-button"
onClick={props.handleClick}
></Button>
</li>
);
};
private get activeTabClass() {
return this.active
? 'relative after:block after:w-full after:h-1 after:absolute after:-bottom-0.5 after:bg-primary after:rounded'
: '';
}

private get activeTabTextClass() {
return this.active ? '' : 'text-neutral-dark';
}

render() {
return (
<Host
role="listitem"
class={`${this.activeTabClass}`}
aria-current={this.active ? 'true' : 'false'}
aria-label={'tab for ' + this.label}
part="button-container"
>
<button
class={`w-full truncate px-2 pb-1 text-xl sm:px-6 ${this.activeTabTextClass}`}
part="tab-button"
onClick={this.select}
>
{this.label}
</button>
</Host>
);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@import '../../../global/global.pcss';

:host {
white-space: nowrap;
width: 100%;
overflow-x: visible;
display: flex;
position: relative;

button {
@apply text-left;
}

tab-popover::part(popover-button) {
@apply text-xl;
@apply sm:px-6;
@apply px-2;
@apply pb-1;
@apply font-normal;
@apply m-0;
@apply text-black;
}
}
Loading
Loading