feat(Button): added ButtonGroup component#179
Conversation
Codecov Report
@@ Coverage Diff @@
## master #179 +/- ##
=========================================
+ Coverage 67.09% 67.69% +0.6%
=========================================
Files 101 103 +2
Lines 1407 1461 +54
Branches 290 288 -2
=========================================
+ Hits 944 989 +45
- Misses 459 468 +9
Partials 4 4
Continue to review full report at Codecov.
|
# Conflicts: # CHANGELOG.md
|
@mnajdova we don't have common tests for collections in SUIR, so I think that Stardust doesn't have them, too. |
|
Got it, thanks @layershifter, will add one common test for the collectionShorthand. |
-updated ButtonGroup-test.tsx to confirm to the collection shorthand test
| expect(Component.propTypes[shorthandPropertyName]).toBeTruthy() | ||
| }) | ||
|
|
||
| test(`array of string values are handled as ${ |
There was a problem hiding this comment.
grammar nit: 'as' -> 'is' :)
There was a problem hiding this comment.
would also recommend to consider test renaming, to better indicate what is going on, something like 'array of string values is spread as ...'
There was a problem hiding this comment.
Agreed, it is better explained that way!
| const props = { [shorthandPropertyName]: shorthandValue } | ||
| const wrapper = mount(<Component {...props} />) | ||
|
|
||
| const shorthandComponentProps = wrapper.find(ShorthandComponent.displayName) |
There was a problem hiding this comment.
seems that name of the variable is not correct - due to wrapper.find(ShorthandComponent.displayName) returns a nodes wrapper, not props
There was a problem hiding this comment.
Thanks for the catch! I changed it in the other test and forgot about this one.. :)
| _.first(shorthandValue), | ||
| ).every( | ||
| propertyName => | ||
| propertyName === 'key' |
There was a problem hiding this comment.
can be simplified
propertyName => propertyName === 'key' || _.first(shorthandValue)[propertyName] === shorthandComponents.first().prop(propertyName)|
|
||
| describe('ButtonGroup', () => { | ||
| isConformant(ButtonGroup) | ||
| buttonGroupImplementsShorthandProp('buttons', Button) |
src/index.ts
Outdated
| export { default as Button } from './components/Button' | ||
| export { ButtonGroup } from './components/Button' | ||
| export { default as Chat } from './components/Chat' | ||
| export { default as ChatMessage } from './components/Chat' |
There was a problem hiding this comment.
seems that we have a problem here - as Chat is exported as ChatMessage. Could you, please, fix this? :)
| height: string | ||
| minWidth: string | ||
| maxWidth: string | ||
| defaultBorderRadius: string |
There was a problem hiding this comment.
are we using any different other than default one for Button? If not, we should probably consider to rename it to something like just borderRadius - what do you think?
There was a problem hiding this comment.
Yes, we have circularRadius as well, that is why this is named like that.
| class ButtonGroup extends UIComponent<Extendable<IButtonGroupProps>, any> { | ||
| public static displayName = 'ButtonGroup' | ||
|
|
||
| public static className = 'ui-button__buttons' |
There was a problem hiding this comment.
seems that BEM conventions are violated here - this reads as 'buttons' element inside 'ui-button' - but I would rather expect something simpler like 'ui-buttons' or 'ui-button-group'
There was a problem hiding this comment.
We have utility function for generating the className inside getComponentInfo.ts:
info.componentClassName = (info.isChild
? `ui-${info.parentDisplayName}__${info.subcomponentName.replace(
/Group$/,
`${info.parentDisplayName}s`,
)}`
: `ui-${info.displayName}`
).toLowerCase()
I was just following it in order to make the component conformant. Do you think we should change this logic?
There was a problem hiding this comment.
the logic of this function seems correct to me - the problem is that for info.parentDisplayName 'button' is used for the case of ButtonGroup, and this is semantically incorrect
There was a problem hiding this comment.
In the end, we decided that the components that contain Group inside the name should result into the main components class with appended 's' in the end (For the ButtonGroup it should be ui-buttons). We are doing this because we already had some logic for the Group components, and we can still keep the group components together with the main components that they represent.
| ) | ||
| } | ||
|
|
||
| getStyleForButtonIndex = (styles, buttons, idx) => { |
There was a problem hiding this comment.
it seems that logic of this function relies (semantically) only on isFirst and isLast flags - for the sake of making its interface lighter and more explicit, could we introduce these two instead of buttons and idx?
| Button.create(button, { | ||
| defaultProps: { | ||
| circular, | ||
| styles: { root: this.getStyleForButtonIndex(styles, buttons, idx) }, |
There was a problem hiding this comment.
this showcases the problem we currently have for variables as well (#162) - with current implementation approach we will have the same negative consequences for styles as the ones described there for variables. Lets consider to address this moment later
kuzhelov
left a comment
There was a problem hiding this comment.
please, take a look on comments before merging - nothing critical, though. Awesome job with introducing implementsCollectionShorthandProp 👍
-addressed comments on the PR
# Conflicts: # CHANGELOG.md # test/specs/components/Menu/Menu-test.tsx
-changed defaultBorderRadius to borderRadius in the button's variables
ButtonGroup
The ButtonGroup component, as part of the Button component, will be used to organize multiple buttons to apear together.
TODO
API Proposal
as?: any
children?: ReactChildren
circular?: boolean
This property is used for creating group of circular buttons
className?: string
content?: React.ReactNode
buttons?: ItemShorthand[]
Shorthand for setting the buttons that should appear in the group.
styles?: IComponentPartStylesInput
variables?: ComponentVariablesInput
Question
Do we have mechanism for testing collectionShorthand (list of itemShorthand). If not, should I create one and use for testing the buttons inside the ButtonGroup component?