diff --git a/projects/demo/src/modules/experimental/badge/badge.template.html b/projects/demo/src/modules/experimental/badge/badge.template.html index ebecb8c9cf65..512337dcc91e 100644 --- a/projects/demo/src/modules/experimental/badge/badge.template.html +++ b/projects/demo/src/modules/experimental/badge/badge.template.html @@ -66,11 +66,11 @@

-

Taiga UI
diff --git a/projects/demo/src/modules/experimental/badge/examples/3/index.html b/projects/demo/src/modules/experimental/badge/examples/3/index.html index 96e36986ef42..90b957a58f30 100644 --- a/projects/demo/src/modules/experimental/badge/examples/3/index.html +++ b/projects/demo/src/modules/experimental/badge/examples/3/index.html @@ -2,36 +2,36 @@

Value with icon

- x-large - large - medium - small diff --git a/projects/demo/src/modules/experimental/badge/examples/4/index.html b/projects/demo/src/modules/experimental/badge/examples/4/index.html index c51e347c0b52..4029c2c05789 100644 --- a/projects/demo/src/modules/experimental/badge/examples/4/index.html +++ b/projects/demo/src/modules/experimental/badge/examples/4/index.html @@ -8,9 +8,9 @@ -
Very long value in badge
diff --git a/projects/demo/src/modules/experimental/badge/examples/5/index.html b/projects/demo/src/modules/experimental/badge/examples/5/index.html index eeec213ce0b9..79d331d5ac37 100644 --- a/projects/demo/src/modules/experimental/badge/examples/5/index.html +++ b/projects/demo/src/modules/experimental/badge/examples/5/index.html @@ -1,9 +1,9 @@ - 10 000 000 $ diff --git a/projects/experimental/components/badge/badge.module.ts b/projects/experimental/components/badge/badge.module.ts index b85e2101fa82..de1ec0905378 100644 --- a/projects/experimental/components/badge/badge.module.ts +++ b/projects/experimental/components/badge/badge.module.ts @@ -1,10 +1,12 @@ import {NgModule} from '@angular/core'; +import {TuiIconsDirective, TuiIconsModule} from '@taiga-ui/experimental/directives/icons'; import {TuiBadgeComponent} from './badge.component'; import {TuiBadgeDirective} from './badge.directive'; @NgModule({ + imports: [TuiIconsModule], declarations: [TuiBadgeComponent, TuiBadgeDirective], - exports: [TuiBadgeDirective], + exports: [TuiBadgeDirective, TuiIconsDirective], }) export class TuiBadgeModule {} diff --git a/projects/experimental/components/badge/badge.style.less b/projects/experimental/components/badge/badge.style.less index 0ab0775c85be..5bfc09a0e331 100644 --- a/projects/experimental/components/badge/badge.style.less +++ b/projects/experimental/components/badge/badge.style.less @@ -34,9 +34,10 @@ tui-badge, } > tui-svg, - > tui-icon { - width: var(--t-icon-size) !important; - height: var(--t-icon-size) !important; + > tui-icon, + &[tuiIcons]:before, + &[tuiIcons]:after { + font-size: var(--t-icon-size) !important; } &[data-appearance='error'] { diff --git a/projects/experimental/components/button/button.directive.ts b/projects/experimental/components/button/button.directive.ts index 10d56618fe4c..114039eca248 100644 --- a/projects/experimental/components/button/button.directive.ts +++ b/projects/experimental/components/button/button.directive.ts @@ -6,9 +6,8 @@ import { Input, ViewEncapsulation, } from '@angular/core'; -import {TuiDirectiveStylesService, TuiStringHandler} from '@taiga-ui/cdk'; +import {TuiDirectiveStylesService} from '@taiga-ui/cdk'; import {MODE_PROVIDER, TUI_MODE, TuiBrightness} from '@taiga-ui/core'; -import {TUI_ICON_RESOLVER} from '@taiga-ui/experimental/tokens'; import {Observable} from 'rxjs'; import {TUI_BUTTON_OPTIONS, TuiButtonOptions} from './button.options'; @@ -30,10 +29,6 @@ export class TuiButtonStylesComponent {} host: { tuiButtonNew: '', tuiAppearance: '', - '[class._icon-left]': 'iconLeft', - '[class._icon-right]': 'iconRight', - '[style.--t-mask-left]': '"url(" + resolver(iconLeft) + ")"', - '[style.--t-mask-right]': '"url(" + resolver(iconRight) + ")"', '[attr.data-size]': 'size', '[attr.data-appearance]': 'appearance', '($.data-mode.attr)': 'mode$', @@ -46,14 +41,7 @@ export class TuiButtonDirective { @Input() appearance = this.options.appearance; - @Input() - iconLeft = ''; - - @Input() - iconRight = ''; - constructor( - @Inject(TUI_ICON_RESOLVER) readonly resolver: TuiStringHandler, @Inject(TUI_BUTTON_OPTIONS) private readonly options: TuiButtonOptions, @Inject(TUI_MODE) readonly mode$: Observable, @Inject(TuiDirectiveStylesService) directiveStyles: TuiDirectiveStylesService, diff --git a/projects/experimental/components/button/button.module.ts b/projects/experimental/components/button/button.module.ts index a33f1a1a4de7..01e1585b850e 100644 --- a/projects/experimental/components/button/button.module.ts +++ b/projects/experimental/components/button/button.module.ts @@ -1,13 +1,14 @@ import {CommonModule} from '@angular/common'; import {NgModule} from '@angular/core'; import {TuiLoaderModule, TuiSvgModule} from '@taiga-ui/core'; +import {TuiIconsDirective, TuiIconsModule} from '@taiga-ui/experimental/directives/icons'; import {TuiButtonComponent} from './button.component'; import {TuiButtonDirective, TuiButtonStylesComponent} from './button.directive'; @NgModule({ - imports: [CommonModule, TuiSvgModule, TuiLoaderModule], + imports: [CommonModule, TuiSvgModule, TuiLoaderModule, TuiIconsModule], declarations: [TuiButtonComponent, TuiButtonDirective, TuiButtonStylesComponent], - exports: [TuiButtonComponent, TuiButtonDirective], + exports: [TuiButtonComponent, TuiButtonDirective, TuiIconsDirective], }) export class TuiButtonModule {} diff --git a/projects/experimental/components/button/button.style.less b/projects/experimental/components/button/button.style.less index 49b6b6d6c8b9..2a2f603964f1 100644 --- a/projects/experimental/components/button/button.style.less +++ b/projects/experimental/components/button/button.style.less @@ -33,7 +33,7 @@ tui-svg, tui-icon, &:before { - width: 1rem; + font-size: 1rem; } } @@ -48,8 +48,7 @@ tui-svg, tui-icon, &:not([tuiIconButton][data-appearance='icon']):before { - width: 1rem; - height: 1rem; + font-size: 1rem; } } @@ -101,28 +100,10 @@ } } - &._icon-left:before { - content: ''; - } - - &._icon-right:after { - content: ''; - } - - &:before { - width: 1.5rem; - height: 1.5rem; - background: currentColor; - mask: var(--t-mask-left) no-repeat center/contain; - } - - &:after { - width: 1rem; - height: 1rem; - background: currentColor; + &[tuiIcons]:after { + font-size: 1rem; margin-inline-start: 0.125rem; margin-inline-end: -0.125rem; - mask: var(--t-mask-right) no-repeat center/contain; } } diff --git a/projects/experimental/components/icon/icon.style.less b/projects/experimental/components/icon/icon.style.less index f7182f6fc98a..a8610cdd0665 100644 --- a/projects/experimental/components/icon/icon.style.less +++ b/projects/experimental/components/icon/icon.style.less @@ -3,8 +3,9 @@ :host { position: relative; display: inline-block; - width: 1.5rem; - height: 1.5rem; + width: 1em; + height: 1em; + font-size: 1.5rem; vertical-align: middle; &._duo { diff --git a/projects/experimental/directives/icons/icons.component.ts b/projects/experimental/directives/icons/icons.component.ts new file mode 100644 index 000000000000..b9fbe9f5d75c --- /dev/null +++ b/projects/experimental/directives/icons/icons.component.ts @@ -0,0 +1,12 @@ +import {ChangeDetectionStrategy, Component, ViewEncapsulation} from '@angular/core'; + +@Component({ + template: '', + styleUrls: ['./icons.styles.less'], + encapsulation: ViewEncapsulation.None, + changeDetection: ChangeDetectionStrategy.OnPush, + host: { + class: 'tui-icons', + }, +}) +export class TuiIconsComponent {} diff --git a/projects/experimental/directives/icons/icons.directive.ts b/projects/experimental/directives/icons/icons.directive.ts new file mode 100644 index 000000000000..2933f0bf662f --- /dev/null +++ b/projects/experimental/directives/icons/icons.directive.ts @@ -0,0 +1,32 @@ +import {Directive, Inject, Input} from '@angular/core'; +import {TuiDirectiveStylesService, TuiStringHandler} from '@taiga-ui/cdk'; +import {TUI_ICON_RESOLVER} from '@taiga-ui/experimental/tokens'; + +import {TuiIconsComponent} from './icons.component'; + +// TODO: Turn into a hostDirective in 4.0 +@Directive({ + selector: + '[iconLeft]:is(button,tui-badge),[iconRight]:is(button,tui-badge),[tuiBadge][iconLeft],[tuiBadge][iconRight]', + host: { + tuiIcons: '', + '[class._icon-left]': 'iconLeft', + '[class._icon-right]': 'iconRight', + '[style.--t-mask-left]': '"url(" + resolver(iconLeft) + ")"', + '[style.--t-mask-right]': '"url(" + resolver(iconRight) + ")"', + }, +}) +export class TuiIconsDirective { + @Input() + iconLeft = ''; + + @Input() + iconRight = ''; + + constructor( + @Inject(TUI_ICON_RESOLVER) readonly resolver: TuiStringHandler, + @Inject(TuiDirectiveStylesService) directiveStyles: TuiDirectiveStylesService, + ) { + directiveStyles.addComponent(TuiIconsComponent); + } +} diff --git a/projects/experimental/directives/icons/icons.module.ts b/projects/experimental/directives/icons/icons.module.ts new file mode 100644 index 000000000000..ce484870520b --- /dev/null +++ b/projects/experimental/directives/icons/icons.module.ts @@ -0,0 +1,10 @@ +import {NgModule} from '@angular/core'; + +import {TuiIconsComponent} from './icons.component'; +import {TuiIconsDirective} from './icons.directive'; + +@NgModule({ + declarations: [TuiIconsComponent, TuiIconsDirective], + exports: [TuiIconsDirective], +}) +export class TuiIconsModule {} diff --git a/projects/experimental/directives/icons/icons.styles.less b/projects/experimental/directives/icons/icons.styles.less new file mode 100644 index 000000000000..297fed933f0f --- /dev/null +++ b/projects/experimental/directives/icons/icons.styles.less @@ -0,0 +1,24 @@ +@import '@taiga-ui/core/styles/taiga-ui-local'; + +[tuiIcons] { + &._icon-left:before { + content: ''; + } + + &._icon-right:after { + content: ''; + } + + &:before, + &:after { + width: 1em; + height: 1em; + font-size: 1.5rem; + background: currentColor; + mask: var(--t-mask-left) no-repeat center/contain; + } + + &:after { + mask: var(--t-mask-right) no-repeat center/contain; + } +} diff --git a/projects/experimental/directives/icons/index.ts b/projects/experimental/directives/icons/index.ts new file mode 100644 index 000000000000..ae4696899609 --- /dev/null +++ b/projects/experimental/directives/icons/index.ts @@ -0,0 +1,3 @@ +export * from './icons.component'; +export * from './icons.directive'; +export * from './icons.module'; diff --git a/projects/experimental/directives/icons/ng-package.json b/projects/experimental/directives/icons/ng-package.json new file mode 100644 index 000000000000..bebf62dcb5e5 --- /dev/null +++ b/projects/experimental/directives/icons/ng-package.json @@ -0,0 +1,5 @@ +{ + "lib": { + "entryFile": "index.ts" + } +} diff --git a/projects/experimental/directives/index.ts b/projects/experimental/directives/index.ts index b7a2caafa531..3ee887a47d2a 100644 --- a/projects/experimental/directives/index.ts +++ b/projects/experimental/directives/index.ts @@ -3,6 +3,7 @@ export * from '@taiga-ui/experimental/directives/button-vertical'; export * from '@taiga-ui/experimental/directives/card'; export * from '@taiga-ui/experimental/directives/cell'; export * from '@taiga-ui/experimental/directives/fade'; +export * from '@taiga-ui/experimental/directives/icons'; export * from '@taiga-ui/experimental/directives/progress-segmented'; export * from '@taiga-ui/experimental/directives/sensitive'; export * from '@taiga-ui/experimental/directives/surface';