-
Notifications
You must be signed in to change notification settings - Fork 54
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grammar nit: 'as' -> 'is' :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be simplified
propertyName => propertyName === 'key' || _.first(shorthandValue)[propertyName] === shorthandComponents.first().prop(propertyName)
|
||
describe('ButtonGroup', () => { | ||
isConformant(ButtonGroup) | ||
buttonGroupImplementsShorthandProp('buttons', Button) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/index.ts
Outdated
@@ -3,6 +3,7 @@ export { themes } | |||
|
|||
export { default as Accordion } from './components/Accordion' | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems that we have a problem here - as Chat
is exported as ChatMessage
. Could you, please, fix this? :)
@@ -6,6 +6,7 @@ export interface IButtonVariables { | |||
height: string | |||
minWidth: string | |||
maxWidth: string | |||
defaultBorderRadius: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?