diff --git a/pages/token/inline-long-popover.page.tsx b/pages/token/inline-long-popover.page.tsx new file mode 100644 index 0000000000..ed46c14a6f --- /dev/null +++ b/pages/token/inline-long-popover.page.tsx @@ -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 = ( + + + + } + /> +); + +const longLabel = 'popover trigger will be very very long and keep going until it has to truncate'; + +export default function InlineLongPopoverPage() { + return ( + +
+ + {longLabel} + + } + ariaLabel={longLabel} + labelTag="label tag here" + onDismiss={() => {}} + dismissLabel="Remove token" + /> +
+
+ ); +} diff --git a/pages/token/permutations.page.tsx b/pages/token/permutations.page.tsx index 3b95801004..160fcb535e 100644 --- a/pages/token/permutations.page.tsx +++ b/pages/token/permutations.page.tsx @@ -15,6 +15,7 @@ const permutations = createPermutations([ { label: ['token'], icon: [undefined, ], + labelTag: [undefined, 'label-tag'], onDismiss: [undefined, () => {}], readOnly: [false, true], variant: ['inline'], @@ -22,6 +23,7 @@ const permutations = createPermutations([ { label: ['token'], icon: [undefined, ], + labelTag: [undefined, 'label-tag'], onDismiss: [undefined, () => {}], disabled: [true], variant: ['inline'], diff --git a/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap b/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap index a3eedb253f..b413de07e2 100644 --- a/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap +++ b/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap @@ -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": { diff --git a/src/internal/components/option/index.tsx b/src/internal/components/option/index.tsx index ca67f6040f..edfa5028b5 100644 --- a/src/internal/components/option/index.tsx +++ b/src/internal/components/option/index.tsx @@ -93,7 +93,7 @@ const Option = ({ > {icon} - + {option.labelContent ? ( {option.labelContent} ) : ( diff --git a/src/internal/components/option/styles.scss b/src/internal/components/option/styles.scss index 94f4cf5ee2..988944dc50 100644 --- a/src/internal/components/option/styles.scss +++ b/src/internal/components/option/styles.scss @@ -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; diff --git a/src/token/__tests__/token.test.tsx b/src/token/__tests__/token.test.tsx index 0808b3b842..b31d2f8e56 100644 --- a/src/token/__tests__/token.test.tsx +++ b/src/token/__tests__/token.test.tsx @@ -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'); diff --git a/src/token/constants.scss b/src/token/constants.scss index 29f24e44ac..2b5169f138 100644 --- a/src/token/constants.scss +++ b/src/token/constants.scss @@ -7,4 +7,5 @@ $token-background: awsui.$color-background-item-selected; $token-border-color: awsui.$color-border-item-selected; $token-max-height-inline: 20px; +$token-min-label-width-inline: 12px; $icon-width: 16px; diff --git a/src/token/interfaces.ts b/src/token/interfaces.ts index 080b6f7d4d..b82ea14c85 100644 --- a/src/token/interfaces.ts +++ b/src/token/interfaces.ts @@ -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. */ diff --git a/src/token/internal.tsx b/src/token/internal.tsx index 9bc1df0256..22e0ee6714 100644 --- a/src/token/internal.tsx +++ b/src/token/internal.tsx @@ -124,6 +124,7 @@ function InternalToken({ return { ...labelObject, disabled, + labelTag, __customIcon: icon && {sizedIcon(icon)}, }; } else { @@ -192,7 +193,7 @@ function InternalToken({ style={tokenRootStyleProps} >