Skip to content

Commit 3d49b6d

Browse files
feat(Text): add text-wrap support via textWrap prop (#1776)
## 📝 Changes - Adds `textWrap` prop to `Text` component: https://developer.mozilla.org/en-US/docs/Web/CSS/text-wrap Specifically, found need in product for specifying `text-wrap: balance`. ## ✅ Checklist Easy UI has certain UX standards that must be met. In general, non-trivial changes should meet the following criteria: - [x] Visuals match Design Specs in Figma - [x] Stories accompany any component changes - [x] Code is in accordance with our style guide - [x] Design tokens are utilized - [x] Unit tests accompany any component changes - ~[ ] TSDoc is written for any API surface area~ - ~[ ] Specs are up-to-date~ - [x] Console is free from warnings - [x] No accessibility violations are reported - [x] Cross-browser check is performed (Chrome, Safari, Firefox) - [x] Changeset is added ~Strikethrough~ any items that are not applicable to this pull request.
1 parent aafbab4 commit 3d49b6d

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

.changeset/green-horses-trade.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@easypost/easy-ui": minor
3+
---
4+
5+
feat(Text): add text-wrap support via textWrap prop

easy-ui-react/src/Text/Text.module.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,23 @@
114114
.fontVariantNumericTabular-nums {
115115
font-variant-numeric: tabular-nums;
116116
}
117+
118+
.textWrapWrap {
119+
text-wrap: wrap;
120+
}
121+
122+
.textWrapNoWrap {
123+
text-wrap: nowrap;
124+
}
125+
126+
.textWrapBalance {
127+
text-wrap: balance;
128+
}
129+
130+
.textWrapPretty {
131+
text-wrap: pretty;
132+
}
133+
134+
.textWrapStable {
135+
text-wrap: stable;
136+
}

easy-ui-react/src/Text/Text.stories.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,25 @@ export const WhiteSpace: Story = {
7373
},
7474
},
7575
};
76+
77+
export const TextWrap: Story = {
78+
render: Template.bind({}),
79+
args: {
80+
as: "p",
81+
variant: "body1",
82+
textWrap: "balance",
83+
children: (
84+
<>
85+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tincidunt
86+
vel lorem nec pretium. Vestibulum ante ipsum primis in faucibus orci
87+
luctus et ultrices posuere cubilia curae; Morbi sollicitudin ex nec
88+
imperdiet pellentesque.
89+
</>
90+
),
91+
},
92+
parameters: {
93+
controls: {
94+
include: ["textWrap"],
95+
},
96+
},
97+
};

easy-ui-react/src/Text/Text.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,12 @@ describe("<Text />", () => {
103103
expect.stringContaining("whiteSpacePre-line"),
104104
);
105105
});
106+
107+
it("should apply textWrap", () => {
108+
render(<Text textWrap="balance">Here is some text</Text>);
109+
expect(screen.getByText("Here is some text")).toHaveAttribute(
110+
"class",
111+
expect.stringContaining("textWrapBalance"),
112+
);
113+
});
106114
});

easy-ui-react/src/Text/Text.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export type TextWhiteSpace =
4040
| "pre-wrap"
4141
| "break-spaces"
4242
| "pre-line";
43+
export type TextWrap = "wrap" | "nowrap" | "balance" | "pretty" | "stable";
4344
export type FontVariantNumeric = "normal" | "tabular-nums";
4445

4546
export type TextProps = {
@@ -59,6 +60,8 @@ export type TextProps = {
5960
id?: string;
6061
/** HTML role attribute */
6162
role?: HTMLAttributes<"span">["role"];
63+
/** Specify wrapping behavior */
64+
textWrap?: TextWrap;
6265
/** Transform text */
6366
transform?: TextTransform;
6467
/** Truncate text overflow with ellipsis */
@@ -122,6 +125,7 @@ export function Text({
122125
color,
123126
fontVariantNumeric,
124127
id,
128+
textWrap,
125129
transform = "none",
126130
truncate = false,
127131
variant,
@@ -138,6 +142,7 @@ export function Text({
138142
breakWord && styles.break,
139143
truncate && styles.truncate,
140144
visuallyHidden && styles.visuallyHidden,
145+
textWrap && styles[variationName("textWrap", textWrap)],
141146
transform && styles[variationName("transform", transform)],
142147
whiteSpace && styles[variationName("whiteSpace", whiteSpace)],
143148
fontVariantNumeric &&

0 commit comments

Comments
 (0)