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

Jim/74978/accordion component ts migration #39

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
653ef3e
refactor: convert accordion component to ts
jim-deriv Sep 6, 2022
6441f49
Merge branch 'master' into Jim/74978/accordion-component-ts-migration
jim-deriv Sep 6, 2022
f4dda15
Merge branch 'master' into Jim/74978/accordion-component-ts-migration
jim-deriv Sep 6, 2022
03c2888
Merge branch 'master' into Jim/74978/accordion-component-ts-migration
jim-deriv Sep 6, 2022
4146feb
Merge branch 'master' into Jim/74978/accordion-component-ts-migration
jim-deriv Sep 7, 2022
c19ec16
Merge branch 'master' into Jim/74978/accordion-component-ts-migration
jim-deriv Sep 8, 2022
2720b39
Merge branch 'master' into Jim/74978/accordion-component-ts-migration
jim-deriv Sep 14, 2022
82f1203
refactor: extend native html element and simplify type
jim-deriv Sep 14, 2022
bc79178
Merge branch 'Jim/74978/accordion-component-ts-migration' of github.c…
jim-deriv Sep 14, 2022
d70b189
Merge branch 'master' into Jim/74978/accordion-component-ts-migration
jim-deriv Sep 29, 2022
53f5d9e
Merge branch 'master' into Jim/74978/accordion-component-ts-migration
jim-deriv Sep 29, 2022
ef90c97
Merge branch 'master' into Jim/74978/accordion-component-ts-migration
jim-deriv Sep 29, 2022
0b772ea
Merge branch 'Jim/74978/accordion-component-ts-migration' of github.c…
jim-deriv Sep 30, 2022
ec82ba9
refactor: update type definition
jim-deriv Sep 30, 2022
ac2584a
Merge branch 'components-shared-ts-migration-parent' of github.com:ji…
jim-deriv Sep 30, 2022
9ae39fe
refactor: make prop optional and export component type
jim-deriv Oct 3, 2022
37b37e3
Merge branch 'components-shared-ts-migration-parent' of github.com:ji…
jim-deriv Oct 3, 2022
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
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 };