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

Add small size to Link #291

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/components/Link/Link.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ limitations under the License.
.link[data-kind="critical"]:active {
background: var(--cpd-color-text-critical-primary);
}

.link[data-size="small"] {
font-size: var(--cpd-font-size-body-sm);
}
9 changes: 8 additions & 1 deletion src/components/Link/Link.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export default {
component: LinkComponent,
tags: ["autodocs"],
argTypes: {},
args: {},
args: {
size: "medium",
},
} as Meta<typeof LinkComponent>;

const Template: StoryFn<typeof LinkComponent> = (args) => (
Expand All @@ -33,3 +35,8 @@ const Template: StoryFn<typeof LinkComponent> = (args) => (

export const Round = Template.bind({});
Round.args = {};

export const Small = Template.bind({});
Small.args = {
size: "small",
};
5 changes: 5 additions & 0 deletions src/components/Link/Link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ describe("Link", () => {
const { asFragment } = render(<Link />);
expect(asFragment()).toMatchSnapshot();
});

it("renders width a small size", () => {
const { asFragment } = render(<Link size="small" />);
expect(asFragment()).toMatchSnapshot();
});
});
12 changes: 10 additions & 2 deletions src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,28 @@ type LinkProps = {
* The type of link.
*/
kind?: "primary" | "critical";
} & Omit<React.HTMLProps<HTMLAnchorElement>, "rel">;
/**
* The size of link.
*/
size?: "small" | "medium";
florianduros marked this conversation as resolved.
Show resolved Hide resolved
} & Omit<React.HTMLProps<HTMLAnchorElement>, "rel" | "size">;

/**
* A link component.
*/
export const Link = forwardRef<HTMLAnchorElement, PropsWithChildren<LinkProps>>(
function Link({ children, className, kind = "primary", ...props }, ref) {
function Link(
{ children, className, kind = "primary", size = "medium", ...props },
ref,
) {
return (
<a
ref={ref}
{...props}
rel="noreferrer noopener"
className={classNames(styles.link, className)}
data-kind={kind}
data-size={size}
>
{children}
</a>
Expand Down
12 changes: 12 additions & 0 deletions src/components/Link/__snapshots__/Link.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ exports[`Link > renders 1`] = `
<a
class="_link_379d57"
data-kind="primary"
data-size="medium"
rel="noreferrer noopener"
/>
</DocumentFragment>
`;

exports[`Link > renders width a small size 1`] = `
<DocumentFragment>
<a
class="_link_379d57"
data-kind="primary"
data-size="small"
rel="noreferrer noopener"
/>
</DocumentFragment>
Expand Down
Loading