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
4 changes: 2 additions & 2 deletions skills/tedi-angular/references/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ Both entry points declare `[tedi-floating-button]`. The Community component is
or scrolling. Corner rounding is carried by the first and last block, not the card.
- **`tedi-card-row` stacks via its `direction` input**, not a flex-direction utility class, because
the row uses `direction` to decide which corners it rounds.
- **`tedi-card-icon` does not inherit the card's background.** Its `background` defaults to
`brand-primary` independently.
- **`tedi-card-icon` does not inherit the card's background.** Its `backgroundColor` defaults to
`secondary`, or `brand-primary` with `type="brand"`, independently.
- **`[tedi-label-row]` projects your own `<label tedi-label>`** plus trailing affixes as siblings, so
native label attributes (`for`, `id`, `aria-*`, handlers) keep working.
- **`tedi-inline-edit` needs an `<ng-template tediInlineEditControl>`.** The control goes in that
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<tedi-card-content
[background]="background() ?? 'primary'"
[backgroundColor]="background() ?? 'primary'"
[padding]="1"
[id]="contentId()"
role="region"
Expand Down
2 changes: 1 addition & 1 deletion src/community/components/form/search/search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
>
<tedi-card
class="tedi-search__panel"
background="primary"
backgroundColor="primary"
[style.width.px]="_width()"
>
@if (loading()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
>
<tedi-card
class="tedi-select__dropdown"
background="primary"
backgroundColor="primary"
[padding]="0"
[style.width]="!!dropdownWidth() ? dropdownWidth() + 'px' : 'auto'"
>
Expand Down
2 changes: 1 addition & 1 deletion src/community/components/form/select/select.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
>
<tedi-card
class="tedi-select__dropdown"
background="primary"
backgroundColor="primary"
[padding]="0"
[style.width]="!!dropdownWidth() ? dropdownWidth() + 'px' : 'auto'"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ng-template #defaultTemplate>
<nav [attr.aria-label]="ariaLabel()" [class]="classes()">
<tedi-card background="primary" [padding]="0">
<tedi-card backgroundColor="primary" [padding]="0">
<tedi-card-content
class="table-of-contents__content"
[padding]="{ top: 0, right: 0, bottom: 1, left: 0 }"
Expand All @@ -19,7 +19,7 @@ <h1 tedi-text modifiers="h4" class="table-of-contents__header">
@if (!isOpen()) {
<ng-container *ngTemplateOutlet="defaultTemplate" />

<tedi-card [class]="footerClasses()" background="primary" [padding]="0">
<tedi-card [class]="footerClasses()" backgroundColor="primary" [padding]="0">
<tedi-card-content>
<button
class="table-of-contents__footer-trigger"
Expand Down
4 changes: 2 additions & 2 deletions src/community/components/navigation/tabs/tabs.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ng-template #tabsList><ng-content select="[tedi-tab]" /></ng-template>

<tedi-card background="primary" [padding]="0">
<tedi-card backgroundColor="primary" [padding]="0">
<tedi-card-content>
<div role="tablist" class="tedi-tabs__tab-list">
@if (!mobileTabsOpened()) {
Expand Down Expand Up @@ -32,7 +32,7 @@
@if (mobileTabsOpened()) {
<tedi-card
class="tedi-tabs__mobile-dropdown"
background="primary"
backgroundColor="primary"
[padding]="0"
>
<tedi-card-content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
>
<tedi-card
class="tedi-dropdown__card"
background="primary"
backgroundColor="primary"
[padding]="0"
[attr.role]="dropdownRole()"
[attr.id]="dropdownId()"
Expand Down
11 changes: 9 additions & 2 deletions src/tedi/components/base/icon/icon.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe("IconComponent", () => {
];

for (const bg of backgrounds) {
fixture.componentRef.setInput("background", bg);
fixture.componentRef.setInput("backgroundColor", bg);
fixture.detectChanges();

expect(iconElement.classList).toContain("tedi-icon--bg");
Expand All @@ -115,7 +115,7 @@ describe("IconComponent", () => {
});

it("should clamp size and set padding for background icons", () => {
fixture.componentRef.setInput("background", "primary");
fixture.componentRef.setInput("backgroundColor", "primary");

fixture.componentRef.setInput("size", 8);
fixture.detectChanges();
Expand Down Expand Up @@ -143,6 +143,13 @@ describe("IconComponent", () => {
);
});

it("should support the deprecated background input", () => {
fixture.componentRef.setInput("background", "primary");
fixture.detectChanges();

expect(iconElement.classList).toContain("tedi-icon--bg-primary");
});

it("should apply filled variant", () => {
fixture.componentRef.setInput("variant", "filled");
fixture.detectChanges();
Expand Down
20 changes: 16 additions & 4 deletions src/tedi/components/base/icon/icon.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ export class IconComponent {
/**
* Background color for the icon (adds a circular background).
*/
backgroundColor = input<IconBackgroundColor>();
/**
* **Deprecated.** Use `backgroundColor` instead.
* @deprecated Use `backgroundColor` instead.
*/
background = input<IconBackgroundColor>();

readonly resolvedBackgroundColor = computed(
() => this.backgroundColor() ?? this.background(),
);
/**
* Whether the icon should be filled or outlined.
* @default outlined
Expand All @@ -96,7 +105,7 @@ export class IconComponent {
iconSizeVar = computed<string | null>(() => {
const size = this.size();

if (this.background()) {
if (this.resolvedBackgroundColor()) {
const bgSize =
size !== undefined &&
size !== "inherit" &&
Expand All @@ -114,7 +123,7 @@ export class IconComponent {
});

iconBgPadding = computed<string | null>(() => {
if (!this.background()) {
if (!this.resolvedBackgroundColor()) {
return null;
}

Expand All @@ -140,8 +149,11 @@ export class IconComponent {
`tedi-icon--color-${this.color()}`,
];

if (this.background()) {
classes.push("tedi-icon--bg", `tedi-icon--bg-${this.background()}`);
if (this.resolvedBackgroundColor()) {
classes.push(
"tedi-icon--bg",
`tedi-icon--bg-${this.resolvedBackgroundColor()}`,
);
} else if (this.size() === "inherit") {
classes.push("tedi-icon--size-inherit");
}
Expand Down
28 changes: 18 additions & 10 deletions src/tedi/components/base/icon/icon.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default {
defaultValue: { summary: "primary" },
},
},
background: {
backgroundColor: {
description:
"Background color for the icon (adds a circular background).",
control: "select",
Expand All @@ -114,6 +114,14 @@ export default {
},
},
},
background: {
description: "**Deprecated.** Use `backgroundColor` instead.",
control: false,
table: {
category: "inputs",
type: { summary: "IconBackgroundColor" },
},
},
type: {
description:
"Type of Material Symbols icon style. <br /> It is recommended to only use one type throughout your app.",
Expand Down Expand Up @@ -192,7 +200,7 @@ export const IconSize: StoryObj<IconComponent> = {

export const IconSizeInsideBackground: StoryObj<IconComponent> = {
args: {
background: "brand-secondary",
backgroundColor: "brand-secondary",
color: "brand",
},
render: (args) => ({
Expand Down Expand Up @@ -280,10 +288,10 @@ export const IconBackgroundColors: StoryObj<IconComponent> = {
props: args,
template: `
<div class="flex align-items-center gap-4">
<tedi-icon ${argsToTemplate(args)} [name]="'vaccines'" color="white" background="brand-primary" [size]="24" />
<tedi-icon ${argsToTemplate(args)} [name]="'info'" color="white" background="brand-primary" [size]="16" />
<tedi-icon ${argsToTemplate(args)} [name]="'vaccines'" color="brand" background="brand-secondary" [size]="24" />
<tedi-icon ${argsToTemplate(args)} [name]="'info'" color="brand" background="brand-secondary" [size]="16" />
<tedi-icon ${argsToTemplate(args)} [name]="'vaccines'" color="white" backgroundColor="brand-primary" [size]="24" />
<tedi-icon ${argsToTemplate(args)} [name]="'info'" color="white" backgroundColor="brand-primary" [size]="16" />
<tedi-icon ${argsToTemplate(args)} [name]="'vaccines'" color="brand" backgroundColor="brand-secondary" [size]="24" />
<tedi-icon ${argsToTemplate(args)} [name]="'info'" color="brand" backgroundColor="brand-secondary" [size]="16" />
<div
class="display-flex gap-3"
[ngStyle]="{
Expand All @@ -292,10 +300,10 @@ export const IconBackgroundColors: StoryObj<IconComponent> = {
'padding': '16px'
}"
>
<tedi-icon ${argsToTemplate(args)} [name]="'vaccines'" color="brand" background="primary" [size]="24" />
<tedi-icon ${argsToTemplate(args)} [name]="'info'" color="brand" background="primary" [size]="16" />
<tedi-icon ${argsToTemplate(args)} [name]="'vaccines'" color="white" background="secondary" [size]="24" />
<tedi-icon ${argsToTemplate(args)} [name]="'info'" color="white" background="secondary" [size]="16" />
<tedi-icon ${argsToTemplate(args)} [name]="'vaccines'" color="brand" backgroundColor="primary" [size]="24" />
<tedi-icon ${argsToTemplate(args)} [name]="'info'" color="brand" backgroundColor="primary" [size]="16" />
<tedi-icon ${argsToTemplate(args)} [name]="'vaccines'" color="white" backgroundColor="secondary" [size]="24" />
<tedi-icon ${argsToTemplate(args)} [name]="'info'" color="white" backgroundColor="secondary" [size]="16" />
</div>
</div>
`,
Expand Down
4 changes: 2 additions & 2 deletions src/tedi/components/content/accordion/accordion.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ const VARIANTS_TEMPLATE = `
<tedi-accordion-item>
<tedi-accordion-item-header>
<span tedi-accordion-title>Pealkiri</span>
<tedi-icon tedi-accordion-before-title name="account_circle" color="brand" background="brand-secondary" [size]="16"></tedi-icon>
<tedi-icon tedi-accordion-before-title name="account_circle" color="brand" backgroundColor="brand-secondary" [size]="16"></tedi-icon>
</tedi-accordion-item-header>
<tedi-accordion-item-content>${contentExample}</tedi-accordion-item-content>
</tedi-accordion-item>
Expand Down Expand Up @@ -977,7 +977,7 @@ const CUSTOMIZED_TEMPLATE = `
[headerClass]="'custom-icon-rotation'"
>
<span tedi-accordion-title>Pealkiri</span>
<tedi-icon tedi-accordion-before-title name="account_circle" color="brand" background="brand-secondary" [size]="16"></tedi-icon>
<tedi-icon tedi-accordion-before-title name="account_circle" color="brand" backgroundColor="brand-secondary" [size]="16"></tedi-icon>
<tedi-status-badge tedi-accordion-after-title color="neutral" text="Uus" />
</tedi-accordion-item-header>
<tedi-accordion-item-content>${contentExample}</tedi-accordion-item-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { BreakpointObserver } from "@angular/cdk/layout";
import { of } from "rxjs";
import { CardComponent } from "../card.component";
import { CardContentComponent } from "./card-content.component";
import { CardHeaderComponent } from "../card-header/card-header.component";
import { CardBackground, CardPadding } from "../card.utils";

@Component({
standalone: true,
imports: [CardContentComponent],
template: `
<tedi-card-content
[background]="background"
[backgroundColor]="background"
[padding]="padding"
[backgroundImage]="backgroundImage"
[backgroundPosition]="backgroundPosition"
Expand All @@ -35,8 +36,8 @@ class TestHostComponent {
standalone: true,
imports: [CardComponent, CardContentComponent],
template: `
<tedi-card [background]="cardBackground" [padding]="cardPadding">
<tedi-card-content [background]="background" [padding]="padding">
<tedi-card [backgroundColor]="cardBackground" [padding]="cardPadding">
<tedi-card-content [backgroundColor]="background" [padding]="padding">
Content
</tedi-card-content>
</tedi-card>
Expand Down Expand Up @@ -194,3 +195,39 @@ describe("CardContentComponent inside CardComponent", () => {
).toBe("2rem");
});
});

@Component({
standalone: true,
imports: [CardComponent, CardContentComponent, CardHeaderComponent],
template: `
<tedi-card background="secondary">
<tedi-card-header background="tertiary">Header</tedi-card-header>
<tedi-card-content>Inherited</tedi-card-content>
<tedi-card-content background="accent">Own</tedi-card-content>
</tedi-card>
`,
})
class DeprecatedBackgroundHostComponent {}

describe("Card deprecated background input", () => {
it("is supported on tedi-card, tedi-card-header and tedi-card-content", () => {
TestBed.configureTestingModule({
imports: [DeprecatedBackgroundHostComponent],
providers: [breakpointObserverMock],
});
const fixture = TestBed.createComponent(DeprecatedBackgroundHostComponent);
fixture.detectChanges();
const el = fixture.nativeElement as HTMLElement;

expect(el.querySelector("tedi-card-header")?.classList).toContain(
"tedi-card-header--background--tertiary",
);
const [inherited, own] = Array.from(
el.querySelectorAll("tedi-card-content"),
);
expect(inherited.classList).toContain(
"tedi-card-content--background--secondary",
);
expect(own.classList).toContain("tedi-card-content--background--accent");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from "../card.utils";

export type CardContentInputs = {
backgroundColor?: CardBackground;
background?: CardBackground;
padding?: CardPadding;
backgroundImage?: string;
Expand All @@ -28,7 +29,7 @@ export type CardContentInputs = {
};

/**
* Content block of a card. Inherits unset `background` and `padding`
* Content block of a card. Inherits unset `backgroundColor` and `padding`
* from the parent `tedi-card`.
*/
@Component({
Expand All @@ -45,8 +46,13 @@ export type CardContentInputs = {
})
export class CardContentComponent implements BreakpointInputs<CardContentInputs> {
/**
* Background color.
* @default primary
* Background color. `tedi-card-content` inherits it from the parent `tedi-card` and falls back to
* `primary`; `tedi-card-header` defaults to `brand-primary` and `tedi-card-icon` to `secondary`.
*/
backgroundColor = input<CardBackground>();
Comment thread
ly-tempel-bitweb marked this conversation as resolved.
Resolved
/**
* **Deprecated.** Use `backgroundColor` instead.
* @deprecated Use `backgroundColor` instead.
*/
background = input<CardBackground>();
/**
Expand Down Expand Up @@ -94,6 +100,7 @@ export class CardContentComponent implements BreakpointInputs<CardContentInputs>

breakpointInputs = computed(() => {
return this.breakpointService.getBreakpointInputs<CardContentInputs>({
backgroundColor: this.backgroundColor(),
background: this.background(),
padding: this.padding(),
backgroundImage: this.backgroundImage(),
Expand All @@ -112,9 +119,12 @@ export class CardContentComponent implements BreakpointInputs<CardContentInputs>
});

classes = computed(() => {
const { background, autoWidth } = this.breakpointInputs();
const { backgroundColor, background, autoWidth } = this.breakpointInputs();
const resolvedBackground =
background ?? this.inheritedBackground() ?? this.defaultBackground;
backgroundColor ??
background ??
this.inheritedBackground() ??
this.defaultBackground;
const classList = [
this.blockClass,
`${this.blockClass}--background--${resolvedBackground}`,
Expand Down Expand Up @@ -160,7 +170,8 @@ export class CardContentComponent implements BreakpointInputs<CardContentInputs>
});

protected inheritedBackground(): CardBackground | undefined {
return this.card?.breakpointInputs().background;
const { backgroundColor, background } = this.card?.breakpointInputs() ?? {};
return backgroundColor ?? background;
}

protected defaultPadding(): CardPadding {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { CardBackground, CardPadding } from "../card.utils";
standalone: true,
imports: [CardComponent, CardHeaderComponent],
template: `
<tedi-card [background]="cardBackground" [padding]="cardPadding">
<tedi-card-header [background]="background" [padding]="padding">
<tedi-card [backgroundColor]="cardBackground" [padding]="cardPadding">
<tedi-card-header [backgroundColor]="background" [padding]="padding">
<span class="projected">Header</span>
</tedi-card-header>
</tedi-card>
Expand Down
Loading
Loading