-
Notifications
You must be signed in to change notification settings - Fork 231
feat: Add TruncatedText component #4543
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React from 'react'; | ||
|
|
||
| import { CopyToClipboard, Link, TruncatedText, TruncatedTextProps } from '~components'; | ||
|
|
||
| import createPermutations from '../utils/permutations'; | ||
| import PermutationsView from '../utils/permutations-view'; | ||
| import ScreenshotArea from '../utils/screenshot-area'; | ||
|
|
||
| const containerStyle: React.CSSProperties = { | ||
| maxWidth: '320px', | ||
| padding: '8px 12px', | ||
| border: '1px solid #d5dbdb', | ||
| borderRadius: '4px', | ||
| }; | ||
|
|
||
| const longArn = 'arn:aws:iam::123456789012:role/my-very-long-role-name-that-should-truncate'; | ||
| const longSentence = 'The instance has been running for an extended period of time and may be slow.'; | ||
|
|
||
| const permutations = createPermutations< | ||
| TruncatedTextProps & { Wrapper: (props: { children: React.ReactNode }) => JSX.Element | null } | ||
| >([ | ||
| { | ||
| Wrapper: [React.Fragment], | ||
| children: [ | ||
| 'Short text', | ||
| longArn, | ||
| longSentence, | ||
| <Link key="link" href="#"> | ||
| {longArn} | ||
| </Link>, | ||
| <CopyToClipboard | ||
| key="copy-inline" | ||
| variant="inline" | ||
| textToCopy={longArn} | ||
| copyButtonAriaLabel="Copy ARN" | ||
| copySuccessText="ARN copied" | ||
| copyErrorText="Failed to copy ARN" | ||
| />, | ||
| ], | ||
| }, | ||
| { | ||
| Wrapper: [ | ||
| ({ children }) => ( | ||
| <CopyToClipboard | ||
| key="copy-inline" | ||
| variant="inline" | ||
| textToCopy={longArn} | ||
| textToDisplay={children} | ||
| wrapText={false} | ||
| copyButtonAriaLabel="Copy ARN" | ||
| copySuccessText="ARN copied" | ||
| copyErrorText="Failed to copy ARN" | ||
| /> | ||
| ), | ||
| ], | ||
| children: [ | ||
| 'Short text', | ||
| longArn, | ||
| longSentence, | ||
| <Link key="link" href="#"> | ||
| {longArn} | ||
| </Link>, | ||
| ], | ||
| }, | ||
| ]); | ||
|
|
||
| export default function TruncatedTextPermutations() { | ||
| return ( | ||
| <> | ||
| <h1>TruncatedText permutations</h1> | ||
| <ScreenshotArea disableAnimations={true}> | ||
| <PermutationsView | ||
| permutations={permutations} | ||
| render={({ Wrapper, ...permutation }) => ( | ||
| <div style={containerStyle}> | ||
| <Wrapper> | ||
| <TruncatedText {...permutation} /> | ||
| </Wrapper> | ||
| </div> | ||
| )} | ||
| /> | ||
| </ScreenshotArea> | ||
| </> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import * as React from 'react'; | ||
|
|
||
| import Box from '~components/box'; | ||
| import CopyToClipboard from '~components/copy-to-clipboard'; | ||
| import Link from '~components/link'; | ||
| import SpaceBetween from '~components/space-between'; | ||
| import StatusIndicator from '~components/status-indicator'; | ||
| import TruncatedText from '~components/truncated-text'; | ||
|
|
||
| const containerStyle: React.CSSProperties = { | ||
| maxWidth: '320px', | ||
| padding: '8px 12px', | ||
| border: '1px solid #d5dbdb', | ||
| borderRadius: '4px', | ||
| }; | ||
|
|
||
| export default function TruncatedTextSimple() { | ||
| return ( | ||
| <> | ||
| <h1>TruncatedText examples</h1> | ||
| <SpaceBetween size="m"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: permutations make the screenshots more isolated, and handle future additions more gracefully |
||
| <Box> | ||
| <Box variant="awsui-key-label">Truncated plain text</Box> | ||
| <div style={containerStyle}> | ||
| <TruncatedText>arn:aws:lambda:us-east-1:123456789012:function:my-function</TruncatedText> | ||
| </div> | ||
| </Box> | ||
|
|
||
| <Box> | ||
| <Box variant="awsui-key-label">Non-truncated plain text</Box> | ||
| <div style={containerStyle}> | ||
| <TruncatedText>arn:aws:lambda</TruncatedText> | ||
| </div> | ||
| </Box> | ||
|
|
||
| <Box> | ||
| <Box variant="awsui-key-label">Truncated with interactive child (uses tooltipText)</Box> | ||
| <div style={containerStyle}> | ||
| <TruncatedText tooltipText="ResourceName-421492941223_may-be-truncated"> | ||
| <Link href="#">ResourceName-421492941223_may-be-truncated</Link> | ||
| </TruncatedText> | ||
| </div> | ||
| </Box> | ||
|
|
||
| <Box> | ||
| <Box variant="awsui-key-label">Truncated text in a flex container</Box> | ||
| <div style={{ ...containerStyle, display: 'flex', alignItems: 'center', gap: '8px' }}> | ||
| <span>Label:</span> | ||
| <div style={{ flex: 1, minWidth: 0 }}> | ||
| <TruncatedText>arn:aws:s3:::my-very-long-bucket-name-with-extra-words</TruncatedText> | ||
| </div> | ||
| </div> | ||
| </Box> | ||
|
|
||
| <Box> | ||
| <Box variant="awsui-key-label">With StatusIndicator (wrapText=true, default)</Box> | ||
| <div style={containerStyle}> | ||
| <TruncatedText> | ||
| <StatusIndicator type="success"> | ||
|
jperals marked this conversation as resolved.
|
||
| The instance has been running for an extended period of time | ||
| </StatusIndicator> | ||
| </TruncatedText> | ||
| </div> | ||
| </Box> | ||
|
|
||
| <Box> | ||
| <Box variant="awsui-key-label">With StatusIndicator (wrapText=false)</Box> | ||
| <div style={containerStyle}> | ||
| <TruncatedText> | ||
| <StatusIndicator type="success" wrapText={false}> | ||
| The instance has been running for an extended period of time | ||
| </StatusIndicator> | ||
| </TruncatedText> | ||
| </div> | ||
| </Box> | ||
|
|
||
| <Box> | ||
| <Box variant="awsui-key-label">With CopyToClipboard (variant=inline)</Box> | ||
| <div style={containerStyle}> | ||
| <TruncatedText tooltipText="arn:aws:iam::123456789012:role/my-very-long-role-name"> | ||
| <CopyToClipboard | ||
| variant="inline" | ||
| textToCopy="arn:aws:iam::123456789012:role/my-very-long-role-name" | ||
| copyButtonAriaLabel="Copy ARN" | ||
| copySuccessText="ARN copied" | ||
| copyErrorText="Failed to copy ARN" | ||
| /> | ||
| </TruncatedText> | ||
| </div> | ||
| </Box> | ||
|
|
||
| <Box> | ||
| <Box variant="awsui-key-label">With CopyToClipboard, internal truncation</Box> | ||
| <div style={containerStyle}> | ||
| <CopyToClipboard | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not entirely expected; there's a parallel update to the component to support single-line wrapping; which has released since this PR was created. Will rebase.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still reproducible after updating the branch
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works fine in the permutations page - just didn't update this one to add |
||
| variant="inline" | ||
| textToCopy="arn:aws:iam::123456789012:role/my-very-long-role-name" | ||
| textToDisplay={<TruncatedText>arn:aws:iam::123456789012:role/my-very-long-role-name</TruncatedText>} | ||
| copyButtonAriaLabel="Copy ARN" | ||
| copySuccessText="ARN copied" | ||
| copyErrorText="Failed to copy ARN" | ||
| /> | ||
| </div> | ||
| </Box> | ||
| </SpaceBetween> | ||
| </> | ||
| ); | ||
| } | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: the page header should preferably be ourside the screenshot area