add button component
This commit is contained in:
parent
5bbd01480f
commit
f1f6f5f438
5 changed files with 89 additions and 24 deletions
41
frontend/src/components/basics/Button.tsx
Normal file
41
frontend/src/components/basics/Button.tsx
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import SvgIcon, { Icon } from "./SvgIcon"
|
||||
|
||||
type ButtonProps = {
|
||||
onClicked: () => void,
|
||||
icon?: Icon,
|
||||
text?: string,
|
||||
buttonType : ButtonType
|
||||
}
|
||||
|
||||
export const ButtonType = {
|
||||
DarkButton: {
|
||||
textColor: "text-white",
|
||||
backgroundColor: "bg-gray-600 hover:bg-gray-800"
|
||||
},
|
||||
PrimaryButton: {
|
||||
textColor: "text-gray-600",
|
||||
backgroundColor: "bg-blue-300 hover:bg-blue-400"
|
||||
},
|
||||
DefaultButton: {
|
||||
textColor: "text-gray-600",
|
||||
backgroundColor: "bg-gray-300 hover:bg-gray-400"
|
||||
}
|
||||
} as const;
|
||||
|
||||
export type ButtonType = typeof ButtonType[keyof typeof ButtonType];
|
||||
|
||||
export default function Button ({onClicked, icon, text, buttonType = ButtonType.DefaultButton} : ButtonProps){
|
||||
return(
|
||||
<button
|
||||
type="button"
|
||||
className={`px-4 py-2 shadow-md rounded-lg whitespace-nowrap ${buttonType.backgroundColor} ${buttonType.textColor}`}
|
||||
onClick={onClicked}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
{/* Render icon only if defined */}
|
||||
{icon && <SvgIcon icon={icon} color={buttonType.textColor} />}
|
||||
{text}
|
||||
</div>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
|
@ -8,21 +8,23 @@
|
|||
*/
|
||||
export const Icon = {
|
||||
LookingGlass: "M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z",
|
||||
X: "M6 18L18 6M6 6l12 12"
|
||||
X: "M6 18L18 6M6 6l12 12",
|
||||
Plus: "M3 12L21 12M12 3L12 21"
|
||||
} as const;
|
||||
|
||||
export type Icon = typeof Icon[keyof typeof Icon];
|
||||
|
||||
type SvgIconProps = {
|
||||
pathDefinition : string
|
||||
icon : Icon
|
||||
color?: string // optional stroke color
|
||||
hoverColor?: string // optional hover color, set to undefined to deactivate hover
|
||||
}
|
||||
|
||||
export default function SvgIcon({icon} : SvgIconProps){
|
||||
export default function SvgIcon({icon, color="text-gray-400", hoverColor="text-gray-500"} : SvgIconProps){
|
||||
return (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="h-6 w-6 text-gray-400 hover:text-gray-500"
|
||||
className={`h-6 w-6 ${color} ${hoverColor !== undefined ? "hover:"+hoverColor : ""}`}
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue