Skip to content

Commit f23db88

Browse files
authored
Merge pull request #65 from forumone/tsc-fixes
Fix type errors
2 parents 42d48d2 + e9d2d3f commit f23db88

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

source/03-components/Accordion/Accordion.stories.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Meta, StoryObj } from '@storybook/react';
22
import parse from 'html-react-parser';
33
import AccordionComponent from './Accordion';
44
import accordionArgs from './accordion.yml';
5+
import { AccordionItemProps } from './AccordionItem';
56

67
const meta: Meta<typeof AccordionComponent> = {
78
title: 'Components/Accordion',
@@ -11,10 +12,18 @@ const meta: Meta<typeof AccordionComponent> = {
1112

1213
type Story = StoryObj<typeof AccordionComponent>;
1314

14-
accordionArgs.accordionItems = accordionArgs.accordionItems.map(item => {
15-
item.content = parse(item.content);
16-
return item;
17-
});
15+
accordionArgs.accordionItems = accordionArgs.accordionItems.map(
16+
(
17+
item:
18+
| (Omit<AccordionItemProps, 'content'> & { content: string })
19+
| AccordionItemProps,
20+
) => {
21+
if (typeof item.content === 'string') {
22+
item.content = parse(item.content) as string;
23+
}
24+
return item;
25+
},
26+
);
1827

1928
const Accordion: Story = {
2029
render: args => <AccordionComponent {...args} />,

source/03-components/Accordion/Accordion.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,25 @@ function Accordion({
3434
}, [accordionItemsStatus]);
3535

3636
const openAccordionItem = (items: AccordionItemProps[], index: number) => {
37-
return items.with(index, {
38-
...items[index],
39-
isOpen: true,
40-
});
37+
return [
38+
...items.slice(0, index),
39+
{
40+
...items[index],
41+
isOpen: true,
42+
},
43+
...items.slice(index + 1),
44+
];
4145
};
4246

4347
const closeAccordionItem = (items: AccordionItemProps[], index: number) => {
44-
return items.with(index, {
45-
...items[index],
46-
isOpen: false,
47-
});
48+
return [
49+
...items.slice(0, index),
50+
{
51+
...items[index],
52+
isOpen: false,
53+
},
54+
...items.slice(index + 1),
55+
];
4856
};
4957

5058
const handleClick = (id: string, isOpen = false) => {

source/03-components/Accordion/AccordionItem.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import clsx from 'clsx';
22
import { GessoComponent } from 'gesso';
3-
import { ElementType, MouseEventHandler, useEffect, useRef } from 'react';
3+
import {
4+
ElementType,
5+
MouseEventHandler,
6+
ReactElement,
7+
useEffect,
8+
useRef,
9+
} from 'react';
410
import styles from './accordion-item.module.css';
511
import { slideCollapse, slideExpand } from '../../06-utility/slide';
612

713
export interface AccordionItemProps extends GessoComponent {
814
id: string;
915
title: string;
10-
content: string;
16+
content: ReactElement;
1117
titleElement?: ElementType;
1218
isOpen?: boolean;
1319
accordionSpeed?: string;

source/06-utility/slide.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export const slideCollapse = (
3434
target.style.paddingBottom = '0';
3535
target.style.marginTop = '0';
3636
target.style.marginBottom = '0';
37-
target.style.marginHeight = 'auto';
3837

3938
window.requestAnimationFrame(() => {
4039
function hideTarget() {
@@ -70,7 +69,7 @@ export const slideCollapse = (
7069
*
7170
* @name slideExpand
7271
* @param {HTMLElement} target - The element expanding.
73-
* @param {integer} duration - The duration of the animation, defaults to gesso token standard.
72+
* @param {number} duration - The duration of the animation, defaults to gesso token standard.
7473
* @param {string} easing - The easing of the animation, defaults to gesso token ease-in-out.
7574
* @param {boolean} hideContent - Whether to hide collapsed content from screen readers, defaults to true.
7675
*/

0 commit comments

Comments
 (0)