Skip to content

Commit

Permalink
feat(experimental): Segmented add new component (#6511)
Browse files Browse the repository at this point in the history
Co-authored-by: taiga-family-bot <[email protected]>
  • Loading branch information
waterplea and taiga-family-bot authored Jan 22, 2024
1 parent eef8e7d commit f982f5d
Show file tree
Hide file tree
Showing 33 changed files with 744 additions and 52 deletions.
30 changes: 3 additions & 27 deletions projects/addon-doc/components/example/example.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Clipboard} from '@angular/cdk/clipboard';
import {Location as NgLocation} from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
Expand All @@ -8,7 +7,6 @@ import {
Input,
Optional,
} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {LOCATION} from '@ng-web-apis/common';
import {TuiCodeEditor, TuiDocExample} from '@taiga-ui/addon-doc/interfaces';
import {
Expand Down Expand Up @@ -90,9 +88,6 @@ export class TuiDocExampleComponent {
@Inject(TUI_IS_E2E) readonly isE2E: boolean,
@Inject(TUI_DOC_CODE_ACTIONS)
readonly codeActions: Array<PolymorpheusContent<TuiContextWithImplicit<string>>>,
@Inject(Router) private readonly router: Router,
@Inject(ActivatedRoute) private readonly route: ActivatedRoute,
@Inject(NgLocation) private readonly ngLocation: NgLocation,
@Inject(TUI_DOC_EXAMPLE_OPTIONS) readonly options: TuiDocExampleOptions,
) {}

Expand All @@ -103,21 +98,10 @@ export class TuiDocExampleComponent {
return this.options.tabTitles.get(fileName) || fileName;
}

copyExampleLink(): void {
const hashPosition = this.location.href.indexOf('#');
const currentUrl =
hashPosition > -1
? this.location.href.slice(0, Math.max(0, hashPosition))
: this.location.href;
const url = `${currentUrl}#${this.id}`;

this.setFragmentWithoutRedirect(this.id);
this.clipboard.copy(url);
copyExampleLink({href}: HTMLAnchorElement): void {
this.clipboard.copy(href);
this.alerts
.open(this.texts[1], {
label: this.texts[2],
status: 'success',
})
.open(this.texts[1], {label: this.texts[2], status: 'success'})
.subscribe();
}

Expand All @@ -130,12 +114,4 @@ export class TuiDocExampleComponent {
.then(() => this.loading$.next(false))
.catch(() => this.loading$.next(false));
}

private setFragmentWithoutRedirect(id: string | null): void {
const url = this.router
.createUrlTree([], {relativeTo: this.route, fragment: id || ''})
.toString();

this.ngLocation.go(url);
}
}
2 changes: 2 additions & 0 deletions projects/addon-doc/components/example/example.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {ClipboardModule} from '@angular/cdk/clipboard';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {RouterModule} from '@angular/router';
import {TuiMapperPipeModule} from '@taiga-ui/cdk';
import {TuiButtonModule, TuiLoaderModule} from '@taiga-ui/core';
import {TuiTabsModule} from '@taiga-ui/kit';
Expand All @@ -22,6 +23,7 @@ import {TuiDocExampleGetTabsPipe} from './example-get-tabs.pipe';
PolymorpheusModule,
TuiMapperPipeModule,
TuiLoaderModule,
RouterModule,
],
declarations: [TuiDocExampleComponent, TuiDocExampleGetTabsPipe],
exports: [TuiDocExampleComponent, TuiDocExampleGetTabsPipe],
Expand Down
8 changes: 5 additions & 3 deletions projects/addon-doc/components/example/example.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
*polymorpheusOutlet="heading as text"
[textContent]="text"
></span>
<button
<a
*ngIf="id"
appearance="icon"
routerLink="."
size="xs"
tuiIconButton
type="button"
class="t-link-icon"
[fragment]="id"
[icon]="options.linkIcon"
[title]="copy$ | async"
(click)="copyExampleLink()"
></button>
(click)="copyExampleLink($any($event.currentTarget))"
></a>
</h3>
<h4
*ngIf="description"
Expand Down
5 changes: 2 additions & 3 deletions projects/cdk/utils/dom/element-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ export function tuiIsElement(
return !!node && 'nodeType' in node && node.nodeType === Node.ELEMENT_NODE;
}

