Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/app/(marketing)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { SignupGroupButton } from "@/components/SiginupGroupButton";
import { BackButton } from "@/shared/BackButton";
import { Button } from "@/shared/button";
import { FeatureButton } from "@/shared/FeatureButton";
import { Icon } from "@/shared/Icon";
Expand Down Expand Up @@ -104,6 +105,8 @@ export default function Home() {

<SignupGroupButton />

<BackButton>์ด์ „</BackButton>

<Button
preset="cta"
disabled={!isReady} // false๋ฉด ํ™œ์„ฑ, true๋ฉด ๋น„ํ™œ์„ฑ
Expand Down
32 changes: 32 additions & 0 deletions src/lib/variants/button.back.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { cva, type VariantProps } from "class-variance-authority";

export const backButtonVariants = cva(
[
"group inline-flex items-center gap-2 px-4 py-2 rounded-md cursor-pointer",
"text-[var(--color-gray-600)] hover:text-[var(--color-gray-900)] ",
"transition-colors duration-200",
].join(" "),
{
variants: {
size: {
sm: "t-14-m",
md: "t-16-m",
},
underline: {
true: "hover:underline underline-offset-2",
false: "",
},
tone: {
default: "",
muted: "text-[var(--color-gray-500)] hover:text-[var(--color-gray-900)]",
},
},
defaultVariants: {
size: "md",
underline: false,
tone: "default",
},
},
);

export type BackButtonVariantProps = VariantProps<typeof backButtonVariants>;
2 changes: 1 addition & 1 deletion src/lib/variants/button.cta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cva } from "class-variance-authority";
export const ctaButtonVariants = cva(
// ๊ณตํ†ต ๋ฒ ์ด์Šค
[
"inline-flex items-center justify-center select-none",
"inline-flex items-center justify-center select-none cursor-pointer",
"rounded-full px-14 py-4 t-16-m",
"transition-[background-color,color,box-shadow] duration-200 ease-out",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-ring)]",
Expand Down
11 changes: 10 additions & 1 deletion src/lib/variants/button.presets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { ButtonPreset } from "@/types/button";
import type { VariantProps } from "class-variance-authority";

import { loginButtonVariants } from "./button.auth";
import { backButtonVariants } from "./button.back";
import { ctaButtonVariants } from "./button.cta";
import { featureButtonVariants } from "./button.feature";
import { heroButtonVariants } from "./button.hero";
Expand All @@ -12,24 +14,27 @@ type FeatureVariantProps = VariantProps<typeof featureButtonVariants>;
type AuthVariantProps = VariantProps<typeof loginButtonVariants>;
type SignupVariantProps = VariantProps<typeof signupButtonVariants>;
type CtaVariantProps = VariantProps<typeof ctaButtonVariants>;
type BackVariantProps = VariantProps<typeof backButtonVariants>;

type HeroOpts = Partial<Pick<HeroVariantProps, "intent" | "glow" | "pill">>;
type FeatureOpts = Partial<Pick<FeatureVariantProps, "radius">>;
type AuthOpts = Partial<Pick<AuthVariantProps, "color">>;
type SignupOpts = Partial<Pick<SignupVariantProps, "bg">>;
type CtaOpts = Partial<Pick<CtaVariantProps, "state">>;
type BackOpts = Partial<Pick<BackVariantProps, "size" | "tone" | "underline">>;

// โœ… ํ”„๋ฆฌ์…‹๋ณ„ ์˜ค๋ฒ„๋กœ๋“œ
export function getButtonClasses(preset: "hero", opts?: HeroOpts): string;
export function getButtonClasses(preset: "feature", opts?: FeatureOpts): string;
export function getButtonClasses(preset: "auth", opts?: AuthOpts): string;
export function getButtonClasses(preset: "signup", opts?: SignupOpts): string;
export function getButtonClasses(preset: "cta", opts?: CtaOpts): string;
export function getButtonClasses(preset: "back", opts?: BackOpts): string;

