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

#445 replace heading balancing with native css text wrap #451

Merged
merged 1 commit into from
Nov 13, 2023
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
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
Loading