diff --git a/platform/ui/src/components/ButtonGroup/ButtonGroup.jsx b/platform/ui/src/components/ButtonGroup/ButtonGroup.jsx new file mode 100644 index 000000000..bb9f3412a --- /dev/null +++ b/platform/ui/src/components/ButtonGroup/ButtonGroup.jsx @@ -0,0 +1,130 @@ +import React, { useRef } from 'react'; +import PropTypes from 'prop-types'; +import classnames from 'classnames'; + +const baseButtonClass = 'border'; +const roundedClasses = { + vertical: { + none: '', + small: 'first:rounded-t last:rounded-b', + medium: 'first:rounded-t-md last:rounded-b-md', + large: 'first:rounded-t-lg last:rounded-b-lg', + full: 'first:rounded-t-full last:rounded-b-full', + }, + horizontal: { + none: '', + small: 'first:rounded-l last:rounded-r', + medium: 'first:rounded-l-md last:rounded-r-md', + large: 'first:rounded-l-lg last:rounded-r-lg', + full: 'first:rounded-l-full last:rounded-r-full', + }, +}; + +const borderClasses = { + text: { + vertical: 'border-t-0 border-l-0 border-r-0 last:border-b-0', + horizontal: 'border-l-0 border-t-0 border-b-0 last:border-r-0', + }, + outlined: { + vertical: 'border border-b-0 last:border-b', + horizontal: 'border border-r-0 last:border-r', + }, + contained: { + vertical: 'border-t-0 border-l-0 border-r-0 last:border-b-0', + horizontal: 'border-l-0 border-t-0 border-b-0 last:border-r-0', + }, +}; + +const variantClasses = { + text: { + default: 'border-custom-aquaBright', + primary: 'border-custom-blue', + secondary: 'border-custom-violetPale', + white: 'border-white', + }, + outlined: { + default: '', + primary: '', + secondary: '', + white: '', + }, + contained: { + default: 'border-white', + primary: 'border-white', + secondary: 'border-white', + white: 'border-black', + }, +}; + +const orientationClasses = { + vertical: 'flex-col', + horizontal: 'flex-row', +}; + +const baseDisplayClass = 'inline-flex'; +const fullWidthDisplayClass = 'flex'; + +const ButtonGroup = ({ + children, + className, + disabled = false, + fullWidth = false, + color = 'default', + orientation = 'horizontal', + rounded = 'medium', + size = 'medium', + variant = 'outlined', + ...other +}) => { + const ref = useRef(null); + + const buttonClasses = classnames( + baseButtonClass, + borderClasses[variant] && borderClasses[variant][orientation], + variantClasses[variant] && variantClasses[variant][color], + roundedClasses[orientation] && roundedClasses[orientation][rounded] + ); + + return ( +
+ {React.Children.map(children, child => { + if (!React.isValidElement(child)) { + return null; + } + + return React.cloneElement(child, { + className: classnames(buttonClasses, child.props.className), + disabled: child.props.disabled || disabled, + color: child.props.color || color, + fullWidth, + rounded: 'none', + size: child.props.size || size, + variant: child.props.variant || variant, + }); + })} +
+ ); +}; + +ButtonGroup.propTypes = { + children: PropTypes.node.isRequired, + className: PropTypes.string, + color: PropTypes.oneOf(['default', 'inherit', 'primary', 'secondary']), + disabled: PropTypes.bool, + fullWidth: PropTypes.bool, + orientation: PropTypes.oneOf(['vertical', 'horizontal']), + rounded: PropTypes.oneOf(['none', 'small', 'medium', 'large', 'full']), + size: PropTypes.oneOf(['small', 'medium', 'large']), + variant: PropTypes.oneOf(['text', 'outlined', 'contained']), +}; + +export default ButtonGroup; diff --git a/platform/ui/src/components/ButtonGroup/ButtonGroup.mdx b/platform/ui/src/components/ButtonGroup/ButtonGroup.mdx new file mode 100644 index 000000000..b58904b1e --- /dev/null +++ b/platform/ui/src/components/ButtonGroup/ButtonGroup.mdx @@ -0,0 +1,120 @@ +--- +name: ButtonGroup +menu: Components +route: components/buttonGroup +--- + +import { Playground, Props } from 'docz'; +import Button from '../Button'; +import IconButton from '../IconButton'; +import ButtonGroup from './'; + +# ButtonGroup + +Group Button display buttons together sharing its configurations + +## Import + +```javascript +import { ButtonGroup } from '@ohfi/ui'; +``` + +## Basic button group + + +
+ + + + + + + + + + + + + + + +
+
+ +## Group sizes and colorss + + +
+ + + + + + + + + + + + + + + +
+
+ +## Group orientation + + +
+ + + + + + + + + + + + + + + +
+
+ +## Split Button + + +
+ + + + + + + + +
+
+ +## Properties + + diff --git a/platform/ui/src/components/ButtonGroup/index.js b/platform/ui/src/components/ButtonGroup/index.js new file mode 100644 index 000000000..14bddfeaa --- /dev/null +++ b/platform/ui/src/components/ButtonGroup/index.js @@ -0,0 +1,2 @@ +import ButtonGroup from './ButtonGroup'; +export default ButtonGroup; diff --git a/platform/ui/tailwind.config.js b/platform/ui/tailwind.config.js index 35be280c2..f46d23b23 100644 --- a/platform/ui/tailwind.config.js +++ b/platform/ui/tailwind.config.js @@ -665,9 +665,9 @@ module.exports = { backgroundSize: ['responsive'], borderCollapse: ['responsive'], borderColor: ['responsive', 'hover', 'focus', 'active'], - borderRadius: ['responsive', 'focus'], + borderRadius: ['responsive', 'focus', 'first', 'last'], borderStyle: ['responsive', 'focus'], - borderWidth: ['responsive', 'focus'], + borderWidth: ['responsive', 'focus', 'first', 'last'], boxShadow: ['responsive', 'hover', 'focus'], boxSizing: ['responsive'], cursor: ['responsive'],