diff --git a/.changeset/thick-coats-speak.md b/.changeset/thick-coats-speak.md new file mode 100644 index 000000000..6c9d2fba8 --- /dev/null +++ b/.changeset/thick-coats-speak.md @@ -0,0 +1,7 @@ +--- +"@getflip/swirl-components": patch +"@getflip/swirl-components-angular": patch +"@getflip/swirl-components-react": patch +--- + +Replace JS text balancing of swirl-heading with native css text wrap diff --git a/packages/swirl-components/package.json b/packages/swirl-components/package.json index 5ccd27574..e69425814 100644 --- a/packages/swirl-components/package.json +++ b/packages/swirl-components/package.json @@ -46,7 +46,6 @@ "@getflip/swirl-tokens": "^2.4.0", "@stencil/core": "^3.3.1", "a11y-dialog": "^7.5.2", - "balance-text": "^3.3.1", "body-scroll-lock": "^4.0.0-beta.0", "classnames": "^2.3.1", "color2k": "^2.0.0", diff --git a/packages/swirl-components/src/components/swirl-heading/swirl-heading.css b/packages/swirl-components/src/components/swirl-heading/swirl-heading.css index d8c76cbde..d47ec9a40 100644 --- a/packages/swirl-components/src/components/swirl-heading/swirl-heading.css +++ b/packages/swirl-components/src/components/swirl-heading/swirl-heading.css @@ -17,6 +17,10 @@ text-align: start; } +.heading--balanced { + text-wrap: balance; +} + .heading--align-start { text-align: start; } diff --git a/packages/swirl-components/src/components/swirl-heading/swirl-heading.spec.tsx b/packages/swirl-components/src/components/swirl-heading/swirl-heading.spec.tsx index dc70aedf1..052d8484b 100644 --- a/packages/swirl-components/src/components/swirl-heading/swirl-heading.spec.tsx +++ b/packages/swirl-components/src/components/swirl-heading/swirl-heading.spec.tsx @@ -12,7 +12,7 @@ describe("swirl-heading", () => { expect(page.root).toEqualHtml(` Heading -

+

`); }); @@ -26,7 +26,7 @@ describe("swirl-heading", () => { expect(page.root).toEqualHtml(` Heading -
+
`); }); diff --git a/packages/swirl-components/src/components/swirl-heading/swirl-heading.tsx b/packages/swirl-components/src/components/swirl-heading/swirl-heading.tsx index 0610ee430..b9ab9598b 100644 --- a/packages/swirl-components/src/components/swirl-heading/swirl-heading.tsx +++ b/packages/swirl-components/src/components/swirl-heading/swirl-heading.tsx @@ -1,6 +1,5 @@ -import { Component, h, Host, Listen, Prop } from "@stencil/core"; +import { Component, h, Host, Prop } from "@stencil/core"; import classnames from "classnames"; -import balanceText from "balance-text"; export type SwirlHeadingAlign = "start" | "center" | "end"; @@ -33,25 +32,6 @@ export class SwirlHeading { @Prop() text!: string; @Prop() truncate?: boolean; - private headingEl: HTMLElement; - - componentDidRender() { - this.rebalance(); - } - - @Listen("resize", { target: "window" }) - onWindowResize() { - this.rebalance(); - } - - private rebalance() { - if (!this.balance || !Boolean(this.headingEl) || Boolean(this.lines)) { - return; - } - - balanceText(this.headingEl); - } - render() { const Tag = this.as || `h${this.level}`; @@ -70,18 +50,14 @@ export class SwirlHeading { `heading--align-${this.align}`, `heading--level-${this.level}`, { + "heading--balanced": this.balance, "heading--truncate": this.truncate, } ); return ( - (this.headingEl = el)} - style={styles} - > + {this.text}