Skip to content

Commit

Permalink
Merge pull request #291 from element-hq/florianduros/link-size-small
Browse files Browse the repository at this point in the history
Add small size to `Link`
  • Loading branch information
florianduros authored Dec 6, 2024
2 parents 9abe854 + e83e21f commit a486456
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
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();
});
});
14 changes: 12 additions & 2 deletions src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,32 @@ type LinkProps = {
className?: string;
/**
* The type of link.
* @default "primary"
*/
kind?: "primary" | "critical";
} & Omit<React.HTMLProps<HTMLAnchorElement>, "rel">;
/**
* The size of link.
* @default "medium"
*/
size?: "small" | "medium";
} & 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

0 comments on commit a486456

Please sign in to comment.