patternfly-react icon indicating copy to clipboard operation
patternfly-react copied to clipboard

ClipboardCopy - Allow truncate flexibility

Open gitdallas opened this issue 1 year ago • 3 comments
trafficstars

ClipboardCopy currently truncates at the end. It may be nice in some cases to truncate at the start or middle (similar to how Truncate component works).

A workaround could currently work with inline-compact with some hacking, see https://codesandbox.io/p/sandbox/red-wind-zdgyqf

    <ClipboardCopy
      variant={"inline-compact"}
      style={{ display: "inline-flex" }}
      clickTip="Copied"
      onCopy={() => {
        navigator.clipboard.writeText(textToCopy);
      }}
    >
      <Truncate
        content={textToCopy}
        trailingNumChars={10}
        position={"middle"}
      />
    </ClipboardCopy>

However, this wouldn't work with other variants. They all use TextInput, as part of this feature I believe TextInput would also have to be updated to work with middle truncate (currently it only has start/end).

Could use props like truncatePosition, and truncateTrailingNumChars for middle.

This came up in a slack conversation with Vince Consola and @christianvogt

It would also be nice if inline-compact supported truncate by itself as well.

gitdallas avatar Aug 28 '24 19:08 gitdallas

@mattnolting would we need css support for this?

tlabaj avatar Sep 19 '24 15:09 tlabaj

Would like to note here that in PF5 ClipboardCopy expects children of type React.ReactNode so the above example can be done without any issues. In PF6, ClipboardCopy expects children of type string. It seems to still work when passing the Truncate component but my IDE is upset about it.

Griffin-Sullivan avatar Sep 23 '24 16:09 Griffin-Sullivan

@mattnolting would we need css support for this?

@tlabaj Doesn't appear to need any additional CSS support. 👍

mattnolting avatar Sep 24 '24 18:09 mattnolting

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar Jan 21 '25 11:01 github-actions[bot]

bump

christianvogt avatar Jan 21 '25 14:01 christianvogt

@gitdallas @christianvogt is the ask here to provide truncation only for inline/inline-compact variants of the ClipboardCopy component? Only asking because I'm not totally sure we could provide truncate customization for a basic ClipboardCopy, where the text input shows truncation at the end when the input doesn't have focus.

thatblindgeye avatar Feb 18 '25 13:02 thatblindgeye

The ask was for ClipboardCopy to support more truncation options such as start and middle because we have a scenario where a token is being copied and the values look identical except for the ends which gets truncated.

christianvogt avatar Feb 25 '25 15:02 christianvogt