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

[CL-17] Tabs - Router #2952

Merged
merged 12 commits into from
Jul 18, 2022
1 change: 1 addition & 0 deletions libs/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export * from "./callout";
export * from "./form-field";
export * from "./menu";
export * from "./utils/i18n-mock.service";
export * from "./tabs";
export * from "./submit-button";
3 changes: 3 additions & 0 deletions libs/components/src/tabs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./tabs.module";
export * from "./tab-group.component";
export * from "./tab-item.component";
6 changes: 6 additions & 0 deletions libs/components/src/tabs/tab-group.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div
role="tablist"
class="tw-flex tw-flex-wrap tw-pl-0 tw-my-0 tw-leading-5 tw-text-left tw-box-border"
>
Hinton marked this conversation as resolved.
Show resolved Hide resolved
<ng-content></ng-content>
</div>
7 changes: 7 additions & 0 deletions libs/components/src/tabs/tab-group.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Component } from "@angular/core";

@Component({
selector: "bit-tab-group",
templateUrl: "./tab-group.component.html",
})
export class TabGroupComponent {}
26 changes: 26 additions & 0 deletions libs/components/src/tabs/tab-item.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<ng-container [ngSwitch]="disabled">
<a
*ngSwitchCase="false"
role="tab"
[class]="baseClassList"
[routerLink]="route"
[routerLinkActive]="activeClassList"
#rla="routerLinkActive"
[attr.aria-selected]="rla.isActive"
>
<ng-container [ngTemplateOutlet]="content"></ng-container>
</a>
<button
*ngSwitchCase="true"
type="button"
role="tab"
[class]="baseClassList"
disabled
aria-disabled="true"
>
<ng-container [ngTemplateOutlet]="content"></ng-container>
</button>
</ng-container>
<ng-template #content>
<ng-content></ng-content>
</ng-template>
60 changes: 60 additions & 0 deletions libs/components/src/tabs/tab-item.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Component, Input } from "@angular/core";

@Component({
selector: "bit-tab-item",
templateUrl: "./tab-item.component.html",
})
export class TabItemComponent {
@Input()
route: string; // ['/route']
Hinton marked this conversation as resolved.
Show resolved Hide resolved

@Input()
disabled = false;

get baseClassList(): string {
return [
"tw-block",
"tw-py-2",
"tw-px-4",
"tw-leading-5",
"tw-text-left",
"tw-font-semibold",
"tw-bg-transparent",
"tw-transition",
"tw-rounded-t",
"tw-border-0",
"tw-border-t-4",
"tw-border-t-transparent",
"tw-border-b",
"tw-border-b-secondary-300",
"tw-border-solid",
"tw-cursor-pointer",
"tw-box-border",
"tw-text-main",
"hover:tw-underline",
"hover:tw-text-main",
"focus:tw-outline-none",
"focus:tw-ring-2",
"focus:tw-ring-primary-700",
"disabled:tw-bg-secondary-100",
"disabled:tw-text-muted",
"disabled:tw-no-underline",
"disabled:tw-border-t-transparent",
Hinton marked this conversation as resolved.
Show resolved Hide resolved
"disabled:tw-cursor-not-allowed",
].join(" ");
Hinton marked this conversation as resolved.
Show resolved Hide resolved
}

get activeClassList(): string {
return [
"tw-border-x",
Hinton marked this conversation as resolved.
Show resolved Hide resolved
"tw-border-x-secondary-300",
"tw-border-t-primary-500",
"tw-border-b-transparent",
"tw-text-primary-500",
"hover:tw-border-t-primary-700",
"hover:!tw-text-primary-700",
"focus:tw-border-t-primary-700",
"focus:tw-text-primary-700",
Hinton marked this conversation as resolved.
Show resolved Hide resolved
].join(" ");
}
}
13 changes: 13 additions & 0 deletions libs/components/src/tabs/tabs.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { CommonModule } from "@angular/common";
import { NgModule } from "@angular/core";
import { RouterModule } from "@angular/router";

import { TabGroupComponent } from "./tab-group.component";
import { TabItemComponent } from "./tab-item.component";

@NgModule({
imports: [CommonModule, RouterModule],
exports: [TabGroupComponent, TabItemComponent],
declarations: [TabGroupComponent, TabItemComponent],
})
export class TabsModule {}
84 changes: 84 additions & 0 deletions libs/components/src/tabs/tabs.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { CommonModule } from "@angular/common";
import { Component } from "@angular/core";
import { RouterModule } from "@angular/router";
import { Meta, moduleMetadata, Story } from "@storybook/angular";

import { TabGroupComponent } from "./tab-group.component";
import { TabItemComponent } from "./tab-item.component";

@Component({
selector: "bit-tab-active-dummy",
template: "Router - Active selected",
})
class ActiveDummyComponent {}

@Component({
selector: "bit-tab-item-2-dummy",
template: "Router - Item 2 selected",
})
class ItemTwoDummyComponent {}

@Component({
selector: "bit-tab-item-3-dummy",
template: "Router - Item 3 selected",
})
class ItemThreeDummyComponent {}

@Component({
selector: "bit-tab-disabled-dummy",
template: "Router - Disabled selected",
})
class DisabledDummyComponent {}

export default {
title: "Component Library/Tabs",
component: TabGroupComponent,
decorators: [
moduleMetadata({
declarations: [
TabGroupComponent,
TabItemComponent,
ActiveDummyComponent,
ItemTwoDummyComponent,
ItemThreeDummyComponent,
DisabledDummyComponent,
],
imports: [
CommonModule,
RouterModule.forRoot(
[
{ path: "", redirectTo: "active", pathMatch: "full" },
{ path: "active", component: ActiveDummyComponent },
{ path: "item-2", component: ItemTwoDummyComponent },
{ path: "item-3", component: ItemThreeDummyComponent },
{ path: "disabled", component: DisabledDummyComponent },
],
{ useHash: true }
),
],
}),
],
parameters: {
design: {
type: "figma",
url: "https://www.figma.com/file/Zt3YSeb6E6lebAffrNLa0h/Tailwind-Component-Library?node-id=1881%3A17922",
},
},
} as Meta;

const TabGroupTemplate: Story<TabGroupComponent> = (args: TabGroupComponent) => ({
props: args,
template: `
<bit-tab-group>
<bit-tab-item [route]="['active']">Active</bit-tab-item>
<bit-tab-item [route]="['item-2']">Item 2</bit-tab-item>
<bit-tab-item [route]="['item-3']">Item 3</bit-tab-item>
<bit-tab-item [route]="['disabled']" [disabled]="true">Disabled</bit-tab-item>
</bit-tab-group>
<div class="tw-bg-transparent tw-text-semibold tw-text-center !tw-text-main tw-py-10">
<router-outlet></router-outlet>
</div>
`,
});

export const TabGroup = TabGroupTemplate.bind({});
2 changes: 2 additions & 0 deletions libs/components/tailwind.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ module.exports = {
info: "var(--color-info-500)",
primary: {
300: "var(--color-primary-300)",
500: "var(--color-primary-500)",
700: "var(--color-primary-700)",
},
},
ringOffsetColor: ({ theme }) => ({
Expand Down