-
Notifications
You must be signed in to change notification settings - Fork 30
Add new linkType to LinkElement: 'standard button' #15151
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
Changes from all commits
c03d718
fe32dc3
a1ced4f
f2a3be9
471911f
ea63f32
8565bea
b109673
bcc5b24
a4c7404
b6834b5
b0f2065
9ac8659
d49e814
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { ProductLinkElementButton } from './ProductLinkElementButton'; | ||
| import { StandardLinkElementButton } from './StandardLinkElementButton'; | ||
|
|
||
| type LinkElementButtonProps = { | ||
| label: string; | ||
| url: string; | ||
| linkType: 'StandardButton' | 'ProductButton'; | ||
| priority?: 'Primary' | 'Tertiary'; | ||
| }; | ||
|
|
||
| const LinkTypePriorityToButtonPriority = { | ||
| Primary: 'primary', | ||
| Tertiary: 'tertiary', | ||
| } as const; | ||
|
|
||
| export const LinkElementButton = ({ | ||
| label, | ||
| url, | ||
| priority = 'Primary', | ||
| linkType, | ||
| }: LinkElementButtonProps) => { | ||
| switch (linkType) { | ||
| case 'StandardButton': { | ||
| return ( | ||
| <StandardLinkElementButton | ||
| label={label} | ||
| url={url} | ||
| priority={LinkTypePriorityToButtonPriority[priority]} | ||
| /> | ||
| ); | ||
| } | ||
| case 'ProductButton': { | ||
| return ( | ||
| <ProductLinkElementButton | ||
| label={label} | ||
| url={url} | ||
| priority={LinkTypePriorityToButtonPriority[priority]} | ||
| /> | ||
| ); | ||
| } | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import type { Meta, StoryFn, StoryObj } from '@storybook/react-webpack5'; | ||
| import { lightDecorator } from '../../../.storybook/decorators/themeDecorator'; | ||
| import { | ||
| ArticleDesign, | ||
| ArticleDisplay, | ||
| ArticleSpecial, | ||
| Pillar, | ||
| } from '../../lib/articleFormat'; | ||
| import type { StandardLinkElementButtonProps } from './StandardLinkElementButton'; | ||
| import { StandardLinkElementButton } from './StandardLinkElementButton'; | ||
|
|
||
| const meta: Meta<typeof StandardLinkElementButton> = { | ||
| title: 'Components/StandardLinkElementButton', | ||
| component: StandardLinkElementButton, | ||
| } satisfies Meta<typeof StandardLinkElementButton>; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| const pillars = [ | ||
| Pillar.News, | ||
| Pillar.Sport, | ||
| Pillar.Culture, | ||
| Pillar.Lifestyle, | ||
| Pillar.Opinion, | ||
| ArticleSpecial.SpecialReport, | ||
| ArticleSpecial.Labs, | ||
| ]; | ||
|
|
||
| const allThemeStandardVariations = pillars.map((theme) => ({ | ||
| design: ArticleDesign.Standard, | ||
| display: ArticleDisplay.Standard, | ||
| theme, | ||
| })); | ||
|
|
||
| const urls = ['https://www.theguardian.com/uk', 'https://www.bbc.co.uk']; | ||
|
|
||
| const Template: StoryFn<typeof StandardLinkElementButton> = ( | ||
| args: Omit<StandardLinkElementButtonProps, 'url' | 'priority'>, | ||
| ) => { | ||
| return ( | ||
| <> | ||
| {urls.map((url) => ( | ||
| <StandardLinkElementButton | ||
| key={url} | ||
| {...args} | ||
| label="Click me" | ||
| url={url} | ||
| /> | ||
| ))} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export const WhenPrimary = { | ||
| args: { | ||
| priority: 'primary', | ||
| }, | ||
| render: Template, | ||
| decorators: [lightDecorator(allThemeStandardVariations)], | ||
| } satisfies Story; | ||
| // ***************************************************************************** | ||
|
|
||
| export const WhenSecondary = { | ||
| args: { | ||
| priority: 'secondary', | ||
| }, | ||
| render: Template, | ||
| decorators: [lightDecorator(allThemeStandardVariations)], | ||
| } satisfies Story; | ||
| // ***************************************************************************** | ||
|
|
||
| export const WhenTertiary = { | ||
| args: { | ||
| priority: 'tertiary', | ||
| }, | ||
| render: Template, | ||
| decorators: [lightDecorator(allThemeStandardVariations)], | ||
| } satisfies Story; | ||
| // ***************************************************************************** | ||
|
|
||
| export const WhenSubdued = { | ||
| args: { | ||
| priority: 'subdued', | ||
| }, | ||
| render: Template, | ||
| decorators: [lightDecorator(allThemeStandardVariations)], | ||
| } satisfies Story; | ||
| // ***************************************************************************** |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import type { ButtonPriority } from '@guardian/source/react-components'; | ||
| import { EditorialLinkButton } from './EditorialLinkButton'; | ||
| import { getPropsForLinkUrl, isExternalLink } from './utils'; | ||
|
|
||
| export type StandardLinkElementButtonProps = { | ||
| label: string; | ||
| url: string; | ||
| priority?: ButtonPriority; | ||
| }; | ||
|
|
||
| export const StandardLinkElementButton = ({ | ||
| label, | ||
| url, | ||
| priority, | ||
| }: StandardLinkElementButtonProps) => { | ||
| const propsForLinkUrl = isExternalLink(url) | ||
| ? getPropsForLinkUrl(label) | ||
| : {}; | ||
|
|
||
| return ( | ||
| <EditorialLinkButton | ||
| iconSide="right" | ||
| priority={priority} | ||
| data-link-name={`standard link button ${priority}`} | ||
| data-spacefinder-role="inline" | ||
| data-ignore="global-link-styling" | ||
| {...propsForLinkUrl} | ||
| > | ||
| {label} | ||
| </EditorialLinkButton> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { SvgArrowRightStraight } from '@guardian/source/react-components'; | ||
|
|
||
| const platformHostnames = [ | ||
| // CODE | ||
| 'https://code.dev-theguardian.com/', | ||
| 'https://m.code.dev-theguardian.com/', | ||
| // PROD | ||
| 'www.theguardian.com', | ||
| ]; | ||
|
|
||
| export const isExternalLink = (url: string) => | ||
| platformHostnames.includes(new URL(url).hostname); | ||
|
|
||
| export const getPropsForLinkUrl = (label: string) => ({ | ||
| rel: 'noreferrer noopener', | ||
| target: '_blank', | ||
| 'aria-label': `${label} (opens in a new tab)`, | ||
| icon: <SvgArrowRightStraight />, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While a design question, I'm not sure if the right arrow gives enough affordance that a link is going to open in a new window. The usual icon for this behaviour is a box with a diagonal arrow protruding from it (
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will have implications for the product button, too (storybook) — happy to raise, let's chat out of band about the best forum 👍 |
||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
iconSide="right"can go ingetPropsForLinkUrl()?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in #15186.