Skip to content

Commit

Permalink
feat: Polymorphism, data attributes, remove custom props
Browse files Browse the repository at this point in the history
  • Loading branch information
mathhulk committed Sep 25, 2024
1 parent 97614b1 commit dec66d9
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 89 deletions.
20 changes: 14 additions & 6 deletions apps/frontend/src/components/Button/Button.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,39 @@
height: 32px;
border-radius: 4px;
padding: 0 12px;
display: flex;
display: inline-flex;
flex-shrink: 0;
align-items: center;
font-size: 14px;
font-weight: 500;
line-height: 1;
cursor: pointer;
transition: all 100ms ease-in-out;
gap: 8px;
user-select: none;
transition:
border-color 100ms ease-in-out,
background-color 100ms ease-in-out,
color 100ms ease-in-out;

&.solid {
&[data-disabled] {
pointer-events: none;
opacity: 0.5;
}

&[data-variant="solid"] {
background-color: var(--blue-500);
color: white;

&:hover {
background-color: var(--blue-600);
}

&:active {
background-color: var(--blue-700);
}
}

&.outline {
&[data-variant="outline"] {
border: 1px solid var(--border-color);
color: var(--paragraph-color);

Expand All @@ -39,4 +47,4 @@
background-color: var(--button-active-color);
}
}
}
}
13 changes: 5 additions & 8 deletions apps/frontend/src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import styles from "./Button.module.scss";

interface Props {
variant?: "solid" | "outline";
disabled?: boolean;
}

