Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scrim): add built-in translations #5435

Merged
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: 0 additions & 4 deletions src/components/scrim/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@ export const CSS = {
scrim: "scrim",
content: "content"
};

export const TEXT = {
loading: "Loading"
};
4 changes: 3 additions & 1 deletion src/components/scrim/scrim.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { newE2EPage } from "@stencil/core/testing";
import { accessible, defaults, hidden, renders } from "../../tests/commonTests";
import { accessible, defaults, hidden, renders, t9n } from "../../tests/commonTests";
import { CSS } from "./resources";

describe("calcite-scrim", () => {
Expand All @@ -19,6 +19,8 @@ describe("calcite-scrim", () => {
}
]));

it("supports translations", () => t9n("calcite-scrim"));

it("shows loading component", async () => {
const page = await newE2EPage();

Expand Down
80 changes: 72 additions & 8 deletions src/components/scrim/scrim.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { Component, Element, Prop, h, VNode } from "@stencil/core";
import { Component, Element, Prop, h, VNode, Watch, State } from "@stencil/core";

import { CSS, TEXT } from "./resources";
import { CSS } from "./resources";
import { connectLocalized, disconnectLocalized, LocalizedComponent } from "../../utils/locale";
import {
connectMessages,
disconnectMessages,
setUpMessages,
T9nComponent,
updateMessages
} from "../../utils/t9n";
import { Messages } from "./assets/scrim/t9n";

/**
* @slot - A slot for adding custom content, primarily loading information.
*/
@Component({
tag: "calcite-scrim",
styleUrl: "scrim.scss",
shadow: true
shadow: true,
assetsDirs: ["assets"]
})
export class Scrim {
export class Scrim implements LocalizedComponent, T9nComponent {
// --------------------------------------------------------------------------
//
// Properties
Expand All @@ -20,15 +30,34 @@ export class Scrim {
/**
* Accessible name when the component is loading.
*
* @default "Loading"
* @deprecated – translations are now built-in, if you need to override a string, please use `messageOverrides`
*/
@Prop() intlLoading?: string = TEXT.loading;
@Prop() intlLoading: string;

/**
* When true, a busy indicator is displayed.
*/
@Prop({ reflect: true }) loading = false;

/**
* Made into a prop for testing purposes only
*
* @internal
*/
@Prop({ mutable: true }) messages: Messages;

/**
* Use this property to override individual strings used by the component.
*/
@Prop({ mutable: true }) messageOverrides: Partial<Messages>;

@Watch("intlLoading")
@Watch("defaultMessages")
@Watch("messageOverrides")
onMessagesChange(): void {
/* wired up by t9n util */
}

// --------------------------------------------------------------------------
//
// Private Properties
Expand All @@ -37,16 +66,51 @@ export class Scrim {

@Element() el: HTMLCalciteScrimElement;

// --------------------------------------------------------------------------
//
// Private State / Properties
//
// --------------------------------------------------------------------------

@State() defaultMessages: Messages;

@State() effectiveLocale = "";

@Watch("effectiveLocale")
effectiveLocaleChange(): void {
updateMessages(this, this.effectiveLocale);
}

//--------------------------------------------------------------------------
//
// Lifecycle
//
//--------------------------------------------------------------------------

connectedCallback(): void {
connectLocalized(this);
connectMessages(this);
}

async componentWillLoad(): Promise<void> {
await setUpMessages(this);
}

disconnectedCallback(): void {
disconnectLocalized(this);
disconnectMessages(this);
}

// --------------------------------------------------------------------------
//
// Render Method
//
// --------------------------------------------------------------------------

render(): VNode {
const { el, loading, intlLoading } = this;
const { el, loading, messages } = this;
const hasContent = el.innerHTML.trim().length > 0;
const loaderNode = loading ? <calcite-loader active label={intlLoading} /> : null;
const loaderNode = loading ? <calcite-loader active label={messages.loading} /> : null;
const contentNode = hasContent ? (
<div class={CSS.content}>
<slot />
Expand Down