* spec update * update md files * add plan: monorepo * feat: add empty apps and packages directories * Add shared tsconfig.base.json * feat add workspaces * feat: move hudozka-writer into apps/ * feat: move migrate-to-pocketbase into apps/ * feat: split package.json for apps/hudozka workspace * feat: extend tsconfig.base.json in apps/hudozka * add dockerfile path * feat: verify Phase 3 monorepo migration of Next app * feat: scaffold @hudozka/utils package * feat: add utils barrel export * feat: extract utilities into hudozka-utils package * feat: extract hooks into hudozka-hooks package * Extract Box/Button/Panel/Title/Overlay into @hudozka/ui * Scope Next ESLint rules to apps/hudozka in root flat config * Update README and CLAUDE.md for monorepo layout * disable image optimisation
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import s from "./button.module.css"
|
|
|
|
import Link from "next/link"
|
|
import cx from "classnames"
|
|
import { useCallback } from "react"
|
|
import type { MouseEvent, MouseEventHandler } from "react"
|
|
|
|
const sizeClass = {
|
|
default: s.sizeDefault,
|
|
small: s.sizeSmall,
|
|
}
|
|
|
|
const themeClass = {
|
|
default: "",
|
|
icon: s.themeIcon,
|
|
ghost: s.themeGhost,
|
|
}
|
|
|
|
export type ButtonProps = {
|
|
children?: React.ReactNode
|
|
value?: string
|
|
style?: React.CSSProperties
|
|
href?: string
|
|
theme?: "default" | "ghost" | "icon"
|
|
size?: "default" | "small"
|
|
disabled?: boolean
|
|
onClick?: (value: string | undefined, event: MouseEvent) => void
|
|
}
|
|
|
|
export const Button: React.FC<ButtonProps> = ({ size = "default", theme = "default", disabled = false, ...props }) => {
|
|
const className = cx(s.button, sizeClass[size], themeClass[theme], {
|
|
[s.disabled]: disabled,
|
|
})
|
|
const onClick = useCallback<MouseEventHandler<HTMLButtonElement>>(event => {
|
|
if (typeof props.onClick === "function") {
|
|
props.onClick(props.value, event)
|
|
}
|
|
}, [props])
|
|
|
|
if (props.href) {
|
|
return (
|
|
<Link href={props.href} className={className} style={props.style}>
|
|
{props.children}
|
|
</Link>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<button
|
|
className={className}
|
|
style={props.style}
|
|
onClick={onClick}
|
|
>
|
|
{props.children}
|
|
</button>
|
|
)
|
|
}
|