Skip to content

Commit

Permalink
refa: Link styles (#1992)
Browse files Browse the repository at this point in the history
* refa: Link styles

* fix

* Create light-lobsters-tan.md

* Update packages/components/src/Link/Link.tsx

* Update packages/components/src/Link/Link.tsx

* Update packages/components/src/Link/Link.tsx

Co-authored-by: sarahgm <sarah.gosmann@reservix.de>
Co-authored-by: Sebastian Sebald <sebastian.sebald@gmail.com>
Co-authored-by: Sebastian Sebald <sebastian.sebald@reservix.de>
  • Loading branch information
4 people authored Apr 14, 2022
1 parent 37b3b0e commit 59f3e6f
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 64 deletions.
8 changes: 8 additions & 0 deletions .changeset/light-lobsters-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@marigold/components": patch
"@marigold/theme-b2b": patch
"@marigold/theme-core": patch
"@marigold/theme-unicorn": patch
---

refa: Link styles
29 changes: 17 additions & 12 deletions packages/components/src/Link/Link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,27 @@ const theme = {
link: 'Inter',
body: 'Oswald',
},
link: {
__default: {
fontFamily: 'link',
color: 'blue',
},
second: {
fontFamily: 'body',
color: 'green',
},
':disabled': {
color: 'grey',

components: {
Link: {
base: {
fontFamily: 'link',
color: 'blue',
'&:disabled': {
color: 'grey',
},
},
variant: {
second: {
fontFamily: 'body',
color: 'green',
},
},
},
},
};

test('uses `text.link` as default variant', () => {
test('uses base variant', () => {
render(
<ThemeProvider theme={theme}>
<Link href="#!">Link</Link>
Expand Down
25 changes: 11 additions & 14 deletions packages/components/src/Link/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import React, { useRef } from 'react';
import { useLink } from '@react-aria/link';
import { conditional } from '@marigold/system';
import { ThemeExtension, useComponentStyles } from '@marigold/system';
import { PolymorphicComponent, PolymorphicProps } from '@marigold/types';

import { Box, BoxOwnProps } from '../Box';

// Theme Extension
// ---------------
export interface LinkThemeExtension<Value> {
link?: Value;
}
export interface LinkThemeExtension extends ThemeExtension<'Link'> {}

// Props
// ---------------
export interface LinkOwnProps extends BoxOwnProps {
disabled?: boolean;
variant?: string;
size?: string;
}

export interface LinkProps extends PolymorphicProps<LinkOwnProps, 'a'> {}

// Component
// ---------------
export const Link = (({
as = 'a',
variant = '',
children,
variant,
size,
children,
disabled,
...props
}: LinkProps) => {
Expand All @@ -38,15 +40,10 @@ export const Link = (({
ref
);

const styles = useComponentStyles('Link', { variant, size });

return (
<Box
as={as}
variant={conditional(`link.${variant}`, { disabled })}
css={{ cursor: disabled ? 'default' : 'pointer' }}
ref={ref}
{...props}
{...linkProps}
>
<Box as={as} css={styles} ref={ref} {...props} {...linkProps}>
{children}
</Box>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { HelpTextThemeExtension } from './Field/HelpText';
import type { ImageThemeExtension } from './Image';
import type { InputThemeExtension } from './Input';
import type { LabelThemeExtension } from './Field/Label';
import type { LinkThemeExtension } from './Link';
import type { TextAreaThemeExtension } from './TextArea';

// Old Styling Solution
Expand All @@ -19,7 +20,6 @@ import { type CardThemeExtension } from './Card';
import { type CheckboxThemeExtension } from './Checkbox';
import { type DividerThemeExtension } from './Divider';
import { type LabelThemeExtension as LegacyLabelThemeExtension } from './Label';
import { type LinkThemeExtension } from './Link';
import { type MenuThemeExtension } from './Menu';
import { type MenuItemThemeExtension } from './MenuItem';
import { type MessageThemeExtension } from './Message';
Expand All @@ -38,6 +38,7 @@ interface ComponentStyles
LabelThemeExtension,
InputThemeExtension,
LabelThemeExtension,
LinkThemeExtension,
TextAreaThemeExtension {}

export interface Theme
Expand All @@ -48,7 +49,6 @@ export interface Theme
CheckboxThemeExtension<CSSObject>,
DividerThemeExtension<CSSObject>,
LegacyLabelThemeExtension<CSSObject>,
LinkThemeExtension<CSSObject>,
MenuThemeExtension<CSSObject>,
MenuItemThemeExtension<CSSObject>,
MessageThemeExtension<CSSObject>,
Expand Down
12 changes: 0 additions & 12 deletions themes/theme-b2b/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,18 +425,6 @@ export const component = {
color: 'gray50',
},
},
link: {
__default: {
color: 'blue60',
':hover': {
textDecoration: 'none',
},
},
menuItemLink: {
color: 'text',
textDecoration: 'none',
},
},
menuItem: {
default: {
display: 'block',
Expand Down
19 changes: 19 additions & 0 deletions themes/theme-b2b/src/components/Link.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Theme } from '@marigold/components';

export const Link: Theme['components']['Link'] = {
base: {
color: 'blue60',
'&:hover': {
textDecoration: 'none',
},
'&disabled': {
cursor: 'disabled',
},
},
variant: {
menuItemLink: {
color: 'text',
textDecoration: 'none',
},
},
};
1 change: 1 addition & 0 deletions themes/theme-b2b/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from './HelpText.style';
export * from './Image.style';
export * from './Input.style';
export * from './Label.style';
export * from './Link.style';
export * from './TextArea.style';
12 changes: 0 additions & 12 deletions themes/theme-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,18 +430,6 @@ export const component = {
color: colors.gray50,
},
},
link: {
__default: {
color: '#900',
':hover, :visited': {
textDecoration: 'none',
},
},
menuItemLink: {
color: 'text',
textDecoration: 'none',
},
},
menuItem: {
default: {
display: 'block',
Expand Down
20 changes: 20 additions & 0 deletions themes/theme-core/src/components/Link.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Theme } from '@marigold/components';

export const Link: Theme['components']['Link'] = {
base: {
color: '#900',
'&:hover, &:visited': {
textDecoration: 'none',
cursor: 'pointer',
},
'&disabled': {
cursor: 'disabled',
},
},
variant: {
menuItemLink: {
color: 'text',
textDecoration: 'none',
},
},
};
1 change: 1 addition & 0 deletions themes/theme-core/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from './HelpText.style';
export * from './Image.style';
export * from './Input.style';
export * from './Label.style';
export * from './Link.style';
export * from './TextArea.style';
12 changes: 0 additions & 12 deletions themes/theme-unicorn/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,18 +419,6 @@ export const component = {
color: 'gray50',
},
},
link: {
__default: {
color: 'primary',
':hover': {
textDecoration: 'none',
},
},
menuItemLink: {
color: 'text',
textDecoration: 'none',
},
},
menuItem: {
default: {
display: 'block',
Expand Down
19 changes: 19 additions & 0 deletions themes/theme-unicorn/src/components/Link.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Theme } from '@marigold/components';

export const Link: Theme['components']['Link'] = {
base: {
color: 'primary',
'&:hover': {
textDecoration: 'none',
},
'&disabled': {
cursor: 'disabled',
},
},
variant: {
menuItemLink: {
color: 'text',
textDecoration: 'none',
},
},
};
1 change: 1 addition & 0 deletions themes/theme-unicorn/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from './HelpText.style';
export * from './Image.style';
export * from './Input.style';
export * from './Label.style';
export * from './Link.style';
export * from './TextArea.style';

0 comments on commit 59f3e6f

Please sign in to comment.