ohif-viewer/platform/ui/src/components/Button/Button.jsx

144 lines
3.9 KiB
React
Raw Normal View History

feat: nuke UI project; start new with updated tooling BREAKING_CHANGE (#1468) BREAKING_CHANGE * initial structure for components rewrite * WIP Input * WIP Label * add button props * add label class name * fix dependency * new examples buttonModules & buttonEmotion + refac * clean up to merge initial code into base branch * remove unused file * extend default theme -- add new colors * chore: prettier formatting * chore: try to exclude feature branch PRs * chore: suggest toml syntax highlighting extension * chore: capture yarn.lock changes * docs: condense readme * chore: update deploy preview to build docz component library * chore: Add component library to deploy preview index * chore: fix invalid tailwindcss config * chore: try tweaking toml to kickstart preview * chore: revert * chore: fix formatting of file index * chore: don't waste precious build minutes on a broken build * chore: chmod build-and-deploy.sh * ci: nuke circleci until we need the workflows on master * debug lerna commands * remove redundant yarn commands * try nohoist * revert tests * attempt to resolve import issue * force update yarn lock * try new workarounds for yarn version * another workaround * shift vtk to extension repo deps * catch vtk addition * update lock * Try older yarn version * try again * debugging * fix: yarn doctor warnings * learn some life lessons from the yarn docs * clean up netlify.toml * clean up netlify.toml * yarn package doctor react-dom * yarn doctor: missing peer dep * yarn doctor, satisfying webpack loader peer deps * fix docz base path for deploy-preview * yarn docter: replaced prePublishOnly usage * More yarn doctoring * ignore .yarn directory * fix last yarn doctor warning * updated yarn lock Co-authored-by: Rodrigo Antinarelli <rodrigoantinarelli@gmail.com>
2020-03-02 19:37:00 +01:00
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
2020-03-04 23:16:51 +01:00
const baseClasses =
'min-w-md leading-none font-sans text-center justify-center items-center outline-none transition duration-300 ease-in-out focus:outline-none';
2020-03-04 23:16:51 +01:00
const defaults = {
feat: nuke UI project; start new with updated tooling BREAKING_CHANGE (#1468) BREAKING_CHANGE * initial structure for components rewrite * WIP Input * WIP Label * add button props * add label class name * fix dependency * new examples buttonModules & buttonEmotion + refac * clean up to merge initial code into base branch * remove unused file * extend default theme -- add new colors * chore: prettier formatting * chore: try to exclude feature branch PRs * chore: suggest toml syntax highlighting extension * chore: capture yarn.lock changes * docs: condense readme * chore: update deploy preview to build docz component library * chore: Add component library to deploy preview index * chore: fix invalid tailwindcss config * chore: try tweaking toml to kickstart preview * chore: revert * chore: fix formatting of file index * chore: don't waste precious build minutes on a broken build * chore: chmod build-and-deploy.sh * ci: nuke circleci until we need the workflows on master * debug lerna commands * remove redundant yarn commands * try nohoist * revert tests * attempt to resolve import issue * force update yarn lock * try new workarounds for yarn version * another workaround * shift vtk to extension repo deps * catch vtk addition * update lock * Try older yarn version * try again * debugging * fix: yarn doctor warnings * learn some life lessons from the yarn docs * clean up netlify.toml * clean up netlify.toml * yarn package doctor react-dom * yarn doctor: missing peer dep * yarn doctor, satisfying webpack loader peer deps * fix docz base path for deploy-preview * yarn docter: replaced prePublishOnly usage * More yarn doctoring * ignore .yarn directory * fix last yarn doctor warning * updated yarn lock Co-authored-by: Rodrigo Antinarelli <rodrigoantinarelli@gmail.com>
2020-03-02 19:37:00 +01:00
variant: 'contained',
color: 'default',
2020-02-28 19:31:42 +01:00
size: 'medium',
feat: nuke UI project; start new with updated tooling BREAKING_CHANGE (#1468) BREAKING_CHANGE * initial structure for components rewrite * WIP Input * WIP Label * add button props * add label class name * fix dependency * new examples buttonModules & buttonEmotion + refac * clean up to merge initial code into base branch * remove unused file * extend default theme -- add new colors * chore: prettier formatting * chore: try to exclude feature branch PRs * chore: suggest toml syntax highlighting extension * chore: capture yarn.lock changes * docs: condense readme * chore: update deploy preview to build docz component library * chore: Add component library to deploy preview index * chore: fix invalid tailwindcss config * chore: try tweaking toml to kickstart preview * chore: revert * chore: fix formatting of file index * chore: don't waste precious build minutes on a broken build * chore: chmod build-and-deploy.sh * ci: nuke circleci until we need the workflows on master * debug lerna commands * remove redundant yarn commands * try nohoist * revert tests * attempt to resolve import issue * force update yarn lock * try new workarounds for yarn version * another workaround * shift vtk to extension repo deps * catch vtk addition * update lock * Try older yarn version * try again * debugging * fix: yarn doctor warnings * learn some life lessons from the yarn docs * clean up netlify.toml * clean up netlify.toml * yarn package doctor react-dom * yarn doctor: missing peer dep * yarn doctor, satisfying webpack loader peer deps * fix docz base path for deploy-preview * yarn docter: replaced prePublishOnly usage * More yarn doctoring * ignore .yarn directory * fix last yarn doctor warning * updated yarn lock Co-authored-by: Rodrigo Antinarelli <rodrigoantinarelli@gmail.com>
2020-03-02 19:37:00 +01:00
radius: 'medium',
disabled: false,
type: 'button',
};
feat: nuke UI project; start new with updated tooling BREAKING_CHANGE (#1468) BREAKING_CHANGE * initial structure for components rewrite * WIP Input * WIP Label * add button props * add label class name * fix dependency * new examples buttonModules & buttonEmotion + refac * clean up to merge initial code into base branch * remove unused file * extend default theme -- add new colors * chore: prettier formatting * chore: try to exclude feature branch PRs * chore: suggest toml syntax highlighting extension * chore: capture yarn.lock changes * docs: condense readme * chore: update deploy preview to build docz component library * chore: Add component library to deploy preview index * chore: fix invalid tailwindcss config * chore: try tweaking toml to kickstart preview * chore: revert * chore: fix formatting of file index * chore: don't waste precious build minutes on a broken build * chore: chmod build-and-deploy.sh * ci: nuke circleci until we need the workflows on master * debug lerna commands * remove redundant yarn commands * try nohoist * revert tests * attempt to resolve import issue * force update yarn lock * try new workarounds for yarn version * another workaround * shift vtk to extension repo deps * catch vtk addition * update lock * Try older yarn version * try again * debugging * fix: yarn doctor warnings * learn some life lessons from the yarn docs * clean up netlify.toml * clean up netlify.toml * yarn package doctor react-dom * yarn doctor: missing peer dep * yarn doctor, satisfying webpack loader peer deps * fix docz base path for deploy-preview * yarn docter: replaced prePublishOnly usage * More yarn doctoring * ignore .yarn directory * fix last yarn doctor warning * updated yarn lock Co-authored-by: Rodrigo Antinarelli <rodrigoantinarelli@gmail.com>
2020-03-02 19:37:00 +01:00
const radiusClasses = {
none: '',
feat: nuke UI project; start new with updated tooling BREAKING_CHANGE (#1468) BREAKING_CHANGE * initial structure for components rewrite * WIP Input * WIP Label * add button props * add label class name * fix dependency * new examples buttonModules & buttonEmotion + refac * clean up to merge initial code into base branch * remove unused file * extend default theme -- add new colors * chore: prettier formatting * chore: try to exclude feature branch PRs * chore: suggest toml syntax highlighting extension * chore: capture yarn.lock changes * docs: condense readme * chore: update deploy preview to build docz component library * chore: Add component library to deploy preview index * chore: fix invalid tailwindcss config * chore: try tweaking toml to kickstart preview * chore: revert * chore: fix formatting of file index * chore: don't waste precious build minutes on a broken build * chore: chmod build-and-deploy.sh * ci: nuke circleci until we need the workflows on master * debug lerna commands * remove redundant yarn commands * try nohoist * revert tests * attempt to resolve import issue * force update yarn lock * try new workarounds for yarn version * another workaround * shift vtk to extension repo deps * catch vtk addition * update lock * Try older yarn version * try again * debugging * fix: yarn doctor warnings * learn some life lessons from the yarn docs * clean up netlify.toml * clean up netlify.toml * yarn package doctor react-dom * yarn doctor: missing peer dep * yarn doctor, satisfying webpack loader peer deps * fix docz base path for deploy-preview * yarn docter: replaced prePublishOnly usage * More yarn doctoring * ignore .yarn directory * fix last yarn doctor warning * updated yarn lock Co-authored-by: Rodrigo Antinarelli <rodrigoantinarelli@gmail.com>
2020-03-02 19:37:00 +01:00
small: 'rounded-sm',
medium: 'rounded-md',
large: 'rounded-lg',
full: 'rounded-full',
};
const disabledClasses = {
true: 'cursor-not-allowed',
false: '',
};
const variantClasses = {
text: {
2020-03-04 23:16:51 +01:00
default:
2020-04-02 20:52:41 +02:00
'text-primary-light hover:bg-primary-light hover:text-white active:opacity-80 focus:bg-primary-light focus:text-white',
2020-03-04 23:16:51 +01:00
primary:
2020-04-02 20:52:41 +02:00
'text-primary-main hover:bg-primary-main hover:text-white active:opacity-80 focus:bg-primary-main focus:text-white',
2020-03-04 23:16:51 +01:00
secondary:
2020-04-02 20:52:41 +02:00
'text-secondary-light hover:bg-secondary-light hover:text-white active:opacity-80 focus:bg-secondary-light focus:text-white',
2020-03-04 23:16:51 +01:00
white:
'text-white hover:bg-white hover:text-black active:opacity-80 focus:bg-white focus:text-black',
},
outlined: {
2020-03-04 23:16:51 +01:00
default:
2020-04-02 20:52:41 +02:00
'border bg-trasparent border-primary-light text-primary-light hover:bg-primary-light hover:text-black focus:text-black focus:bg-primary-light active:opacity-80',
2020-03-04 23:16:51 +01:00
primary:
2020-04-02 20:52:41 +02:00
'border bg-transparent border-primary-main text-primary-main hover:opacity-80 active:opacity-100 focus:opacity-80',
2020-03-04 23:16:51 +01:00
secondary:
2020-04-02 20:52:41 +02:00
'border bg-transparent border-secondary-light text-secondary-light hover:opacity-80 active:opacity-100 focus:opacity-80',
2020-03-04 23:16:51 +01:00
white:
'border bg-transparent border-white text-white hover:opacity-80 active:opacity-100 focus:opacity-80',
},
contained: {
2020-03-04 23:16:51 +01:00
default:
2020-04-02 20:52:41 +02:00
'bg-primary-light text-black hover:opacity-80 active:opacity-100 focus:opacity-80',
2020-03-04 23:16:51 +01:00
primary:
2020-04-02 20:52:41 +02:00
'bg-primary-main text-white hover:opacity-80 active:opacity-100 focus:opacity-80',
2020-03-04 23:16:51 +01:00
secondary:
2020-04-02 20:52:41 +02:00
'bg-secondary-light text-white hover:opacity-80 active:opacity-100 focus:opacity-80',
2020-03-04 23:16:51 +01:00
white:
'bg-white text-black hover:opacity-80 active:opacity-100 focus:opacity-80',
},
};
const sizeClasses = {
small: 'py-2 px-2 text-sm',
2020-03-04 23:16:51 +01:00
medium: 'py-2 px-2 text-lg',
large: 'py-2 px-6 text-xl',
};
const fullWidthClasses = {
true: 'flex w-full',
false: 'inline-flex',
};
const Button = ({
children,
variant = defaults.variant,
color = defaults.color,
size = defaults.size,
feat: nuke UI project; start new with updated tooling BREAKING_CHANGE (#1468) BREAKING_CHANGE * initial structure for components rewrite * WIP Input * WIP Label * add button props * add label class name * fix dependency * new examples buttonModules & buttonEmotion + refac * clean up to merge initial code into base branch * remove unused file * extend default theme -- add new colors * chore: prettier formatting * chore: try to exclude feature branch PRs * chore: suggest toml syntax highlighting extension * chore: capture yarn.lock changes * docs: condense readme * chore: update deploy preview to build docz component library * chore: Add component library to deploy preview index * chore: fix invalid tailwindcss config * chore: try tweaking toml to kickstart preview * chore: revert * chore: fix formatting of file index * chore: don't waste precious build minutes on a broken build * chore: chmod build-and-deploy.sh * ci: nuke circleci until we need the workflows on master * debug lerna commands * remove redundant yarn commands * try nohoist * revert tests * attempt to resolve import issue * force update yarn lock * try new workarounds for yarn version * another workaround * shift vtk to extension repo deps * catch vtk addition * update lock * Try older yarn version * try again * debugging * fix: yarn doctor warnings * learn some life lessons from the yarn docs * clean up netlify.toml * clean up netlify.toml * yarn package doctor react-dom * yarn doctor: missing peer dep * yarn doctor, satisfying webpack loader peer deps * fix docz base path for deploy-preview * yarn docter: replaced prePublishOnly usage * More yarn doctoring * ignore .yarn directory * fix last yarn doctor warning * updated yarn lock Co-authored-by: Rodrigo Antinarelli <rodrigoantinarelli@gmail.com>
2020-03-02 19:37:00 +01:00
radius = defaults.radius,
disabled = defaults.disabled,
type = defaults.type,
2020-03-02 20:10:51 +01:00
fullWidth = defaults.fullWidth,
startIcon: startIconProp,
endIcon: endIconProp,
className,
...rest
}) => {
feat: nuke UI project; start new with updated tooling BREAKING_CHANGE (#1468) BREAKING_CHANGE * initial structure for components rewrite * WIP Input * WIP Label * add button props * add label class name * fix dependency * new examples buttonModules & buttonEmotion + refac * clean up to merge initial code into base branch * remove unused file * extend default theme -- add new colors * chore: prettier formatting * chore: try to exclude feature branch PRs * chore: suggest toml syntax highlighting extension * chore: capture yarn.lock changes * docs: condense readme * chore: update deploy preview to build docz component library * chore: Add component library to deploy preview index * chore: fix invalid tailwindcss config * chore: try tweaking toml to kickstart preview * chore: revert * chore: fix formatting of file index * chore: don't waste precious build minutes on a broken build * chore: chmod build-and-deploy.sh * ci: nuke circleci until we need the workflows on master * debug lerna commands * remove redundant yarn commands * try nohoist * revert tests * attempt to resolve import issue * force update yarn lock * try new workarounds for yarn version * another workaround * shift vtk to extension repo deps * catch vtk addition * update lock * Try older yarn version * try again * debugging * fix: yarn doctor warnings * learn some life lessons from the yarn docs * clean up netlify.toml * clean up netlify.toml * yarn package doctor react-dom * yarn doctor: missing peer dep * yarn doctor, satisfying webpack loader peer deps * fix docz base path for deploy-preview * yarn docter: replaced prePublishOnly usage * More yarn doctoring * ignore .yarn directory * fix last yarn doctor warning * updated yarn lock Co-authored-by: Rodrigo Antinarelli <rodrigoantinarelli@gmail.com>
2020-03-02 19:37:00 +01:00
const baseClasses =
'inline-flex items-center outline-none transition duration-300 ease-in-out font-bold focus:outline-none';
2020-02-28 19:31:42 +01:00
feat: nuke UI project; start new with updated tooling BREAKING_CHANGE (#1468) BREAKING_CHANGE * initial structure for components rewrite * WIP Input * WIP Label * add button props * add label class name * fix dependency * new examples buttonModules & buttonEmotion + refac * clean up to merge initial code into base branch * remove unused file * extend default theme -- add new colors * chore: prettier formatting * chore: try to exclude feature branch PRs * chore: suggest toml syntax highlighting extension * chore: capture yarn.lock changes * docs: condense readme * chore: update deploy preview to build docz component library * chore: Add component library to deploy preview index * chore: fix invalid tailwindcss config * chore: try tweaking toml to kickstart preview * chore: revert * chore: fix formatting of file index * chore: don't waste precious build minutes on a broken build * chore: chmod build-and-deploy.sh * ci: nuke circleci until we need the workflows on master * debug lerna commands * remove redundant yarn commands * try nohoist * revert tests * attempt to resolve import issue * force update yarn lock * try new workarounds for yarn version * another workaround * shift vtk to extension repo deps * catch vtk addition * update lock * Try older yarn version * try again * debugging * fix: yarn doctor warnings * learn some life lessons from the yarn docs * clean up netlify.toml * clean up netlify.toml * yarn package doctor react-dom * yarn doctor: missing peer dep * yarn doctor, satisfying webpack loader peer deps * fix docz base path for deploy-preview * yarn docter: replaced prePublishOnly usage * More yarn doctoring * ignore .yarn directory * fix last yarn doctor warning * updated yarn lock Co-authored-by: Rodrigo Antinarelli <rodrigoantinarelli@gmail.com>
2020-03-02 19:37:00 +01:00
const startIcon = startIconProp && (
<div className="mr-2">{startIconProp}</div>
);
2020-04-02 20:52:41 +02:00
const handleOnClick = e => {
buttonElement.current.blur();
if (rest.onClick) {
rest.onClick(e);
}
};
return (
<button
className={classnames(
className,
baseClasses,
variantClasses[variant][color],
feat: nuke UI project; start new with updated tooling BREAKING_CHANGE (#1468) BREAKING_CHANGE * initial structure for components rewrite * WIP Input * WIP Label * add button props * add label class name * fix dependency * new examples buttonModules & buttonEmotion + refac * clean up to merge initial code into base branch * remove unused file * extend default theme -- add new colors * chore: prettier formatting * chore: try to exclude feature branch PRs * chore: suggest toml syntax highlighting extension * chore: capture yarn.lock changes * docs: condense readme * chore: update deploy preview to build docz component library * chore: Add component library to deploy preview index * chore: fix invalid tailwindcss config * chore: try tweaking toml to kickstart preview * chore: revert * chore: fix formatting of file index * chore: don't waste precious build minutes on a broken build * chore: chmod build-and-deploy.sh * ci: nuke circleci until we need the workflows on master * debug lerna commands * remove redundant yarn commands * try nohoist * revert tests * attempt to resolve import issue * force update yarn lock * try new workarounds for yarn version * another workaround * shift vtk to extension repo deps * catch vtk addition * update lock * Try older yarn version * try again * debugging * fix: yarn doctor warnings * learn some life lessons from the yarn docs * clean up netlify.toml * clean up netlify.toml * yarn package doctor react-dom * yarn doctor: missing peer dep * yarn doctor, satisfying webpack loader peer deps * fix docz base path for deploy-preview * yarn docter: replaced prePublishOnly usage * More yarn doctoring * ignore .yarn directory * fix last yarn doctor warning * updated yarn lock Co-authored-by: Rodrigo Antinarelli <rodrigoantinarelli@gmail.com>
2020-03-02 19:37:00 +01:00
radiusClasses[radius],
sizeClasses[size],
fullWidthClasses[fullWidth],
disabledClasses[disabled]
)}
type={type}
{...rest}
>
{startIcon}
{children}
{endIcon}
</button>
);
};
Button.propTypes = {
2020-02-14 23:46:27 +01:00
children: PropTypes.node,
size: PropTypes.oneOf(['small', 'medium', 'large']),
feat: nuke UI project; start new with updated tooling BREAKING_CHANGE (#1468) BREAKING_CHANGE * initial structure for components rewrite * WIP Input * WIP Label * add button props * add label class name * fix dependency * new examples buttonModules & buttonEmotion + refac * clean up to merge initial code into base branch * remove unused file * extend default theme -- add new colors * chore: prettier formatting * chore: try to exclude feature branch PRs * chore: suggest toml syntax highlighting extension * chore: capture yarn.lock changes * docs: condense readme * chore: update deploy preview to build docz component library * chore: Add component library to deploy preview index * chore: fix invalid tailwindcss config * chore: try tweaking toml to kickstart preview * chore: revert * chore: fix formatting of file index * chore: don't waste precious build minutes on a broken build * chore: chmod build-and-deploy.sh * ci: nuke circleci until we need the workflows on master * debug lerna commands * remove redundant yarn commands * try nohoist * revert tests * attempt to resolve import issue * force update yarn lock * try new workarounds for yarn version * another workaround * shift vtk to extension repo deps * catch vtk addition * update lock * Try older yarn version * try again * debugging * fix: yarn doctor warnings * learn some life lessons from the yarn docs * clean up netlify.toml * clean up netlify.toml * yarn package doctor react-dom * yarn doctor: missing peer dep * yarn doctor, satisfying webpack loader peer deps * fix docz base path for deploy-preview * yarn docter: replaced prePublishOnly usage * More yarn doctoring * ignore .yarn directory * fix last yarn doctor warning * updated yarn lock Co-authored-by: Rodrigo Antinarelli <rodrigoantinarelli@gmail.com>
2020-03-02 19:37:00 +01:00
radius: PropTypes.oneOf(['none', 'small', 'medium', 'large', 'full']),
variant: PropTypes.oneOf(['text', 'outlined', 'contained']),
color: PropTypes.oneOf([
'default',
'primary',
'secondary',
'white',
'inherit',
]),
fullWidth: PropTypes.bool,
2020-02-14 23:46:27 +01:00
disabled: PropTypes.bool,
type: PropTypes.string,
startIcon: PropTypes.node,
endIcon: PropTypes.node,
2020-03-03 23:36:22 +01:00
className: PropTypes.string,
};
export default Button;