Skip to content

Commit aa78ea5

Browse files
committed
feat(dialog): update @halvaradop/ui-dialog package
- Resolve inconsistency by `Modal` component and `innerDialogVariants` - Rename `Modal` to `Dialog` - Rename `innerDialogVariants` to `modalVariants` * chore(docs): update `README.md` file
1 parent 701b2db commit aa78ea5

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

packages/ui-dialog/README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @halvaradop/ui-dialog
22

3-
The `@halvaradop/ui-dialog` is an accessible, reusable, and customizable `Modal` component that is part of the `@halvaradop/ui` library for React. Built with `React` and styled using `TailwindCSS`, it provides a set of pre-styled components designed to streamline and accelerate the development of user interfaces.
3+
The `@halvaradop/ui-dialog` is an accessible, reusable, and customizable `Dialog` component that is part of the `@halvaradop/ui` library for React. Built with `React` and styled using `TailwindCSS`, it provides a set of pre-styled components designed to streamline and accelerate the development of user interfaces.
44

55
## Installation
66

@@ -28,13 +28,13 @@ pnpm add @halvaradop/ui-dialog@beta
2828

2929
## Usage
3030

31-
The `Modal` component offers two additional props for customization: `variant` and `size`. Import the `Modal` component as shown below:
31+
The `Dialog` component does not accept any props; it simply applies default styles. Import the `Dialog` component as shown below:
3232

3333
```tsx
3434
"use client"
3535
import { useRef } from "react"
3636
import { Button } from "@halvaradop/ui-button"
37-
import { Modal, innerDialogVariants } from "@halvaradop/ui-dialog"
37+
import { Dialog, modalVariants } from "@halvaradop/ui-dialog"
3838

3939
export default function App() {
4040
const modalRef = useRef<HTMLDialogElement>(null)
@@ -50,23 +50,23 @@ export default function App() {
5050
return (
5151
<>
5252
<Button onClick={() => handleToggleModal(true)}>Open</Button>
53-
<Modal ref={modalRef}>
54-
<div className={innerDialogVariants({ variant: "fixed" })}>
53+
<Dialog ref={modalRef}>
54+
<div className={modalVariants({ variant: "fixed" })}>
5555
<div>Modal content</div>
5656
<Button className="mt-4" onClick={() => handleToggleModal(false)}>
5757
Close
5858
</Button>
5959
</div>
60-
</Modal>
60+
</Dialog>
6161
</>
6262
)
6363
}
6464
```
6565

6666
> [!TIP]
67-
> The `Modal` component represents the dialog HTML tag to create the window at the top layer. The `innerDialogVariants` function contains the styles for the content within the `Modal` component.
67+
> The `Dialog` component represents the dialog HTML tag to create the window at the top layer. The `modalVariants` function contains the styles for the content within the `Dialog` component or just known as `modal`, the function exports a set of styles based in two variants called `variant` and `size`, this variants are similars that the receive like other components like `Button`, `Form`, `Input` and more.
6868
69-
### Prop Values
69+
### Variant Values
7070

7171
| Prop | Values | Default |
7272
| ------- | ------------------------ | ------- |
@@ -93,7 +93,7 @@ export default config
9393

9494
### Customizing with CSS Variables
9595

96-
The `Modal` component supports CSS variables to customize its styles based on your design system. To set the CSS variables, define the required variables in your project's `.css` file. Then, extend the `colors` field in the `tailwind.config.ts` file to create new color names using the values of the previously defined CSS variables.
96+
The `Dialog` component supports CSS variables to customize its styles based on your design system. To set the CSS variables, define the required variables in your project's `.css` file. Then, extend the `colors` field in the `tailwind.config.ts` file to create new color names using the values of the previously defined CSS variables.
9797

