Skip to content

Commit

Permalink
#445 replace heading balancing with native css text wrap (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sqrrl authored Nov 13, 2023
1 parent 9da5880 commit 8d4ce24
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 30 deletions.
7 changes: 7 additions & 0 deletions .changeset/thick-coats-speak.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion packages/swirl-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
text-align: start;
}

.heading--balanced {
text-wrap: balance;
}

.heading--align-start {
text-align: start;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("swirl-heading", () => {
expect(page.root).toEqualHtml(`
<swirl-heading heading-id="id" level="3">
Heading
<h3 class="heading heading--align-start heading--level-3" id="id"></h3>
<h3 class="heading heading--align-start heading--balanced heading--level-3" id="id"></h3>
</swirl-heading>
`);
});
Expand All @@ -26,7 +26,7 @@ describe("swirl-heading", () => {
expect(page.root).toEqualHtml(`
<swirl-heading as="h6" heading-id="id" level="3">
Heading
<h6 class="heading heading--align-start heading--level-3" id="id"></h6>
<h6 class="heading heading--align-start heading--balanced heading--level-3" id="id"></h6>
</swirl-heading>
`);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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}`;

Expand All @@ -70,18 +50,14 @@ export class SwirlHeading {
`heading--align-${this.align}`,
`heading--level-${this.level}`,
{
"heading--balanced": this.balance,
"heading--truncate": this.truncate,
}
);

return (
<Host>
<Tag
class={className}
id={this.headingId}
ref={(el) => (this.headingEl = el)}
style={styles}
>
<Tag class={className} id={this.headingId} style={styles}>
{this.text}
</Tag>
</Host>
Expand Down

0 comments on commit 8d4ce24

Please sign in to comment.