-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[UI v2] feat: Simplifies typography by introducing a simple typography component #16231
Merged
+110
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { Typography } from "./typography"; | ||
|
||
const meta: Meta<typeof Typography> = { | ||
title: "UI/Typography", | ||
component: Typography, | ||
parameters: { | ||
docs: { | ||
description: { | ||
component: "Typography is used as your basic text component", | ||
}, | ||
}, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof Typography>; | ||
|
||
export const Usage: Story = { | ||
render: () => { | ||
return ( | ||
<div> | ||
<Typography variant="h1">h1 Typography</Typography> | ||
<Typography variant="h2">h2 Typography</Typography> | ||
<Typography variant="h3">h3 Typography</Typography> | ||
<Typography variant="h4">h4 Typography</Typography> | ||
<Typography variant="bodyLarge">bodyLarge Typography</Typography> | ||
<Typography variant="body">body Typography</Typography> | ||
<Typography variant="bodySmall">bodySmall Typography</Typography> | ||
</div> | ||
); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { cn } from "@/lib/utils"; | ||
import { forwardRef } from "react"; | ||
|
||
type Variant = "h1" | "h2" | "h3" | "h4" | "bodyLarge" | "body" | "bodySmall"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be cool to follow a variant structure similar to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can look into it in a followup PR. Didn't know we had a library like that |
||
|
||
type Props = { | ||
className?: string; | ||
variant?: Variant; | ||
children: React.ReactNode; | ||
}; | ||
|
||
export const Typography = forwardRef<HTMLDivElement, Props>( | ||
({ variant = "body", className, children }, ref) => { | ||
switch (variant) { | ||
case "h1": | ||
return ( | ||
<h1 | ||
ref={ref} | ||
className={cn("text-4xl font-extrabold tracking-tight", className)} | ||
> | ||
{children} | ||
</h1> | ||
); | ||
case "h2": | ||
return ( | ||
<h2 | ||
ref={ref} | ||
className={cn("text-3xl font-semibold tracking-tight", className)} | ||
> | ||
{children} | ||
</h2> | ||
); | ||
case "h3": | ||
return ( | ||
<h3 | ||
ref={ref} | ||
className={cn("text-2xl font-semibold tracking-tight", className)} | ||
> | ||
{children} | ||
</h3> | ||
); | ||
case "h4": | ||
return ( | ||
<h4 | ||
ref={ref} | ||
className={cn("text-xl font-semibold tracking-tight", className)} | ||
> | ||
{children} | ||
</h4> | ||
); | ||
|
||
case "bodyLarge": | ||
return ( | ||
<h4 ref={ref} className={cn("text-lg", className)}> | ||
{children} | ||
</h4> | ||
); | ||
|
||
case "bodySmall": | ||
return ( | ||
<p ref={ref} className={cn("text-sm", className)}> | ||
{children} | ||
</p> | ||
); | ||
|
||
case "body": | ||
default: | ||
return ( | ||
<p ref={ref} className={cn("text-base", className)}> | ||
{children} | ||
</p> | ||
); | ||
} | ||
}, | ||
); | ||
Typography.displayName = "Typography"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could probably do this a bit more streamline in the future with
createElement
feature