-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core):
Tooltip
add directive, move component to legacy (#7810)
Signed-off-by: waterplea <alexander@inkin.ru> Co-authored-by: taiga-family-bot <taiga-family-bot@users.noreply.github.com>
- Loading branch information
1 parent
6e19a82
commit 4baa2fa
Showing
88 changed files
with
279 additions
and
757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './tooltip.directive'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import type {DoCheck, Signal} from '@angular/core'; | ||
import { | ||
ChangeDetectionStrategy, | ||
ChangeDetectorRef, | ||
Component, | ||
Directive, | ||
HostListener, | ||
inject, | ||
ViewEncapsulation, | ||
} from '@angular/core'; | ||
import {toSignal} from '@angular/core/rxjs-interop'; | ||
import {TUI_IS_MOBILE, tuiDirectiveBinding, tuiWatch, tuiWithStyles} from '@taiga-ui/cdk'; | ||
import {TuiTextfieldComponent} from '@taiga-ui/core/components/textfield'; | ||
import { | ||
TUI_APPEARANCE_OPTIONS, | ||
TuiAppearance, | ||
} from '@taiga-ui/core/directives/appearance'; | ||
import { | ||
TUI_HINT_OPTIONS, | ||
TuiHintDescribe, | ||
TuiHintDirective, | ||
TuiHintHoverDirective, | ||
} from '@taiga-ui/core/directives/hint'; | ||
import {TUI_ICON} from '@taiga-ui/core/tokens'; | ||
import type {TuiInteractiveState} from '@taiga-ui/core/types'; | ||
import {map} from 'rxjs'; | ||
|
||
@Component({ | ||
standalone: true, | ||
template: '', | ||
styleUrls: ['./tooltip.style.less'], | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
host: { | ||
class: 'tui-tooltip', | ||
}, | ||
}) | ||
class TuiTooltipStyles {} | ||
|
||
@Directive({ | ||
standalone: true, | ||
selector: 'tui-icon[tuiTooltip]', | ||
providers: [ | ||
{ | ||
provide: TUI_APPEARANCE_OPTIONS, | ||
useValue: {appearance: 'icon'}, | ||
}, | ||
{ | ||
provide: TUI_ICON, | ||
useFactory: () => inject(TUI_HINT_OPTIONS).icon, | ||
}, | ||
], | ||
hostDirectives: [ | ||
{ | ||
directive: TuiAppearance, | ||
inputs: ['tuiAppearance: appearance'], | ||
}, | ||
{ | ||
directive: TuiHintDescribe, | ||
inputs: ['tuiHintDescribe'], | ||
}, | ||
{ | ||
directive: TuiHintDirective, | ||
inputs: ['tuiHint: tuiTooltip', 'tuiHintAppearance', 'tuiHintContext'], | ||
}, | ||
], | ||
host: {tuiTooltip: ''}, | ||
}) | ||
export class TuiTooltip implements DoCheck { | ||
private readonly textfield = inject(TuiTextfieldComponent, {optional: true}); | ||
private readonly isMobile = inject(TUI_IS_MOBILE); | ||
private readonly describe = inject(TuiHintDescribe); | ||
private readonly driver = inject(TuiHintHoverDirective); | ||
|
||
protected readonly nothing = tuiWithStyles(TuiTooltipStyles); | ||
protected readonly state = bindAppearanceState(); | ||
|
||
public ngDoCheck(): void { | ||
if (this.textfield?.id) { | ||
this.describe.tuiHintDescribe = this.textfield.id; | ||
} | ||
} | ||
|
||
@HostListener('mousedown', ['$event']) | ||
protected stopOnMobile(event: MouseEvent): void { | ||
if (this.isMobile) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
|
||
this.driver.toggle(); | ||
} | ||
} | ||
|
||
function bindAppearanceState(): Signal<TuiInteractiveState | null> { | ||
return tuiDirectiveBinding( | ||
TuiAppearance, | ||
'tuiAppearanceState', | ||
toSignal( | ||
inject(TuiHintHoverDirective).pipe( | ||
map(hover => (hover ? 'hover' : null)), | ||
tuiWatch(inject(ChangeDetectorRef)), | ||
), | ||
{initialValue: null}, | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[tuiTooltip] { | ||
border: 0.25rem solid transparent; | ||
border-radius: 100%; | ||
cursor: pointer; | ||
pointer-events: auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.