Skip to content

Commit

Permalink
fix(core): Hint/Dropdown fix directives order mattering
Browse files Browse the repository at this point in the history
  • Loading branch information
waterplea committed Feb 21, 2023
1 parent 4452896 commit 74f111d
Show file tree
Hide file tree
Showing 46 changed files with 237 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@
type="button"
size="xs"
appearance=""
tuiHintDescribe
class="t-direction"
[class.t-direction_active]="isDirectionActive(button)"
[icon]="getIcon(button)"
[tuiHint]="button"
[tuiHintDescribe]="''"
(click)="onDirectionChange(button)"
></button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import {TuiEditorPortalService} from './editor-portal.service';
],
})
export class TuiEditorPortalDirective extends TuiRectAccessor {
readonly type = 'viewport';

constructor(
@Inject(ElementRef) private readonly elementRef: ElementRef<HTMLElement>,
) {
super();
}

override getClientRect(): ClientRect {
getClientRect(): ClientRect {
return this.elementRef.nativeElement.getBoundingClientRect();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
icon="tuiIconAlignLeftLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
[tuiHint]="texts.justify"
[tuiHintDescribe]="''"
[pseudoActive]="align.open"
[focusable]="align.open"
></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
icon="tuiIconCodeLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
[tuiHint]="hintText$ | async"
[tuiHintDescribe]="''"
[pseudoActive]="codes.open || (insideCode$ | async)"
[focusable]="codes.open"
></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
icon="tuiIconSpoilerDeleteLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
[tuiHint]="text.removeDetails"
[tuiHintDescribe]="''"
[focusable]="false"
[disabled]="!!(disabled$ | async)"
(click)="removeDetails()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
icon="tuiIconSpoilerLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
[tuiHint]="text.setDetails"
[tuiHintDescribe]="''"
[focusable]="false"
(click)="setDetails()"
></button>
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
appearance="icon"
icon="tuiIconFontLarge"
tuiHintDirection="top-left"
tuiHintDescribe
[tuiHint]="fontText$ | async"
[tuiHintDescribe]="''"
[pseudoActive]="fonts.open"
[focusable]="fonts.open"
></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
appearance="icon"
tuiHintDirection="top-left"
automation-id="toolbar__font-style-button"
tuiHintDescribe
[tuiHint]="texts.fontStyle"
[tuiHintDescribe]="''"
[pseudoActive]="format.open || state.bold || state.italic || state.underline || state.strike"
[focusable]="format.open"
></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
size="s"
icon="tuiIconPlusLarge"
appearance="icon"
tuiHintDescribe
[focusable]="false"
[tuiHint]="insertGroupText$ | async"
[tuiHintDescribe]="''"
(click)="addGroup()"
></button>

Expand All @@ -16,9 +16,9 @@
size="s"
icon="tuiIconCloseLarge"
appearance="icon"
tuiHintDescribe
[focusable]="false"
[disabled]="!!(disabled$ | async)"
[tuiHint]="removeGroupText$ | async"
[tuiHintDescribe]="''"
(click)="removeGroup()"
></button>
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
appearance="icon"
icon="tuiIconHiliteLarge"
automation-id="toolbar__hilite-button"
tuiHintDescribe
class="t-tool"
[tuiHint]="backColorText$ | async"
[tuiHintDescribe]="''"
[pseudoActive]="hilite.open"
[focusable]="hilite.open"
></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
appearance="icon"
tuiHintDirection="top-left"
automation-id="toolbar__ordering-list-button"
tuiHintDescribe
[tuiHint]="texts.list"
[tuiHintDescribe]="''"
[pseudoActive]="list?.open || listState?.unordered || listState?.ordered || false"
[focusable]="list.open"
></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
tuiHintDirection="top-left"
appearance="icon"
icon="tuiIconPaintLarge"
tuiHintDescribe
[tuiHint]="colorText$ | async"
[tuiHintDescribe]="''"
[pseudoActive]="colorSelect.open"
[focusable]="colorSelect.open"
[disabled]="!isActive"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
icon="tuiIconTableLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
[tuiHint]="insertTableText$ | async"
[tuiHintDescribe]="''"
[focusable]="table.open"
></button>
</tui-hosted-dropdown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
size="s"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
[icon]="can.mergeCells ? 'tuiIconTableMergeLarge' : 'tuiIconTableSplitLarge'"
[tuiHint]="can.mergeCells ? texts.mergeCells : texts.splitCells"
[tuiHintDescribe]="''"
[focusable]="false"
[disabled]="!can.mergeCells && !can.splitCells"
(click)="can.mergeCells ? mergeCells() : splitCell()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
icon="tuiIconAddRowLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
[tuiHint]="rowsColumnsManagingText$ | async"
[tuiHintDescribe]="''"
[focusable]="tableCommand.open"
[disabled]="!active"
></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
appearance="icon"
tuiHintDirection="top-left"
automation-id="toolbar__color-button"
tuiHintDescribe
[tuiHint]="foreColorText$ | async"
[tuiHintDescribe]="''"
[pseudoActive]="color.open"
[focusable]="color.open"
></button>
Expand Down
24 changes: 12 additions & 12 deletions projects/addon-editor/components/toolbar/toolbar.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
icon="tuiIconUndoLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
class="t-tool t-tool_margin"
[tuiHint]="texts.undo"
[tuiHintDescribe]="''"
[disabled]="undoDisabled"
[focusable]="false"
(click)="undo()"
Expand All @@ -46,9 +46,9 @@
icon="tuiIconRedoLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
class="t-tool t-tool_margin"
[tuiHint]="texts.redo"
[tuiHintDescribe]="''"
[disabled]="redoDisabled"
[focusable]="false"
(click)="redo()"
Expand Down Expand Up @@ -96,9 +96,9 @@
icon="tuiIconQuoteLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
class="t-tool t-tool_margin"
[tuiHint]="texts.quote"
[tuiHintDescribe]="''"
[pseudoActive]="blockquote"
[disabled]="unorderedList || orderedList"
[focusable]="false"
Expand All @@ -120,9 +120,9 @@
icon="tuiIconLinkLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
class="t-tool"
[tuiHint]="texts.link"
[tuiHintDescribe]="''"
[pseudoActive]="link.open || a"
[focusable]="link.open"
></button>
Expand All @@ -148,10 +148,10 @@
icon="tuiIconAnchorLarge"
tuiHintDirection="top-left"
appearance="icon"
tuiHintDescribe
[focusable]="false"
[pseudoActive]="anchor.open || jumpAnchor"
[tuiHint]="texts.insertAnchor"
[tuiHintDescribe]="''"
></button>
<ng-template #anchorDropdown>
<tui-edit-link
Expand All @@ -171,9 +171,9 @@
icon="tuiIconPaperclipLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
class="t-tool t-tool_margin"
[tuiHint]="texts.attach"
[tuiHintDescribe]="''"
[focusable]="false"
(click)="fileUpload.click()"
></button>
Expand Down Expand Up @@ -203,9 +203,9 @@
icon="tuiIconSubscriptLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
class="t-tool t-tool_margin"
[tuiHint]="texts.subscript"
[tuiHintDescribe]="''"
[pseudoActive]="subscript"
[focusable]="false"
(click)="toggleSubscript()"
Expand All @@ -220,9 +220,9 @@
icon="tuiIconSuperscriptLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
class="t-tool t-tool_margin"
[tuiHint]="texts.superscript"
[tuiHintDescribe]="''"
[pseudoActive]="superscript"
[focusable]="false"
(click)="toggleSuperscript()"
Expand Down Expand Up @@ -266,9 +266,9 @@
icon="tuiIconTeXLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
class="t-tool"
[tuiHint]="texts.tex"
[tuiHintDescribe]="''"
[focusable]="false"
(click)="onTeX()"
></button>
Expand All @@ -285,9 +285,9 @@
icon="tuiIconImageLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
class="t-tool"
[tuiHint]="texts.image"
[tuiHintDescribe]="''"
[focusable]="false"
(click)="image.click()"
></button>
Expand All @@ -311,9 +311,9 @@
icon="tuiIconHrLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
class="t-tool t-tool_margin"
[tuiHint]="texts.insertHorizontalRule"
[tuiHintDescribe]="''"
[focusable]="false"
(click)="insertHorizontalRule()"
></button>
Expand All @@ -331,9 +331,9 @@
icon="tuiIconClearFormatLarge"
appearance="icon"
tuiHintDirection="top-left"
tuiHintDescribe
class="t-tool t-tool_margin"
[tuiHint]="texts.clear"
[tuiHintDescribe]="''"
[focusable]="false"
(click)="removeFormat()"
></button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
icon="tuiIconRotate"
tuiHintDirection="top-right"
tuiHintAppearance="onDark"
tuiHintDescribe
class="t-rotate-button"
[tuiHint]="texts.rotate"
[tuiHintDescribe]="''"
(click)="rotate()"
></button>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
icon="tuiIconMinimize"
tuiHintDirection="top-right"
tuiHintAppearance="onDark"
tuiHintDescribe
class="t-reset-button"
[tuiHint]="texts.reset"
[tuiHintDescribe]="''"
[class.t-invisible]="!collapseVisible"
(click)="onReset()"
></button>
Expand Down
28 changes: 18 additions & 10 deletions projects/core/abstract/abstract-driver.directive.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import {Directive, Inject, Self} from '@angular/core';
import {Directive, Inject, OnInit, Self} from '@angular/core';
import {TuiDestroyService} from '@taiga-ui/cdk';
import {Observable} from 'rxjs';
import {merge, Observable} from 'rxjs';
import {distinctUntilChanged, takeUntil} from 'rxjs/operators';

import {TuiDriver} from './driver';
import {TuiVehicle} from './vehicle';

@Directive()
export abstract class AbstractTuiDriverDirective {
export abstract class AbstractTuiDriverDirective implements OnInit {
abstract type: string;

constructor(
@Self() @Inject(TuiDestroyService) destroy$: Observable<unknown>,
@Inject(TuiDriver) driver$: Observable<boolean>,
@Inject(TuiVehicle) vehicle: TuiVehicle,
) {
driver$.pipe(distinctUntilChanged(), takeUntil(destroy$)).subscribe(value => {
vehicle.toggle(value);
});
@Self() @Inject(TuiDestroyService) private readonly destroy$: Observable<unknown>,
@Inject(TuiDriver) private readonly drivers: TuiDriver[],
@Inject(TuiVehicle) private readonly vehicles: TuiVehicle[],
) {}

ngOnInit(): void {
const vehicle = this.vehicles.find(({type}) => type === this.type);

merge(...this.drivers.filter(({type}) => type === this.type))
.pipe(distinctUntilChanged(), takeUntil(this.destroy$))
.subscribe(value => {
vehicle?.toggle(value);
});
}
}
5 changes: 4 additions & 1 deletion projects/core/abstract/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import {ExistingProvider, Type} from '@angular/core';
import {Observable} from 'rxjs';

// eslint-disable-next-line @typescript-eslint/naming-convention
export abstract class TuiDriver extends Observable<boolean> {}
export abstract class TuiDriver extends Observable<boolean> {
abstract readonly type: string;
}

export function tuiAsDriver(useExisting: Type<TuiDriver>): ExistingProvider {
return {
provide: TuiDriver,
multi: true,
useExisting,
};
}
Loading

0 comments on commit 74f111d

Please sign in to comment.