Skip to content

[BD-46] feat: development Truncate component - #1472

Merged
adamstankiewicz merged 17 commits into
openedx:masterfrom
raccoongang:Peter_Kulko/development-Truncate-text-component
Aug 19, 2022
Merged

[BD-46] feat: development Truncate component#1472
adamstankiewicz merged 17 commits into
openedx:masterfrom
raccoongang:Peter_Kulko/development-Truncate-text-component

Conversation

@peterkulko

@peterkulko peterkulko commented Jul 13, 2022

Copy link
Copy Markdown
Contributor

Description

The base requirements for a standalone component would be as follows:

  1. Customize the number of lines of text that should be preserved.
  2. Customize the ellipsis, but it should default to … (accepting string or another component)
  3. Provide an option to trim unnecessary whitespace.. That is, any extra spaces between a truncated string and the `…, e.g. "courses ..." would become "courses..."
  4. Standalone component page on the Paragon documentation site with example usage.
  5. Added new onTruncate props.

Deploy Preview

Truncate component

Merge Checklist

  • If your update includes visual changes, have they been reviewed by a designer? Send them a link to the Netlify deploy preview, if applicable.
  • Does your change adhere to the documented style conventions?
  • Do any prop types have missing descriptions in the Props API tables in the documentation site (check deploy preview)?
  • Were your changes tested using all available themes (see theme switcher in the header of the deploy preview, under the "Settings" icon)?
  • Were your changes tested in the example app?
  • Is there adequate test coverage for your changes?
  • Consider whether this change needs to reviewed/QA'ed for accessibility (a11y). If so, please add wittjeff and adamstankiewicz as reviewers on this PR.

Post-merge Checklist

  • Verify your changes were released to NPM at the expected version.
  • If you'd like, share your contribution in #show-and-tell.
  • 🎉 🙌 Celebrate! Thanks for your contribution.

@openedx-webhooks openedx-webhooks added the blended PR is managed through 2U's blended developmnt program label Jul 13, 2022
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @PKulkoRaccoonGang!

When this pull request is ready, tag your edX technical lead.

@netlify

netlify Bot commented Jul 13, 2022

Copy link
Copy Markdown

Deploy Preview for paragon-openedx ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2d249fd
🔍 Latest deploy log https://app.netlify.com/sites/paragon-openedx/deploys/62fc8d8a92978a0008d71980
😎 Deploy Preview https://deploy-preview-1472--paragon-openedx.netlify.app/components/truncate
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@peterkulko peterkulko changed the title [BD-46] docs: development Truncate component [BD-46] DRAFT: development Truncate component Jul 13, 2022
@codecov

codecov Bot commented Jul 13, 2022

Copy link
Copy Markdown

Codecov Report

Merging #1472 (2d249fd) into master (a5fd4fa) will increase coverage by 0.27%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1472      +/-   ##
==========================================
+ Coverage   91.30%   91.57%   +0.27%     
==========================================
  Files         205      208       +3     
  Lines        3438     3537      +99     
  Branches      799      821      +22     
==========================================
+ Hits         3139     3239     +100     
+ Misses        285      283       -2     
- Partials       14       15       +1     
Impacted Files Coverage Δ
src/Truncate/index.jsx 100.00% <100.00%> (ø)
src/Truncate/utils.js 100.00% <100.00%> (ø)
src/Card/index.jsx 100.00% <0.00%> (ø)
src/Tabs/index.jsx 93.54% <0.00%> (ø)
src/Menu/SelectMenu.jsx 64.06% <0.00%> (ø)
src/Form/FormControl.jsx 100.00% <0.00%> (ø)
src/Collapsible/index.jsx 69.23% <0.00%> (ø)
src/Dropzone/DefaultContent.jsx 100.00% <0.00%> (ø)
src/Collapsible/CollapsibleBody.jsx 100.00% <0.00%> (ø)
src/Collapsible/CollapsibleAdvanced.jsx 88.57% <0.00%> (ø)
... and 7 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@peterkulko
peterkulko force-pushed the Peter_Kulko/development-Truncate-text-component branch from 8487b5a to 1552b60 Compare July 15, 2022 16:30
@peterkulko
peterkulko force-pushed the Peter_Kulko/development-Truncate-text-component branch from a0b2f5a to 4d9fb56 Compare July 18, 2022 12:06
@peterkulko
peterkulko force-pushed the Peter_Kulko/development-Truncate-text-component branch 2 times, most recently from 6875acf to 189c2b7 Compare July 18, 2022 20:39
@peterkulko
peterkulko force-pushed the Peter_Kulko/development-Truncate-text-component branch from 189c2b7 to 6ebe95d Compare July 19, 2022 12:54
@peterkulko
peterkulko force-pushed the Peter_Kulko/development-Truncate-text-component branch from e7b58dd to 57d8a80 Compare July 21, 2022 23:40
@peterkulko peterkulko changed the title [BD-46] DRAFT: development Truncate component [BD-46] docs: development Truncate component Jul 22, 2022
Comment thread src/Truncate/index.jsx Outdated
Comment thread src/Truncate/utils.js Outdated
@peterkulko peterkulko changed the title [BD-46] docs: development Truncate component [BD-46] feat: development Truncate component Jul 22, 2022
@viktorrusakov viktorrusakov linked an issue Jul 27, 2022 that may be closed by this pull request

@adamstankiewicz adamstankiewicz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool! Been toying around with different examples in the docs site and it seems to be working as intended. Left a few feedback comments.

Comment thread src/Card/Card.scss Outdated
Comment thread src/Truncate/index.jsx Outdated
Comment thread src/Truncate/utils.js
Comment thread src/Truncate/index.jsx Outdated
Comment thread src/Truncate/index.jsx Outdated
@adamstankiewicz

Copy link
Copy Markdown
Member

I've noticed the occasional odd behavior with Truncate (e.g., it occasionally shows 2.5 lines with the ellipsis half way through a line), though I haven't been able to really identify an exact issue. From the sync earlier today, @monteri mentioned potentially using ResizeObserver here which might improve the truncate behavior.

Likewise, we discussed another prop (onTruncate) for this component that would be great for consumers to know when their content is truncated (e.g., to render a tooltip only when text is truncated). We can treat that as a separate task (let's file a new Github issue in this case), or build it into this PR; I'll leave that decision up to you!

@peterkulko
peterkulko force-pushed the Peter_Kulko/development-Truncate-text-component branch from 1e11e3f to a622750 Compare August 10, 2022 13:36
@peterkulko
peterkulko force-pushed the Peter_Kulko/development-Truncate-text-component branch from a622750 to ed2d8c7 Compare August 10, 2022 13:47
Comment thread src/Truncate/README.md
### Basic Usage

```jsx live
<Truncate lines={2}>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PKulkoRaccoonGang Even though lines={2} in the "Basic Usage" example on the docs site, I'm seeing it with like 2.5 lines on initial render, until I click "Show code example"; then, it reverts to 2 lines as expected:

image

image

Any ideas what might be causing this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior is caused by the width of the container, which is different for each theme. When using truncation by the consumer, there will be no such problems.

Comment thread src/Truncate/README.md Outdated
### With the custom ellipsis

```jsx live
() => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this example solely about the custom ellipsis, and add a separate example for using onTruncate. For now, we can just include an example that includes a console.log() inside of onTruncate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, done

Comment thread src/Truncate/README.md Outdated
}
```

### Usage in component properties

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe rename this to Example usage in Card?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed

@adamstankiewicz
adamstankiewicz merged commit da3a247 into openedx:master Aug 19, 2022
@openedx-webhooks

Copy link
Copy Markdown

@PKulkoRaccoonGang 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

edx-semantic-release pushed a commit that referenced this pull request Aug 19, 2022
# [20.10.0](v20.9.3...v20.10.0) (2022-08-19)

### Features

* [BD-46] add Truncate component ([#1472](#1472)) ([da3a247](da3a247))
@edx-semantic-release

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 20.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blended PR is managed through 2U's blended developmnt program released

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

Show truncation examples for Card

5 participants