Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Feature 69 - ButtonsGroup [Dev] #81

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open

Feature 69 - ButtonsGroup [Dev] #81

wants to merge 8 commits into from

Conversation

danielvaldivv
Copy link
Contributor

Checklist ✅

Button One clicked

button1

Button Two clicked

button2

Button Three clicked

button3

resolves [#69]

@danielvaldivv danielvaldivv added documentation Improvements or additions to documentation components A components feature weight:5 something that need work labels Nov 23, 2021
@danielvaldivv danielvaldivv added this to the Sprint 5 - UI milestone Nov 23, 2021
@danielvaldivv danielvaldivv self-assigned this Nov 23, 2021
@danielvaldivv danielvaldivv changed the title Feature 69 Feature 69 - ButtonsGroup Component Nov 23, 2021
@danielvaldivv danielvaldivv changed the title Feature 69 - ButtonsGroup Component Feature 69 - ButtonsGroup [Dev] Nov 23, 2021
@danielvaldivv danielvaldivv added feature New feature or request documentation Improvements or additions to documentation weight:1 something that is easy to do and removed documentation Improvements or additions to documentation weight:5 something that need work labels Nov 23, 2021
import { PropTypes } from 'prop-types';

const useStyleSheet = createStyleSheet(
(theme, { borderWrapperComponent }) => ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

borderWrapperComponent? 🤔 this name makes me thinks that it is a component, but is a border radius unit right? maybe a name that specifies that? Like wrapperRadius?

import { ButtonsGroup } from '@platzily-ui/components';
import { useState, Fragment } from 'react';

.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont get this points 🤔, what are we trying to communicate here?

});

ButtonsGroup.propTypes = {
actions: PropTypes.oneOfType([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this prop type be different?

acions: PropTypes.arrayOf(PropTypes.shape({
      childrenButton: PropTypes.element,
      onClick: PropTypes.func,
      selected: PropTypes.boolean,
})).isRequired


return (
<div ref={ref} className={cx(classes.buttonsGroupWrapper, className)} {...otherProps}>
{state.map((button, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State needs to be an array always, so if the prop of actions is an object it will break.

<button
type="button"
key={index}
onClick={() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we abstract this to another function?

if (selectedButtonDefault <= (state.length - 1)) {
setState(state.map((element, indexMap) => (
(selectedButtonDefault === indexMap)
? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ternary can be avoided if you return the object this way:

return {
...element,
selected: index === indexMap
}


useEffect(() => {
if (selectedButtonDefault <= (state.length - 1)) {
setState(state.map((element, indexMap) => (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function does the same as setStateRender right?

const cornerButtonsGroup = (index) => {
let styleButton;
if (index === 0) { styleButton = classes.firstButtonStyle; }
if (index === (stateLength - 1)) { styleButton = classes.lastButtonStyle; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of doing this haha.

I would prefer:

if (index === (stateLength - 1)) {
    styleButton = classes.lastButtonStyle; 
}

return separationStyle;
};

function setStateRender(index) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is a good thing abstrating the selected style with this function, but that meas that in the actions the user should not send the selected key anymore right? Why dont we remove it?

import ButtonsGroup from './ButtonsGroup';

describe('@Components/ButtonsGroup', () => {
it('Given the ButtonsGroup Component, when the props provide borderWrapperComponent with a number then the ButtonsGroup component will take border-radius attribute', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add more tests here, we could test that for example the buttons rendered are the same length as the actions. And the last clicked button has the selected styles.

key={index}
onClick={() => {
setStateRender(index);
onClick();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We needs to pass the event to the onClick prop, lets send also the index of the button so the user can identify it.

@omarefg
Copy link
Contributor

omarefg commented Nov 27, 2021

@danielvaldivv can we link the issue associated to this PR?

@omarefg
Copy link
Contributor

omarefg commented Nov 27, 2021

Screenshot from 2021-11-27 10-27-31

Lets also fill the responsible please.

@danielvaldivv danielvaldivv linked an issue Nov 27, 2021 that may be closed by this pull request
2 tasks
@edanfesi edanfesi modified the milestones: Sprint 5 - UI, Sprint 6 - UI Dec 1, 2021
@edanfesi edanfesi added the carry-over-5 task that started in sprint 5 but it's not finished. label Dec 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
carry-over-5 task that started in sprint 5 but it's not finished. components A components feature documentation Improvements or additions to documentation feature New feature or request weight:1 something that is easy to do
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

Feature 69 - ButtonsGroup [Dev]
3 participants