type ButtonProps<C extends ElementType> = PolymorphicComponentPropsWithRef<
Expand All @@ -24,6 +25,7 @@ const Button = forwardRef(
active,
children,
className,
disabled,
variant = "solid",
...props
}: ButtonProps<C>,
Expand All @@ -32,14 +34,9 @@ const Button = forwardRef(
return (
<button
ref={ref}
className={classNames(
styles.root,
{
[styles.solid]: variant === "solid",
[styles.outline]: variant === "outline",
},
className
)}
data-variant={variant}
data-disabled={disabled}
className={classNames(styles.root, className)}
{...props}
>
{children}
Expand Down
21 changes: 16 additions & 5 deletions apps/frontend/src/components/Footer/Footer.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
&.invert {
border-color: var(--neutral-700);

.group .description, .column .label {
.icon-button {
color: var(--neutral-400);
}

.column .link, .group .description .link {
.group .description,
.column .label {
color: var(--neutral-400);
}

.column .link,
.group .description .link {
color: white;

&:hover {
Expand Down Expand Up @@ -75,15 +81,20 @@
.brand {
font-size: 24px;
font-weight: 580;
font-feature-settings: 'cv05' on, 'cv13' on, 'ss07' on, 'cv12' on, 'cv06' on;
font-feature-settings:
"cv05" on,
"cv13" on,
"ss07" on,
"cv12" on,
"cv06" on;
color: var(--blue-500);
cursor: pointer;
transition: all 100ms ease-in-out;
margin-right: auto;

&:hover {
color: var(--blue-600);
}
}
}
}
}
54 changes: 33 additions & 21 deletions apps/frontend/src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,45 @@ export default function Footer({ invert }: FooterProps) {
</p>
<div className={styles.row}>
<IconButton
invert={invert}
className={styles.iconButton}
onClick={() =>
setTheme((theme) => (theme === "dark" ? "light" : "dark"))
}
>
{theme === "dark" ? <SunLight /> : <HalfMoon />}
</IconButton>
<a href="https://www.instagram.com/" target="_blank">
<IconButton invert={invert}>
<Instagram />
</IconButton>
</a>
<a href="https://discord.gg/uP2bTPh99U" target="_blank">
<IconButton invert={invert}>
<Discord />
</IconButton>
</a>
<a href="https://facebook.com/berkeleytime" target="_blank">
<IconButton invert={invert}>
<Facebook />
</IconButton>
</a>
<a href="https://github.com/asuc-octo/berkeleytime" target="_blank">
<IconButton invert={invert}>
<Github />
</IconButton>
</a>
<IconButton
className={styles.iconButton}
as="a"
href="https://www.instagram.com/"
target="_blank"
>
<Instagram />
</IconButton>
<IconButton
className={styles.iconButton}
as="a"
href="https://discord.gg/uP2bTPh99U"
target="_blank"
>
<Discord />
</IconButton>
<IconButton
className={styles.iconButton}
href="https://facebook.com/berkeleytime"
target="_blank"
as="a"
>
<Facebook />
</IconButton>
<IconButton
className={styles.iconButton}
href="https://github.com/asuc-octo/berkeleytime"
target="_blank"
as="a"
>
<Github />
</IconButton>
</div>
</div>
<div className={styles.column}>
Expand Down
23 changes: 15 additions & 8 deletions apps/frontend/src/components/IconButton/IconButton.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,31 @@
width: 32px;
flex-shrink: 0;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
display: inline-grid;
place-items: center;
cursor: pointer;
transition: all 100ms ease-in-out;
user-select: none;
transition:
border-color 100ms ease-in-out,
background-color 100ms ease-in-out,
color 100ms ease-in-out;

&.outline {
&[data-disabled] {
pointer-events: none;
opacity: 0.5;
}

&[data-variant="outline"] {
border: 1px solid var(--border-color);
color: var(--paragraph-color);

&:hover {
background-color: var(--button-hover-color);
color: var(--heading-color);
}

&:active {
background-color: var(--button-active-color);
}
}
}
}
19 changes: 7 additions & 12 deletions apps/frontend/src/components/IconButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementType, ReactElement, forwardRef } from "react";
import { ElementType, ReactNode, forwardRef } from "react";

import classNames from "classnames";

Expand All @@ -11,7 +11,7 @@ import styles from "./IconButton.module.scss";

interface Props {
variant?: "outline";
invert?: boolean;
disabled?: boolean;
}

type IconButtonProps<C extends ElementType> = PolymorphicComponentPropsWithRef<
Expand All @@ -24,7 +24,7 @@ const IconButton = forwardRef(
{
children,
className,
invert,
disabled,
as,
variant = "outline",
...props
Expand All @@ -35,14 +35,9 @@ const IconButton = forwardRef(

return (
<Component
className={classNames(
styles.root,
{
[styles.invert]: invert,
[styles.outline]: variant === "outline",
},
className
)}
data-disabled={disabled}
data-variant={variant}
className={classNames(styles.root, className)}
ref={ref}
{...props}
>
Expand All @@ -56,4 +51,4 @@ IconButton.displayName = "IconButton";

export default IconButton as <T extends ElementType = "button">(
props: IconButtonProps<T>
) => ReactElement | null;
) => ReactNode | null;
70 changes: 44 additions & 26 deletions apps/frontend/src/components/MenuItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
import { ComponentPropsWithoutRef, ElementType, ReactNode } from "react";
import { ElementType, ReactNode, forwardRef } from "react";

import classNames from "classnames";

import {
PolymorphicComponentPropsWithRef,
PolymorphicRef,
} from "@/lib/polymorphism";

import styles from "./MenuItem.module.scss";

interface MenuItemProps<T = ElementType> {
interface Props {
active?: boolean;
children: ReactNode;
className?: string;
as?: T;
disabled?: boolean;
}

export default function MenuItem({
active,
children,
className,
...props
}: MenuItemProps & ComponentPropsWithoutRef<"button">) {
return (
<button
{...props}
className={classNames(
styles.root,
{
active,
},
className
)}
>
{children}
</button>
);
}
type MenuItemProps<C extends ElementType> = PolymorphicComponentPropsWithRef<
C,
Props
>;

const MenuItem = forwardRef(
<C extends ElementType = "button">(
{ active, children, className, disabled, as, ...props }: MenuItemProps<C>,
ref: PolymorphicRef<C>
) => {
const Component = as || "button";

return (
<Component
ref={ref}
data-disabled={disabled}
className={classNames(
styles.root,
{
active,
},
className
)}
{...props}
>
{children}
</Component>
);
}
);

MenuItem.displayName = "MenuItem";

export default MenuItem as <T extends ElementType = "button">(
props: MenuItemProps<T>
) => ReactNode | null;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
.brand {
font-size: 24px;
font-weight: 580;
font-feature-settings: 'cv05' on, 'cv13' on, 'ss07' on, 'cv12' on, 'cv06' on;
font-feature-settings:
"cv05" on,
"cv13" on,
"ss07" on,
"cv12" on,
"cv06" on;
color: var(--blue-500);
cursor: pointer;
transition: all 100ms ease-in-out;
Expand All @@ -33,6 +38,10 @@
&.invert {
padding: 12px 12px 0;

.icon-button {
color: var(--paragraph-color);
}

.brand {
color: white;

Expand Down Expand Up @@ -71,4 +80,4 @@
}
}
}
}
}
Loading

0 comments on commit dec66d9

Please sign in to comment.