Skip to content

Commit

Permalink
(HDS-1834) Linkbox size to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
mrTuomoK committed Jun 3, 2024
1 parent 3168b8c commit 27483b3
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- [Component] What has been changed
- [Notification] Change auto closing notification progressbar to decrease instead of increase.
- [LinkBox] Change size prop to an enum (LinkboxSize.Small, LinkboxSize.Medium, LinkboxSize.Large), not a breaking change though since the enum values are identical to the old ones.

#### Fixed

Expand Down
32 changes: 19 additions & 13 deletions packages/react/src/components/linkbox/Linkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import styles from './Linkbox.module.scss';
import { IconArrowRight, IconLinkExternal } from '../../icons';
import classNames from '../../utils/classNames';

export enum LinkboxSize {
Small = 'small',
Medium = 'medium',
Large = 'large',
}

export type LinkboxProps = {
/**
* Boolean indicating for external link that takes user to an entirely new web site. Defaults to false.
Expand Down Expand Up @@ -58,7 +64,7 @@ export type LinkboxProps = {
/**
* Size variant for the linkbox. Affects texts and paddings.
*/
size?: 'small' | 'medium' | 'large';
size?: LinkboxSize;
} & Omit<React.ComponentPropsWithoutRef<'a'>, 'tabIndex'>;

