This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
feat(Button): added ButtonGroup component #179
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f63a600
-added ButtonGroup component
105cbc9
-updated CHANGELOG
7112472
Merge branch 'master' into feat/button-group
abc813a
-added iconOnly in the buttons group example
e27e3c9
-added common test for collection shorthand
7320243
-added collection shorthand tests for the List and Menu components
be1e838
Merge branch 'master' into feat/button-group
526601e
-resolved merge conflicts
75ecf4f
-fixed generation of the className in the groups component
9453d62
Merge branch 'master' into feat/button-group
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
15 changes: 15 additions & 0 deletions
15
docs/src/examples/components/Button/Groups/ButtonGroupCircularExample.shorthand.tsx
This file contains hidden or 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,15 @@ | ||
| import React from 'react' | ||
| import { Button } from '@stardust-ui/react' | ||
|
|
||
| const ButtonGroupCircularExampleShorthand = () => ( | ||
| <Button.Group | ||
| circular | ||
| buttons={[ | ||
| { icon: 'book', type: 'primary' }, | ||
| { icon: 'coffee' }, | ||
| { icon: 'play', type: 'primary' }, | ||
| ]} | ||
| /> | ||
| ) | ||
|
|
||
| export default ButtonGroupCircularExampleShorthand |
14 changes: 14 additions & 0 deletions
14
docs/src/examples/components/Button/Groups/ButtonGroupExample.shorthand.tsx
This file contains hidden or 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,14 @@ | ||
| import React from 'react' | ||
| import { Button } from '@stardust-ui/react' | ||
|
|
||
| const ButtonGroupExampleShorthand = () => ( | ||
| <Button.Group | ||
| buttons={[ | ||
| { icon: 'book', iconOnly: true }, | ||
| { icon: 'coffee', iconOnly: true }, | ||
| { icon: 'play', iconOnly: true }, | ||
| ]} | ||
| /> | ||
| ) | ||
|
|
||
| export default ButtonGroupExampleShorthand |
This file contains hidden or 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,20 @@ | ||
| import React from 'react' | ||
| import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
| import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
|
||
| const Groups = () => ( | ||
| <ExampleSection title="Groups"> | ||
| <ComponentExample | ||
| title="Group" | ||
| description="Buttons can exist together as a group." | ||
| examplePath="components/Button/Groups/ButtonGroupExample" | ||
| /> | ||
| <ComponentExample | ||
| title="Circular group" | ||
| description="Buttons inside a group can be styled as circular." | ||
| examplePath="components/Button/Groups/ButtonGroupCircularExample" | ||
| /> | ||
| </ExampleSection> | ||
| ) | ||
|
|
||
| export default Groups |
This file contains hidden or 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 hidden or 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 hidden or 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,118 @@ | ||
| import * as PropTypes from 'prop-types' | ||
| import * as React from 'react' | ||
| import * as _ from 'lodash' | ||
|
|
||
| import { UIComponent, childrenExist, customPropTypes } from '../../lib' | ||
| import { ComponentVariablesInput, IComponentPartStylesInput } from '../../../types/theme' | ||
| import { Extendable, ItemShorthand, ReactChildren } from '../../../types/utils' | ||
| import Button from './Button' | ||
|
|
||
| export interface IButtonGroupProps { | ||
| as?: any | ||
| children?: ReactChildren | ||
| circular?: boolean | ||
| className?: string | ||
| content?: React.ReactNode | ||
| buttons?: ItemShorthand[] | ||
| styles?: IComponentPartStylesInput | ||
| variables?: ComponentVariablesInput | ||
| } | ||
|
|
||
| /** | ||
| * A button group. | ||
| */ | ||
| class ButtonGroup extends UIComponent<Extendable<IButtonGroupProps>, any> { | ||
| public static displayName = 'ButtonGroup' | ||
|
|
||
| public static className = 'ui-buttons' | ||
|
|
||
| public static propTypes = { | ||
| /** An element type to render as (string or function). */ | ||
| as: customPropTypes.as, | ||
|
|
||
| /** A button can take the width of its container. */ | ||
| buttons: customPropTypes.collectionShorthand, | ||
|
|
||
| /** Primary content. */ | ||
| children: PropTypes.node, | ||
|
|
||
| /** Additional classes. */ | ||
| className: PropTypes.string, | ||
|
|
||
| /** The buttons inside group can appear circular. */ | ||
| circular: PropTypes.bool, | ||
|
|
||
| /** Shorthand for primary content. */ | ||
| content: customPropTypes.contentShorthand, | ||
|
|
||
| /** Custom styles to be applied for component. */ | ||
| styles: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), | ||
|
|
||
| /** Custom variables to be applied for component. */ | ||
| variables: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), | ||
| } | ||
|
|
||
| static handledProps = [ | ||
| 'as', | ||
| 'buttons', | ||
| 'children', | ||
| 'circular', | ||
| 'className', | ||
| 'content', | ||
| 'styles', | ||
| 'variables', | ||
| ] | ||
|
|
||
| public static defaultProps = { | ||
| as: 'div', | ||
| } | ||
|
|
||
| public renderComponent({ | ||
| ElementType, | ||
| classes, | ||
| accessibility, | ||
| variables, | ||
| styles, | ||
| rest, | ||
| }): React.ReactNode { | ||
| const { children, content, buttons, circular } = this.props | ||
| if (_.isNil(buttons)) { | ||
| return ( | ||
| <ElementType {...rest} className={classes.root}> | ||
| {childrenExist(children) ? children : content} | ||
| </ElementType> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <ElementType {...rest} className={classes.root}> | ||
| {_.map(buttons, (button, idx) => | ||
| Button.create(button, { | ||
| defaultProps: { | ||
| circular, | ||
| styles: { | ||
| root: this.getStyleForButtonIndex(styles, idx === 0, idx === buttons.length - 1), | ||
| }, | ||
| }, | ||
| }), | ||
| )} | ||
| </ElementType> | ||
| ) | ||
| } | ||
|
|
||
| getStyleForButtonIndex = (styles, isFirst, isLast) => { | ||
| let resultStyles = {} | ||
| if (isFirst) { | ||
| resultStyles = styles.firstButton | ||
| } | ||
| if (isLast) { | ||
| resultStyles = { ...resultStyles, ...styles.lastButton } | ||
| } | ||
| if (!isFirst && !isLast) { | ||
| resultStyles = styles.middleButton | ||
| } | ||
| return resultStyles | ||
| } | ||
| } | ||
|
|
||
| export default ButtonGroup | ||
This file contains hidden or 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 +1,2 @@ | ||
| export { default } from './Button' | ||
| export { default as ButtonGroup } from './ButtonGroup' |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,32 @@ | ||
| import { IComponentPartStylesInput, ICSSInJSStyle } from '../../../../../types/theme' | ||
| import { IButtonGroupProps } from '../../../../components/Button/ButtonGroup' | ||
|
|
||
| const commonButtonsStyles = (circular: boolean) => ({ | ||
| ...(!circular && { | ||
| margin: '0px', | ||
| borderRadius: '0px', | ||
| }), | ||
| }) | ||
|
|
||
| const buttonGroupStyles: IComponentPartStylesInput = { | ||
| root: (): ICSSInJSStyle => ({}), | ||
| middleButton: ({ props: p }: { props: IButtonGroupProps; variables: any }) => ({ | ||
| ...commonButtonsStyles(p.circular), | ||
| }), | ||
| firstButton: ({ props: p, variables: v }: { props: IButtonGroupProps; variables: any }) => ({ | ||
| ...commonButtonsStyles(p.circular), | ||
| ...(!p.circular && { | ||
| borderTopLeftRadius: v.borderRadius, | ||
| borderBottomLeftRadius: v.borderRadius, | ||
| }), | ||
| }), | ||
| lastButton: ({ props: p, variables: v }: { props: IButtonGroupProps; variables: any }) => ({ | ||
| ...commonButtonsStyles(p.circular), | ||
| ...(!p.circular && { | ||
| borderTopRightRadius: v.borderRadius, | ||
| borderBottomRightRadius: v.borderRadius, | ||
| }), | ||
| }), | ||
| } | ||
|
|
||
| export default buttonGroupStyles |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.