-
Notifications
You must be signed in to change notification settings - Fork 90
feat: truncate component rework #4037
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
base: release-23.x
Are you sure you want to change the base?
feat: truncate component rework #4037
Conversation
✅ Deploy Preview for paragon-openedx-v23 ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
d13ac64 to
cca4d3a
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release-23.x #4037 +/- ##
================================================
+ Coverage 94.39% 94.50% +0.11%
================================================
Files 242 245 +3
Lines 4296 4328 +32
Branches 981 1034 +53
================================================
+ Hits 4055 4090 +35
+ Misses 237 230 -7
- Partials 4 8 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
On slack you mentioned needing to use inline styles. I wasn't able to completely get away from them but I was able to at least minimize it down to setting a css var diff --git a/src/Truncate/Truncate.tsx b/src/Truncate/Truncate.tsx
index fa421b68f6..ab9dd95753 100644
--- a/src/Truncate/Truncate.tsx
+++ b/src/Truncate/Truncate.tsx
@@ -9,11 +9,6 @@ interface TruncateProps {
}
function Truncate({ children, lines = 1 }: TruncateProps) {
- const style = {
- lineClamp: lines,
- WebkitLineClamp: lines,
- };
-
const initialText = Array.isArray(children) ? assembleStringFromChildrenArray(children) : String(children);
return (
@@ -21,7 +16,7 @@ function Truncate({ children, lines = 1 }: TruncateProps) {
title={initialText}
aria-label={initialText}
className="truncate-text"
- style={style}
+ style={{ "--truncate-prop-lines": lines } as React.CSSProperties}
data-testid="truncate-element"
>
{children}
diff --git a/src/Truncate/index.scss b/src/Truncate/index.scss
index a2f9fbde1f..418641008b 100644
--- a/src/Truncate/index.scss
+++ b/src/Truncate/index.scss
@@ -2,6 +2,6 @@
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
- -webkit-line-clamp: 1;
- line-clamp: 1;
+ -webkit-line-clamp: var(--truncate-prop-lines);
+ line-clamp: var(--truncate-prop-lines);
}As for the naming of the variable, this is definitely setting a new pattern so I'd love to hear opinions. My reasoning behind
|
Yes I think this makes sense and would be a clear way of indicating that this is a local variable and not a design token. W.r.t the style conventions, it also mentions that all CSS classes should be prefixed with |
Description
Corresponding issue: #3311
This refactors the
Truncatecomponent to use CSS properties instead of complex JS. The-webkit-line-clampproperty has support for most common browsers (source). Eventually,line-clampshould have support but that is not currently the case.This was discussed in Paragon Working Group (session notes).
Both
titleandaria-labelare used for accessibility in the same way it was used before. TheassembleStringFromChildrenArrayutility function has been moved to autils.tsfile and thus converted to TypeScript.The deprecated component as well as it's utils file still exist under the
Truncatedirectory. The deprecated component is still accessible atTruncate.Deprecated. Theutilsfile has been renamed toutils.deprecated. It didn't make sense to convert the entire utils file to TS when only the one utility function (assembleStringFromChildrenArray) was needed.The tests for the deprecated component are under
TruncateDeprecated.test.jsx.Deploy Preview
https://deploy-preview-4037--paragon-openedx-v23.netlify.app/components/truncate/
Merge Checklist
exampleapp?Post-merge Checklist