export const Linkbox = ({
Expand All @@ -77,7 +83,7 @@ export const Linkbox = ({
openInNewTabAriaLabel,
text,
border = false,
size = 'medium',
size = LinkboxSize.Medium,
...rest
}: LinkboxProps) => {
const linkRef = useRef(null);
Expand Down Expand Up @@ -117,22 +123,22 @@ export const Linkbox = ({
!noBackground && styles.withBackground,
noBackground && !imgProps && styles.paddingWithoutImageAndWithoutBackground,
!noBackground && !imgProps && styles.paddingWithoutImageAndWithBackground,
imgProps && size === 'small' && styles.withSmallImage,
imgProps && size === 'medium' && styles.withMediumImage,
imgProps && size === 'large' && styles.withLargeImage,
size === 'small' && styles.contentSmall,
size === 'medium' && styles.contentMedium,
size === 'large' && styles.contentLarge,
imgProps && size === LinkboxSize.Small && styles.withSmallImage,
imgProps && size === LinkboxSize.Medium && styles.withMediumImage,
imgProps && size === LinkboxSize.Large && styles.withLargeImage,
size === LinkboxSize.Small && styles.contentSmall,
size === LinkboxSize.Medium && styles.contentMedium,
size === LinkboxSize.Large && styles.contentLarge,
)}
>
{heading && (
<div
role="heading"
aria-level={headingAriaLevel}
className={classNames(
size === 'small' && styles.headingSmall,
size === 'medium' && styles.headingMedium,
size === 'large' && styles.headingLarge,
size === LinkboxSize.Small && styles.headingSmall,
size === LinkboxSize.Medium && styles.headingMedium,
size === LinkboxSize.Large && styles.headingLarge,
)}
>
{heading}
Expand All @@ -156,7 +162,7 @@ export const Linkbox = ({
styles.icon,
noBackground
? styles.iconWhenNoBackground
: size === 'large' && styles.iconPositionForLinkboxLargeVariant,
: size === LinkboxSize.Large && styles.iconPositionForLinkboxLargeVariant,
)}
size="l"
aria-hidden
Expand All @@ -167,7 +173,7 @@ export const Linkbox = ({
styles.icon,
noBackground
? styles.iconWhenNoBackground
: size === 'large' && styles.iconPositionForLinkboxLargeVariant,
: size === LinkboxSize.Large && styles.iconPositionForLinkboxLargeVariant,
)}
size="l"
aria-hidden
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { Linkbox } from './Linkbox';
import { Linkbox, LinkboxSize } from './Linkbox';

export default {
component: Linkbox,
Expand Down Expand Up @@ -49,23 +49,23 @@ export const External = () => (

export const SmallSize = () => (
<div style={{ width: '288px' }}>
<Linkbox linkboxAriaLabel="Linkbox: HDS" linkAriaLabel="HDS" href="https://hds.hel.fi" size="small">
<Linkbox linkboxAriaLabel="Linkbox: HDS" linkAriaLabel="HDS" href="https://hds.hel.fi" size={LinkboxSize.Small}>
<div style={{ height: '192px' }} />
</Linkbox>
</div>
);

export const MediumSize = () => (
<div style={{ width: '320px' }}>
<Linkbox linkboxAriaLabel="Linkbox: HDS" linkAriaLabel="HDS" href="https://hds.hel.fi" size="medium">
<Linkbox linkboxAriaLabel="Linkbox: HDS" linkAriaLabel="HDS" href="https://hds.hel.fi" size={LinkboxSize.Medium}>
<div style={{ height: '224px' }} />
</Linkbox>
</div>
);

export const LargeSize = () => (
<div style={{ width: '400px' }}>
<Linkbox linkboxAriaLabel="Linkbox: HDS" linkAriaLabel="HDS" href="https://hds.hel.fi" size="large">
<Linkbox linkboxAriaLabel="Linkbox: HDS" linkAriaLabel="HDS" href="https://hds.hel.fi" size={LinkboxSize.Large}>
<div style={{ height: '296px' }} />
</Linkbox>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { Linkbox } from './Linkbox';
import { Linkbox, LinkboxSize } from './Linkbox';

export default {
component: Linkbox,
Expand Down Expand Up @@ -75,7 +75,7 @@ export const SmallSize = () => (
href="https://hds.hel.fi"
heading="Linkbox title"
text="Linkbox text"
size="small"
size={LinkboxSize.Small}
/>
</div>
);
Expand All @@ -88,7 +88,7 @@ export const MediumSize = () => (
href="https://hds.hel.fi"
heading="Linkbox title"
text="Linkbox text"
size="medium"
size={LinkboxSize.Medium}
/>
</div>
);
Expand All @@ -100,6 +100,6 @@ export const LargeSize = () => (
href="https://hds.hel.fi"
heading="Linkbox title"
text="Linkbox text"
size="large"
size={LinkboxSize.Large}
/>
);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { Linkbox } from './Linkbox';
import { Linkbox, LinkboxSize } from './Linkbox';
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore
import smallImage from '../../assets/img/linkbox/placeholder-small.png';
Expand Down Expand Up @@ -88,7 +88,7 @@ export const SmallSize = () => (
heading="Linkbox title"
text="Linkbox text"
imgProps={{ src: smallImage, width: 284, height: 181 }}
size="small"
size={LinkboxSize.Small}
/>
</div>
);
Expand All @@ -102,7 +102,7 @@ export const MediumSize = () => (
heading="Linkbox title"
text="Linkbox text"
imgProps={{ src: mediumImage, width: 384, height: 245 }}
size="medium"
size={LinkboxSize.Medium}
/>
</div>
);
Expand All @@ -116,7 +116,7 @@ export const LargeSize = () => (
heading="Linkbox title"
text="Linkbox text"
imgProps={{ src: largeImage, width: 567, height: 363 }}
size="large"
size={LinkboxSize.Large}
/>
</div>
);
14 changes: 7 additions & 7 deletions site/src/docs/components/linkbox/code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ slug: '/components/linkbox/code'
title: 'Linkbox - Code'
---

import { Linkbox } from 'hds-react';
import { Linkbox, LinkboxSize } from 'hds-react';
import { withPrefix } from "gatsby"
import TabsLayout from './tabs.mdx';

Expand Down Expand Up @@ -164,10 +164,10 @@ import { Linkbox } from 'hds-react';
</Playground>

### Linkbox size variants
<Playground scope={{ Linkbox, withPrefix }}>
<Playground scope={{ Linkbox, LinkboxSize, withPrefix }}>

```jsx
import { Linkbox } from 'hds-react';
import { Linkbox, LinkboxSize } from 'hds-react';

() => (
<div style={{ backgroundColor: 'var(--color-black-5)', padding: 'var(--spacing-s)' }}>
Expand All @@ -178,7 +178,7 @@ import { Linkbox } from 'hds-react';
href="https://hds.hel.fi"
heading="Linkbox title"
text="Linkbox text"
size="small"
size={LinkboxSize.Small}
imgProps={{ src: withPrefix('/images/foundation/visual-assets/placeholders/[email protected]'), width: 284, height: 181 }}
/>
</div>
Expand All @@ -189,7 +189,7 @@ import { Linkbox } from 'hds-react';
href="https://hds.hel.fi"
heading="Linkbox title"
text="Linkbox text"
size="medium"
size={LinkboxSize.Medium}
imgProps={{ src: withPrefix('/images/foundation/visual-assets/placeholders/[email protected]'), width: 384, height: 245 }}
/>
</div>
Expand All @@ -200,7 +200,7 @@ import { Linkbox } from 'hds-react';
href="https://hds.hel.fi"
heading="Linkbox title"
text="Linkbox text"
size="large"
size={LinkboxSize.Large}
imgProps={{ src: withPrefix('/images/foundation/visual-assets/placeholders/[email protected]'), width: 567, height: 363 }}
/>
</div>
Expand All @@ -227,7 +227,7 @@ Note! You can find the full list of properties in the <Link openInNewTab openInN
| `openInExternalDomainAriaLabel` | Aria-label which is read if the link is external. | `string` | - |
| `openInNewTab` | If set to true, the link opens in a new tab. | `boolean` | false |
| `openInNewTabAriaLabel` | Aria-label which is read if the link is opened in a new tab. | `string` | - |
| `size` | Controls the size of the Linkbox. | `"small"`, `"medium"`, `"large"` | `"medium"` |
| `size` | Controls the size of the Linkbox. | `LinkboxSize.Small`, `LinkboxSize.Medium`, `LinkboxSize.Large` | `LinkboxSize.Medium` |
| `href` | Hypertext reference of the link. | `string` | - |
| `linkAriaLabel` | Aria-label for the link (arrow or external icon) that is located at the bottom of the linkbox. | `string` | - |
| `linkboxAriaLabel` | Aria label for the whole linkbox region. Remember to tell users of assistive technology that they are inside a linkbox. Check storybook examples on how it can be done. | `string` | - |
Expand Down
10 changes: 5 additions & 5 deletions site/src/docs/components/linkbox/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: 'Linkbox'
navTitle: 'Linkbox'
---

import { Linkbox } from 'hds-react';
import { Linkbox, LinkboxSize } from 'hds-react';
import { withPrefix } from "gatsby"
import TabsLayout from './tabs.mdx';

Expand Down Expand Up @@ -170,7 +170,7 @@ HDS offers styling for a Linkbox with an image as its content.

#### Linkbox size variants

HDS Linkbox includes three (3) size variants; small, default, and large.
HDS Linkbox includes three (3) size variants; small, default, and large (LinkboxSize.Small, LinkboxSize.Medium and LinkboxSize.Large).
You can use different sizes depending on the screen size or use case.
Size variants differ in (default) heading size and inner spacing. Use the size property to alter the size.

Expand All @@ -182,7 +182,7 @@ Size variants differ in (default) heading size and inner spacing. Use the size p
href="https://hds.hel.fi"
heading="Linkbox title"
text="Linkbox text"
size="small"
size={LinkboxSize.Small}
imgProps={{ src: withPrefix('/images/foundation/visual-assets/placeholders/[email protected]'), width: 284, height: 181 }}
/>
</div>
Expand All @@ -193,7 +193,7 @@ Size variants differ in (default) heading size and inner spacing. Use the size p
href="https://hds.hel.fi"
heading="Linkbox title"
text="Linkbox text"
size="medium"
size={LinkboxSize.Medium}
imgProps={{ src: withPrefix('/images/foundation/visual-assets/placeholders/[email protected]'), width: 384, height: 245 }}
/>
</div>
Expand All @@ -204,7 +204,7 @@ Size variants differ in (default) heading size and inner spacing. Use the size p
href="https://hds.hel.fi"
heading="Linkbox title"
text="Linkbox text"
size="large"
size={LinkboxSize.Large}
imgProps={{ src: withPrefix('/images/foundation/visual-assets/placeholders/[email protected]'), width: 567, height: 363 }}
/>
</div>
Expand Down

0 comments on commit 27483b3

Please sign in to comment.