Skip to content

Commit

Permalink
Merge pull request #516 from ably/Accordion_add_onClick
Browse files Browse the repository at this point in the history
Add onClick function in the AccordionData
  • Loading branch information
aralovelace authored Oct 23, 2024
2 parents 625f86d + 3c8dadf commit c7893e5
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ably/ui",
"version": "14.7.4",
"version": "14.7.5",
"description": "Home of the Ably design system library ([design.ably.com](https://design.ably.com)). It provides a showcase, development/test environment and a publishing pipeline for different distributables.",
"repository": {
"type": "git",
Expand Down
5 changes: 4 additions & 1 deletion src/core/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ const Accordion = ({
name={item.name}
rowIcon={item.icon}
open={fullyOpen ?? openIndexes.includes(currentIndex)}
onClick={() => handleSetIndex(currentIndex)}
onClick={() => {
handleSetIndex(currentIndex);
item.onClick?.(currentIndex);
}}
toggleIcons={icons}
theme={theme}
options={options}
Expand Down
20 changes: 20 additions & 0 deletions src/core/Accordion/Accordion.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ const longData = data.map((datum) => ({
),
}));

const dataWithCustomClickable = data.map((datum) => ({
...datum,
onClick: () => alert(`Custom onClick for ${datum.name} section`),
}));

const AccordionPresentation = ({ data, options }: AccordionProps) => (
<div className="grid sm:grid-cols-2 gap-16 w-full">
{accordionThemes
Expand Down Expand Up @@ -204,3 +209,18 @@ export const StaticAndFullyOpen = {
},
},
};

export const WithCustomOnClick = {
render: () =>
AccordionPresentation({
data: dataWithCustomClickable,
}),
parameters: {
docs: {
description: {
story:
"When you set an onClick entry, it will be called when the section is clicked. It will add an additional action to be performed apart from the open/close behavior.",
},
},
},
};
1 change: 1 addition & 0 deletions src/core/Accordion/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type AccordionData = {
name: string;
icon?: IconName;
content: ReactNode;
onClick?: (index: number) => void;
};

export type AccordionIcons = {
Expand Down
4 changes: 2 additions & 2 deletions src/core/icons/icon-display-chat-mono.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/core/icons/icon-display-data-broadcast-mono.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions src/core/icons/icon-display-equalisers-mono.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/core/icons/icon-display-push-notifications-mono.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions src/core/icons/icon-display-support-chat-mono.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c7893e5

Please sign in to comment.