vitamin-web icon indicating copy to clipboard operation
vitamin-web copied to clipboard

feat(@vtmn/svelte, @vtmn/react): added `onClose` and `onOpen` directives on both React & Svelte `VtmnAccordion` components

Open DKT-cdrag opened this issue 1 year ago • 8 comments

FEAT - Added onOpen onClose callback events on both React and Svelte Accordion components

Changes description

  • Added on:close and on:open directives on Svelte Accordion component
  • Added onClose and onOpen props on React Accordion component

Context

In a project hosting Decathlon Design System components, the devs needed an Accordion which can call a callback whenever the user open / closes the Accordion

Checklist

  • [x] Tested on related showcases.
  • [x] Added unit testing on Svelte component

Does this introduce a breaking change?

No

Other information

Not sure about the implementation of the React component : I didn't want to override the current implementation (adding state etc), so I added a ref and a callback (without preventing the default behaviour), but I'm not sure about the onClose and onOpen parameter (event)

DKT-cdrag avatar Aug 03 '22 15:08 DKT-cdrag

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Aug 03 '22 15:08 CLAassistant

On the file packages/showcases/core/csf/components/structure/accordion.csf.js you can add close and open to add the new actions :)

Tlahey avatar Aug 03 '22 15:08 Tlahey

For some reason, on the Svelte package, I was unable to add the on:close & on:open directives into the events section, instead there are interpretated as regular props, leaving the events section empty.

image image

DKT-cdrag avatar Aug 05 '22 11:08 DKT-cdrag

For some reason, on the Svelte package, I was unable to add the on:close & on:open directives into the events section, instead there are interpretated as regular props, leaving the events section empty.

image image

Maybe you can override Storybook parameters? https://storybook.js.org/docs/react/api/csf

lauthieb avatar Aug 05 '22 11:08 lauthieb

Hi @DKT-cdrag, just converted to draft as @Tlahey give you some comments. Feel free to make this pr "ready for review" again when you will be ready for a new review. Thanks :)

lauthieb avatar Aug 19 '22 13:08 lauthieb

Hi @DKT-cdrag, are you okay to do these changes? Thanks :)

lauthieb avatar Aug 29 '22 12:08 lauthieb

Hello @DKT-cdrag

For your issue, you can check what we have done on the VtmnQuantity.stories.svelte

<script>
  import { action } from '@storybook/addon-actions';
</script>

<Story name="xxxxx" let:args>
  <VtmnAccordion
    summary="Item 1"
    class="accordion-stories"
    open
    on:close={action('close')}
    on:open={action('open')}
    {...args}
  >
    {args.slot}
  </VtmnAccordion>
</Story>

And update on your accordion.csf the the handles

export const parameters = {
  actions: {
    handles: ['mouseenter', 'click', 'focusin', 'focusout', 'on:close', 'on:open'],
  },
  design: {
    type: 'figma',
    url: 'https://www.figma.com/file/zDZIyayUlr1yTWrsi7cFoo/?node-id=8029%3A29057',
  },
};

enjoy :)

Tlahey avatar Sep 01 '22 11:09 Tlahey

Hello everyone,

The changes requested have been applied, I'll let you review those changes I figured out that the on:close and on:open were not displayed because the dispatch function had a ternary expression as the first argument, I just had to replace it into two distinct dispatches.

DKT-cdrag avatar Sep 21 '22 10:09 DKT-cdrag

@DKT-cdrag this PR is stale for weeks. In order to have visibility, can we close it for now, and you can reopen it when you will be available? Thanks :)

lauthieb avatar Oct 27 '22 21:10 lauthieb

@DKT-cdrag this PR is stale for weeks. In order to have visibility, can we close it for now, and you can reopen it when you will be available? Thanks :)

Hello all, as this PR is still stale & related to a community library, I propose to reopen it when you will have time to do this. Have a great day :) Laurent

lauthieb avatar Nov 04 '22 13:11 lauthieb