-
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.
Merge branch 'bose/2469' into staging
- Loading branch information
Showing
11 changed files
with
891 additions
and
5,778 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,125 @@ | ||
import { IconType } from '@equinor/eds-core-react/dist/types/components/Icon/Icon.types' | ||
import { ButtonHTMLAttributes, forwardRef } from 'react' | ||
import envisTwMerge from '../../twMerge' | ||
|
||
export const commonButtonStyling = ` | ||
w-fit | ||
text-sm | ||
px-4 | ||
py-3 | ||
rounded-md | ||
focus:outline-none | ||
focus-visible:envis-outline | ||
dark:focus:outline-none | ||
dark:focus-visible:envis-outline-invert | ||
active:scale-99 | ||
flex | ||
items-center | ||
gap-3 | ||
` | ||
|
||
export type Variants = 'contained' | 'outlined' | 'ghost' | 'contained-secondary' | 'outlined-secondary' | ||
|
||
/** Use for common button styling in Button,IconButton, Link/ButtonLink */ | ||
export const getVariant = (variant: Variants): string => { | ||
switch (variant) { | ||
case 'ghost': | ||
return ` | ||
hover:bg-moss-green-60 | ||
focus:outline-none | ||
focus-visible:envis-outline | ||
active:scale-99 | ||
dark:text-white-100 | ||
dark:hover:bg-white-transparent | ||
dark:focus-visible:envis-outline-invert | ||
` | ||
case 'outlined': | ||
return ` | ||
border | ||
border-north-sea-100 | ||
text-norwegian-woods-100 | ||
hover:bg-moss-green-60 | ||
hover:text-moss-green-100 | ||
focus:outline-none | ||
focus-visible:outline-slate-blue-95 | ||
dark:text-white-100 | ||
dark:border-white-100 | ||
dark:hover:bg-white-transparent | ||
dark:focus-visible:outline-white-100 | ||
` | ||
case 'outlined-secondary': | ||
return ` | ||
px-3 | ||
py-2 | ||
lg:px-5 | ||
lg:py-3 | ||
border | ||
border-north-sea-100 | ||
text-black-80 | ||
hover:bg-slate-blue-100 | ||
hover:text-white-100 | ||
focus:outline-none | ||
focus-visible:outline-slate-blue-95 | ||
dark:text-white-100 | ||
dark:border-white-100 | ||
dark:hover:bg-white-transparent | ||
dark:focus-visible:outline-white-100 | ||
` | ||
case 'contained-secondary': | ||
return ` | ||
px-3 | ||
py-2 | ||
lg:px-5 | ||
lg:py-3 | ||
bg-slate-blue-95 | ||
text-white-100 | ||
hover:bg-slate-blue-100 | ||
hover:text-white-100 | ||
focus:outline-none | ||
focus-visible:outline-slate-blue-95 | ||
` | ||
case 'contained': | ||
default: | ||
return `bg-norwegian-woods-100 | ||
text-white-100 | ||
hover:bg-moss-green-100 | ||
focus:outline-none | ||
focus-visible:outline-norwegian-woods-100 | ||
dark:bg-white-100 | ||
dark:hover:bg-norwegian-woods-40 | ||
dark:text-slate-80 | ||
dark:focus-visible:outline-white-100 | ||
` | ||
} | ||
} | ||
|
||
export type ButtonProps = { | ||
/** Specifies which variant to use */ | ||
variant?: Variants | ||
/** Type of button | ||
* @default 'button' | ||
*/ | ||
type?: string | ||
/** Should make our own Icon component ? */ | ||
icon?: IconType | ||
} & ButtonHTMLAttributes<HTMLButtonElement> | ||
|
||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>( | ||
({ variant = 'contained', type = 'button', children, icon: Icon, className = '', ...rest }, ref) => { | ||
const variantClassNames = getVariant(variant) | ||
|
||
const buttonClassNames = envisTwMerge( | ||
commonButtonStyling, | ||
variantClassNames, | ||
`${Icon ? 'flex gap-2' : ''}`, | ||
className, | ||
) | ||
|
||
return ( | ||
<button ref={ref} type={type} className={buttonClassNames} {...rest}> | ||
{Icon && <Icon />} | ||
{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,35 @@ | ||
import { ButtonHTMLAttributes, forwardRef } from 'react' | ||
import envisTwMerge from '../../twMerge' | ||
import { IconData } from '@equinor/eds-icons' | ||
import { TransformableIcon } from '../../icons/TransformableIcon' | ||
|
||
export type LinkButtonProps = { | ||
iconData?: IconData | ||
iconClassName?: string | ||
} & ButtonHTMLAttributes<HTMLButtonElement> | ||
|
||
export const LinkButton = forwardRef<HTMLButtonElement, LinkButtonProps>( | ||
({ children, iconData, className = '', iconClassName = '', ...rest }, ref) => { | ||
return ( | ||
<button | ||
ref={ref} | ||
type="button" | ||
className={envisTwMerge( | ||
`flex | ||
gap-1 | ||
text-xs | ||
underline | ||
hover:no-underline | ||
focus:outline-none | ||
focus-visible:envis-outline | ||
active:scale-99`, | ||
className, | ||
)} | ||
{...rest} | ||
> | ||
{iconData && <TransformableIcon iconData={iconData} className={iconClassName} />} | ||
{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 |
---|---|---|
@@ -1,118 +1,2 @@ | ||
import { IconType } from '@equinor/eds-core-react/dist/types/components/Icon/Icon.types' | ||
import { ButtonHTMLAttributes, forwardRef } from 'react' | ||
import envisTwMerge from '../../twMerge' | ||
|
||
export const commonButtonStyling = ` | ||
w-fit | ||
text-sm | ||
px-3 | ||
py-2 | ||
lg:px-5 | ||
lg:py-3 | ||
rounded-md | ||
focus:outline-none | ||
focus-visible:envis-outline | ||
dark:focus:outline-none | ||
dark:focus-visible:envis-outline-invert | ||
active:scale-99 | ||
flex | ||
items-center | ||
gap-3 | ||
` | ||
|
||
export type Variants = 'contained' | 'outlined' | 'ghost' | 'contained-secondary' | 'outlined-secondary' | ||
|
||
/** Use for common button styling in Button,IconButton, Link/ButtonLink */ | ||
export const getVariant = (variant: Variants): string => { | ||
switch (variant) { | ||
case 'ghost': | ||
return ` | ||
hover:bg-moss-green-60 | ||
focus:outline-none | ||
focus-visible:envis-outline | ||
active:scale-99 | ||
dark:text-white-100 | ||
dark:hover:bg-white-transparent | ||
dark:focus-visible:envis-outline-invert | ||
` | ||
case 'outlined': | ||
return ` | ||
border | ||
border-north-sea-100 | ||
text-norwegian-woods-100 | ||
hover:bg-moss-green-60 | ||
hover:text-moss-green-100 | ||
focus:outline-none | ||
focus-visible:outline-slate-blue-95 | ||
dark:text-white-100 | ||
dark:border-white-100 | ||
dark:hover:bg-white-transparent | ||
dark:focus-visible:outline-white-100 | ||
` | ||
case 'outlined-secondary': | ||
return ` | ||
border | ||
border-north-sea-100 | ||
text-black-80 | ||
hover:bg-slate-blue-100 | ||
hover:text-white-100 | ||
focus:outline-none | ||
focus-visible:outline-slate-blue-95 | ||
dark:text-white-100 | ||
dark:border-white-100 | ||
dark:hover:bg-white-transparent | ||
dark:focus-visible:outline-white-100 | ||
` | ||
case 'contained-secondary': | ||
return `bg-slate-blue-95 | ||
text-white-100 | ||
hover:bg-slate-blue-100 | ||
hover:text-white-100 | ||
focus:outline-none | ||
focus-visible:outline-slate-blue-95 | ||
` | ||
case 'contained': | ||
default: | ||
return `bg-norwegian-woods-100 | ||
text-white-100 | ||
hover:bg-moss-green-100 | ||
focus:outline-none | ||
focus-visible:outline-norwegian-woods-100 | ||
dark:bg-white-100 | ||
dark:hover:bg-norwegian-woods-40 | ||
dark:text-slate-80 | ||
dark:focus-visible:outline-white-100 | ||
` | ||
} | ||
} | ||
|
||
export type ButtonProps = { | ||
/** Specifies which variant to use */ | ||
variant?: Variants | ||
/** Type of button | ||
* @default 'button' | ||
*/ | ||
type?: string | ||
/** Should make our own Icon component ? */ | ||
icon?: IconType | ||
} & ButtonHTMLAttributes<HTMLButtonElement> | ||
|
||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>( | ||
({ variant = 'contained', type = 'button', children, icon: Icon, className = '', ...rest }, ref) => { | ||
const variantClassNames = getVariant(variant) | ||
|
||
const buttonClassNames = envisTwMerge( | ||
commonButtonStyling, | ||
variantClassNames, | ||
`${Icon ? 'flex gap-2' : ''}`, | ||
className, | ||
) | ||
|
||
return ( | ||
<button ref={ref} type={type} className={buttonClassNames} {...rest}> | ||
{Icon && <Icon />} | ||
{children} | ||
</button> | ||
) | ||
}, | ||
) | ||
export { Button, commonButtonStyling, getVariant, type ButtonProps } from './Button' | ||
export { LinkButton, type LinkButtonProps } from './LinkButton' |
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.