Skip to content
Open
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
43 changes: 43 additions & 0 deletions pages/token/inline-long-popover.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React from 'react';

import Icon from '~components/icon';
import Popover from '~components/popover';
import Token from '~components/token';

import { SimplePage } from '../app/templates';

const dot = (
<Icon
svg={
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" focusable="false">
<circle cx="8" cy="8" r="4" fill="#d13212" className="no-stroke" />
</svg>
}
/>
);

const longLabel = 'popover trigger will be very very long and keep going until it has to truncate';

export default function InlineLongPopoverPage() {
return (
<SimplePage title="Inline token with long popover trigger and label tag">
<div style={{ maxInlineSize: 300 }}>
<Token
variant="inline"
icon={dot}
label={
<Popover triggerType="text-inline" header={longLabel} content="Popover content" wrapTriggerText={false}>
{longLabel}
</Popover>
}
ariaLabel={longLabel}
labelTag="label tag here"
onDismiss={() => {}}
dismissLabel="Remove token"
/>
</div>
</SimplePage>
);
}
2 changes: 2 additions & 0 deletions pages/token/permutations.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ const permutations = createPermutations<TokenProps>([
{
label: ['token'],
icon: [undefined, <Icon key="icon" name="settings" size="small" />],
labelTag: [undefined, 'label-tag'],
Comment thread
NathanZlion marked this conversation as resolved.
onDismiss: [undefined, () => {}],
readOnly: [false, true],
variant: ['inline'],
},
{
label: ['token'],
icon: [undefined, <Icon key="icon" name="settings" size="small" />],
labelTag: [undefined, 'label-tag'],
onDismiss: [undefined, () => {}],
disabled: [true],
variant: ['inline'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33907,7 +33907,7 @@ Only applies to plain text labels.",
{
"description": "Specifies the token's visual style and functionality.

For \`inline\` only label, icon and dismiss button are displayed.
When set to \`inline\`, only label, label tag, icon and dismiss button are displayed. Description and tags are not.

Defaults to \`normal\` if not specified.",
"inlineType": {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/components/option/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const Option = ({
>
{icon}
<SpanOrDivTag className={styles.content}>
<SpanOrDivTag className={styles['label-content']}>
<SpanOrDivTag className={clsx(styles['label-content'], triggerVariant && styles['trigger-variant'])}>
{option.labelContent ? (
<SpanOrDivTag className={clsx(styles.label, analyticsSelectors.label)}>{option.labelContent}</SpanOrDivTag>
) : (
Expand Down
17 changes: 17 additions & 0 deletions src/internal/components/option/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@
}
}

// Inline tokens stay on one line: the label truncates and the label tag keeps its size.
.label-content.trigger-variant {
flex-wrap: nowrap;

> .label {
flex: 0 1 auto;
min-inline-size: 0;
}

> .label-tag {
flex: 0 0 auto;
overflow: visible;
text-overflow: clip;
white-space: nowrap;
}
}

.tags,
.description {
@include styles.font-body-s;
Expand Down
12 changes: 12 additions & 0 deletions src/token/__tests__/token.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ describe('Token', () => {
});
});

describe('Label tag', () => {
test('renders label tag for normal variant', () => {
const wrapper = renderToken({ label: 'Test token', labelTag: '17%' });
expect(wrapper.findLabelTag()!.getElement()).toHaveTextContent('17%');
});

test('renders label tag for inline variant', () => {
const wrapper = renderToken({ label: 'Test token', variant: 'inline', labelTag: '17%' });
expect(wrapper.findLabelTag()!.getElement()).toHaveTextContent('17%');
});
});

describe('One theme', () => {
beforeEach(() => {
document.body.classList.add('awsui-one-theme');
Expand Down
2 changes: 1 addition & 1 deletion src/token/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface TokenProps extends BaseComponentProps {
/**
* Specifies the token's visual style and functionality.
*
* For `inline` only label, icon and dismiss button are displayed.
* When set to `inline`, only label, label tag, icon and dismiss button are displayed. Description and tags are not.
*
* Defaults to `normal` if not specified.
*/
Expand Down
1 change: 1 addition & 0 deletions src/token/internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function InternalToken({
return {
...labelObject,
disabled,
labelTag,

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.

There is no visual distinction between the "main" label and the label tag (other than being aligned on opposite ends). Is this the intended design?

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.

confirmed this with design, this is expected. if there's a need for visual difference like a font size difference or text color difference is needed and the need arises from customers we can follow up with it. Our current usecase:
Image

__customIcon: icon && <span className={clsx(styles.icon, styles['icon-inline'])}>{sizedIcon(icon)}</span>,
};
} else {
Expand Down
Loading