Skip to content

Commit

Permalink
feat: rename clickable component
Browse files Browse the repository at this point in the history
  • Loading branch information
Diedra authored and dierat committed Sep 9, 2021
1 parent d9c8db7 commit fa0f29a
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 64 deletions.
8 changes: 4 additions & 4 deletions packages/components/src/Button/button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Story } from "@storybook/react/types-6-0";
import React from "react";
import Clickable from "../Clickable";
import ClickableStyleWrapper from "../ClickableStyleWrapper";
import Heading from "../Heading";
import CheckCircleRoundedIcon from "../Icons/CheckCircleRounded";
import Text from "../Text";
Expand Down Expand Up @@ -189,8 +189,8 @@ const renderSize = (
{colors.map((color) => (
<td key={color} className={styles.color}>
{/* To pass the "state" prop (only used for demonstration in storybook),
we must use Clickable instead of Button */}
<Clickable
we must use ClickableStyleWrapper instead of Button */}
<ClickableStyleWrapper
as={"button"}
size={size}
color={color}
Expand All @@ -199,7 +199,7 @@ const renderSize = (
disabled={state === "disabled"}
>
{children}
</Clickable>
</ClickableStyleWrapper>
</td>
))}
</tr>
Expand Down
12 changes: 7 additions & 5 deletions packages/components/src/Button/button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { ReactNode, forwardRef } from "react";
import Clickable, { ClickableProps } from "../Clickable";
import ClickableStyleWrapper, {
ClickableStyleWrapperProps,
} from "../ClickableStyleWrapper";

type ButtonHTMLElementProps = React.ButtonHTMLAttributes<HTMLButtonElement>;

Expand All @@ -8,10 +10,10 @@ export type ButtonProps = ButtonHTMLElementProps & {
* The button contents or label.
*/
children: ReactNode;
color?: ClickableProps<"button">["color"];
color?: ClickableStyleWrapperProps<"button">["color"];
"data-testid"?: string;
size?: ClickableProps<"button">["size"];
variant?: ClickableProps<"button">["variant"];
size?: ClickableStyleWrapperProps<"button">["size"];
variant?: ClickableStyleWrapperProps<"button">["variant"];
};

/**
Expand All @@ -34,7 +36,7 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
ref,
) => {
return (
<Clickable
<ClickableStyleWrapper
{...rest}
as="button"
variant={variant}
Expand Down
6 changes: 0 additions & 6 deletions packages/components/src/Clickable/Clickable.spec.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions packages/components/src/Clickable/Clickable.stories.tsx

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions packages/components/src/Clickable/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { generateSnapshots } from "@chanzuckerberg/story-utils";
import * as ClickableStyleWrapperStoryFile from "./ClickableStyleWrapper.stories";

describe("<ClickableStyleWrapper />", () => {
generateSnapshots(ClickableStyleWrapperStoryFile);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Story } from "@storybook/react/types-6-0";
import React from "react";
import ClickableStyleWrapper from "./ClickableStyleWrapper";

export default {
title: "ClickableStyleWrapper",
component: ClickableStyleWrapper,
};

type Args = React.ComponentProps<typeof ClickableStyleWrapper>;

const Template: Story<Args> = (args) => <ClickableStyleWrapper {...args} />;

export const ClickableStyleWrapperAsAnATag = Template.bind(null);
ClickableStyleWrapperAsAnATag.args = {
as: "a",
color: "brand",
variant: "flat",
size: "medium",
children: "ClickableStyleWrapper As An A Tag",
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import clsx from "clsx";
import React from "react";
import styles from "./Clickable.module.css";
import styles from "./ClickableStyleWrapper.module.css";

export type ClickableProps<IComponent extends React.ElementType> = {
export type ClickableStyleWrapperProps<IComponent extends React.ElementType> = {
/**
* CSS class for custom styles.
*/
Expand Down Expand Up @@ -30,7 +30,7 @@ export type ClickableProps<IComponent extends React.ElementType> = {
*
* See the Button stories for usage examples.
*/
const Clickable = React.forwardRef(
const ClickableStyleWrapper = React.forwardRef(
<IComponent extends React.ElementType>(
{
as: Component,
Expand All @@ -41,7 +41,7 @@ const Clickable = React.forwardRef(
variant,
className,
...rest
}: ClickableProps<IComponent>,
}: ClickableStyleWrapperProps<IComponent>,
ref: React.ForwardedRef<HTMLElement>,
) => {
return (
Expand Down Expand Up @@ -81,6 +81,6 @@ const Clickable = React.forwardRef(
},
);

Clickable.displayName = "Clickable";
ClickableStyleWrapper.displayName = "ClickableStyleWrapper";

export default Clickable;
export default ClickableStyleWrapper;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<ClickableStyleWrapper /> ClickableStyleWrapperAsAnATag story renders snapshot 1`] = `
<a
class="button sizeMedium variantFlat colorBrand"
>
ClickableStyleWrapper As An A Tag
</a>
`;
2 changes: 2 additions & 0 deletions packages/components/src/ClickableStyleWrapper/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from "./ClickableStyleWrapper";
export type { ClickableStyleWrapperProps } from "./ClickableStyleWrapper";
8 changes: 4 additions & 4 deletions packages/components/src/Link/Link.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Story } from "@storybook/react/types-6-0";
import React from "react";
import Clickable from "../Clickable";
import ClickableStyleWrapper from "../ClickableStyleWrapper";
import Heading from "../Heading";
import CheckCircleRoundedIcon from "../Icons/CheckCircleRounded";
import Text from "../Text";
Expand Down Expand Up @@ -105,8 +105,8 @@ const renderSize = (
{colors.map((color) => (
<td key={color} className={styles.color}>
{/* To pass the "state" prop (only used for demonstration in storybook),
we must use Clickable instead of Link */}
<Clickable
we must use ClickableStyleWrapper instead of Link */}
<ClickableStyleWrapper
as={"a"}
size={size}
color={color}
Expand All @@ -115,7 +115,7 @@ const renderSize = (
href=""
>
{children}
</Clickable>
</ClickableStyleWrapper>
</td>
))}
</tr>
Expand Down
12 changes: 7 additions & 5 deletions packages/components/src/Link/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { ReactNode, forwardRef } from "react";
import Clickable, { ClickableProps } from "../Clickable";
import ClickableStyleWrapper, {
ClickableStyleWrapperProps,
} from "../ClickableStyleWrapper";

type LinkHTMLElementProps = Omit<
React.AnchorHTMLAttributes<HTMLAnchorElement>,
Expand All @@ -11,10 +13,10 @@ export type LinkProps = LinkHTMLElementProps & {
* The link contents or label.
*/
children: ReactNode;
color?: ClickableProps<"a">["color"];
color?: ClickableStyleWrapperProps<"a">["color"];
"data-testid"?: string;
size?: ClickableProps<"a">["size"];
variant?: ClickableProps<"a">["variant"];
size?: ClickableStyleWrapperProps<"a">["size"];
variant?: ClickableStyleWrapperProps<"a">["variant"];
};

/**
Expand All @@ -30,7 +32,7 @@ export type LinkProps = LinkHTMLElementProps & {
const Link = forwardRef<HTMLAnchorElement, LinkProps>(
({ variant = "link", color = "brand", size = "medium", ...rest }, ref) => {
return (
<Clickable
<ClickableStyleWrapper
{...rest}
as="a"
variant={variant}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { default as Banner } from "./Banner";
export { default as Button } from "./Button";
export { default as Clickable } from "./Clickable";
export { default as ClickableStyleWrapper } from "./ClickableStyleWrapper";
export { default as Heading } from "./Heading";
export { default as SvgIcon } from "./SvgIcon";
export type { IconProps } from "./SvgIcon";
Expand Down

0 comments on commit fa0f29a

Please sign in to comment.