-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Khumoyun Inoyatov
committed
Feb 26, 2024
1 parent
d1d5d0a
commit ed4531d
Showing
7 changed files
with
247 additions
and
38 deletions.
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
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
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 |
---|---|---|
@@ -1,24 +1,33 @@ | ||
import { useState } from "react"; | ||
import { Text } from "./components/text/text.tsx"; | ||
import "./app.styles.css"; | ||
|
||
export const App = () => { | ||
const [count, setCount] = useState(0); | ||
|
||
const handleClick = () => { | ||
setCount(previous => previous + 1); | ||
}; | ||
|
||
return ( | ||
<> | ||
<h1>Vite + React</h1> | ||
<div className="card"> | ||
<button type="button" onClick={handleClick}> | ||
count is {count} | ||
</button> | ||
<p> | ||
Edit <code>src/App.jsx</code> and save to test HMR | ||
</p> | ||
</div> | ||
<Text>Default</Text> | ||
<Text variant="link" link="#" color="secondary"> | ||
Link | ||
</Text> | ||
<Text variant="title" headingLevel="h1"> | ||
What is e-waste? | ||
</Text> | ||
<Text variant="title" headingLevel="h2"> | ||
Heading level 2 | ||
</Text> | ||
<Text variant="title" headingLevel="h3"> | ||
Heading level 3 | ||
</Text> | ||
<Text variant="title" headingLevel="h4"> | ||
Heading level 4 | ||
</Text> | ||
<Text variant="paragraph"> | ||
Paragraph text. Lorem ipsum dolor sit amet. Conserteum lorem ipsum dolor | ||
sit amet | ||
</Text> | ||
<Text variant="small"> | ||
Paragraph text. Lorem ipsum dolor sit amet. Conserteum lorem ipsum dolor | ||
sit amet | ||
</Text> | ||
</> | ||
); | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
---|---|---|
@@ -1,41 +1,61 @@ | ||
import { ReactNode } from "react"; | ||
import cc from "classcat"; | ||
import { Link } from "react-router-dom"; | ||
import "./text.scss"; | ||
|
||
export type TextVariant = "link" | "name" | "title" | "text" | "default"; | ||
export type TextVariant = "link" | "title" | "paragraph" | "small" | "default"; | ||
export type TextColor = | ||
| "primary" | ||
| "secondary" | ||
| "tertiary" | ||
| "black" | ||
| "white"; | ||
|
||
export interface IProps { | ||
variant: TextVariant; | ||
className: string; | ||
variant?: TextVariant; | ||
className?: string; | ||
children: string | ReactNode; | ||
link: string; | ||
link?: string; | ||
headingLevel?: keyof JSX.IntrinsicElements; | ||
color?: TextColor; | ||
} | ||
|
||
export const Text = ({ | ||
variant = "default", | ||
className, | ||
children, | ||
link, | ||
headingLevel = "h2", | ||
color = "black", | ||
}: IProps) => { | ||
const commonProps = { | ||
className: cc(["text", variant, headingLevel, className, color]), | ||
children, | ||
}; | ||
|
||
switch (variant) { | ||
case "link": | ||
return ( | ||
<Link to={link} className={cc(["text", variant, className])}> | ||
{children} | ||
</Link> | ||
return link ? ( | ||
// eslint-disable-next-line jsx-a11y/anchor-has-content | ||
<a href={link} {...commonProps} /> | ||
) : ( | ||
<span {...commonProps} /> | ||
); | ||
case "name": | ||
case "title": | ||
const HeadingComponent: React.ElementType = headingLevel; | ||
return ( | ||
<span className={cc(["text", variant, className])}>{children}</span> | ||
<HeadingComponent | ||
className={cc(["text", variant, headingLevel, color, className])} | ||
> | ||
<span>{children}</span> | ||
</HeadingComponent> | ||
); | ||
case "title": | ||
return <h1 className={cc(["text", variant, className])}>{children}</h1>; | ||
case "text": | ||
return <p className={cc(["text", variant, className])}>{children}</p>; | ||
case "paragraph": | ||
return <p {...commonProps} />; | ||
case "small": | ||
return <p {...commonProps} />; | ||
case "default": | ||
return <div className={cc(["text", variant, className])}>{children}</div>; | ||
return <div {...commonProps} />; | ||
default: | ||
return <div className={cc(["text", variant, className])}>{children}</div>; | ||
return <div {...commonProps} />; | ||
} | ||
}; |
Oops, something went wrong.