9898
Below are some of the CSS variables used by the `@halvaradop/ui-dialog` component. For a complete list of CSS variables, refer to the [index.css](https://github.com/halvaradop/ui/blob/master/index.css) file:
9999

packages/ui-dialog/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@halvaradop/ui-dialog",
33
"version": "0.2.0-beta.1",
44
"private": false,
5-
"description": "A customizable dialog component for @halvaradop/ui library with Tailwind CSS styling.",
5+
"description": "A customizable Dialog component for @halvaradop/ui library with Tailwind CSS styling.",
66
"type": "module",
77
"scripts": {
88
"dev": "tsup --watch",

packages/ui-dialog/src/dialog.stories.tsx

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { useRef } from "react"
22
import type { Meta, StoryObj } from "@storybook/react"
3-
import { Modal, innerDialogVariants } from "./index.js"
4-
import { Button } from "../../ui-button/src/index.js"
3+
import { Dialog, modalVariants } from "./index.js"
4+
import { Button } from "@halvaradop/ui-button"
55
import { decorator } from "@halvaradop/ui-utils/decorator"
66
import { DocsPage } from "@halvaradop/ui-utils/docs-page"
7+
import type { VariantProps } from "class-variance-authority"
8+
9+
type ModalProps = VariantProps<typeof modalVariants>
710

811
const meta: Meta = {
912
title: "ui-dialog",
1013
tags: ["autodocs"],
11-
component: Modal,
14+
component: Dialog as any,
1215
args: {
1316
size: "base",
1417
variant: "base",
@@ -51,7 +54,7 @@ const meta: Meta = {
5154
},
5255
},
5356
decorators: [decorator],
54-
} satisfies Meta<typeof Modal>
57+
} satisfies Meta<ModalProps>
5558

5659
type Story = StoryObj<typeof meta>
5760

@@ -73,14 +76,18 @@ export const Base: Story = {
7376
return (
7477
<>
7578
<Button onClick={() => handleToggleModal(true)}>Open</Button>
76-
<Modal ref={modalRef}>
77-
<div className={innerDialogVariants({ size, variant })}>
78-
<div>Modal content</div>
79+
<Dialog ref={modalRef}>
80+
<div className={modalVariants({ size, variant })}>
81+
<div className="text-center">
82+
<h1 className="font-medium">Modal Content</h1>
83+
<span className="block">size: {size}</span>
84+
<span className="block">variant: {variant}</span>
85+
</div>
7986
<Button className="mt-4" onClick={() => handleToggleModal(false)}>
8087
Close
8188
</Button>
8289
</div>
83-
</Modal>
90+
</Dialog>
8491
</>
8592
)
8693
},

packages/ui-dialog/src/index.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { merge, type ComponentProps, type WithChildrenProps, type ArgsFunction } from "@halvaradop/ui-core"
2-
import { cva, type VariantProps } from "class-variance-authority"
1+
import { merge, type ComponentProps, type WithChildrenProps } from "@halvaradop/ui-core"
2+
import { cva } from "class-variance-authority"
33

4-
export type DialogProps<T extends ArgsFunction> = VariantProps<T> & WithChildrenProps<ComponentProps<"dialog">>
4+
export type DialogProps = WithChildrenProps<ComponentProps<"dialog">>
55

6-
export const innerDialogVariants = cva("flex items-center justify-center", {
6+
export const modalVariants = cva("flex items-center justify-center", {
77
variants: {
88
variant: {
99
base: "flex-col shadow bg-modal",
@@ -23,7 +23,7 @@ export const innerDialogVariants = cva("flex items-center justify-center", {
2323
},
2424
})
2525

26-
export const Modal = ({ className, children, ref, ...props }: DialogProps<typeof innerDialogVariants>) => {
26+
export const Dialog = ({ className, children, ref, ...props }: DialogProps) => {
2727
return (
2828
<dialog
2929
className={merge(
@@ -38,4 +38,4 @@ export const Modal = ({ className, children, ref, ...props }: DialogProps<typeof
3838
)
3939
}
4040

41-
Modal.displayName = "Dialog"
41+
Dialog.displayName = "Dialog"

0 commit comments

Comments
 (0)