From 56500342e379a022ab6880cc4adfbc2bae0c33a9 Mon Sep 17 00:00:00 2001 From: Radek Podrazky Date: Wed, 27 Sep 2023 17:57:31 +0200 Subject: [PATCH] feat(Link): add experimental underline Ref UXD-1253 --- src/components/_internal/BaseLink/BaseLink.ts | 4 +-- src/components/typographyLegacy/Link/Link.tsx | 26 +++++++++++++++++-- src/theme/DSProvider/DSProvider.tsx | 5 +++- src/theme/DSProvider/DSProvider.types.ts | 3 +++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/components/_internal/BaseLink/BaseLink.ts b/src/components/_internal/BaseLink/BaseLink.ts index e29fa9eb5..d3a9f17b3 100644 --- a/src/components/_internal/BaseLink/BaseLink.ts +++ b/src/components/_internal/BaseLink/BaseLink.ts @@ -3,7 +3,7 @@ import { css } from 'styled-components'; import { getFontWeight, getRadii, getToken } from '../../../utils'; import { Colors } from './BaseLink.types'; -type LinkStylesProps = { $color: Colors }; +type LinkStylesProps = { $color: Colors; $isExperimental: boolean }; export const LinkBaseStyles = css` margin: 0; @@ -24,7 +24,7 @@ export const LinkFocusStyles = css` color: ${(p) => getToken(`color-action-link-${p.$color}-hover`, p)}; text-decoration: underline; background-color: ${(p) => - getToken(`color-action-link-background${p.$color}-focus`, p)}; + getToken(`color-action-link-background-${p.$color}-focus`, p)}; border-radius: ${getRadii('default')}; `; export const LinkActiveStyles = css` diff --git a/src/components/typographyLegacy/Link/Link.tsx b/src/components/typographyLegacy/Link/Link.tsx index f9c1f2f87..881fbb9dc 100644 --- a/src/components/typographyLegacy/Link/Link.tsx +++ b/src/components/typographyLegacy/Link/Link.tsx @@ -1,6 +1,6 @@ -import React from 'react'; +import React, { useContext } from 'react'; import PropTypes from 'prop-types'; -import styled from 'styled-components'; +import styled, { css } from 'styled-components'; import { isNotNull, isNull } from 'ramda-adjunct'; import cls from 'classnames'; @@ -14,6 +14,24 @@ import { LinkHoverStyles, } from '../../_internal/BaseLink'; import { CLX_TYPOGRAPHY } from '../../../theme/constants'; +import { DSContext } from '../../../theme/DSProvider/DSProvider'; +import { getColor, getFontWeight, getToken } from '../../../utils'; + +const experimetalLink = css>` + text-decoration: underline; + font-weight: ${getFontWeight('regular')}; + + &:hover { + color: ${({ $color, theme }) => + $color === LinkColors.secondary + ? getColor('neutral.700', { theme }) + : getToken(`color-action-link-primary-hover`, { theme })}; + } + + &:focus-visible { + text-decoration: none; + } +`; const LinkRoot = styled.a` ${LinkBaseStyles}; @@ -29,6 +47,8 @@ const LinkRoot = styled.a` &:active { ${LinkActiveStyles}; } + + ${({ $isExperimental }) => $isExperimental && experimetalLink} `; const Link: React.FC> = ({ @@ -45,6 +65,7 @@ const Link: React.FC> = ({ if (isNull(as) && isNotNull(to)) { RouterLink = requireRouterLink(); } + const { experimental } = useContext(DSContext); const domTag = as || @@ -67,6 +88,7 @@ const Link: React.FC> = ({ to={to} onClick={onClick} {...props} + $isExperimental={experimental.accessibleLink} > {children} diff --git a/src/theme/DSProvider/DSProvider.tsx b/src/theme/DSProvider/DSProvider.tsx index 3144216e6..08601a5a0 100644 --- a/src/theme/DSProvider/DSProvider.tsx +++ b/src/theme/DSProvider/DSProvider.tsx @@ -7,10 +7,13 @@ import { createTheme } from '../theme'; import { GlobalStyles } from '../GlobalStyles'; import { DSContextValue, DSProviderProps } from './DSProvider.types'; -export const defaultDSContext = { +export const defaultDSContext: DSContextValue = { portalsContainerId: 'portals', hasIncludedGlobalStyles: true, debugMode: false, + experimental: { + accessibleLink: false, + }, }; export const DSContext = React.createContext(defaultDSContext); diff --git a/src/theme/DSProvider/DSProvider.types.ts b/src/theme/DSProvider/DSProvider.types.ts index 013c2aa8e..4b997506e 100644 --- a/src/theme/DSProvider/DSProvider.types.ts +++ b/src/theme/DSProvider/DSProvider.types.ts @@ -6,6 +6,9 @@ export interface DSContextValue { portalsContainerId: string; hasIncludedGlobalStyles: boolean; debugMode: boolean; + experimental: { + accessibleLink: boolean; + }; } export interface DSProviderProps { /**