diff --git a/.changeset/giant-lamps-happen.md b/.changeset/giant-lamps-happen.md new file mode 100644 index 0000000000..1bc4ae6eab --- /dev/null +++ b/.changeset/giant-lamps-happen.md @@ -0,0 +1,5 @@ +--- +'@backstage/ui': patch +--- + +Improved the Link component structure in Backstage UI. diff --git a/packages/ui/report.api.md b/packages/ui/report.api.md index 7cdee27d0e..91b6def80a 100644 --- a/packages/ui/report.api.md +++ b/packages/ui/report.api.md @@ -553,6 +553,14 @@ export const componentDefinitions: { readonly dataAttributes: { readonly variant: readonly ['subtitle', 'body', 'caption', 'label']; readonly weight: readonly ['regular', 'bold']; + readonly color: readonly [ + 'primary', + 'secondary', + 'danger', + 'warning', + 'success', + ]; + readonly truncate: readonly [true, false]; }; }; readonly List: { diff --git a/packages/ui/src/components/Link/Link.module.css b/packages/ui/src/components/Link/Link.module.css index 5d017e9681..a319dfb66b 100644 --- a/packages/ui/src/components/Link/Link.module.css +++ b/packages/ui/src/components/Link/Link.module.css @@ -33,4 +33,78 @@ text-decoration-color: color-mix(in srgb, currentColor 30%, transparent); } } + + .bui-Link[data-variant='title-large'] { + font-size: var(--bui-font-size-8); + line-height: 140%; + } + + .bui-Link[data-variant='title-medium'] { + font-size: var(--bui-font-size-7); + line-height: 140%; + } + + .bui-Link[data-variant='title-small'] { + font-size: var(--bui-font-size-6); + line-height: 140%; + } + + .bui-Link[data-variant='title-x-small'] { + font-size: var(--bui-font-size-5); + line-height: 140%; + } + + .bui-Link[data-variant='body-large'] { + font-size: var(--bui-font-size-4); + line-height: 140%; + } + + .bui-Link[data-variant='body-medium'] { + font-size: var(--bui-font-size-3); + line-height: 140%; + } + + .bui-Link[data-variant='body-small'] { + font-size: var(--bui-font-size-2); + line-height: 140%; + } + + .bui-Link[data-variant='body-x-small'] { + font-size: var(--bui-font-size-1); + line-height: 140%; + } + + .bui-Link[data-weight='regular'] { + font-weight: var(--bui-font-weight-regular); + } + + .bui-Link[data-weight='bold'] { + font-weight: var(--bui-font-weight-bold); + } + + .bui-Link[data-color='primary'] { + color: var(--bui-fg-primary); + } + + .bui-Link[data-color='secondary'] { + color: var(--bui-fg-secondary); + } + + .bui-Link[data-color='danger'] { + color: var(--bui-fg-danger); + } + + .bui-Link[data-color='warning'] { + color: var(--bui-fg-warning); + } + + .bui-Link[data-color='success'] { + color: var(--bui-fg-success); + } + + .bui-Link[data-truncate] { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } } diff --git a/packages/ui/src/components/Link/Link.tsx b/packages/ui/src/components/Link/Link.tsx index 478b6cc67b..c121fd9551 100644 --- a/packages/ui/src/components/Link/Link.tsx +++ b/packages/ui/src/components/Link/Link.tsx @@ -21,65 +21,41 @@ import { useStyles } from '../../hooks/useStyles'; import type { LinkProps } from './types'; import { useNavigate, useHref } from 'react-router-dom'; import { isExternalLink } from '../../utils/isExternalLink'; -import stylesLink from './Link.module.css'; -import stylesText from '../Text/Text.module.css'; +import styles from './Link.module.css'; /** @public */ export const Link = forwardRef((props, ref) => { const navigate = useNavigate(); - const { classNames: classNamesLink } = useStyles('Link', props); - const { - classNames: classNamesText, - dataAttributes: textDataAttributes, - cleanedProps, - } = useStyles('Text', { + const { classNames, dataAttributes, cleanedProps } = useStyles('Link', { variant: 'body', weight: 'regular', color: 'primary', ...props, }); - const { className, variant, weight, color, truncate, href, ...restProps } = - cleanedProps; + + const { className, href, ...restProps } = cleanedProps; const isExternal = isExternalLink(href); + const component = ( + + ); + // If it's an external link, render AriaLink without RouterProvider if (isExternal) { - return ( - - ); + return component; } // For internal links, use RouterProvider return ( - + {component} ); }); diff --git a/packages/ui/src/utils/componentDefinitions.ts b/packages/ui/src/utils/componentDefinitions.ts index e9ba832bf8..1a861768fb 100644 --- a/packages/ui/src/utils/componentDefinitions.ts +++ b/packages/ui/src/utils/componentDefinitions.ts @@ -228,6 +228,8 @@ export const componentDefinitions = { dataAttributes: { variant: ['subtitle', 'body', 'caption', 'label'] as const, weight: ['regular', 'bold'] as const, + color: ['primary', 'secondary', 'danger', 'warning', 'success'] as const, + truncate: [true, false] as const, }, }, List: {