// ๊ตฌํ˜„์ฒด
export function getButtonClasses(
preset: ButtonPreset,
opts: HeroOpts | FeatureOpts | AuthOpts | SignupOpts | CtaOpts = {},
opts: HeroOpts | FeatureOpts | AuthOpts | SignupOpts | CtaOpts | BackOpts = {},
): string {
switch (preset) {
case "hero": {
Expand All @@ -52,5 +57,9 @@ export function getButtonClasses(
const { state } = opts as CtaOpts;
return ctaButtonVariants({ state });
}
case "back": {
const { size, tone, underline } = opts as BackOpts;
return backButtonVariants({ size, tone, underline });
}
}
}
21 changes: 21 additions & 0 deletions src/shared/BackButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use client";

import { Button } from "@/shared/button";
import { Icon } from "@/shared/Icon";
import type { ButtonProps } from "@/types/button";
import * as React from "react";

type BackOnlyProps = Omit<Extract<ButtonProps, { preset: "back" }>, "preset">;

export const BackButton = React.forwardRef<HTMLButtonElement, BackOnlyProps>(
({ children = "์ด์ „", ...rest }, ref) => {
return (
<Button ref={ref} preset="back" {...rest}>
<Icon name="chevronleft" size={19} />
<span>{children}</span>
</Button>
);
},
);

BackButton.displayName = "BackButton";
2 changes: 2 additions & 0 deletions src/shared/Icon.registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
CalendarRange,
Check,
CheckSquare,
ChevronLeft,
Clock,
Eye,
EyeOff,
Expand Down Expand Up @@ -57,6 +58,7 @@ export const icons = {
calendarDays: CalendarDays,
calendarRange: CalendarRange,
checkSquare: CheckSquare,
chevronleft: ChevronLeft,
stickyNote: StickyNote,
rotateCcw: RotateCcw,
bell: Bell,
Expand Down
22 changes: 20 additions & 2 deletions src/shared/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,33 @@ function computePlan(props: ButtonProps) {
const native = omitKeys(props, [
"preset",
"disabled",
"fullWidth",
"className",
"asChild",
"children",
] as const);
return { asChild, className, children, classes, native };
}

// 5๏ธโƒฃ Auth (๊ธฐ๋ณธ)
// 5๏ธโƒฃ Back
if (props.preset === "back") {
const size = props.size ?? "md";
const tone = props.tone ?? "default";
const underline = props.underline ?? false;

const classes = getButtonClasses("back", { size, tone, underline });
const native = omitKeys(props, [
"preset",
"size",
"tone",
"underline",
"className",
"asChild",
"children",
] as const);
return { asChild, className, children, classes, native };
}

// 6๏ธโƒฃ Auth (๊ธฐ๋ณธ)
const color = props.color ?? "black";
const classes = getButtonClasses("auth", { color });
const native = omitKeys(props, ["preset", "color", "className", "asChild", "children"] as const);
Expand Down
24 changes: 18 additions & 6 deletions src/types/button.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { backButtonVariants } from "@/lib/variants/button.back";
import type { VariantProps } from "class-variance-authority";
import type { ButtonHTMLAttributes } from "react";

export type ButtonPreset = "hero" | "feature" | "auth" | "signup" | "cta";
export type ButtonPreset = "hero" | "feature" | "auth" | "signup" | "cta" | "back";
export type ButtonIntent = "primary";
export type Radius = "sm" | "md" | "lg" | "xl" | "2xl";
export type AuthColor = "black" | "white";
Expand Down Expand Up @@ -57,12 +59,9 @@ export type SignupProps = BaseButtonProps & {
color?: never;
};

/** cta ์ „์šฉ */
/** cta ์ „์šฉ */
export type CtaProps = BaseButtonProps & {
preset: "cta";
/** ์ „์ฒด ํญ ํ™•์žฅ ์—ฌ๋ถ€ */
fullWidth?: boolean;
/** ๊ธฐ๋ณธ์ ์œผ๋กœ `disabled`๋กœ ๋น„ํ™œ์„ฑํ™” โ†’ active์ผ ๋•Œ hover ๋“ฑ ๋™์ž‘ */
disabled?: boolean;
// ๊ธˆ์ง€
intent?: never;
Expand All @@ -73,5 +72,18 @@ export type CtaProps = BaseButtonProps & {
bg?: never;
};

/** back ์ „์šฉ */
export type BackProps = BaseButtonProps &
VariantProps<typeof backButtonVariants> & {
preset: "back";
// ๊ธˆ์ง€
intent?: never;
glow?: never;
pill?: never;
radius?: never;
color?: never;
bg?: never;
};

/** ์ „์ฒด ๋ฒ„ํŠผ ํƒ€์ž… ์œ ๋‹ˆ์˜จ */
export type ButtonProps = HeroProps | FeatureProps | AuthProps | SignupProps | CtaProps;
export type ButtonProps = HeroProps | FeatureProps | AuthProps | SignupProps | CtaProps | BackProps;