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

🎨 Refactor link and button styles and more common styling #2721 #2737

Merged
merged 6 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
6 changes: 0 additions & 6 deletions sanityv3/schemas/objects/teaser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,6 @@ export default {
],
validation: (Rule: Rule) => Rule.max(2).error('Only two action is permitted'),
},
{
title: 'Use resource link style',
description: 'Default is read more link style',
name: 'useResourceLinks',
type: 'boolean',
},
{
name: 'image',
title: 'Image',
Expand Down
13 changes: 0 additions & 13 deletions sanityv3/schemas/objects/textBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type TextBlock = {
bigText?: PortableTextBlock[]
action?: Reference[]
splitList?: boolean
overrideButtonStyle?: boolean
background?: ColorSelectorValue
}

Expand Down Expand Up @@ -193,18 +192,6 @@ export default {
description:
'You can also display links/downloads as two columns if there are a lot of links. Ensure that titles are short enough to do this.',
},
{
title: 'Use link style',
name: 'overrideButtonStyle',
type: 'boolean',
fieldset: 'actions',
initialValue: false,
description:
'You can override the default button style to link style. This can only be done if you have one link, and should be used with caution.',
readOnly: ({ parent }: { parent: TextBlock }) => {
return !(parent.action && parent?.action.length === 1)
},
},
{
name: 'designOptions',
type: 'backgroundOptions',
Expand Down
60 changes: 38 additions & 22 deletions web/core/Link/BaseLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,43 @@ export const BaseLink = forwardRef<HTMLAnchorElement, BaseLinkProps>(function Ba
className,
)

return type === 'externalUrl' ? (
// https://web.dev/articles/referrer-best-practices
// strict-origin-when-cross-origin only share the origin
// and thus protects privacy but gives Referrer origin
// for SEO
// eslint-disable-next-line react/jsx-no-target-blank
<a
className={classNames}
ref={ref}
href={href}
target="_blank"
{...rest}
rel="noopener"
referrerPolicy="strict-origin-when-cross-origin"
>
{children}
</a>
) : (
<NextLink ref={ref} href={href} prefetch={false} className={classNames} {...rest}>
{children}
</NextLink>
)
const getLinkElement = () => {
switch (type) {
case 'externalUrl':
return (
// https://web.dev/articles/referrer-best-practices
// strict-origin-when-cross-origin only share the origin
// and thus protects privacy but gives Referrer origin
// for SEO
// eslint-disable-next-line react/jsx-no-target-blank
<a
className={classNames}
ref={ref}
href={href}
target="_blank"
{...rest}
rel="noopener"
referrerPolicy="strict-origin-when-cross-origin"
>
{children}
</a>
)
case 'icsLink':
return (
<a className={classNames} ref={ref} href={href} {...rest}>
{children}
</a>
)

default:
return (
<NextLink ref={ref} href={href} prefetch={false} className={classNames} {...rest}>
{children}
</NextLink>
)
}
}

return getLinkElement()
})
export default BaseLink
5 changes: 3 additions & 2 deletions web/core/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(function Link(
items-center
gap-2.5
underline
hover:no-underline
hover:text-norwegian-woods-100
dark:hover:text-slate-blue-95
`,
className,
)

return (
<BaseLink className={classNames} type={type} ref={ref} href={href} {...rest}>
{children}
{type === 'externalUrl' && <ArrowRight className="inline-block pt-1 -rotate-45 origin-bottom-left" />}
{type === 'externalUrl' && <ArrowRight className="text-no inline-block pt-1 -rotate-45 origin-bottom-left" />}
</BaseLink>
)
})
Expand Down
75 changes: 0 additions & 75 deletions web/core/Link/ReadMoreLink.tsx

This file was deleted.

Loading
Loading