Skip to content

Commit

Permalink
feat(Link): add experimental underline
Browse files Browse the repository at this point in the history
Ref UXD-1253
  • Loading branch information
ajkl2533 committed Sep 27, 2023
1 parent 84791f6 commit 5650034
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/_internal/BaseLink/BaseLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<LinkStylesProps>`
margin: 0;
Expand All @@ -24,7 +24,7 @@ export const LinkFocusStyles = css<LinkStylesProps>`
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<LinkStylesProps>`
Expand Down
26 changes: 24 additions & 2 deletions src/components/typographyLegacy/Link/Link.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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<Required<{ $color: LinkProps['color'] }>>`
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};
Expand All @@ -29,6 +47,8 @@ const LinkRoot = styled.a`
&:active {
${LinkActiveStyles};
}
${({ $isExperimental }) => $isExperimental && experimetalLink}
`;

const Link: React.FC<LinkProps & React.ComponentProps<typeof LinkRoot>> = ({
Expand All @@ -45,6 +65,7 @@ const Link: React.FC<LinkProps & React.ComponentProps<typeof LinkRoot>> = ({
if (isNull(as) && isNotNull(to)) {
RouterLink = requireRouterLink();
}
const { experimental } = useContext(DSContext);

const domTag =
as ||
Expand All @@ -67,6 +88,7 @@ const Link: React.FC<LinkProps & React.ComponentProps<typeof LinkRoot>> = ({
to={to}
onClick={onClick}
{...props}
$isExperimental={experimental.accessibleLink}
>
{children}
</LinkRoot>
Expand Down
5 changes: 4 additions & 1 deletion src/theme/DSProvider/DSProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<DSContextValue>(defaultDSContext);

Expand Down
3 changes: 3 additions & 0 deletions src/theme/DSProvider/DSProvider.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export interface DSContextValue {
portalsContainerId: string;
hasIncludedGlobalStyles: boolean;
debugMode: boolean;
experimental: {
accessibleLink: boolean;
};
}
export interface DSProviderProps {
/**
Expand Down

0 comments on commit 5650034

Please sign in to comment.