Skip to content

Commit

Permalink
add: color and hover
Browse files Browse the repository at this point in the history
  • Loading branch information
Khumoyun Inoyatov committed Feb 26, 2024
1 parent d1d5d0a commit ed4531d
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 38 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
"no-void": "off",
"no-continue": "off",
"no-unused-vars": "off",
"no-case-declarations": "off",
"no-restricted-imports": [
"error",
{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"sass": "^1.71.1",
"typescript": "^5.3.3",
"vite": "^5.1.1"
}
Expand Down
41 changes: 25 additions & 16 deletions src/app.component.tsx
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>
</>
);
};
3 changes: 3 additions & 0 deletions src/assets/wavy_line.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 114 additions & 0 deletions src/components/text/text.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,118 @@
line-height: 24px;
letter-spacing: 0;
text-align: left;
}

.white {
color: #ffffff;
}

.black {
color: #002F3F;
}

.primary {
color: #0E7C73;
}

.secondary {
color: #97CAEF;
}

.tertiary {
color: #973CEF;
}

.link {
font-family: Lato, sans-serif;
font-size: 16px;
font-weight: 600;
line-height: 24px;
letter-spacing: 0;
text-align: left;
}

.title {
font-family: Lato, sans-serif;
font-weight: 500;
&:hover {
span {
&:before {
width: 100%;
transition: all ease-out 0.3s;
}
}
}
span {
display: inline;
position: relative;
&:before {
content: "";
position: absolute;
left: 0;
bottom: -2px;
height: 2px;
width: 33%;
background-color: #0E7C73;
}
}

&.h1 {
font-size: 40px;
line-height: 48px;
letter-spacing: 0;
text-align: left;
}

&.h2 {
font-size: 32px;
line-height: 48px;
letter-spacing: 0;
text-align: left;
}

&.h3 {
font-size: 24px;
line-height: 36px;
letter-spacing: 0;
text-align: left;
}

&.h4 {
font-size: 20px;
line-height: 30px;
letter-spacing: 0;
text-align: left;
span {
&:before {
display: none;
}
}
}
}

.paragraph {
font-family: Open Sans, sans-serif;
font-size: 16px;
font-weight: 400;
line-height: 24px;
letter-spacing: 0;
text-align: left;
}

.small {
font-family: Open Sans, sans-serif;
font-size: 14px;
font-weight: 400;
line-height: 24px;
letter-spacing: 0;
}

.default {
font-family: Lato, sans-serif;
font-size: 16px;
font-weight: 600;
line-height: 24px;
letter-spacing: 0;
text-align: left;
}
54 changes: 37 additions & 17 deletions src/components/text/text.tsx
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} />;
}
};
Loading

0 comments on commit ed4531d

Please sign in to comment.