Skip to content

Commit

Permalink
feat(typography): allow classname pass through on text components
Browse files Browse the repository at this point in the history
  • Loading branch information
Devin Witherspoon authored and dcwither committed Apr 22, 2021
1 parent 99e401c commit 396d3ee
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/components/src/Heading/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Props = {
*/
as?: HeadingElement;
children: TypographyProps<HeadingElement>["children"];
className: TypographyProps<HeadingElement>["className"];
color?: TypographyProps<HeadingElement>["color"];
size: TypographyProps<HeadingElement>["size"];
weight?: TypographyProps<HeadingElement>["weight"];
Expand Down
20 changes: 20 additions & 0 deletions packages/components/src/Text/Text.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import * as TextStoryFile from "./Text.stories";

import { render, screen } from "@testing-library/react";

import React from "react";
import Text from "./Text";
import { generateSnapshots } from "@chanzuckerberg/story-utils";

describe("<Text />", () => {
generateSnapshots(TextStoryFile);

it("should add the passthrough className", () => {
render(
<Text size="body" className="passthrough">
Some Text
</Text>,
);
expect(screen.getByText("Some Text")).toMatchInlineSnapshot(`
<p
class="passthrough typography sizeBody colorBase"
>
Some Text
</p>
`);
});
});
1 change: 1 addition & 0 deletions packages/components/src/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Props = {
*/
as?: TextElement;
children: TypographyProps<TextElement>["children"];
className: TypographyProps<TextElement>["className"];
color?: TypographyProps<TextElement>["color"];
size: TypographyProps<TextElement>["size"];
weight?: TypographyProps<TextElement>["weight"];
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/common/typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export type TypographyProps<IComponent extends React.ElementType> = {
* The text content to present.
*/
children: ReactNode;
/**
* CSS class for custom styles.
*/
className?: string;
/**
* The color of the text element. If no color provided, defaults to a base color.
*/
Expand Down Expand Up @@ -70,12 +74,14 @@ function Typography<IComponent extends React.ElementType>({
size,
weight = null,
spacing,
className,
...rest
}: TypographyProps<IComponent>) {
const Component = as;
return (
<Component
className={clsx(
className,
styles.typography,
// Sizes
size === "h1" && styles.sizeH1,
Expand Down

0 comments on commit 396d3ee

Please sign in to comment.