Skip to content

Feat/modal component #76

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

Merged
merged 3 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kleros/ui-components-library",
"version": "3.0.1",
"version": "3.1.2",
"description": "UI components library which implements the Kleros design system.",
"source": "./src/lib/index.ts",
"main": "./dist/esm/ui-components-library.js",
Expand Down
41 changes: 34 additions & 7 deletions src/lib/container/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,50 @@ import React from "react";
import { cn } from "../../utils";
import {
Modal as AriaModal,
Dialog,
ModalOverlay,
type DialogProps,
type ModalOverlayProps,
} from "react-aria-components";

interface ModalProps
extends Omit<ModalOverlayProps, "children">,
React.RefAttributes<HTMLDivElement> {
/** classname that applies to the modal overlay. */
modalOverlayClassname?: ModalOverlayProps["className"];
children?: DialogProps["children"];
}

/** A modal is an overlay element which blocks interaction with elements outside it. */
function Modal({
className,
modalOverlayClassname,
children,
...props
}: ModalOverlayProps & React.RefAttributes<HTMLDivElement>) {
}: Readonly<ModalProps>) {
return (
<AriaModal
<ModalOverlay
className={cn(
"bg-klerosUIComponentsWhiteBackground h-[200px] w-[328px]",
"rounded-base box-border",
className,
"fixed top-0 left-0 isolate",
"z-20 h-(--visual-viewport-height) w-full bg-black/[50%] backdrop-blur-md",
"flex items-center justify-center",
"entering:animate-[fadeIn_100ms_ease-out] exiting:animate-[fadeOut_100ms_ease-in]",
modalOverlayClassname,
)}
{...props}
>
{props.children}
</AriaModal>
<AriaModal {...props}>
<Dialog
className={cn(
"bg-klerosUIComponentsWhiteBackground h-[200px] w-[328px] outline-none",
"rounded-base box-border",
className,
)}
>
{children}
</Dialog>
</AriaModal>
</ModalOverlay>
);
}
export default Modal;
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export { default as Button } from "./button";

export { default as Card } from "./container/card";
export { default as Box } from "./container/box";
export { default as Modal } from "./container/modal";

export { default as DisplayLarge } from "./display/large";
export { default as DisplayIcon } from "./display/icon";
Expand Down
29 changes: 27 additions & 2 deletions src/stories/modal.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import type { Meta, StoryObj } from "@storybook/react";

import React, { useState } from "react";
import { IPreviewArgs } from "./utils";

import ModalComponent from "../lib/container/box";
import ModalComponent from "../lib/container/modal";
import { Button } from "../lib";

const meta = {
component: ModalComponent,
title: "Containers/Modal",
tags: ["autodocs"],
argTypes: {
isOpen: {
control: "boolean",
},
isDismissable: {
control: "boolean",
},
},
} satisfies Meta<typeof ModalComponent>;

export default meta;
Expand All @@ -19,5 +28,21 @@ export const Modal: Story = {
themeUI: "dark",
backgroundUI: "light",
className: "w-[500px]",
isDismissable: true,
},
render: function Render(args) {
const [isOpen, setOpen] = useState(false);
return (
<div>
<Button text="Press me!" onPress={() => setOpen(true)} />
<ModalComponent {...args} isOpen={isOpen} onOpenChange={setOpen}>
<div className="flex size-full items-center justify-center">
<p className="text-klerosUIComponentsPrimaryText font-semibold">
I am a Modal.
</p>
</div>
</ModalComponent>
</div>
);
},
};
2 changes: 1 addition & 1 deletion src/styles/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
--klerosUIComponentsBaseRadius: 3px;
}

:root[class="dark"] {
:root.dark {
--klerosUIComponentsName: dark;
--klerosUIComponentsPrimaryPurple: #7e1bd4;
--klerosUIComponentsSecondaryPurple: #b45fff;
Expand Down