Skip to content

Commit 1c79ca2

Browse files
authored
Merge pull request #76 from kleros/feat/modal-component
Feat/modal component
2 parents a994a51 + 59b5a66 commit 1c79ca2

File tree

5 files changed

+64
-11
lines changed

5 files changed

+64
-11
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kleros/ui-components-library",
3-
"version": "3.0.1",
3+
"version": "3.1.2",
44
"description": "UI components library which implements the Kleros design system.",
55
"source": "./src/lib/index.ts",
66
"main": "./dist/esm/ui-components-library.js",

src/lib/container/modal.tsx

+34-7
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,50 @@ import React from "react";
22
import { cn } from "../../utils";
33
import {
44
Modal as AriaModal,
5+
Dialog,
6+
ModalOverlay,
7+
type DialogProps,
58
type ModalOverlayProps,
69
} from "react-aria-components";
710

11+
interface ModalProps
12+
extends Omit<ModalOverlayProps, "children">,
13+
React.RefAttributes<HTMLDivElement> {
14+
/** classname that applies to the modal overlay. */
15+
modalOverlayClassname?: ModalOverlayProps["className"];
16+
children?: DialogProps["children"];
17+
}
18+
19+
/** A modal is an overlay element which blocks interaction with elements outside it. */
820
function Modal({
921
className,
22+
modalOverlayClassname,
23+
children,
1024
...props
11-
}: ModalOverlayProps & React.RefAttributes<HTMLDivElement>) {
25+
}: Readonly<ModalProps>) {
1226
return (
13-
<AriaModal
27+
<ModalOverlay
1428
className={cn(
15-
"bg-klerosUIComponentsWhiteBackground h-[200px] w-[328px]",
16-
"rounded-base box-border",
17-
className,
29+
"fixed top-0 left-0 isolate",
30+
"z-20 h-(--visual-viewport-height) w-full bg-black/[50%] backdrop-blur-md",
31+
"flex items-center justify-center",
32+
"entering:animate-[fadeIn_100ms_ease-out] exiting:animate-[fadeOut_100ms_ease-in]",
33+
modalOverlayClassname,
1834
)}
35+
{...props}
1936
>
20-
{props.children}
21-
</AriaModal>
37+
<AriaModal {...props}>
38+
<Dialog
39+
className={cn(
40+
"bg-klerosUIComponentsWhiteBackground h-[200px] w-[328px] outline-none",
41+
"rounded-base box-border",
42+
className,
43+
)}
44+
>
45+
{children}
46+
</Dialog>
47+
</AriaModal>
48+
</ModalOverlay>
2249
);
2350
}
2451
export default Modal;

src/lib/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export { default as Button } from "./button";
66

77
export { default as Card } from "./container/card";
88
export { default as Box } from "./container/box";
9+
export { default as Modal } from "./container/modal";
910

1011
export { default as DisplayLarge } from "./display/large";
1112
export { default as DisplayIcon } from "./display/icon";

src/stories/modal.stories.tsx

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import type { Meta, StoryObj } from "@storybook/react";
2-
2+
import React, { useState } from "react";
33
import { IPreviewArgs } from "./utils";
44

5-
import ModalComponent from "../lib/container/box";
5+
import ModalComponent from "../lib/container/modal";
6+
import { Button } from "../lib";
67

78
const meta = {
89
component: ModalComponent,
910
title: "Containers/Modal",
1011
tags: ["autodocs"],
12+
argTypes: {
13+
isOpen: {
14+
control: "boolean",
15+
},
16+
isDismissable: {
17+
control: "boolean",
18+
},
19+
},
1120
} satisfies Meta<typeof ModalComponent>;
1221

1322
export default meta;
@@ -19,5 +28,21 @@ export const Modal: Story = {
1928
themeUI: "dark",
2029
backgroundUI: "light",
2130
className: "w-[500px]",
31+
isDismissable: true,
32+
},
33+
render: function Render(args) {
34+
const [isOpen, setOpen] = useState(false);
35+
return (
36+
<div>
37+
<Button text="Press me!" onPress={() => setOpen(true)} />
38+
<ModalComponent {...args} isOpen={isOpen} onOpenChange={setOpen}>
39+
<div className="flex size-full items-center justify-center">
40+
<p className="text-klerosUIComponentsPrimaryText font-semibold">
41+
I am a Modal.
42+
</p>
43+
</div>
44+
</ModalComponent>
45+
</div>
46+
);
2247
},
2348
};

src/styles/theme.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
--klerosUIComponentsBaseRadius: 3px;
3535
}
3636

37-
:root[class="dark"] {
37+
:root.dark {
3838
--klerosUIComponentsName: dark;
3939
--klerosUIComponentsPrimaryPurple: #7e1bd4;
4040
--klerosUIComponentsSecondaryPurple: #b45fff;

0 commit comments

Comments
 (0)