-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91f8111
commit 8cd648d
Showing
21 changed files
with
749 additions
and
144 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,73 +1,56 @@ | ||
import clsx from "clsx"; | ||
import React from "react"; | ||
import React, { LegacyRef } from "react"; | ||
|
||
import "./button.scss"; | ||
|
||
export type ButtonProps = React.PropsWithChildren<{ | ||
type BaseButtonProps = { | ||
variant?: "primary" | "transparent"; | ||
}>; | ||
|
||
/** | ||
* Higher-order component (HOC) applying button logic to WrappedComponent | ||
* @param WrappedComponent | ||
* @private | ||
*/ | ||
const withButtonBehavior = <P extends ButtonProps>( | ||
WrappedComponent: React.ComponentType<P>, | ||
) => { | ||
// Define the enhanced component | ||
const EnhancedButton: React.FC<P> = ({ | ||
children, | ||
variant = "primary", | ||
...props | ||
}) => { | ||
return ( | ||
<WrappedComponent | ||
className={clsx("mykn-button", `mykn-button--variant-${variant}`)} | ||
{...(props as P)} | ||
> | ||
{children} | ||
</WrappedComponent> | ||
); | ||
}; | ||
|
||
return EnhancedButton; | ||
}; | ||
|
||
/** | ||
* Base template for Button component | ||
* @private | ||
*/ | ||
const BaseButton: React.FC< | ||
ButtonProps & React.ButtonHTMLAttributes<HTMLButtonElement> | ||
> = (props) => { | ||
return <button {...props}>{props.children}</button>; | ||
}; | ||
export type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & | ||
BaseButtonProps; | ||
|
||
/** | ||
* Base template for ButtonLink component | ||
* @private | ||
*/ | ||
const BaseButtonLink: React.FC< | ||
ButtonProps & React.AnchorHTMLAttributes<HTMLAnchorElement> | ||
> = (props) => { | ||
return <a {...props}>{props.children}</a>; | ||
}; | ||
export type ButtonLinkProps = React.AnchorHTMLAttributes<HTMLAnchorElement> & | ||
BaseButtonProps; | ||
|
||
/** | ||
* Button component | ||
* @param children | ||
* @param type | ||
* @param variant | ||
* @param props | ||
* @constructor | ||
*/ | ||
export const Button = withButtonBehavior(BaseButton); | ||
export const Button = React.forwardRef<HTMLAnchorElement, ButtonProps>( | ||
({ variant = "primary", ...props }, ref) => { | ||
return ( | ||
<button | ||
ref={ref as LegacyRef<HTMLButtonElement>} | ||
className={clsx("mykn-button", `mykn-button--variant-${variant}`)} | ||
{...props} | ||
> | ||
{props.children} | ||
</button> | ||
); | ||
}, | ||
); | ||
Button.displayName = "Button"; | ||
|
||
/** | ||
* Anchor (<a>) version of button component | ||
* @param children | ||
* @param type | ||
* Button component | ||
* @param variant | ||
* @param props | ||
* @constructor | ||
*/ | ||
export const ButtonLink = withButtonBehavior(BaseButtonLink); | ||
export const ButtonLink = React.forwardRef<HTMLAnchorElement, ButtonLinkProps>( | ||
({ variant, ...props }, ref) => { | ||
return ( | ||
<a | ||
ref={ref as LegacyRef<HTMLAnchorElement>} | ||
className={clsx("mykn-button", `mykn-button--variant-${variant}`)} | ||
{...props} | ||
> | ||
{props.children} | ||
</a> | ||
); | ||
}, | ||
); | ||
ButtonLink.displayName = "ButtonLink"; |
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,45 @@ | ||
@use '../../settings/style'; | ||
|
||
.mykn-dropdown { | ||
display: inline-flex; | ||
position: relative; | ||
justify-content: center; | ||
|
||
&--open > .mykn-button { | ||
outline: 1px solid var(--theme-color-primary-800) | ||
} | ||
|
||
|
||
.mykn-a, | ||
.mykn-button, | ||
.mykn-dropdown { | ||
width: 100%; | ||
} | ||
|
||
&__dropdown { | ||
width: fit-content; | ||
border: 1px solid var(--theme-color-primary-800); | ||
border-radius: 4px; | ||
box-sizing: border-box; | ||
padding: 2px; | ||
} | ||
|
||
@media screen and (max-width: style.$breakpoint-desktop - 1px) { | ||
&__dropdown { | ||
width: 100%; // Fallback. | ||
width: min(100%, max(calc(100vw - 2 * var(--spacing-h-xl)), 100cqw)); | ||
} | ||
} | ||
|
||
@media screen and (min-width: style.$breakpoint-desktop) { | ||
&__dropdown .mykn-toolbar--direction-horizontal { | ||
width: min-content; | ||
} | ||
} | ||
|
||
@media screen and (min-width: style.$breakpoint-desktop) { | ||
&__dropdown .mykn-toolbar--direction-vertical { | ||
width: max-content; | ||
} | ||
} | ||
} |
Oops, something went wrong.