Skip to content

Commit

Permalink
Merge pull request #39 from jim-deriv/Jim/74978/accordion-component-t…
Browse files Browse the repository at this point in the history
…s-migration

Jim/74978/accordion component ts migration
  • Loading branch information
jim-deriv authored Oct 3, 2022
2 parents 898b8c4 + 37b37e3 commit c47c0c4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import { usePrevious } from '../../hooks';
import Icon from '../icon';
import { TAccordionProps } from '../types';

const Accordion = ({ className, icon_close, icon_open, list }) => {
const [open_idx, setOpenIdx] = React.useState(null);
const Accordion = ({ className, icon_close, icon_open, list }: TAccordionProps) => {
const [open_idx, setOpenIdx] = React.useState<number | null>(null);

const prev_list = usePrevious(list);

Expand All @@ -14,7 +14,7 @@ const Accordion = ({ className, icon_close, icon_open, list }) => {
}, [list, prev_list]);

// close if clicking the accordion that's open, otherwise open the new one
const onClick = index => setOpenIdx(index === open_idx ? null : index);
const onClick = (index: number) => setOpenIdx(index === open_idx ? null : index);

return (
<div className={classNames('dc-accordion__wrapper', className)}>
Expand Down Expand Up @@ -47,11 +47,4 @@ const Accordion = ({ className, icon_close, icon_open, list }) => {
);
};

Accordion.propTypes = {
className: PropTypes.string,
icon_close: PropTypes.string,
icon_open: PropTypes.string,
list: PropTypes.arrayOf(PropTypes.object),
};

export default Accordion;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Accordion from './accordion.jsx';
import Accordion from './accordion';
import './accordion.scss';

export default Accordion;
11 changes: 11 additions & 0 deletions packages/components/src/components/types/accordion.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type TAccordionItem = Array<{
header: string;
content: React.ReactNode;
}>;

export type TAccordionProps = {
className?: string;
icon_close?: string;
icon_open?: string;
list: TAccordionItem;
};
3 changes: 2 additions & 1 deletion packages/components/src/components/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TIconsManifest, TIconProps } from './icons.types';
import { TAccordionProps, TAccordionItem } from './accordion.types';

export type { TIconsManifest, TIconProps };
export type { TIconsManifest, TIconProps, TAccordionProps, TAccordionItem };

0 comments on commit c47c0c4

Please sign in to comment.