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

Link: export linkStyles to allow styling React Router Links #504

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading