Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature / Breaking change] Link list and link improvements #710

Merged
merged 26 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
973575a
add mock files for link list
LJKaski Mar 16, 2023
5bad1a6
create list link and link list components
LJKaski Mar 22, 2023
47ed65e
add exampe and index and styleguidist entries
LJKaski Mar 22, 2023
40cd7ca
refine routerlink typing in ListLink props
LJKaski Mar 24, 2023
9aaf7a4
remove built-in heading from link list
LJKaski Mar 24, 2023
4680943
adjust styles
LJKaski Mar 27, 2023
f671bff
fix link list interface and tests
LJKaski Mar 27, 2023
508fa5a
create standalone variant of list link
LJKaski Mar 27, 2023
a9a4c27
add standalone variant to component example
LJKaski Mar 27, 2023
dd49951
rename ListLink to LinkListItem and move under correct folder
LJKaski Apr 12, 2023
5d53b73
clean up styling and examples across links
LJKaski Apr 12, 2023
f7d2814
add smallScreen option to link list
LJKaski Apr 13, 2023
5ca143e
add smallScreen option to links and update examples
LJKaski Apr 13, 2023
7ec8b03
adjust styles and tests and update snapshots
LJKaski Apr 14, 2023
60df30d
remove redundant brackets from link accent icons
LJKaski Apr 20, 2023
73a6a59
remove redundant line changes from jsdoc formatting
LJKaski Apr 20, 2023
0817ff9
fix icon imports and uses in links after rebase
LJKaski Jun 9, 2023
dc30ff2
adjust accent icon vertical align
LJKaski Jun 9, 2023
413f6ea
update snapshots
LJKaski Jun 9, 2023
6dd76f1
move LinkList under its own page in styleguidist
LJKaski Jun 12, 2023
8d2cbf6
improve LinkList examples and documentation
LJKaski Jun 12, 2023
3d267bb
clarify LinkList documentation in terms of heading use
LJKaski Jun 12, 2023
84b890a
rename arrow link examples to accented links
LJKaski Jun 16, 2023
3d76551
update snapshots
LJKaski Jun 16, 2023
29adac6
fix underline styles in accent link and adjust examples
LJKaski Jun 16, 2023
c51517f
fix typo in linklist example
LJKaski Jun 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .styleguidist/styleguidist.sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ module.exports = {
'RouterLink/RouterLink',
]),
},
{
name: 'LinkList',
components: getComponentWithVariants('Link')([
'LinkList/LinkList',
'LinkListItem/LinkListItem',
]),
},
{
name: 'Chip',
components: getComponentWithVariants('Chip')([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,30 @@ exports[`calling render with the same component on the same container does not r
float: left;
}

.c8 {
vertical-align: baseline;
}

.c8.fi-icon {
display: inline-block;
}

.c8 .fi-icon-base-fill {
fill: currentColor;
}

.c8 .fi-icon-base-stroke {
stroke: currentColor;
}

.c8.fi-icon--cursor-pointer {
cursor: pointer;
}

.c8.fi-icon--cursor-pointer * {
cursor: inherit;
}

.c7 {
-webkit-letter-spacing: 0;
-moz-letter-spacing: 0;
Expand Down Expand Up @@ -251,28 +275,22 @@ exports[`calling render with the same component on the same container does not r
text-decoration: none;
}

.c8 {
vertical-align: baseline;
}

.c8.fi-icon {
display: inline-block;
}

.c8 .fi-icon-base-fill {
fill: currentColor;
}

.c8 .fi-icon-base-stroke {
stroke: currentColor;
.c7.fi-link.fi-link--accent {
-webkit-text-decoration: none;
text-decoration: none;
}

.c8.fi-icon--cursor-pointer {
cursor: pointer;
.c7.fi-link.fi-link--accent .fi-link--accent_icon {
font-size: 16px;
margin-left: -3px;
margin-right: 2px;
-webkit-transform: translateY(0.15em);
-ms-transform: translateY(0.15em);
transform: translateY(0.15em);
}

.c8.fi-icon--cursor-pointer * {
cursor: inherit;
.c7.fi-link.fi-link--small {
font-size: 16px;
}

.c5 {
Expand Down
12 changes: 12 additions & 0 deletions src/core/Link/BaseLink/BaseLink.baseStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,17 @@ export const baseStyles = (theme: SuomifiTheme) => css`
text-decoration: none;
}
}
&.fi-link--accent {
text-decoration: none;
& .fi-link--accent_icon {
font-size: 16px;
jenkrisu marked this conversation as resolved.
Show resolved Hide resolved
margin-left: -3px;
margin-right: 2px;
transform: translateY(0.15em);
}
}
&.fi-link--small {
font-size: 16px;
}
}
`;
6 changes: 6 additions & 0 deletions src/core/Link/BaseLink/BaseLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export const baseClassName = 'fi-link';

export const linkClassNames = {
linkUnderline: `${baseClassName}--initial-underline`,
accent: `${baseClassName}--accent`,
accentIcon: `${baseClassName}--accent_icon`,
small: `${baseClassName}--small`,
};

export type UnderlineVariant = 'initial' | 'hover';
Expand All @@ -29,5 +32,8 @@ export interface BaseLinkProps extends HtmlAProps {
* @default hover
*/
underline?: UnderlineVariant;
/** Style variant for the link */
variant?: 'default' | 'accent';
asProp?: asPropType;
smallScreen?: boolean;
}
1 change: 1 addition & 0 deletions src/core/Link/ExternalLink/ExternalLink.baseStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { baseStyles } from '../BaseLink/BaseLink.baseStyles';
export const ExternalLinkStyles = (theme: SuomifiTheme) => css`
${baseStyles(theme)}
& .fi-link_icon {
margin: 0;
padding-left: ${theme.spacing.insetXs};
font-size: 16px;
box-sizing: content-box;
Expand Down
2 changes: 1 addition & 1 deletion src/core/Link/ExternalLink/ExternalLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const TestExternalLink = (
</ExternalLink>
);

test('calling render with the same component on the same container does not remount', () => {
test('matches snapshot', () => {
const LinkRendered = render(TestExternalLink);
const { getByTestId, container } = LinkRendered;
expect(container.firstChild).toMatchSnapshot();
Expand Down
17 changes: 14 additions & 3 deletions src/core/Link/ExternalLink/ExternalLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Component, forwardRef } from 'react';
import { default as styled } from 'styled-components';
import classnames from 'classnames';
import { SuomifiThemeProp, SuomifiThemeConsumer } from '../../theme';
import { IconLinkExternal } from 'suomifi-icons';
import { IconChevronRight, IconLinkExternal } from 'suomifi-icons';
import { VisuallyHidden } from '../../VisuallyHidden/VisuallyHidden';
import { ExternalLinkStyles } from './ExternalLink.baseStyles';
import { HtmlA } from '../../../reset';
Expand Down Expand Up @@ -38,14 +38,17 @@ interface InternalExternalLinkProps extends BaseLinkProps {

export type ExternalLinkProps = newWindowProps & InternalExternalLinkProps;

class BaseExternalLink extends Component<ExternalLinkProps> {
class BaseExternalLink extends Component<ExternalLinkProps & SuomifiThemeProp> {
render() {
const {
asProp,
children,
className,
variant = 'default',
toNewWindow = true,
labelNewWindow,
smallScreen,
theme,
hideIcon,
underline = 'hover',
...passProps
Expand All @@ -55,11 +58,19 @@ class BaseExternalLink extends Component<ExternalLinkProps> {
{...passProps}
className={classnames(baseClassName, className, externalClassName, {
[linkClassNames.linkUnderline]: underline === 'initial',
[linkClassNames.accent]: variant === 'accent',
[linkClassNames.small]: smallScreen,
})}
target={!!toNewWindow ? '_blank' : undefined}
rel={!!toNewWindow ? 'noopener' : undefined}
as={asProp}
>
{variant === 'accent' && (
<IconChevronRight
color={theme.colors.accentBase}
className={linkClassNames.accentIcon}
/>
)}
{children}
{toNewWindow && <VisuallyHidden>{labelNewWindow}</VisuallyHidden>}
{!hideIcon && <IconLinkExternal className={iconClassName} />}
Expand All @@ -71,7 +82,7 @@ class BaseExternalLink extends Component<ExternalLinkProps> {
const StyledExternalLink = styled(
(props: ExternalLinkProps & SuomifiThemeProp) => {
const { theme, ...passProps } = props;
return <BaseExternalLink {...passProps} />;
return <BaseExternalLink theme={theme} {...passProps} />;
},
)`
${({ theme }) => ExternalLinkStyles(theme)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`calling render with the same component on the same container does not remount 1`] = `
exports[`matches snapshot 1`] = `
.c4 {
vertical-align: baseline;
}
Expand Down Expand Up @@ -173,7 +173,26 @@ exports[`calling render with the same component on the same container does not r
text-decoration: none;
}

.c1.fi-link.fi-link--accent {
-webkit-text-decoration: none;
text-decoration: none;
}

.c1.fi-link.fi-link--accent .fi-link--accent_icon {
font-size: 16px;
margin-left: -3px;
margin-right: 2px;
-webkit-transform: translateY(0.15em);
-ms-transform: translateY(0.15em);
transform: translateY(0.15em);
}

.c1.fi-link.fi-link--small {
font-size: 16px;
}

.c1 .fi-link_icon {
margin: 0;
padding-left: 4px;
font-size: 16px;
box-sizing: content-box;
Expand Down
41 changes: 30 additions & 11 deletions src/core/Link/Link/Link.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
```js
import { Link, Paragraph } from 'suomifi-ui-components';

<Paragraph>
<>
<Link
className="test-classname"
href="https://www.notvisitedlink.com/"
underline="initial"
>
Not visited link
</Link>{' '}
</Link>

<Link className="test-classname" href="#" underline="initial">
Visited link
</Link>{' '}
</Link>

<Link href="https://www.notvisitedlink.com/" underline="hover">
Link without underline
</Link>

<Link
className="test-classname"
variant="accent"
href="https://www.notvisitedlink.com/"
underline="hover"
underline="initial"
LJKaski marked this conversation as resolved.
Show resolved Hide resolved
>
Link without underline
Accented link
</Link>
</Paragraph>;

<Link
variant="accent"
href="https://www.notvisitedlink.com/"
underline="initial"
smallScreen
>
Small text accented link
</Link>
</>;
```

### Skip link
Expand All @@ -38,9 +52,7 @@ import { SkipLink } from 'suomifi-ui-components';
style={{
height: '80px',
width: '210px',
borderStyle: 'dashed',
borderColor: '#000',
borderWidth: '1px'
border: '1px dashed #000'
}}
>
<SkipLink href="#">Skip to main content</SkipLink>
Expand All @@ -66,6 +78,13 @@ import { ExternalLink } from 'suomifi-ui-components';
>
External link in same window
</ExternalLink>
<ExternalLink
href="https://designsystem.suomi.fi/fi/"
labelNewWindow="Opens to a new window"
variant="accent"
>
Accented external link
</ExternalLink>
</>;
```

Expand Down
16 changes: 15 additions & 1 deletion src/core/Link/Link/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { forwardRef } from 'react';
import { default as styled } from 'styled-components';
import classnames from 'classnames';
import { IconChevronRight } from 'suomifi-icons';
import { LinkStyles } from '../Link/Link.baseStyles';
import { SuomifiThemeProp, SuomifiThemeConsumer } from '../../theme';
import { HtmlA } from '../../../reset';
Expand All @@ -19,17 +20,30 @@ const StyledLink = styled(
({
asProp,
className,
smallScreen,
theme,
variant = 'default',
children,
underline = 'hover',
...passProps
}: LinkProps & SuomifiThemeProp) => (
<HtmlA
{...passProps}
className={classnames(baseClassName, className, {
[linkClassNames.linkUnderline]: underline === 'initial',
[linkClassNames.accent]: variant === 'accent',
[linkClassNames.small]: smallScreen,
})}
as={asProp}
/>
>
{variant === 'accent' && (
<IconChevronRight
color={theme.colors.accentBase}
className={linkClassNames.accentIcon}
/>
)}
{children}
</HtmlA>
),
)`
${({ theme }) => LinkStyles(theme)}
Expand Down
18 changes: 18 additions & 0 deletions src/core/Link/Link/__snapshots__/Link.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ exports[`calling render with the same component on the same container does not r
text-decoration: none;
}

.c1.fi-link.fi-link--accent {
-webkit-text-decoration: none;
text-decoration: none;
}

.c1.fi-link.fi-link--accent .fi-link--accent_icon {
font-size: 16px;
margin-left: -3px;
margin-right: 2px;
-webkit-transform: translateY(0.15em);
-ms-transform: translateY(0.15em);
transform: translateY(0.15em);
}

.c1.fi-link.fi-link--small {
font-size: 16px;
}

<a
class="c0 fi-link c1"
data-testid="test-link"
Expand Down
18 changes: 18 additions & 0 deletions src/core/Link/LinkList/LinkList.baseStyles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { SuomifiTheme } from 'core/theme';
import { css } from 'styled-components';
import { font } from '../../theme/reset';

export const LinkListStyles = (theme: SuomifiTheme) => css`
&.fi-link-list {
padding: 0;
margin: 5px 0 0 0;
}
&.fi-link-list--small {
& .fi-link-list-item_icon .fi-icon {
transform: translateY(0.15em);
}
& .fi-link {
${font(theme)('bodyTextSmall')}
}
}
`;
Loading