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(button): add built-in translations #5447

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
45a5379
feat(button): add built-in translations
anveshmekala Oct 11, 2022
cd712cc
change watcher order
anveshmekala Oct 11, 2022
c74615b
remove intl default test assertion
anveshmekala Oct 14, 2022
355d1d7
Merge branch 'master' into anveshmekala/4961-button-add-built-in-tran…
anveshmekala Oct 14, 2022
b3eac70
cleanup
anveshmekala Oct 14, 2022
12ba7cd
Merge branch 'master' into anveshmekala/4961-button-add-built-in-tran…
anveshmekala Oct 14, 2022
9989992
handle edge case
anveshmekala Oct 14, 2022
f4fe653
Merge branch 'master' into anveshmekala/4961-button-add-built-in-tran…
anveshmekala Oct 19, 2022
d98a2b0
fix build errors
anveshmekala Oct 19, 2022
2c95999
Merge branch 'master' into anveshmekala/4961-button-add-built-in-tran…
anveshmekala Oct 19, 2022
0eb8a16
Merge branch 'master' into anveshmekala/4961-button-add-built-in-tran…
anveshmekala Oct 19, 2022
3643365
docs(conventions): update style guide (#5530)
benelan Oct 20, 2022
519df13
fix(slider): fix slider (single-value) error when clicking range (#5533)
jcfranco Oct 20, 2022
f9cdb01
1.0.0-next.603
github-actions[bot] Oct 20, 2022
f6e192a
ci(screener): reenable screener on pushes to master to update baselin…
benelan Oct 21, 2022
ed55933
fix: components should only react to primary button pointer events. (…
driskull Oct 21, 2022
8392732
1.0.0-next.604
github-actions[bot] Oct 21, 2022
2e025d8
feat(date-picker, input-date-picker): add numberingSystem property (#…
benelan Oct 22, 2022
f679dd1
1.0.0-next.605
github-actions[bot] Oct 22, 2022
6540c49
docs: consistent api styling + define card thumbnailPosition (#5518)
geospatialem Oct 23, 2022
49d871d
fix(value-list-item): Change drag handle color. (#5543)
driskull Oct 24, 2022
819236a
1.0.0-next.606
github-actions[bot] Oct 24, 2022
04cb8cb
fix: add custom logic for floating-ui positioning across shadow DOM i…
jcfranco Oct 24, 2022
4c939ea
fix: fix jarring positioning when a closed component is first opened …
jcfranco Oct 24, 2022
e3ab8b7
1.0.0-next.607
github-actions[bot] Oct 24, 2022
4cb0ea1
fix(calcite-loader, calcite-input-message): drop active in favor of h…
Elijbet Oct 25, 2022
f07df87
1.0.0-next.608
github-actions[bot] Oct 25, 2022
f35ebb6
Merge branch 'master' into anveshmekala/4961-button-add-built-in-tran…
anveshmekala Oct 25, 2022
85e89d6
feat(flow-item): Add calciteFlowItemScroll event (#5547)
driskull Oct 25, 2022
3e40e4f
1.0.0-next.609
github-actions[bot] Oct 25, 2022
b12ad32
ci: adds w3c url for a11y issue filing (#5556)
geospatialem Oct 25, 2022
ef3ebf8
fix(date-picker): display correct date format order in header for zh-…
anveshmekala Oct 25, 2022
d580d06
1.0.0-next.610
github-actions[bot] Oct 25, 2022
187620a
fix(stepper-item): make sure numberingSystem is rendered on load (#5640)
benelan Oct 26, 2022
b4ce296
1.0.0-next.611
github-actions[bot] Oct 26, 2022
5fb8b7f
feedback changes
anveshmekala Oct 26, 2022
6670c48
remove browser build conditional
anveshmekala Oct 26, 2022
dc48d00
fix(slider): dragging range fires input event (#5641)
alisonailea Oct 26, 2022
35b3fe0
fix(tooltip): Prevent opening when closeOnClick is true and reference…
driskull Oct 26, 2022
3ae1826
fix(types): fix type issue caused by unintentionally moving @floating…
jcfranco Oct 26, 2022
3a3ad46
avoid fetching in hydrate builds
anveshmekala Oct 26, 2022
1146332
Merge branch 'master' into anveshmekala/4961-button-add-built-in-tran…
anveshmekala Oct 26, 2022
68a5c88
Merge branch 'anveshmekala/4961-add-built-in-pseudo-translations' int…
anveshmekala Oct 26, 2022
3592e2d
resolve conflicts
anveshmekala Oct 26, 2022
7c48122
clean up
anveshmekala Oct 26, 2022
0ccc5b2
more cleanup
anveshmekala Oct 26, 2022
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
8 changes: 3 additions & 5 deletions src/components/button/button.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { E2EElement, newE2EPage } from "@stencil/core/testing";
import { accessible, disabled, HYDRATED_ATTR, labelable, defaults, hidden } from "../../tests/commonTests";
import { accessible, disabled, HYDRATED_ATTR, labelable, defaults, hidden, t9n } from "../../tests/commonTests";
import { CSS } from "./resources";
import { GlobalTestProps } from "../../tests/utils";
import { html } from "../../../support/formatting";
Expand Down Expand Up @@ -43,10 +43,6 @@ describe("calcite-button", () => {
propertyName: "iconStart",
defaultValue: undefined
},
{
propertyName: "intlLoading",
defaultValue: "Loading"
},
{
propertyName: "loading",
defaultValue: false
Expand Down Expand Up @@ -601,4 +597,6 @@ describe("calcite-button", () => {
it("submits", async () => assertOnFormButtonType("submit"));
it("resets", async () => assertOnFormButtonType("reset"));
});

it("supports translation", () => t9n("calcite-button"));
});
114 changes: 88 additions & 26 deletions src/components/button/button.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import "form-request-submit-polyfill/form-request-submit-polyfill";
import { Component, Element, h, Method, Prop, Build, State, VNode, Watch } from "@stencil/core";
import { CSS, TEXT } from "./resources";
import { CSS } from "./resources";
import { closestElementCrossShadowBoundary } from "../../utils/dom";
import { ButtonAlignment, ButtonAppearance, ButtonColor } from "./interfaces";
import { FlipContext, Scale, Width } from "../interfaces";
import { LabelableComponent, connectLabel, disconnectLabel, getLabelText } from "../../utils/label";
import { createObserver } from "../../utils/observers";
import { InteractiveComponent, updateHostInteraction } from "../../utils/interactive";
import { submitForm, resetForm, FormOwner } from "../../utils/form";
import { connectLocalized, disconnectLocalized, LocalizedComponent } from "../../utils/locale";
import {
connectMessages,
disconnectMessages,
setUpMessages,
T9nComponent,
updateMessages
} from "../../utils/t9n";
import { Messages } from "./assets/button/t9n";

/** Passing a 'href' will render an anchor link, instead of a button. Role will be set to link, or button, depending on this. */
/** It is the consumers responsibility to add aria information, rel, target, for links, and any button attributes for form submission */
Expand All @@ -16,9 +25,12 @@ import { submitForm, resetForm, FormOwner } from "../../utils/form";
@Component({
tag: "calcite-button",
styleUrl: "button.scss",
shadow: true
shadow: true,
assetsDirs: ["assets"]
})
export class Button implements LabelableComponent, InteractiveComponent, FormOwner {
export class Button
implements LabelableComponent, InteractiveComponent, FormOwner, LocalizedComponent, T9nComponent
{
//--------------------------------------------------------------------------
//
// Element
Expand All @@ -33,74 +45,103 @@ export class Button implements LabelableComponent, InteractiveComponent, FormOwn
//
//--------------------------------------------------------------------------

/** optionally specify alignment of button elements. */
/** Specifies the alignment of the component's elements. */
@Prop({ reflect: true }) alignment?: ButtonAlignment = "center";

/** specify the appearance style of the button, defaults to solid. */
/** Specifies the appearance style of the component. */
@Prop({ reflect: true }) appearance: ButtonAppearance = "solid";

/** Applies to the aria-label attribute on the button or hyperlink */
/** Accessible name for the component. */
@Prop() label?: string;

/** specify the color of the button, defaults to blue */
/** Specifies the color of the component. */
@Prop({ reflect: true }) color: ButtonColor = "blue";

/** is the button disabled */
/** When `true`, interaction is prevented and the component is displayed with lower opacity. */
@Prop({ reflect: true }) disabled = false;

/** optionally pass a href - used to determine if the component should render as a button or an anchor */
/**
* Specifies the URL of the linked resource, which can be set as an absolute or relative path.
*/
@Prop({ reflect: true }) href?: string;

/** Specifies an icon to display at the end of the component. */
@Prop({ reflect: true }) iconEnd?: string;

/** When true, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */
/** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl?: FlipContext;

/** Specifies an icon to display at the start of the component. */
@Prop({ reflect: true }) iconStart?: string;

/**
* string to override English loading text
* 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;

/** optionally add a calcite-loader component to the button, disabling interaction. */
/**
* When `true`, a busy indicator is displayed and interaction is disabled.
*/
@Prop({ reflect: true }) loading = false;

/** The name attribute to apply to the button */
/** Specifies the name of the component on form submission. */
@Prop({ reflect: true }) name?: string;

/** The rel attribute to apply to the hyperlink */
/**
* Defines the relationship between the `href` value and the current document.
*
* @mdn [rel](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel)
*/
@Prop({ reflect: true }) rel?: string;

/**
* The form ID to associate with the component
* The form ID to associate with the component.
*
* @deprecated – this property is no longer needed if placed inside a form.
* @deprecated – The property is no longer needed if the component is placed inside a form.
*/
@Prop() form?: string;

/** optionally add a round style to the button */
/** When `true`, adds a round style to the component. */
@Prop({ reflect: true }) round = false;

/** specify the scale of the button, defaults to m */
/** Specifies the size of the component. */
@Prop({ reflect: true }) scale: Scale = "m";

/** is the button a child of a calcite-split-button */
/** Specifies if the component is a child of a `calcite-split-button`. */
@Prop({ reflect: true }) splitChild?: "primary" | "secondary" | false = false;

/** The target attribute to apply to the hyperlink */
/**
* Specifies where to open the linked document defined in the `href` property.
*
* @mdn [target](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target)
*/
@Prop({ reflect: true }) target?: string;

/** The type attribute to apply to the button */
/**
* Specifies the default behavior of the button.
*
* @mdn [type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-type)
*/
@Prop({ mutable: true, reflect: true }) type = "button";

/** specify the width of the button, defaults to auto */
/** Specifies the width of the component. */
@Prop({ reflect: true }) width: Width = "auto";

/**
* 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("loading")
loadingChanged(newValue: boolean, oldValue: boolean): void {
if (!!newValue && !oldValue) {
Expand All @@ -113,13 +154,22 @@ export class Button implements LabelableComponent, InteractiveComponent, FormOwn
}
}

@Watch("intlLoading")
@Watch("defaultMessages")
@Watch("messageOverrides")
onMessagesChange(): void {
/** referred in t9n util */
}

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

connectedCallback(): void {
async connectedCallback(): Promise<void> {
connectLocalized(this);
connectMessages(this);
this.hasLoader = this.loading;
this.setupTextContentObserver();
connectLabel(this);
Expand All @@ -132,12 +182,15 @@ export class Button implements LabelableComponent, InteractiveComponent, FormOwn
disconnectedCallback(): void {
this.mutationObserver?.disconnect();
disconnectLabel(this);
disconnectLocalized(this);
disconnectMessages(this);
this.formEl = null;
}

componentWillLoad(): void {
async componentWillLoad(): Promise<void> {
if (Build.isBrowser) {
this.updateHasContent();
await setUpMessages(this);
}
}

Expand All @@ -154,7 +207,7 @@ export class Button implements LabelableComponent, InteractiveComponent, FormOwn
active
class={this.loading ? CSS.loadingIn : CSS.loadingOut}
inline
label={this.intlLoading}
label={this.messages.loading}
scale={this.scale === "l" ? "m" : "s"}
/>
</div>
Expand Down Expand Up @@ -244,6 +297,15 @@ export class Button implements LabelableComponent, InteractiveComponent, FormOwn
/** determine if loader present for styling purposes */
@State() private hasLoader = false;

@State() effectiveLocale = "";

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

@State() defaultMessages: Messages;

private updateHasContent() {
const slottedContent = this.el.textContent.trim().length > 0 || this.el.childNodes.length > 0;
this.hasContent =
Expand Down
4 changes: 0 additions & 4 deletions src/components/button/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ export const CSS = {
iconStartEmpty: "icon-start-empty",
iconEndEmpty: "icon-end-empty"
};

export const TEXT = {
loading: "Loading"
};
21 changes: 21 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* This module helps users provide custom configuration for component internals.
*
* @internal
*/

const configOverrides = globalThis["calciteComponentsConfig"];

const config = {
/**
* We apply a custom fix to improve positioning for non-Chromium browsers.
* The fix comes at a performance cost, so provides users a way to opt-out if necessary.
*
* @internal
*/
floatingUINonChromiumPositioningFix: true,

...configOverrides
};

export { config };
Loading