Skip to content

Commit 402c7fc

Browse files
committed
feat: ad
d container and typography components
1 parent 1d9d67f commit 402c7fc

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,19 @@ We're looking for maintainers and contributors!
4747
- [x] Stack
4848
- [x] Box
4949
- [x] Navigation Rail
50-
- [ ] Container
51-
- [ ] Typography
50+
- [x] Container
51+
- [x] Typography
5252

5353
### Credits
5454

5555
Huge shout out to Elizabeth Mitchell ([asyncLiz](https://github.com/asyncliz/)) and the rest of the Material Design team for their awesome Web Components implementation.
5656

5757
Thank you [Travis Reeder](https://github.com/treeder) for your Web Component implementation of Navigation Rail. I had to copy it to this project. I couldn't use yours directly because it would import `@material/web` again and bring conflicts.
5858

59+
Thanks for making the crappy, brain-dead wrapper components:
60+
61+
- [ChatGPT](https://chatgpt.com/share/574a9601-8927-4992-884e-16c58f24a982)
62+
5963
Thanks for improving the demo:
6064

6165
- [TalhaHere12](https://github.com/TalhaHere12)

packages/ui/src/container/index.tsx

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from "react";
2+
import { twMerge } from "tailwind-merge";
3+
const Container = React.forwardRef(
4+
(
5+
{
6+
component: Component = "div",
7+
disableGutters = false,
8+
fixed = false,
9+
maxWidth = "lg",
10+
className,
11+
...props
12+
}: any,
13+
ref
14+
) => {
15+
const maxWidthClasses = {
16+
xs: "max-w-xs",
17+
sm: "max-w-sm",
18+
md: "max-w-md",
19+
lg: "max-w-lg",
20+
xl: "max-w-xl",
21+
false: "",
22+
};
23+
24+
return (
25+
<Component
26+
ref={ref}
27+
className={twMerge(
28+
"container",
29+
disableGutters && "px-0",
30+
!disableGutters && "mx-auto",
31+
!fixed && maxWidth && [maxWidthClasses[maxWidth]],
32+
fixed && "w-full",
33+
className
34+
)}
35+
{...props}
36+
>
37+
{props.children}
38+
</Component>
39+
);
40+
}
41+
);
42+
43+
export default Container;

packages/ui/src/typography/index.tsx

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from "react";
2+
import { twMerge } from "tailwind-merge";
3+
4+
const defaultVariantMapping = {
5+
h1: { component: "h1", className: "text-4xl font-bold" },
6+
h2: { component: "h2", className: "text-3xl font-bold" },
7+
h3: { component: "h3", className: "text-2xl font-bold" },
8+
h4: { component: "h4", className: "text-xl font-bold" },
9+
h5: { component: "h5", className: "text-lg font-bold" },
10+
h6: { component: "h6", className: "text-base font-bold" },
11+
subtitle1: { component: "h6", className: "text-base font-medium" },
12+
subtitle2: { component: "h6", className: "text-sm font-medium" },
13+
body1: { component: "p", className: "text-base" },
14+
body2: { component: "p", className: "text-sm" },
15+
button: { component: "span", className: "text-sm uppercase font-medium" },
16+
caption: { component: "span", className: "text-xs" },
17+
overline: { component: "span", className: "text-xs uppercase" },
18+
inherit: { component: "p", className: "" },
19+
};
20+
21+
const alignClasses = {
22+
center: "text-center",
23+
justify: "text-justify",
24+
left: "text-left",
25+
right: "text-right",
26+
inherit: "",
27+
};
28+
29+
const Typography = React.forwardRef(
30+
(
31+
{
32+
component: _Component,
33+
variant = "body1",
34+
align = "inherit",
35+
gutterBottom = false,
36+
noWrap = false,
37+
paragraph = false,
38+
className,
39+
variantMapping,
40+
...props
41+
}: any,
42+
ref
43+
) => {
44+
const _variantMapping = variantMapping || defaultVariantMapping
45+
46+
const variantProps = (!paragraph && _variantMapping[variant]) || { component: _Component || "p", className: "" };
47+
48+
const appliedClasses = twMerge(
49+
variantProps.className,
50+
alignClasses[align],
51+
gutterBottom && "mb-2",
52+
noWrap && "truncate line-clamp-1",
53+
// paragraph && "mb-6",
54+
className
55+
);
56+
57+
const Component = _Component || (variantProps.component || variantProps);
58+
59+
return <Component ref={ref} className={appliedClasses} {...props}>{props.children}</Component>;
60+
}
61+
);
62+
63+
export default Typography;

0 commit comments

Comments
 (0)