Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/components-dev/button/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/
import { KbqButtonModule, KbqButtonStyles } from '@koobiq/components/button';
import { KbqComponentColors } from '@koobiq/components/core';
import { KbqIconModule } from '@koobiq/components/icon';
import { KbqTitleModule } from '@koobiq/components/title';
import { ButtonExamplesModule } from 'packages/docs-examples/components/button';

@Component({
Expand All @@ -26,7 +27,7 @@ export class DevDocsExamples {}

@Component({
selector: 'dev-app',
imports: [KbqButtonModule, KbqIconModule, DevDocsExamples],
imports: [KbqButtonModule, KbqIconModule, DevDocsExamples, KbqTitleModule],
templateUrl: 'template.html',
styleUrls: ['styles.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
Expand Down
60 changes: 60 additions & 0 deletions packages/components-dev/button/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,66 @@

<hr />

<div id="icon-slots-demo">
<h4>Explicit prefix/suffix slots (source order is reversed on purpose)</h4>

<!-- prefix written AFTER the text, suffix written BEFORE — slots put them in place -->
<button kbq-button [color]="colors.Contrast">
Кнопка
<i kbqButtonPrefix kbq-icon="kbq-plus_16"></i>
</button>
&nbsp;
<button kbq-button [color]="colors.Contrast">
<i kbqButtonSuffix kbq-icon="kbq-chevron-down-s_16"></i>
Кнопка
</button>
&nbsp;
<button kbq-button [color]="colors.Contrast">
<i kbqButtonSuffix kbq-icon="kbq-chevron-down-s_16"></i>
Кнопка
<i kbqButtonPrefix kbq-icon="kbq-plus_16"></i>
</button>
&nbsp;
<!-- icon-only two-icon trigger, markers in reversed order -->
<button kbq-button class="kbq-dropdown-trigger" [color]="colors.Contrast">
<i kbqButtonSuffix kbq-icon="kbq-chevron-down-s_16"></i>
<i kbqButtonPrefix kbq-icon="kbq-play_16"></i>
</button>
&nbsp;
<!-- non-icon slot content: any element can be projected into a slot and is spaced from the text -->
<button kbq-button [color]="colors.Contrast">
<span kbqButtonPrefix>1</span>
Кнопка
<span kbqButtonSuffix>⌘K</span>
</button>
</div>

<hr />

<div id="ellipsis-demo">
<h4>Text ellipsis (width-constrained)</h4>

<!-- text only -->
<button kbq-button style="max-width: 160px" kbq-title [color]="colors.Contrast">
Очень длинный текст кнопки, который не помещается
</button>
&nbsp;
<!-- with marker icons: icons stay, only the text is clipped -->
<button kbq-button style="max-width: 160px" kbq-title [color]="colors.Contrast">
<i kbqButtonPrefix kbq-icon="kbq-plus_16"></i>
Очень длинный текст кнопки, который не помещается
<i kbqButtonSuffix kbq-icon="kbq-chevron-down-s_16"></i>
</button>
&nbsp;
<!-- legacy: icon in default slot, nested inside .kbq-button-text -->
<button kbq-button style="max-width: 160px" kbq-title [color]="colors.Contrast">
<i kbq-icon="kbq-plus_16"></i>
Очень длинный текст кнопки, который не помещается
</button>
</div>

<hr />

<div>
<div>
<button disabled kbq-button class="kbq-dropdown-trigger">
Expand Down
20 changes: 20 additions & 0 deletions packages/components/button/_button-base.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@use '../core/styles/common/button';
@use '../core/styles/common/list';

@use '../core/styles/common/tokens' as *;

Expand Down Expand Up @@ -47,6 +48,17 @@
& .kbq-button-wrapper {
display: flex;
align-items: center;

min-width: 0;
}

& .kbq-button-text {
@include list.kbq-truncate-line();

display: flex;
align-items: center;

min-width: 0;
}

& .kbq-icon_left {
Expand All @@ -56,4 +68,12 @@
& .kbq-icon_right {
margin-left: var(--kbq-button-size-content-padding);
}

& .kbq-button-prefix {
margin-right: var(--kbq-button-size-content-padding);
}

& .kbq-button-suffix {
margin-left: var(--kbq-button-size-content-padding);
}
}
14 changes: 3 additions & 11 deletions packages/components/button/_button-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
}

@mixin kbq-button-theme() {
.kbq-button-overlay {
display: none;
}

.kbq-button,
.kbq-button-icon {
-webkit-font-smoothing: antialiased;
Expand Down Expand Up @@ -87,7 +83,9 @@
&.kbq-button_filled,
&.kbq-button_outline,
&.kbq-button_transparent {
&.cdk-keyboard-focused {
// :not(.kbq-disabled): a disabled <a kbq-button> can keep DOM focus (tabindex=-1 does
// not blur it), and FocusMonitor stays attached for the whole component lifetime.
&.cdk-keyboard-focused:not(.kbq-disabled) {
$focused-color: var(--kbq-states-line-focus-theme);
outline: 1px solid $focused-color;
border-color: $focused-color;
Expand All @@ -101,10 +99,4 @@
.kbq-button-icon {
@include kbq-typography-level-to-styles-css-variables(typography, text-normal-medium);
}

.kbq-button-icon.kbq-button-wrapper {
.kbq-icon {
@include kbq-css-font-variable(typography, body, line-height, '');
}
}
}
19 changes: 19 additions & 0 deletions packages/components/button/button-slots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Directive } from '@angular/core';

/** Marks content to be projected into the prefix (leading) slot of a button. */
@Directive({
selector: '[kbqButtonPrefix]',
host: {
class: 'kbq-button-prefix'
}
})
export class KbqButtonPrefix {}

/** Marks content to be projected into the suffix (trailing) slot of a button. */
@Directive({
selector: '[kbqButtonSuffix]',
host: {
class: 'kbq-button-suffix'
}
})
export class KbqButtonSuffix {}
14 changes: 11 additions & 3 deletions packages/components/button/button.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<span #kbqTitleText class="kbq-button-wrapper" (cdkObserveContent)="projectContentChanged()">
<ng-content />
<span
#parentTextElement
class="kbq-button-wrapper"
[cdkObserveContentDisabled]="!styler.icons().length"
(cdkObserveContent)="projectContentChanged()"
>
<ng-content select="[kbqButtonPrefix]" />
<span #kbqTitleText class="kbq-button-text">
<ng-content />
</span>
<ng-content select="[kbqButtonSuffix]" />
</span>
<span class="kbq-button-overlay" (click)="haltDisabledEvents($event)"></span>
Loading
Loading