generated from timelessco/react-components-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(button): ✨ finish button theming
- Loading branch information
1 parent
22b8f21
commit 3cb557b
Showing
10 changed files
with
3,028 additions
and
210 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 |
---|---|---|
@@ -1,47 +1,50 @@ | ||
import * as React from "react"; | ||
|
||
import { Box } from "../box"; | ||
import { Spinner } from "../spinner"; | ||
import { useTheme } from "../theme"; | ||
import { cx, passProps } from "../utils"; | ||
import { cx, passPropsNew } from "../utils"; | ||
|
||
import { ButtonProps } from "./Button"; | ||
|
||
export type ButtonSpinnerProps = Partial< | ||
Pick<ButtonProps, "spinner" | "size" | "prefix" | "suffix" | "children"> | ||
> & { | ||
children?: React.ReactNode; | ||
}; | ||
>; | ||
|
||
export const ButtonSpinner: React.FC<ButtonSpinnerProps> = props => { | ||
const { | ||
size = "md", | ||
spinner = <Spinner size="em" />, | ||
spinner = <Spinner size="em" themeColor="current" />, | ||
prefix, | ||
suffix, | ||
} = props; | ||
|
||
const button = useTheme("button"); | ||
const spinnerStyles = cx( | ||
prefix | ||
? button.size.prefix[size] | ||
? button.size[size].prefix | ||
: suffix | ||
? button.size.suffix[size] | ||
: button.size.iconOnly[size], | ||
? button.size[size].suffix | ||
: button.size[size].iconOnly.spinner, | ||
); | ||
|
||
return <>{passProps(spinner, { className: spinnerStyles })}</>; | ||
return <>{passPropsNew(spinner, { className: spinnerStyles })}</>; | ||
}; | ||
|
||
export const ButtonFullWidthSpinner: React.FC<ButtonSpinnerProps> = props => { | ||
const { size = "md", spinner = <Spinner size="em" />, children } = props; | ||
const { | ||
size = "md", | ||
spinner = <Spinner size="em" themeColor="current" />, | ||
children, | ||
} = props; | ||
|
||
// This is only the grey area in button for now which user cannot customize | ||
return ( | ||
<> | ||
<div className="absolute flex items-center justify-center"> | ||
<ButtonSpinner spinner={spinner} size={size} /> | ||
</div> | ||
<div className="opacity-0">{children}</div> | ||
<Box className="opacity-0">{children}</Box> | ||
</> | ||
); | ||
}; |
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,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Button should render properly 1`] = ` | ||
<DocumentFragment> | ||
<button | ||
class="inline-flex items-center justify-center relative transition-all disabled:cursor-not-allowed outline-none appearance-none select-none whitespace-nowrap align-middle translate-y-0 hover:-translate-y-px active:translate-y-0 will-change-transform min-h-[30px] min-w-[30px] w-auto px-2.5 border rounded-lg text-sm font-medium bg-gray-900 text-white-900 border-transparent enabled:hover:bg-gray-800 enabled:hover:z-10 enabled:active:bg-gray-700 focus-visible:ring-3 focus-visible:ring-gray-500 focus-visible:z-10 disabled:bg-gray-200 disabled:text-gray-500" | ||
data-command="" | ||
type="button" | ||
> | ||
Hello World | ||
</button> | ||
</DocumentFragment> | ||
`; |
Oops, something went wrong.