export function tuiIsHTMLElement(node: unknown): node is HTMLElement {
// TODO: iframe warning
return node instanceof HTMLElement;
export function tuiIsHTMLElement(node: any): node is HTMLElement {
return !!node && node instanceof node.ownerDocument.defaultView.HTMLElement;
}

export function tuiIsTextNode(node: Node): node is Text {
Expand Down
9 changes: 9 additions & 0 deletions projects/demo/src/modules/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,15 @@ export const ROUTES: Routes = [
title: 'Rating',
},
},
{
path: 'experimental/segmented',
loadChildren: async () =>
(await import('../experimental/segmented/segmented.module'))
.ExampleTuiSegmentedModule,
data: {
title: 'Segmented',
},
},
{
path: 'experimental/sensitive',
loadChildren: async () =>
Expand Down
18 changes: 12 additions & 6 deletions projects/demo/src/modules/app/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,18 +936,18 @@ export const pages: TuiDocPages = [
keywords: 'overflow, ellipsis, gradient, clamp, line',
route: '/experimental/fade',
},
{
section: 'Experimental',
title: 'Header',
keywords: 'header, заголовок, item',
route: '/experimental/header',
},
{
section: 'Experimental',
title: 'Icon',
keywords: 'icons, image, картинка, свг, svg, графика, иконка',
route: '/experimental/icon',
},
{
section: 'Experimental',
title: 'Header',
keywords: 'header, заголовок, item',
route: '/experimental/header',
},
{
section: 'Experimental',
title: 'ProgressSegmented ',
Expand All @@ -961,6 +961,12 @@ export const pages: TuiDocPages = [
keywords: 'рейтинг, оценка, звезда, rating, star, rate',
route: '/experimental/rating',
},
{
section: 'Experimental',
title: 'Segmented',
keywords: 'tabs, control, radio, navigation, навигация, вкладки, таб',
route: '/experimental/segmented',
},
{
section: 'Experimental',
title: 'Sensitive',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<tui-segmented
*ngFor="let size of sizes"
[size]="size"
>
<button>
<tui-icon icon="tuiIconSun"></tui-icon>
All
<tui-badge-notification [size]="size">3</tui-badge-notification>
<tui-icon icon="tuiIconMoon"></tui-icon>
</button>
<button>Incoming</button>
<button>Outgoing</button>
</tui-segmented>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:host {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 1rem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';

@Component({
selector: 'tui-segmented-example-1',
templateUrl: './index.html',
styleUrls: ['./index.less'],
encapsulation,
changeDetection,
})
export class TuiSegmentedExample1 {
readonly sizes = ['s', 'm', 'l'] as const;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<tui-segmented>
<button>Dynamic width</button>
<button>Items</button>
</tui-segmented>

<tui-segmented class="full">
<button>Fixed width</button>
<button tuiFade>with fadeout effect</button>
</tui-segmented>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
:host {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 1rem;
}

.full {
width: 100%;

& > * {
flex: 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';

@Component({
selector: 'tui-segmented-example-2',
templateUrl: './index.html',
styleUrls: ['./index.less'],
encapsulation,
changeDetection,
})
export class TuiSegmentedExample2 {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<header>
<tui-segmented
class="colors"
[(activeItemIndex)]="active"
>
<button
*ngFor="let button of buttons; let index = index"
[class.active]="index === active"
>
{{ button }}
</button>
</tui-segmented>
</header>

<tui-segmented [style.border-radius.rem]="10">
<button>Border radius</button>
<button>Can be</button>
<button>Customized</button>
</tui-segmented>

<tui-segmented [style.font-weight]="'bold'">
<button>Fonts</button>
<button>Can also be</button>
<button>Overridden</button>
</tui-segmented>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
:host {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 1rem;
}

header {
background: var(--tui-clear);
box-shadow: 0 -10rem 0 10.5rem var(--tui-clear);
}

.colors {
color: var(--tui-base-01);

&:before {
color: var(--tui-link);
box-shadow: none;
}

.active {
color: var(--tui-text-01-night);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';

@Component({
selector: 'tui-segmented-example-3',
templateUrl: './index.html',
styleUrls: ['./index.less'],
encapsulation,
changeDetection,
})
export class TuiSegmentedExample3 {
readonly buttons = ['Track active index', 'To color tabs', 'Differently'];
active = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<strong>Buttons</strong>
<tui-segmented>
<button>Buttons</button>
<button>Can be</button>
<button>Used</button>
</tui-segmented>
<hr />
<strong>Links</strong>
<tui-segmented>
<a
routerLink="/components/link"
routerLinkActive
>
Use routerLink
</a>
<a
routerLink="/experimental/segmented"
routerLinkActive
[routerLinkActiveOptions]="options"
>
And routerLinkActive
</a>
<a
fragment="content"
routerLink="/experimental/segmented"
routerLinkActive
[routerLinkActiveOptions]="options"
>
To work with links
</a>
</tui-segmented>
<hr />
<strong>Icons</strong>
<tui-segmented>
<button>
<tui-icon icon="tuiIconSun"></tui-icon>
</button>
<button>
<tui-icon icon="tuiIconMoon"></tui-icon>
</button>
</tui-segmented>
<hr />
<strong>Control</strong>
<tui-segmented>
<label>
<input
name="radio"
type="radio"
value="a"
[(ngModel)]="selected"
/>
Use radio inside
</label>
<label>
<input
name="radio"
type="radio"
value="b"
[(ngModel)]="selected"
/>
It would be hidden
</label>
<label>
<input
name="radio"
type="radio"
value="c"
[(ngModel)]="selected"
/>
Automatically
</label>
</tui-segmented>
<button
appearance="floating"
size="s"
tuiButton
(click)="selected = 'b'"
>
Select second option
</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
:host {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 1rem;
}

hr {
width: 100%;
}
Loading

0 comments on commit f982f5d

Please sign in to comment.