Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(collapse): added onToggleCallback prop on CollapseCardBase #727

Conversation

bernard-arnaud
Copy link
Contributor

@bernard-arnaud bernard-arnaud commented Oct 16, 2020

Related issue

Reference to the issue

Fix #721

Description of the issue

Accordion rewrites onToggle for CollapseCardBase, a possible solution is to add a callback function props that would be called after onToggle

Person(s) for reviewing proposed changes

You can add @mention here

Important

Before creating a pull request run unit tests

$ npm test

# watch for changes
$ npm test -- --watch

# For a specific file (e.g., in packages/context/__tests__/command.test.js)
$ npm test -- --watch packages/action

xballoy
xballoy previously approved these changes Oct 19, 2020
@xballoy
Copy link
Contributor

xballoy commented Oct 19, 2020

@bernard-arnaud can you rebase with master and push again to fix your CI issues?

@xballoy
Copy link
Contributor

xballoy commented Oct 20, 2020

@bernard-arnaud tu as un conflit, les stories ont été déplacées à coté des composants. Tu peux corriger et repush ? Merci !

@bernard-arnaud bernard-arnaud force-pushed the feature/collapse-accordion-callback branch from f028e79 to f8dfec5 Compare October 20, 2020 11:56
xballoy
xballoy previously approved these changes Oct 20, 2020
Copy link
Contributor

@youf-olivier youf-olivier left a comment

Choose a reason for hiding this comment

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

Je met en request Changes, y a des trucs qui me chagrinent.

Le temps de montrer ce qui me gène je la bloque :)

Copy link
Contributor

@youf-olivier youf-olivier left a comment

Choose a reason for hiding this comment

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

La correction doit se faire au niveau de l'accordeon.

Le but sera de mixer ta callback avec celle de l'accordeon dans lequel tu as :

export const AccordionBase = ({
  children,
  className,
  classModifier,
  handleToggle,
  collapses,
}: Props) => {
  const renderedChildren = React.Children.map(children, (child, index) => {
    return React.cloneElement(child, {
      ...child.props,
      index,
      onToggle: handleToggle,
      collapse:
        collapses[index] !== undefined
          ? collapses[index]
          : child.props.collapse,
      className: child.props.className,
      classModifier: child.props.classModifier,
    });
  });
  const componentClassName = ClassManager.getComponentClassName(
    className,
    classModifier,
    defaultClassName
  );
  return (
    <div
      className={componentClassName}
      role="tablist"
      aria-multiselectable="true">
      {renderedChildren}
    </div>
  );
};

Là on a deux choix.

Soit on choisi un des deux :

      onToggle: child.props.onToggle || handleToggle,

Soit on peut mixer et appeler les deux. Dans le style (Je dis bien le style, j'écris ça vite fais)

const mixCallback = (
  funcA: (e: HeaderToggleElement) => void,
  funcB: (e: HeaderToggleElement) => void
) =>  (e: HeaderToggleElement) =>{
  funcA && funcA(e);
  funcB && funcB(e);
};
// Plus loin
 onToggle: mixCallback(child.props.onToggle, handleToggle),

Ou alors on peut passer un tableau de callback... Ici apres la solution est open.

Si j'arrive a faire tourner le storybook (qui est pas gagné) je regarderai la meilleure solution selon moi, mais en l'état je pense qu'on peut revoir le truc.

Qu'en pensez vous ?

index,
})
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ca clairement ça me choque.

On a une grosse duplication. Pour moi le soucis doit pas se corriger ici.

Copy link
Contributor

Choose a reason for hiding this comment

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

C'est vrai que c'est plus propre comme ca. Sinon pour le storybook ca devrait fonctionner sans problème maintenant que la PR pour les migrer avec les composants est passée

@youf-olivier
Copy link
Contributor

Je viens de tester la méthode de mixage des fonctions. Elle permet d'utiliser le composant comme tu voulais l'utiliser à la base :

<Accordion
    classModifier={text('classModifier', '')}
    className={text('className', '')}
    onlyOne={boolean('onlyOne', true)}>
    <CollapseCardBase
      id="idcollaspe1"
      onToggle={action('onToggle')}>
      <CollapseCard.Header>
        {text(KNOBS_LABELS.collapse1.title, LABELS.collapse1.title)}
      </CollapseCard.Header>
      <CollapseCard.Body>
        {text(KNOBS_LABELS.collapse1.text, LABELS.collapse1.text)}
        <b>{text(KNOBS_LABELS.collapse1.textb, LABELS.collapse1.textb)}</b>
      </CollapseCard.Body>
    </CollapseCardBase>
  </Accordion>

image

xballoy
xballoy previously approved these changes Oct 21, 2020
youf-olivier
youf-olivier previously approved these changes Oct 21, 2020
@youf-olivier
Copy link
Contributor

Good Job

@youf-olivier
Copy link
Contributor

étrange, y a pas un précommit hook ?

@xballoy
Copy link
Contributor

xballoy commented Oct 21, 2020

Si il y a un hook, il ne se lancait pas avant mais j'ai fixé ca dans une autre PR qui a été mergée.

@xballoy
Copy link
Contributor

xballoy commented Oct 21, 2020

@youf-olivier @arnaudforaison vous pouvez merger car Sonar ne passera jamais (c'est un fork)

@arnaudforaison arnaudforaison merged commit 4f367fd into AxaFrance:master Oct 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CollapseCardBase] onToggle is never called
4 participants