@luscii-healthtech/web-ui 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AccordionItemProps } from "./AccordionItem";
|
|
3
|
+
export interface AccordionProps {
|
|
4
|
+
dataTestId?: string;
|
|
5
|
+
items: AccordionItemProps[];
|
|
6
|
+
className?: string;
|
|
7
|
+
isCollapsedByDefault?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const Accordion: React.VFC<AccordionProps>;
|
|
10
|
+
export default Accordion;
|
package/package.json
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { AccordionItem, AccordionItemProps } from "./AccordionItem";
|
|
4
|
+
|
|
5
|
+
export interface AccordionProps {
|
|
6
|
+
dataTestId?: string;
|
|
7
|
+
items: AccordionItemProps[];
|
|
8
|
+
className?: string;
|
|
9
|
+
isCollapsedByDefault?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const Accordion: React.VFC<AccordionProps> = ({
|
|
13
|
+
dataTestId,
|
|
14
|
+
isCollapsedByDefault = false,
|
|
15
|
+
items,
|
|
16
|
+
className,
|
|
17
|
+
}) => {
|
|
18
|
+
return (
|
|
19
|
+
<ul data-test-id={dataTestId} className={className}>
|
|
20
|
+
{items.map?.((item) => (
|
|
21
|
+
<AccordionItem
|
|
22
|
+
{...item}
|
|
23
|
+
key={item.id}
|
|
24
|
+
isCollapsedByDefault={
|
|
25
|
+
item.isCollapsedByDefault ?? isCollapsedByDefault
|
|
26
|
+
}
|
|
27
|
+
/>
|
|
28
|
+
))}
|
|
29
|
+
</ul>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default Accordion;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { useReducer } from "react";
|
|
2
|
+
import classNames from "classnames";
|
|
3
|
+
|
|
4
|
+
import { ChevronRightIcon } from "../Icons/ChevronRightIcon";
|
|
5
|
+
import { ChevronDownIcon } from "../Icons/ChevronDownIcon";
|
|
6
|
+
import Text from "../Text/Text";
|
|
7
|
+
|
|
8
|
+
export interface AccordionItemProps {
|
|
9
|
+
id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
content: React.ReactNode;
|
|
12
|
+
className?: string;
|
|
13
|
+
isCollapsedByDefault?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const AccordionItem: React.VFC<AccordionItemProps> = ({
|
|
17
|
+
id,
|
|
18
|
+
title,
|
|
19
|
+
content,
|
|
20
|
+
isCollapsedByDefault = false,
|
|
21
|
+
}) => {
|
|
22
|
+
const [isCollapsed, toggleIsCollapsed] = useReducer(
|
|
23
|
+
(state) => !state,
|
|
24
|
+
isCollapsedByDefault
|
|
25
|
+
);
|
|
26
|
+
const Chevron = isCollapsed ? ChevronRightIcon : ChevronDownIcon;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<li
|
|
30
|
+
className={"bg-white border-b last:border-b-0 border-slate-100"}
|
|
31
|
+
data-test-id={id}
|
|
32
|
+
>
|
|
33
|
+
<div
|
|
34
|
+
onClick={toggleIsCollapsed}
|
|
35
|
+
className={classNames(
|
|
36
|
+
"p-4 w-full flex flex-row space-x-4 select-none",
|
|
37
|
+
"cursor-pointer hover:bg-blue-50 transition-colors ease-in-out duration-300",
|
|
38
|
+
{
|
|
39
|
+
"border-b border-slate-100": !isCollapsed,
|
|
40
|
+
}
|
|
41
|
+
)}
|
|
42
|
+
>
|
|
43
|
+
<Chevron className={"text-slate-300"} />
|
|
44
|
+
<Text text={title} type={"lg-strong"} />
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<div className={classNames({ hidden: isCollapsed })}>{content}</div>
|
|
48
|
+
</li>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// This type is used to allow for other props to be injected into the component
|
|
2
|
-
// For instance, for a data-
|
|
2
|
+
// For instance, for a data-test-id or key
|
|
3
3
|
export interface RestPropped {
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
5
|
[key: string]: any;
|