diff --git a/src/ui/components/ButtonGroupChain.js b/src/ui/components/ButtonGroupChain.js new file mode 100644 index 000000000..0cbfa4789 --- /dev/null +++ b/src/ui/components/ButtonGroupChain.js @@ -0,0 +1,97 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + */ +import React, {Component} from 'react'; +import PropTypes from 'prop-types'; + +import styled from '../styled/index.js'; +import Glyph from './Glyph.js'; + +const IconContainer = styled('div')({ + width: 0, + zIndex: 1, + display: 'inline-flex', + alignItems: 'center', + pointerEvents: 'none', +}); + +const ButtonGroupChainContainer = styled('div')(props => ({ + display: 'inline-flex', + marginLeft: 10, + '&:first-child>*:not(:first-child):nth-child(odd)': { + paddingLeft: props.iconSize + 6, + }, + '&:first-child>*': { + borderRightStyle: 'none', + borderLeftStyle: 'none', + }, + '&:first-child>:first-child': { + borderLeftStyle: 'solid', + }, + '&:first-child>:last-child': { + borderRightStyle: 'solid', + }, +})); + +type Props = { + /** + * Children. + */ + children: React$Node, + /** + * Size of the button seperator icon in pixels. + */ + iconSize: 8 | 10 | 12 | 16 | 18 | 20 | 24 | 32, + /** + * Name of the icon seperating the buttons. Defaults to 'chevron-right'. + */ + icon?: string, +}; + +/** + * Groups a series of buttons together with + * a right-chevron icon to seperate them. + * Used to create a navigation heirarchy. + * + * ```jsx + * + * + * + * + * + * ``` + */ +export default class ButtonGroupChain extends Component { + getChildContext() { + return {inButtonGroup: true}; + } + + render() { + const {children, iconSize, icon} = this.props; + + return ( + + {React.Children.map(children, (child, idx) => { + if (idx === 0) { + return child; + } + return ( + <> + + + + {child} + + ); + })} + + ); + } +} + +ButtonGroupChain.childContextTypes = { + inButtonGroup: PropTypes.bool, +}; diff --git a/src/ui/index.js b/src/ui/index.js index 0aec53693..c0f4be16c 100644 --- a/src/ui/index.js +++ b/src/ui/index.js @@ -12,6 +12,7 @@ export { default as ButtonNavigationGroup, } from './components/ButtonNavigationGroup.js'; export {default as ButtonGroup} from './components/ButtonGroup.js'; +export {default as ButtonGroupChain} from './components/ButtonGroupChain.js'; // export {colors, darkColors, brandColors} from './components/colors.js';