Repository navigation
[CLOV-1815][BpkText] Add underline and line clamp controls - #4978
Conversation
|
Visit https://backpack.github.io/storybook-prs/4978 to see this build running in a browser. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds new text-decoration and truncation capabilities to BpkText, including underline support and configurable line clamping with invalid-value handling.
Changes:
- Introduces
underlineprop and styling, including combined underline + strikethrough rendering. - Adds
lineClampprop with CSS-variable-driven clamping and guards for invalid values. - Updates Storybook, tests, and README documentation for the new props.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/backpack-web/src/bpk-component-text/src/BpkText.tsx | Adds underline / lineClamp props, classnames, and style merging for clamp CSS variable. |
| packages/backpack-web/src/bpk-component-text/src/BpkText.stories.tsx | Adds Storybook examples for underline and line clamping, plus inclusion in visual test story. |
| packages/backpack-web/src/bpk-component-text/src/BpkText.stories.module.scss | Adds layout constraint for the line clamp Storybook example container. |
| packages/backpack-web/src/bpk-component-text/src/BpkText.module.scss | Adds underline and line clamp CSS classes, including combined underline+strikethrough. |
| packages/backpack-web/src/bpk-component-text/src/BpkText-test.tsx | Adds tests for underline, combined decorations, and valid/invalid lineClamp behavior. |
| packages/backpack-web/src/bpk-component-text/README.md | Documents new underline and lineClamp props with usage guidance. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export default () => ( | ||
| <BpkText underline>Underlined text</BpkText> | ||
| <BpkText color={TEXT_COLORS.textError} underline> | ||
| Underlined error text | ||
| </BpkText> | ||
| ); |
| truncation or a larger value for multi-line truncation. The text must have a | ||
| constrained available width in order to wrap and truncate. Invalid values such | ||
| as `0`, negative numbers, and non-integers are ignored. |
|
Visit https://backpack.github.io/storybook-prs/4978 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4978 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4978 to see this build running in a browser. |
Ezreal Yang (Supremeyh)
left a comment
There was a problem hiding this comment.
Three new public props (underline, truncate, lineClamp) and one new CSS custom property (--bpk-text-line-clamp) are introduced. New optional props are a backwards-compatible addition and require a minor bump. The current patch label will mis-categorise the changelog entry and produce incorrect version increments for consumers.
And it worth add some snapshots in PR description
| constrained available width. Invalid `lineClamp` values are ignored, and a | ||
| valid `lineClamp` takes precedence when both props are provided. | ||
|
|
||
| ```javascript |
| `false`. The underline uses the current text color, including when the `color` | ||
| prop or dark mode is used. | ||
|
|
||
| ```javascript |
There was a problem hiding this comment.
it should use tsx instead
| * Truncates overflowing text to a single line with an ellipsis. | ||
| */ | ||
| truncate?: boolean; | ||
| underline?: boolean; |
There was a problem hiding this comment.
lineClamp and truncate both carry TSDoc block comments. underline added in the same diff hunk has none. Constitution V requires JSDoc/TSDoc for all public props. Add a /** Renders the text with an underline. */ comment consistent with the truncate pattern.
| :where(.bpk-stories-text_flex-container) { | ||
| display: flex; | ||
| } |
There was a problem hiding this comment.
The rule :where(.bpk-stories-text_flex-container) { display: flex; } uses a literal, unhashed class name. CSS Modules compiles all local class names to [local]-[hash:base64:5] at build time, so this selector never matches the runtime class. The display: flex declaration is dead code, meaning justify-content, align-items, and gap inside &_flex-container (lines 40–44) have no effect — the flex container story is silently broken. Additionally, the :where() rule is emitted as a global, unscoped selector.
Fix: move display: flex into the &_flex-container block and remove the :where() rule entirely:
&_flex-container {
display: flex; // ← add here
justify-content: space-between;
align-items: center;
gap: tokens.bpk-spacing-sm();
}| render: () => <StrikethroughExample />, | ||
| }; | ||
|
|
||
| export const Underline = { |
There was a problem hiding this comment.
Underline and Strikethrough have standalone named story exports. truncate is only demonstrated as a comparison row inside LineClampExample, making the prop invisible in isolation in Storybook. A TruncateExample component + export const Truncate would follow the pattern set by every other BpkText prop.
| // declarations above; revisit the display model when standard line-clamp | ||
| // support is broadly available. | ||
| line-clamp: var(--bpk-text-line-clamp); | ||
| overflow-wrap: anywhere; |
There was a problem hiding this comment.
here added overflow-wrap: anywhere (allowing for line breaks at any character), which changed the text arrangement behavior of the element, but the README did not mention it. It might come as a surprise to consumers who already have custom line-breaking rules
it can be suggested to add a note in the README to inform consumers that they need to pay attention to the minimum width shrinkage behavior when using Lineclamps on flex/grid sub-items
| const lineClampStyle = shouldClamp | ||
| ? ({ | ||
| ...style, | ||
| '--bpk-text-line-clamp': lineClamp, | ||
| } as CSSProperties) | ||
| : style; |
There was a problem hiding this comment.
'--bpk-text-line-clamp': The lineClamp passes a number, not a string
CSS custom properties in the DOM layer only accepts a string, the React by internal element. The style.css. SetProperty (name, value) set the custom property, will reduce the number implicit coerce into a string, so no problem when running. However, the CSSProperties type does not accept the number value, so the as CSSProperties strong conversion was used to suppress the TS error and cover up the type mismatch.
A more explicit way of writing
const lineClampStyle = shouldClamp
? ({
... style,
'--bpk-text-line-clamp': '${lineClamp}', // explicitly converts to string
} as CSSProperties)
: style;
|
Visit https://backpack.github.io/storybook-prs/4978 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4978 to see this build running in a browser. |
Description
Adds text decoration and truncation controls to
BpkText.underlineboolean prop, including support for combining underline and strikethrough.truncateboolean prop for no-wrap, single-line ellipsis truncation.lineClampprop for configurable single- or multi-line ellipsis truncation.lineClamp; zero, negative, fractional,NaN, and infinite values are ignored.lineClampprecedence when both truncation props are supplied.truncate, andlineClampat the same width, including flex-layout and unbroken-text cases.Jira: CLOV-1815
snapshot
underline
truncate
lineclamp and comparison between truncate
Testing
pnpm exec jest packages/backpack-web/src/bpk-component-text/src/BpkText-test.tsx packages/backpack-web/src/bpk-component-text/src/accessibility-test.tsx --runInBand --watchman=falsepnpm exec eslint packages/backpack-web/src/bpk-component-text/src/BpkText.tsx packages/backpack-web/src/bpk-component-text/src/BpkText-test.tsx packages/backpack-web/src/bpk-component-text/src/BpkText.stories.tsx packages/backpack-web/src/bpk-component-text/src/accessibility-test.tsxpnpm exec stylelint packages/backpack-web/src/bpk-component-text/src/BpkText.module.scss packages/backpack-web/src/bpk-component-text/src/BpkText.stories.module.scsspnpm nx run backpack-web:typecheckpnpm nx run backpack-web:build-sassChecklist
README.mdupdated.