Skip to content

feat(Truncate): added Truncate component#6713

Merged
jpuzz0 merged 7 commits intopatternfly:mainfrom
gabipodolnikova:new-component-truncate
Jan 20, 2022
Merged

feat(Truncate): added Truncate component#6713
jpuzz0 merged 7 commits intopatternfly:mainfrom
gabipodolnikova:new-component-truncate

Conversation

@gabipodolnikova
Copy link
Contributor

What: Closes #6566

@patternfly-build
Copy link
Collaborator

patternfly-build commented Dec 22, 2021

@jpuzz0
Copy link
Contributor

jpuzz0 commented Dec 22, 2021

A couple styling questions that might be more for patternfly core to address:
Should users be able to drag the truncation extender icon beyond container elements?
image

Should we consider adding some padding between the end of the content and the extender icon?
image

Should we consider applying a minimum width in some cases?
image

end: styles.truncateStart
};

interface TruncateProps extends React.HTMLProps<HTMLDivElement> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this should be extending HTMLProps from HTMLSpanElement instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I originally had div there and then changed it and forgot to do this...

/** Class to add to outer span */
className?: string;
/** Text to truncate */
content: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we considered just using children for content instead. I don't have much of a preference, but curious about your thoughts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that if we know that the content will always be a string, there is no need to have it as children and just use a prop content. But this was one thing that I knew that someone will be commenting, so totally up for debate :D

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if at some point we'd want content to be bold or italicized. In that case, I think we'd want to just use ReactNode. If there's potential for that, I think it's worth a debate, or at least the changing of the type, otherwise if we know it will always be a string, what you have is fine with me.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good question for @mattnolting
Will the css that controls the truncation still work if someone wants to put an icon or link somewhere in the string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The text can be bold or italicized, you can just add those tags around. But with the icon it won't work. So I think that it is best we keep it as string.

@gabipodolnikova
Copy link
Contributor Author

A couple styling questions that might be more for patternfly core to address: Should users be able to drag the truncation extender icon beyond container elements?

Should we consider adding some padding between the end of the content and the extender icon?

Should we consider applying a minimum width in some cases?

I used the same styling as it is in core. So this is definitely a question for maybe @mattnolting ? :)

Copy link
Member

@mcarrano mcarrano left a comment

Choose a reason for hiding this comment

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

This is looking good @gabipodolnikova . I also had a question about the drag/resize icon and capability. Is that actually part of the component or is it part of the example to let the user see how truncation works? If the former, I don't think we'd want to allow that in all cases. In most places where truncation is used, there is not space to make the field wider.

Also, in either case, it would be good to introduce some padding between the icon and string.

@gabipodolnikova
Copy link
Contributor Author

This is looking good @gabipodolnikova . I also had a question about the drag/resize icon and capability. Is that actually part of the component or is it part of the example to let the user see how truncation works? If the former, I don't think we'd want to allow that in all cases. In most places where truncation is used, there is not space to make the field wider.

Also, in either case, it would be good to introduce some padding between the icon and string.

It is not a part of the component, it is just to help to demonstrate how it works. I can add some padding. But the padding should also be added in the core example as I totally used what is in there :) @mattnolting

Copy link
Contributor

@jpuzz0 jpuzz0 left a comment

Choose a reason for hiding this comment

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

Looks good to me other than the styling issues mentioned here, which I assume will be handled outside of this repo if at all.

@mattnolting
Copy link
Contributor

It is not a part of the component, it is just to help to demonstrate how it works. I can add some padding. But the padding should also be added in the core example as I totally used what is in there :) @mattnolting

@mcarrano, @gabipodolnikova is right, I should fix up the Core example in a new issue.

@tlabaj
Copy link
Contributor

tlabaj commented Jan 6, 2022

@mattnolting @mcarrano It looks like when the truncation is in the middle, there is sometimes a noticeable large space to the right of the ellipses. On the left, the ellipses are always right next to last character before them. Is this intentional?
image

@mcarrano
Copy link
Member

