This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 323
feat: revamp buttons #208
Merged
Merged
feat: revamp buttons #208
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1c4f731
added base styles for buttons
kasperkristensen c829249
added button component and styles from design system
kasperkristensen 2ce4f55
merged feat/revamp
kasperkristensen eaa6458
finished button component and moved it to fundamentals
kasperkristensen 74eee26
added spinner
kasperkristensen 48b9567
made loading optional
kasperkristensen d9374a5
added clsx and removed switch statement
kasperkristensen 025a37b
removed test btn
kasperkristensen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import clsx from "clsx" | ||
import React from "react" | ||
|
||
type SpinnerProps = { | ||
size: "large" | "medium" | "small" | ||
variant: "primary" | "secondary" | ||
} | ||
|
||
const Spinner: React.FC<SpinnerProps> = ({ | ||
size = "large", | ||
variant = "primary", | ||
}) => { | ||
return ( | ||
<div | ||
className={clsx( | ||
"flex items-center justify-center", | ||
{ "h-[24px] w-[24px]": size === "large" }, | ||
{ "h-[20px] w-[20px]": size === "medium" }, | ||
{ "h-[16px] w-[16px]": size === "small" } | ||
)} | ||
> | ||
<div className="inline-block relative w-full h-full"> | ||
<div | ||
className={clsx( | ||
"animate-ring border-2 h-4/5 w-4/5 rounded-circle border-transparent", | ||
{ "border-t-grey-0": variant === "primary" }, | ||
{ "border-t-violet-60": variant === "secondary" } | ||
)} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Spinner |
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,54 @@ | ||
import clsx from "clsx" | ||
import React, { Children } from "react" | ||
import Spinner from "../../atoms/spinner" | ||
|
||
type ButtonProps = { | ||
variant: "primary" | "secondary" | "ghost" | ||
size: "small" | "medium" | "large" | ||
loading?: boolean | ||
} & React.ButtonHTMLAttributes<HTMLButtonElement> | ||
|
||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( | ||
( | ||
{ | ||
variant = "primary", | ||
size = "large", | ||
loading = false, | ||
children, | ||
...attributes | ||
}, | ||
ref | ||
) => { | ||
const handleClick = e => { | ||
if (!loading && attributes.onClick) { | ||
attributes.onClick(e) | ||
} | ||
} | ||
|
||
const buttonClass = "btn-" + variant + "-" + size | ||
|
||
return ( | ||
<button | ||
{...attributes} | ||
className={clsx(buttonClass, attributes.className)} | ||
disabled={attributes.disabled || loading} | ||
ref={ref} | ||
onClick={handleClick} | ||
> | ||
{loading ? ( | ||
<Spinner size={size} variant={"secondary"} /> | ||
) : ( | ||
Children.map(children, (child, i) => { | ||
return ( | ||
<span key={i} className="mr-xsmall last:mr-0"> | ||
{child} | ||
</span> | ||
) | ||
}) | ||
)} | ||
</button> | ||
) | ||
} | ||
) | ||
|
||
export default 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