Skip to content

Commit

Permalink
feat: link style variants
Browse files Browse the repository at this point in the history
  • Loading branch information
maxholman committed Dec 7, 2022
1 parent 76bb744 commit c599584
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
55 changes: 44 additions & 11 deletions lib/links.css.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
import { style } from '@vanilla-extract/css';
import { createVar, style, styleVariants } from '@vanilla-extract/css';
import { genericVars } from './design-system.css.js';
import { colorThemeVars } from './schemes/color.css.js';
import { hsl } from './utils.js';

export const linkStyle = style({
export type LinkVariant = 'strong' | 'standard' | 'weak';

const linkColorVar = createVar();

const linkStyle = style({
vars: {
[linkColorVar]: hsl(
colorThemeVars.accent.h,
colorThemeVars.accent.s,
colorThemeVars.accent.l,
),
},
cursor: 'pointer',
selectors: {
'&:hover': {
});

export const linkStyleVariant = styleVariants(
{
strong: {
color: linkColorVar,
fontWeight: genericVars.text.weight.semiBold,
},
standard: {
color: linkColorVar,
},
weak: {
textDecoration: 'underline',
selectors: {
'&:hover': {
color: linkColorVar,
},
},
},
},
color: hsl(
colorThemeVars.accent.h,
colorThemeVars.accent.s,
colorThemeVars.accent.l,
),
});
} as const,
(cssProps) => [
linkStyle,
{
selectors: {
'&:hover': {
textDecoration: 'underline',
},
},
...cssProps,
},
],
);
14 changes: 6 additions & 8 deletions lib/links.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import type { FC } from 'react';
import { Box, BoxBasedComponentProps } from './core.js';
import { linkStyle } from './links.css.js';
import { linkStyleVariant, LinkVariant } from './links.css.js';

export const TextLink: FC<BoxBasedComponentProps<'span' | 'a'>> = ({
children,
className,
...props
}) => (
export const TextLink: FC<
BoxBasedComponentProps<'span' | 'a'> & { weight?: LinkVariant }
> = ({ children, className, weight = 'standard', ...props }) => (
<Box
// if someone is trying to use it as a link, use an anchor tag
// if someone is trying to use this as a link, use an anchor element
component={'href' in props ? 'a' : 'span'}
className={[linkStyle, className]}
className={[linkStyleVariant[weight], className]}
{...props}
>
{children}
Expand Down
13 changes: 11 additions & 2 deletions src/pages/typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,22 @@ export const TypographyPage: FC = () => (
</Text>
<Text>
Sometimes I like to look at{' '}
<TextLink href="/buttons">button components</TextLink> on my computer.
<TextLink href="/buttons">button components</TextLink> and{' '}
<TextLink href="/panels" weight="strong">
strong panels
</TextLink>{' '}
or{' '}
<TextLink href="/buttons" weight="weak">
weak badges
</TextLink>{' '}
on my computer.
</Text>
</Block>
<Block>
<Heading level="1">
Sometimes I like to look at{' '}
<TextLink href="/buttons">button components</TextLink> on my computer.
<TextLink href="/buttons">button components</TextLink> or on my
computer.
</Heading>
</Block>
<Callout tone="critical">
Expand Down

0 comments on commit c599584

Please sign in to comment.