Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build-tools/utils/pluralize.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const pluralizationMap = {
Tooltip: 'Tooltips',
TopNavigation: 'TopNavigations',
TreeView: 'TreeViews',
TruncatedText: 'TruncatedTexts',
TutorialPanel: 'TutorialPanels',
Wizard: 'Wizards',
};
Expand Down
87 changes: 87 additions & 0 deletions pages/truncated-text/permutations.page.tsx
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>
</>
);
}
110 changes: 110 additions & 0 deletions pages/truncated-text/simple.page.tsx
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>
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.

Minor: the page header should preferably be ourside the screenshot area

<SpaceBetween size="m">
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.

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">
Comment thread
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
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.

Is this wrapping after the icon expected because builders should instead wrap the CopyToClipboard inside TruncatedText, as in the previous element?

Image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.

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.

Still reproducible after updating the branch

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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 wrapText.

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>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32775,6 +32775,51 @@ use the \`id\` attribute, consider setting it on a parent element instead.",
}
`;

exports[`Components definition for truncated-text matches the snapshot: truncated-text 1`] = `
{
"dashCaseName": "truncated-text",
"events": [],
"functions": [],
"name": "TruncatedText",
"properties": [
{
"deprecatedTag": "Custom CSS is not supported. For testing and other use cases, use [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes).",
"description": "Adds the specified classes to the root element of the component.",
"name": "className",
"optional": true,
"type": "string",
},
{
"deprecatedTag": "The usage of the \`id\` attribute is reserved for internal use cases. For testing and other use cases,
use [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes). If you must
use the \`id\` attribute, consider setting it on a parent element instead.",
"description": "Adds the specified ID to the root element of the component.",
"name": "id",
"optional": true,
"type": "string",
},
{
"description": "The content of the tooltip shown when the text is truncated. By default, the
tooltip content is the same as the \`children\` slot. Use only if the \`children\`
slot may contain interactive elements.",
"name": "tooltipText",
"optional": true,
"type": "string",
},
],
"regions": [
{
"description": "The inline text to display. If there isn't enough space to render the text
in a single line, it is truncated with an ellipsis and the full content is
shown on pointer hover or keyboard focus.",
"isDefault": true,
"name": "children",
},
],
"releaseStatus": "stable",
}
`;

exports[`Components definition for tutorial-panel matches the snapshot: tutorial-panel 1`] = `
{
"dashCaseName": "tutorial-panel",
Expand Down Expand Up @@ -45313,6 +45358,19 @@ Supported options:
],
"name": "TreeViewItemWrapper",
},
{
"methods": [
{
"name": "findTooltip",
"parameters": [],
"returnType": {
"isNullable": true,
"name": "TooltipWrapper",
},
},
],
"name": "TruncatedTextWrapper",
},
{
"methods": [
{
Expand Down Expand Up @@ -54066,6 +54124,19 @@ Supported options:
],
"name": "TreeViewItemWrapper",
},
{
"methods": [
{
"name": "findTooltip",
"parameters": [],
"returnType": {
"isNullable": false,
"name": "TooltipWrapper",
},
},
],
"name": "TruncatedTextWrapper",
},
{
"methods": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,9 @@ exports[`test-utils selectors 1`] = `
"awsui_root_1js4f",
"awsui_treeitem_1js4f",
],
"truncated-text": [
"awsui_root_lwmqr",
],
"tutorial-panel": [
"awsui_collapse-button_ig8mp",
"awsui_completed_ig8mp",
Expand Down
Loading
Loading