-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove polymorphic, use asChild
- Loading branch information
Showing
17 changed files
with
383 additions
and
259 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,82 @@ | ||
import { ElementType } from "react"; | ||
import { classNames, variantClassNames } from "../../util/classes"; | ||
import { Slot, Slottable } from "../Slot"; | ||
import { ButtonProps } from "./Button"; | ||
|
||
import { Button } from "./Button"; | ||
|
||
const DEFAULT_BUTTON_TAG = "button" as const; | ||
|
||
export type InternalButtonProps< | ||
T extends ElementType = typeof DEFAULT_BUTTON_TAG, | ||
> = Omit<ButtonProps<T>, "variant" | "size"> & InternalButtonOwnProps; | ||
export type InternalButtonProps = Omit<ButtonProps, "variant" | "size"> & | ||
InternalButtonOwnProps; | ||
|
||
export type InternalButtonVariant = "wallet" | "wallet-inside"; | ||
|
||
export interface InternalButtonOwnProps { | ||
variant: InternalButtonVariant | ButtonProps["variant"]; | ||
} | ||
|
||
export const InternalButton = < | ||
T extends ElementType = typeof DEFAULT_BUTTON_TAG, | ||
>({ | ||
export const InternalButton: React.FC<InternalButtonProps> = ({ | ||
children, | ||
className, | ||
variant, | ||
iconLeft, | ||
asChild, | ||
...props | ||
}: InternalButtonProps<T>) => { | ||
}) => { | ||
const Component = asChild ? Slot : Button; | ||
return ( | ||
<Button | ||
<Component | ||
className={classNames( | ||
variantClassNames(variant as InternalButtonVariant, { | ||
wallet: | ||
"ink:bg-background-light-transparent ink:pl-1 ink:pr-1.5 ink:py-2 ink:text-body-2-bold ink:text-text-default ink:hover:bg-background-light ink:disabled:bg-background-light-transparent-disabled ink:disabled:text-muted ink:active:bg-background-light", | ||
"wallet-inside": | ||
"ink:bg-background-light-invisible ink:px-1.5 ink:rounded-xs ink:text-body-2-bold ink:text-text-default ink:hover:bg-background-container ink:disabled:bg-background-light-transparent-disabled ink:disabled:text-muted ink:active:bg-background-light", | ||
"ink:bg-background-light-invisible ink:px-1.5 ink:py-2 ink:rounded-xs ink:text-body-2-bold ink:text-text-default ink:hover:bg-background-container ink:disabled:bg-background-light-transparent-disabled ink:disabled:text-muted ink:active:bg-background-light", | ||
}), | ||
className | ||
)} | ||
size="md" | ||
variant={ | ||
variant === "primary" || variant === "secondary" ? variant : undefined | ||
} | ||
{...(props as ButtonProps<T>)} | ||
{...props} | ||
> | ||
<div | ||
className={classNames( | ||
"ink:w-full ink:flex-1 ink:flex ink:items-center ink:gap-1.5", | ||
variantClassNames(variant as InternalButtonVariant, { | ||
wallet: "ink:justify-center", | ||
"wallet-inside": "ink:justify-start", | ||
}) | ||
)} | ||
> | ||
{iconLeft && ( | ||
<Slottable child={children}> | ||
{(child) => ( | ||
<div | ||
className={classNames( | ||
"ink:flex ink:items-center ink:justify-center", | ||
"ink:w-full ink:flex-1 ink:flex ink:items-center ink:gap-1.5", | ||
variantClassNames(variant as InternalButtonVariant, { | ||
wallet: "ink:size-4", | ||
"wallet-inside": "ink:size-3", | ||
wallet: "ink:justify-center", | ||
"wallet-inside": "ink:justify-start", | ||
}) | ||
)} | ||
> | ||
<div | ||
className={classNames( | ||
"ink:flex ink:items-center ink:justify-center ink:rounded-full ink:overflow-hidden", | ||
variantClassNames(variant as InternalButtonVariant, { | ||
wallet: "ink:size-4", | ||
"wallet-inside": "ink:size-3", | ||
}) | ||
)} | ||
> | ||
{iconLeft} | ||
</div> | ||
{iconLeft && ( | ||
<div | ||
className={classNames( | ||
"ink:flex ink:items-center ink:justify-center", | ||
variantClassNames(variant as InternalButtonVariant, { | ||
wallet: "ink:size-4", | ||
"wallet-inside": "ink:size-3", | ||
}) | ||
)} | ||
> | ||
<div | ||
className={classNames( | ||
"ink:flex ink:items-center ink:justify-center ink:rounded-full ink:overflow-hidden", | ||
variantClassNames(variant as InternalButtonVariant, { | ||
wallet: "ink:size-4", | ||
"wallet-inside": "ink:size-3", | ||
}) | ||
)} | ||
> | ||
{iconLeft} | ||
</div> | ||
</div> | ||
)} | ||
{child} | ||
</div> | ||
)} | ||
<div>{children}</div> | ||
</div> | ||
</Button> | ||
</Slottable> | ||
</Component> | ||
); | ||
}; |
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
Oops, something went wrong.