feat: patron button and modal
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import { cn } from "~/lib/utils"
|
||||
import React, {
|
||||
ChangeEvent,
|
||||
FocusEvent,
|
||||
Dispatch,
|
||||
SetStateAction,
|
||||
useMemo,
|
||||
useState,
|
||||
} from "react"
|
||||
import { UniLink } from "./UniLink"
|
||||
import { useTranslation } from "next-i18next"
|
||||
import { nanoid } from "nanoid"
|
||||
import { Input } from "~/components/ui/Input"
|
||||
|
||||
export type RadioItem = {
|
||||
text: string
|
||||
value?: string
|
||||
default?: boolean
|
||||
}
|
||||
|
||||
export const BoxRadio: React.FC<{
|
||||
value: string
|
||||
setValue: Dispatch<SetStateAction<string>>
|
||||
items: RadioItem[]
|
||||
}> = ({ value, setValue, items }) => {
|
||||
const { t } = useTranslation(["dashboard"])
|
||||
const randomId = useMemo(() => nanoid(), [])
|
||||
const [isCustom, setIsCustom] = useState(false)
|
||||
|
||||
const toCustom = (
|
||||
e: ChangeEvent<HTMLInputElement> | FocusEvent<HTMLInputElement>,
|
||||
) => {
|
||||
setIsCustom(true)
|
||||
setValue(e.target.value)
|
||||
}
|
||||
|
||||
const toDefined = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
setIsCustom(false)
|
||||
setValue(e.target.value)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid gap-4 grid-cols-3">
|
||||
{items.map((item) => {
|
||||
return (
|
||||
<div key={item.value} className="relative w-full min-h-[80px]">
|
||||
{item.value ? (
|
||||
<>
|
||||
<input
|
||||
className={cn(
|
||||
"opacity-0 absolute left-0 right-0 top-0 bottom-0 pointer-events-none",
|
||||
)}
|
||||
type="radio"
|
||||
id={`${randomId}-${item.value}`}
|
||||
name={randomId}
|
||||
value={item.value}
|
||||
checked={value === item.value}
|
||||
onChange={toDefined}
|
||||
/>
|
||||
<label
|
||||
className={cn(
|
||||
"absolute left-0 right-0 top-0 bottom-0 flex items-center justify-center rounded-lg cursor-pointer border",
|
||||
value === item.value
|
||||
? "border-accent border-2 text-accent"
|
||||
: "",
|
||||
)}
|
||||
htmlFor={`${randomId}-${item.value}`}
|
||||
>
|
||||
{t(item.text)}
|
||||
</label>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Input
|
||||
className={cn("w-full min-h-[80px] text-center", {
|
||||
"border-accent border-2 text-accent": isCustom,
|
||||
})}
|
||||
type="text"
|
||||
id={`${randomId}-${item.value}`}
|
||||
name={randomId}
|
||||
placeholder={t(item.text) || ""}
|
||||
onChange={toCustom}
|
||||
onFocus={toCustom}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { cn } from "~/lib/utils"
|
||||
import React from "react"
|
||||
import { UniLink } from "./UniLink"
|
||||
import { useTranslation } from "next-i18next"
|
||||
import { Tooltip } from "~/components/ui/Tooltip"
|
||||
|
||||
export type TabItem = {
|
||||
text: string
|
||||
@@ -9,6 +10,7 @@ export type TabItem = {
|
||||
hidden?: boolean
|
||||
onClick?: () => void
|
||||
active?: boolean
|
||||
tooltip?: string
|
||||
}
|
||||
|
||||
export const Tabs: React.FC<{ items: TabItem[] }> = ({ items }) => {
|
||||
@@ -25,13 +27,19 @@ export const Tabs: React.FC<{ items: TabItem[] }> = ({ items }) => {
|
||||
onClick={item.onClick}
|
||||
key={item.text}
|
||||
className={cn(
|
||||
`border-b-2 inline-flex items-center h-10 whitespace-nowrap`,
|
||||
`border-b-2 inline-flex items-center h-10 whitespace-nowrap cursor-pointer`,
|
||||
item.active
|
||||
? `border-accent text-black font-medium`
|
||||
: `text-gray-500 border-transparent hover:border-gray-300`,
|
||||
)}
|
||||
>
|
||||
{t(item.text)}
|
||||
{item.tooltip ? (
|
||||
<Tooltip label={item.tooltip}>
|
||||
<>{t(item.text)}</>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<>{t(item.text)}</>
|
||||
)}
|
||||
</UniLink>
|
||||
)
|
||||
})}
|
||||
|
||||
@@ -20,6 +20,7 @@ interface Props {
|
||||
placement?: Placement
|
||||
children: JSX.Element
|
||||
className?: string
|
||||
inline?: boolean
|
||||
}
|
||||
|
||||
export const Tooltip = ({
|
||||
@@ -27,6 +28,7 @@ export const Tooltip = ({
|
||||
label,
|
||||
placement = "top",
|
||||
className,
|
||||
inline,
|
||||
}: Props) => {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
@@ -54,7 +56,7 @@ export const Tooltip = ({
|
||||
<div
|
||||
ref={refs.setReference}
|
||||
{...getReferenceProps()}
|
||||
className="flex items-center"
|
||||
className={cn("items-center", inline ? "inline-flex" : "flex")}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user