Skip to content

Commit

Permalink
Link: export linkStyles to allow styling React Router Links
Browse files Browse the repository at this point in the history
  • Loading branch information
hoorayimhelping committed Dec 11, 2024
1 parent 90368c3 commit 5d1c479
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
32 changes: 2 additions & 30 deletions src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import {
} from "react";
import { Icon, IconName } from "@/components";
import { styled } from "styled-components";

type TextSize = "xs" | "sm" | "md" | "lg";
type TextWeight = "normal" | "medium" | "semibold" | "bold";
import { linkStyles, TextSize, TextWeight } from "./common";

export interface LinkProps<T extends ElementType = "a"> {
size?: TextSize;
Expand All @@ -22,33 +20,7 @@ export interface LinkProps<T extends ElementType = "a"> {
}

const CuiLink = styled.a<{ $size: TextSize; $weight: TextWeight }>`
font: ${({ $size, $weight = "normal", theme }) =>
theme.typography.styles.product.text[$weight][$size]};
color: ${({ theme }) => theme.click.global.color.text.link.default};
margin: 0;
text-decoration: none;
display: inline-flex;
gap: ${({ $size, theme }) =>
$size === "xs" || $size === "sm"
? theme.click.link.space.sm.gap
: theme.click.link.space.md.gap};
margin-right: ${({ $size, theme }) =>
$size === "xs" || $size === "sm"
? theme.click.link.space.sm.gap
: theme.click.link.space.md.gap};
align-items: center;
&:hover,
&:focus {
color: ${({ theme }) => theme.click.global.color.text.link.hover};
transition: ${({ theme }) => theme.transition.default};
text-decoration: underline;
cursor: pointer;
}
&:visited {
color: ${({ theme }) => theme.click.global.color.text.link.default};
}
${linkStyles}
`;

const IconWrapper = styled.span<{ $size: TextSize }>`
Expand Down
36 changes: 36 additions & 0 deletions src/components/Link/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { css } from "styled-components";

export type TextSize = "xs" | "sm" | "md" | "lg";
export type TextWeight = "normal" | "medium" | "semibold" | "bold";

export type StyledLinkProps = { $size: TextSize; $weight: TextWeight };

export const linkStyles = css<StyledLinkProps>`
font: ${({ $size, $weight = "normal", theme }) =>
theme.typography.styles.product.text[$weight][$size]};
color: ${({ theme }) => theme.click.global.color.text.link.default};
margin: 0;
text-decoration: none;
display: inline-flex;
gap: ${({ $size, theme }) =>
$size === "xs" || $size === "sm"
? theme.click.link.space.sm.gap
: theme.click.link.space.md.gap};
margin-right: ${({ $size, theme }) =>
$size === "xs" || $size === "sm"
? theme.click.link.space.sm.gap
: theme.click.link.space.md.gap};
align-items: center;
&:hover,
&:focus {
color: ${({ theme }) => theme.click.global.color.text.link.hover};
transition: ${({ theme }) => theme.transition.default};
text-decoration: underline;
cursor: pointer;
}
&:visited {
color: ${({ theme }) => theme.click.global.color.text.link.default};
}
`;
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export { default as Flags } from "./icons/Flags";
export { Grid } from "./Grid/Grid";
export { HoverCard } from "./HoverCard/HoverCard";
export { Link } from "./Link/Link";
export { linkStyles } from "./Link/common";
export { Logo } from "./Logos/Logo";
export { NumberField } from "./Input/NumberField";
export { PasswordField } from "./Input/PasswordField";
Expand Down
1 change: 1 addition & 0 deletions src/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type {
GridContextMenuItemProps,
Rectangle,
} from "./Grid/types";
export type { StyledLinkProps } from "./Link/common";

export type States = "default" | "active" | "disabled" | "error" | "hover";
export type HorizontalDirection = "start" | "end";
Expand Down

0 comments on commit 5d1c479

Please sign in to comment.