Skip to content

Commit 047d79e

Browse files
committed
feat: className props 추가
1 parent ea36992 commit 047d79e

File tree

11 files changed

+63
-27
lines changed

11 files changed

+63
-27
lines changed

package/CHANGE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
### What's New?
44

5-
-
5+
-

package/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shinyongjun/react-dialog",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"main": "./dist/cjs/index.js",
55
"module": "./dist/esm/index.js",
66
"source": "./src/index.tsx",

package/src/components/DialogProvider.tsx

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,35 @@
22

33
import * as React from 'react';
44
import { ReactNode } from 'react';
5-
import ConfirmDialog from './dialog/ConfirmDialog';
65
import AlertDialog from './dialog/AlertDialog';
6+
import ConfirmDialog from './dialog/ConfirmDialog';
77
import PromptDialog from './dialog/PromptDialog';
88

99
interface IProps {
1010
children: ReactNode;
1111
confirmText?: string;
1212
cancelText?: string;
13+
className?: string;
1314
}
1415

1516
function DialogProvider({
1617
children,
1718
confirmText = 'ok',
1819
cancelText = 'cancel',
20+
className = '',
1921
}: IProps) {
2022
return (
21-
<PromptDialog confirmText={confirmText} cancelText={cancelText}>
22-
<AlertDialog confirmText={confirmText} cancelText={cancelText}>
23-
<ConfirmDialog confirmText={confirmText} cancelText={cancelText}>
23+
<PromptDialog
24+
confirmText={confirmText}
25+
cancelText={cancelText}
26+
className={className}
27+
>
28+
<AlertDialog confirmText={confirmText} className={className}>
29+
<ConfirmDialog
30+
confirmText={confirmText}
31+
cancelText={cancelText}
32+
className={className}
33+
>
2434
{children}
2535
</ConfirmDialog>
2636
</AlertDialog>

package/src/components/UI/Alert.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { useEffect, useRef } from 'react';
33
import DialogWrapper from './Wrapper';
44

55
interface IProps {
6+
className: string;
67
message: string;
78
confirmText: string;
8-
cancelText: string;
99
onClose: () => void;
1010
}
1111

12-
const Alert = ({ message, confirmText, cancelText, onClose }: IProps) => {
12+
const Alert = ({ className, message, confirmText, onClose }: IProps) => {
1313
const okRef = useRef<HTMLButtonElement>(null);
1414

1515
useEffect(() => {
@@ -31,7 +31,7 @@ const Alert = ({ message, confirmText, cancelText, onClose }: IProps) => {
3131
}, []);
3232

3333
return (
34-
<DialogWrapper>
34+
<DialogWrapper className={className}>
3535
<div
3636
className="react-dialog__message"
3737
dangerouslySetInnerHTML={{ __html: message }}

package/src/components/UI/Confirm.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable jsx-a11y/no-autofocus */
22
import * as React from 'react';
3-
import { useRef, useEffect } from 'react';
3+
import { useEffect, useRef } from 'react';
44
import DialogWrapper from './Wrapper';
55

66
interface IProps {
7+
className: string;
78
message: string;
89
confirmText: string;
910
cancelText: string;
@@ -12,6 +13,7 @@ interface IProps {
1213
}
1314

1415
const Confirm = ({
16+
className,
1517
message,
1618
confirmText,
1719
cancelText,
@@ -39,7 +41,7 @@ const Confirm = ({
3941
}, []);
4042

4143
return (
42-
<DialogWrapper>
44+
<DialogWrapper className={className}>
4345
<div
4446
className="react-dialog__message"
4547
dangerouslySetInnerHTML={{ __html: message }}

package/src/components/UI/Prompt.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useEffect, useRef } from 'react';
44
import DialogWrapper from './Wrapper';
55

66
interface IProps {
7+
className: string;
78
message: string;
89
confirmText: string;
910
cancelText: string;
@@ -12,7 +13,15 @@ interface IProps {
1213
onClickCancel: () => void;
1314
}
1415

15-
const Prompt = ({ message, confirmText, cancelText, _default, onClickOK, onClickCancel }: IProps) => {
16+
const Prompt = ({
17+
className,
18+
message,
19+
confirmText,
20+
cancelText,
21+
_default,
22+
onClickOK,
23+
onClickCancel,
24+
}: IProps) => {
1625
const inputRef = useRef<HTMLInputElement>(null);
1726

1827
useEffect(() => {
@@ -42,7 +51,7 @@ const Prompt = ({ message, confirmText, cancelText, _default, onClickOK, onClick
4251
}, []);
4352

4453
return (
45-
<DialogWrapper>
54+
<DialogWrapper className={className}>
4655
<form onSubmit={handleSubmit}>
4756
<div
4857
className="react-dialog__message"

package/src/components/UI/Wrapper.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { ReactNode } from 'react';
44
import Portal from './Portal';
55

66
interface IProps {
7+
className: string;
78
children: ReactNode;
89
}
910

10-
const DialogWrapper = ({ children }: IProps) => {
11+
const DialogWrapper = ({ className, children }: IProps) => {
1112
return (
1213
<Portal selector="body">
13-
<div className="react-dialog__wrapper">
14+
<div className={`react-dialog__wrapper${className && ` ${className}`}`}>
1415
<div className="react-dialog__dialog">{children}</div>
1516
</div>
1617
</Portal>

package/src/components/dialog/AlertDialog.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import { ReactNode, useState } from 'react';
33
import AlertContext from '../../context/AlertContext';
44
import Alert from '../UI/Alert';
55

6-
type AlertState = {
6+
type TAlertState = {
77
message: string;
88
onClose: () => void;
99
};
1010

1111
interface IProps {
12+
className: string;
1213
confirmText: string;
13-
cancelText: string;
1414
children: ReactNode;
1515
}
1616

17-
function AlertDialog({ children, confirmText, cancelText }: IProps) {
18-
const [state, setState] = useState<AlertState>();
17+
function AlertDialog({ children, confirmText, className }: IProps) {
18+
const [state, setState] = useState<TAlertState>();
1919

2020
const alert = (message?: any): Promise<undefined> => {
2121
return new Promise((resolve) => {
@@ -34,8 +34,8 @@ function AlertDialog({ children, confirmText, cancelText }: IProps) {
3434
{children}
3535
{state && (
3636
<Alert
37+
className={className}
3738
confirmText={confirmText}
38-
cancelText={cancelText}
3939
message={state.message}
4040
onClose={state.onClose}
4141
/>

package/src/components/dialog/ConfirmDialog.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,26 @@ import { ReactNode, useState } from 'react';
33
import ConfirmContext from '../../context/ConfirmContext';
44
import Confirm from '../UI/Confirm';
55

6-
type ConfirmState = {
6+
type TConfirmState = {
77
message: string;
88
onClickOK: () => void;
99
onClickCancel: () => void;
1010
};
1111

1212
interface IProps {
13+
className: string;
1314
confirmText: string;
1415
cancelText: string;
1516
children: ReactNode;
1617
}
1718

18-
function ConfirmDialog({ children, confirmText, cancelText }: IProps) {
19-
const [state, setState] = useState<ConfirmState>();
19+
function ConfirmDialog({
20+
className,
21+
children,
22+
confirmText,
23+
cancelText,
24+
}: IProps) {
25+
const [state, setState] = useState<TConfirmState>();
2026

2127
const confirm = (message?: string): Promise<boolean> => {
2228
return new Promise((resolve) => {
@@ -43,6 +49,7 @@ function ConfirmDialog({ children, confirmText, cancelText }: IProps) {
4349
{/* state 여부에 따라 Confirm 다이얼로그 띄우기 */}
4450
{state && (
4551
<Confirm
52+
className={className}
4653
confirmText={confirmText}
4754
cancelText={cancelText}
4855
message={state.message}

package/src/components/dialog/PromptDialog.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@ import { ReactNode, useState } from 'react';
33
import PromptContext from '../../context/PromptContext';
44
import Prompt from '../UI/Prompt';
55

6-
type PromptState = {
6+
type TPromptState = {
77
message: string;
88
_default: string;
99
onClickOK: (result: string) => void;
1010
onClickCancel: () => void;
1111
};
1212

1313
interface IProps {
14+
className: string;
1415
confirmText: string;
1516
cancelText: string;
1617
children: ReactNode;
1718
}
1819

19-
function PromptDialog({ children, confirmText, cancelText }: IProps) {
20-
const [state, setState] = useState<PromptState>();
20+
function PromptDialog({
21+
className,
22+
children,
23+
confirmText,
24+
cancelText,
25+
}: IProps) {
26+
const [state, setState] = useState<TPromptState>();
2127

2228
const prompt = (
2329
message?: string,
@@ -44,6 +50,7 @@ function PromptDialog({ children, confirmText, cancelText }: IProps) {
4450
{children}
4551
{state && (
4652
<Prompt
53+
className={className}
4754
confirmText={confirmText}
4855
cancelText={cancelText}
4956
message={state.message}

test/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { DialogProvider } from '@shinyongjun/react-dialog';
12
import * as React from 'react';
23
import * as ReactDOM from 'react-dom/client';
34
import App from './App';
4-
import { DialogProvider } from '@shinyongjun/react-dialog';
55

66
const root = ReactDOM.createRoot(document.getElementById('root'));
77
root.render(

0 commit comments

Comments
 (0)