-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replacing Primary+ SeconaryButton with AcitonButton. (#313)
Co-authored-by: Sigrid <[email protected]> Co-authored-by: Mathilde Haukø Haugum <[email protected]> Co-authored-by: Mathilde Haukø Haugum <[email protected]>
- Loading branch information
1 parent
f602093
commit 169eff9
Showing
19 changed files
with
369 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from "react"; | ||
import BaseButton from "./BaseButton"; | ||
import { IconBox } from "./IconBox"; | ||
|
||
export type ActionButtonProps = { | ||
variant: "primary" | "secondary" | "terniary"; | ||
iconLeft?: React.ReactNode; | ||
iconRight?: React.ReactNode; | ||
small?: boolean; | ||
fullWidth?: true; | ||
onClick?: () => void; | ||
disabled?: true; | ||
children?: React.ReactNode; | ||
className?: string; | ||
isIconBtn?: true; | ||
}; | ||
|
||
export default function ActionButton({ | ||
variant, | ||
iconLeft, | ||
iconRight, | ||
small, | ||
fullWidth, | ||
disabled, | ||
onClick, | ||
children, | ||
className = "", | ||
isIconBtn, | ||
}: ActionButtonProps) { | ||
const variantClass = | ||
{ | ||
primary: | ||
"bg-primary text-white hover:bg-primary_darker hover:border-primary_darker", | ||
secondary: | ||
"bg-white text-primary border border-primary/50 hover:bg-primary/10 hover:border-primary", | ||
terniary: | ||
"bg-white text-primary hover:bg-primary/10 hover:border-primary", | ||
}[variant] ?? "Default"; | ||
|
||
const disabledClass = disabled ? "bg-opacity-50" : ""; | ||
const fullWidthClass = fullWidth ? "w-full" : ""; | ||
|
||
const paddingClass = isIconBtn ? "p-2" : "px-3 py-2"; | ||
const roundedBorders = small ? "rounded h-8" : "rounded-lg h-10"; | ||
|
||
return ( | ||
<BaseButton | ||
className={`${variantClass} ${disabledClass} ${fullWidthClass} ${paddingClass} ${roundedBorders} ${className} `} | ||
onClick={onClick} | ||
> | ||
<IconBox small={small}>{iconLeft}</IconBox> | ||
{children} | ||
<IconBox small={small}>{iconRight}</IconBox> | ||
</BaseButton> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from "react"; | ||
|
||
export default function BaseButton({ | ||
onClick, | ||
disabled, | ||
className, | ||
children, | ||
}: { | ||
onClick?: () => void; | ||
disabled?: true; | ||
className: string; | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<button | ||
disabled={disabled} | ||
className={`normal-semibold inline-flex items-center justify-center gap-2 ${className}`} | ||
onClick={onClick} | ||
> | ||
{children} | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from "react"; | ||
import ActionButton, { ActionButtonProps } from "./ActionButton"; | ||
import { IconBox } from "./IconBox"; | ||
|
||
type IconActionButtonProps = ActionButtonProps & { | ||
icon: React.ReactNode; | ||
small?: true; | ||
}; | ||
|
||
export default function IconActionButton(props: IconActionButtonProps) { | ||
return ( | ||
<ActionButton {...props} isIconBtn> | ||
<IconBox small={props.small}>{props.icon}</IconBox> | ||
</ActionButton> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from "react"; | ||
|
||
export function IconBox({ | ||
children, | ||
small, | ||
}: { | ||
children: React.ReactNode; | ||
small?: boolean; | ||
}) { | ||
const size = small ? "h-4 w-4" : "h-6 w-6"; | ||
|
||
if (!children) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={`flex items-center justify-center ${size}`}>{children}</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
frontend/src/components/EasyModal/ButtonExampleModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
"use client"; | ||
|
||
import BaseModal from "../BaseModal"; | ||
import { Check, Plus } from "react-feather"; | ||
import { EasyModalHeader } from "./EasyModalHeader"; | ||
import ActionButton from "../Buttons/ActionButton"; | ||
import IconActionButton from "../Buttons/IconActionButton"; | ||
import { useModal } from "@/hooks/useModal"; | ||
|
||
function ButtonExampleModal() { | ||
const { modalRef, openModal, closeModal } = useModal(); | ||
|
||
const dialogElement = modalRef?.current; | ||
|
||
function handleClose() { | ||
dialogElement?.close(); | ||
} | ||
|
||
function handleSave() { | ||
dialogElement?.close(); | ||
} | ||
|
||
return ( | ||
<> | ||
<BaseModal modalRef={modalRef}> | ||
<div className="w-[332px]"> | ||
<EasyModalHeader | ||
title="Button Examples" | ||
handleClose={handleClose} | ||
showCloseButton={true} | ||
/> | ||
|
||
<div className="space-y-2 space-x-2"> | ||
<ActionButton variant="primary" onClick={handleSave}> | ||
Button | ||
</ActionButton> | ||
<ActionButton variant="secondary" onClick={handleSave}> | ||
Button | ||
</ActionButton> | ||
<ActionButton variant="terniary" onClick={handleSave}> | ||
Button | ||
</ActionButton> | ||
<IconActionButton | ||
variant="secondary" | ||
onClick={handleSave} | ||
small | ||
icon={<Plus />} | ||
/> | ||
<IconActionButton | ||
variant="primary" | ||
onClick={handleSave} | ||
icon={<Check />} | ||
/> | ||
<ActionButton | ||
variant="primary" | ||
onClick={handleSave} | ||
iconLeft={<Plus />} | ||
> | ||
Button | ||
</ActionButton> | ||
<ActionButton variant="primary" onClick={handleSave}> | ||
Button | ||
</ActionButton> | ||
<ActionButton variant="secondary" onClick={handleSave}> | ||
Button | ||
</ActionButton> | ||
<ActionButton | ||
variant="primary" | ||
onClick={handleSave} | ||
iconLeft={<Plus />} | ||
iconRight={<Plus />} | ||
> | ||
Button | ||
</ActionButton> | ||
<ActionButton | ||
variant="secondary" | ||
onClick={handleSave} | ||
iconLeft={<Plus />} | ||
iconRight={<Plus />} | ||
> | ||
Button | ||
</ActionButton> | ||
<ActionButton | ||
variant="secondary" | ||
onClick={handleSave} | ||
iconLeft={<Plus />} | ||
iconRight={<Plus />} | ||
small | ||
> | ||
Button | ||
</ActionButton> | ||
<ActionButton | ||
variant="terniary" | ||
onClick={handleSave} | ||
small | ||
iconRight={<Plus />} | ||
iconLeft={<Plus />} | ||
> | ||
Button | ||
</ActionButton> | ||
<ActionButton | ||
variant="primary" | ||
onClick={handleSave} | ||
small | ||
iconRight={<Plus />} | ||
iconLeft={<Plus />} | ||
> | ||
Button | ||
</ActionButton> | ||
<ActionButton | ||
variant="secondary" | ||
onClick={handleSave} | ||
iconLeft={<Plus />} | ||
fullWidth | ||
small | ||
> | ||
Button | ||
</ActionButton> | ||
<ActionButton | ||
variant="terniary" | ||
onClick={handleSave} | ||
small | ||
fullWidth | ||
iconLeft={<Plus />} | ||
> | ||
Button | ||
</ActionButton> | ||
<ActionButton | ||
variant="primary" | ||
onClick={handleSave} | ||
small | ||
fullWidth | ||
iconLeft={<Plus />} | ||
> | ||
Button | ||
</ActionButton> | ||
</div> | ||
</div> | ||
</BaseModal> | ||
<ActionButton variant="primary" onClick={openModal}> | ||
Button Examples | ||
</ActionButton> | ||
</> | ||
); | ||
} | ||
|
||
export default ButtonExampleModal; |
Oops, something went wrong.