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

Add onClick function in the AccordionData #516

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading