Skip to content

Commit 12623fb

Browse files
committed
refactor: use modal header and modal footer as compound components
1 parent 82512d1 commit 12623fb

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

packages/components/modal/specs/index.snapshot.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { Modal, ModalFooter, ModalHeader } from "../src/index";
2+
import { Modal } from "../src/index";
33
import { LayersProvider } from "@react-ck/layers";
44
import { getActRender } from "@react-ck/jest-config";
55

@@ -8,8 +8,8 @@ describe("snapshot Modal", () => {
88
const component = await getActRender(
99
<LayersProvider>
1010
<Modal>
11-
<ModalHeader heading="Heading" />
12-
<ModalFooter>Footer</ModalFooter>
11+
<Modal.Header heading="Heading" />
12+
<Modal.Footer>Footer</Modal.Footer>
1313
</Modal>
1414
</LayersProvider>,
1515
);

packages/components/modal/specs/index.unit.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ describe("unit Modal", () => {
99
const content = "Modal";
1010
render(
1111
<LayersProvider>
12-
<Modal>{content}</Modal>
12+
<Modal.Header heading="Heading" />
13+
{content}
14+
<Modal.Footer>Footer</Modal.Footer>
1315
</LayersProvider>,
1416
);
1517
const find = await screen.findByText(content);

packages/components/modal/src/index.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/components/modal/src/Modal.tsx renamed to packages/components/modal/src/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { Icon } from "@react-ck/icon";
88
import { Button } from "@react-ck/button";
99
import { Text } from "@react-ck/text";
1010
import { Layer } from "@react-ck/layers";
11+
import { ModalHeader } from "./ModalHeader";
12+
import { ModalFooter } from "./ModalFooter";
1113

1214
/**
1315
* ModalProps interface represents the properties for the Modal component.
@@ -32,7 +34,7 @@ interface ModalProps extends React.HTMLAttributes<HTMLDivElement> {
3234
* @returns a React element
3335
*/
3436

35-
export const Modal = ({
37+
const Modal = ({
3638
open = true,
3739
dismissable = true,
3840
children,
@@ -120,3 +122,9 @@ export const Modal = ({
120122
)
121123
);
122124
};
125+
126+
Modal.Header = ModalHeader;
127+
128+
Modal.Footer = ModalFooter;
129+
130+
export { Modal, type ModalProps };

packages/docs/stories/src/modal.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Manager } from "@react-ck/manager";
44
import { faker } from "@faker-js/faker";
55
import { Text } from "@react-ck/text/src";
66
import { configureStory } from "@react-ck/story-config";
7-
import { Modal, ModalHeader, ModalFooter } from "@react-ck/modal/src";
7+
import { Modal } from "@react-ck/modal/src";
88
import { Button } from "@react-ck/button";
99

1010
type Story = StoryObj<typeof Modal>;
@@ -33,13 +33,13 @@ export const Component: Story = {
3333
args: {
3434
children: (
3535
<>
36-
<ModalHeader heading={faker.lorem.sentence(4)} />
36+
<Modal.Header heading={faker.lorem.sentence(4)} />
3737

3838
<Text>{faker.lorem.sentence(6)}</Text>
3939

40-
<ModalFooter>
40+
<Modal.Footer>
4141
<Button>{faker.lorem.word()}</Button>
42-
</ModalFooter>
42+
</Modal.Footer>
4343
</>
4444
),
4545
},

0 commit comments

Comments
 (0)