Skip to content

Commit

Permalink
feat(Link): Add prop to disable text decoration on hover (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
eszthoff authored Mar 28, 2022
1 parent 91e250f commit 684e64a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"main": "dist/oneui.min.js",
"types": "dist/dts/src/index.d.ts",
"scripts": {
"start": "npm run storybook",
"storybook": "start-storybook -s ./stories/static -p 9001 -c .storybook",
"storybook:build": "build-storybook -s ./stories/static -c .storybook -o .out",
"storybook:deploy": "storybook-to-ghpages --script=storybook:build --out=.out",
Expand Down
4 changes: 4 additions & 0 deletions src/components/Link/Link.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
text-decoration: var(--link-decoration-hover);
}

&--dontDecorateOnHover:hover {
text-decoration: var(--link-decoration-normal);
}

&--context_muted {
color: var(--color-muted);

Expand Down
5 changes: 4 additions & 1 deletion src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ interface Props extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
context?: 'brand' | 'muted';
/** Ref to access the anchor */
ref?: React.RefObject<HTMLAnchorElement>;
/** Do not underline text on hover */
dontDecorateOnHover?: boolean;
}

const { block } = bem('Link', styles);

export const Link: React.FC<Props> = React.forwardRef((props, ref) => {
const { children, context, ...rest } = props;
const { children, context, dontDecorateOnHover, ...rest } = props;
return (
<a ref={ref} {...rest} {...block(props)}>
{children}
Expand All @@ -26,4 +28,5 @@ Link.displayName = 'Link';

Link.defaultProps = {
context: 'brand',
dontDecorateOnHover: false,
};
3 changes: 2 additions & 1 deletion stories/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { text, select, withKnobs } from '@storybook/addon-knobs';
import { text, select, boolean, withKnobs } from '@storybook/addon-knobs';
import { Link } from '@textkernel/oneui';

storiesOf('Atoms|Link', module)
Expand All @@ -10,6 +10,7 @@ storiesOf('Atoms|Link', module)
target="_blank"
href="https://textkernel.com"
context={select('Context', ['muted', 'brand'], 'brand')}
dontDecorateOnHover={boolean("Don't decorate on hover", false)}
>
{text('Link text', 'Click me')}
</Link>
Expand Down

0 comments on commit 684e64a

Please sign in to comment.