Button component -> ui
This commit is contained in:
1 parent
ac8a54895f
commit
6c71a78fe6
6 files changed
+4
-4
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import s from "./styles.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?: any
|
||||
style?: React.CSSProperties
|
||||
href?: string
|
||||
theme?: "default" | "ghost" | "icon"
|
||||
size?: "default" | "small"
|
||||
disabled?: boolean
|
||||
onClick?: (value: any, 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}>
|
||||
<a className={className} style={props.style}>
|
||||
{props.children}
|
||||
</a>
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
className={className}
|
||||
style={props.style}
|
||||
onClick={onClick}
|
||||
>
|
||||
{props.children}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
.button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
font-size: var(--font-size-default);
|
||||
|
||||
text-align: center;
|
||||
|
||||
border-radius: 100px;
|
||||
border: 1px solid var(--color-shadow);
|
||||
|
||||
color: var(--color-text);
|
||||
background-color: var(--color-back);
|
||||
|
||||
transition: box-shadow 150ms;
|
||||
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
margin: 1px;
|
||||
/* margin-left: 1px;
|
||||
margin-right: 1px; */
|
||||
|
||||
border: none;
|
||||
box-shadow: var(--shadow-active);
|
||||
}
|
||||
|
||||
/* MODIFICATORS */
|
||||
|
||||
.disabled {
|
||||
pointer-events: none;
|
||||
color: var(--color-text-second);
|
||||
}
|
||||
|
||||
/* SIZE */
|
||||
|
||||
.sizeDefault {
|
||||
padding: var(--size-s) var(--size-m);
|
||||
}
|
||||
|
||||
.sizeSmall {
|
||||
padding: var(--size-xs) var(--size-s);
|
||||
font-size: var(--font-size-second);
|
||||
}
|
||||
|
||||
/* THEME */
|
||||
|
||||
.themeGhost {
|
||||
border-color: rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
.themeIcon {
|
||||
padding: var(--size-xs) var(--size-xs);
|
||||
}
|
||||
Reference in new issue
Block a user