mcarrano commented Jan 7, 2022

@mattnolting @mcarrano It looks like when the truncation is in the middle, there is sometimes a noticeable large space to the right of the ellipses. On the left, the ellipses are always right next to last character before them. Is this intentional?

This is definitely not intentional. Do you know what's causing that @mattnolting ? Is it just an artifact of the example with a resizable container? Ideally there would be no extra space between the "..." and the second string.

@nicolethoen
Copy link
Contributor

should we attach a resize observer to the component parent container to recalculate where to break the strings on resize? to avoid the gap?

@nicolethoen
Copy link
Contributor

@gabipodolnikova,
after talking to @mattnolting, he is going to make a core change so there is still no need for a resize observer. disregard my last comment.

If this PR needs an update after the core PR is done, Im happy to update it, too if you'd like. Just let me know.

@mattnolting
Copy link
Contributor

@gabipodolnikova
Copy link
Contributor Author

@gabipodolnikova, after talking to @mattnolting, he is going to make a core change so there is still no need for a resize observer. disregard my last comment.

If this PR needs an update after the core PR is done, Im happy to update it, too if you'd like. Just let me know.

Thanks for resolving this for me Nicole and Matt! :D I will update this PR when the core is merged :)

@nicolethoen
Copy link
Contributor

@gabipodolnikova The PR was merged! :)
patternfly/patternfly#4599

Copy link
Member

@mcarrano mcarrano left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks @gabipodolnikova !

Copy link
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

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

Looks great! thanks Gabi.

className?: string;
/** Text to truncate */
content: string;
/** Number of characters that shoul be sliced at the end of the content string. Works best if the number is between 5 to 10. */
Copy link
Contributor

@jpuzz0 jpuzz0 Jan 20, 2022

Choose a reason for hiding this comment

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

Some suggested spelling adjustments:
"that should be sliced"
"between 5 and 10"

Also, I'm curious why a number between 5 and 10 would work the best. I'm thinking others might wonder the same thing reading this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the spellcheck... And why numbers between 5 and 10, I am taking it from this PR patternfly/patternfly#4599 I could probably just say that we suggest these numbers... It is not mentioned in the core, just in that PR, so I wanted to mention it somewhere :) I welcome any better formulation of this piece of information.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think specifying it's a suggestion for the sake of readability makes sense. Maybe the example text which echos the same thing could be updated with that verbiage as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

1 other suggestion is to rename the prop to something like charGap (or something like gap) to add some more context to what the slicing will do, which is create a gap of whitespace. Not a blocking comment, just figured I'd throw this out there to see what you or others thought.

Copy link
Contributor

@mattnolting mattnolting left a comment

Choose a reason for hiding this comment

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

This looks fantastic, thanks for your hard work and patience with this issue, Gabi!!! Well done 👏👏👏

@jpuzz0 jpuzz0 merged commit c803b5d into patternfly:main Jan 20, 2022
@patternfly-build
Copy link
Collaborator

Your changes have been released in:

  • eslint-plugin-patternfly-react@4.31.0
  • @patternfly/react-catalog-view-extension@4.43.0
  • @patternfly/react-charts@6.45.0
  • @patternfly/react-code-editor@4.33.0
  • @patternfly/react-console@4.43.0
  • @patternfly/react-core@4.192.0
  • @patternfly/react-docs@5.53.0
  • @patternfly/react-icons@4.43.0
  • @patternfly/react-inline-edit-extension@4.37.0
  • demo-app-ts@4.152.0
  • @patternfly/react-integration@4.154.0
  • @patternfly/react-log-viewer@4.37.0
  • @patternfly/react-styles@4.42.0
  • @patternfly/react-table@4.61.0
  • @patternfly/react-tokens@4.44.0
  • @patternfly/react-topology@4.39.0
  • @patternfly/react-virtualized-extension@4.39.0
  • transformer-cjs-imports@4.30.0

Thanks for your contribution! 🎉

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Truncation component

8 participants