Skip to content

Commit 8207a9d

Browse files
committed
jsx style component
1 parent 365de7f commit 8207a9d

File tree

5 files changed

+50
-37
lines changed

5 files changed

+50
-37
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.7.6",
2+
"version": "1.7.8",
33
"license": "MIT",
44
"main": "dist/index.js",
55
"typings": "dist/index.d.ts",

src/components/Draggable.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import React, { FC, useCallback, useEffect, useRef, useState } from 'react';
2-
import styles from '../style/style.module.css';
2+
import * as styles from '../style/styles';
33

4-
export const Draggable: FC = ({ children }) => {
4+
interface IProps {
5+
bodyStyle: React.CSSProperties;
6+
}
7+
8+
export const Draggable: FC<IProps> = ({ children, bodyStyle }) => {
59
const boxRef = useRef<HTMLDivElement>(null);
610
const dragRef = useRef<HTMLDivElement>(null);
711
const [isDragActive, setIsDragActive] = useState<boolean>(false);
@@ -47,8 +51,12 @@ export const Draggable: FC = ({ children }) => {
4751
}, [dragEndHandler, dragStartHandler, draggingHandler]);
4852

4953
return (
50-
<div ref={boxRef} className={styles.ReactPortalDialog__Body}>
51-
<div ref={dragRef} className={styles.ReactPortalDialog__Move}>
54+
<div ref={boxRef} style={bodyStyle} className="ReactPortalDialog__Body">
55+
<div
56+
ref={dragRef}
57+
style={styles.ReactPortalDialog__Move}
58+
className="ReactPortalDialog__Move"
59+
>
5260
Move Here
5361
</div>
5462
{children}

src/index.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { FC, useEffect, useRef, useState } from 'react';
22
import ReactDOM from 'react-dom';
33
import { Draggable } from './components/Draggable';
4-
import styles from './style/style.module.css';
4+
import * as styles from './style/styles';
55

66
interface Props {
77
isOpen: boolean;
@@ -23,10 +23,6 @@ const Modal: FC<Props> = ({
2323
const divRef = useRef<HTMLElement | null>(null);
2424
const [divCreated, setDivCreated] = useState<Boolean>(false);
2525

26-
const overlayStyle = {
27-
backgroundColor: isOverlay ? 'rgba(0, 0, 0, 0.5)' : 'transparent',
28-
};
29-
3026
useEffect(() => {
3127
if (isOpen) {
3228
bodyRef.current = document.querySelector('body');
@@ -47,21 +43,28 @@ const Modal: FC<Props> = ({
4743
divRef.current?.remove();
4844
};
4945

46+
const overlayStyle = {
47+
...styles.ReactPortalDialog__Overlay,
48+
backgroundColor: isOverlay ? 'rgba(0, 0, 0, 0.5)' : 'transparent',
49+
};
50+
51+
const bodyStyle = customStyles || styles.ReactPortalDialog__Body;
52+
5053
return divCreated && divRef.current
5154
? ReactDOM.createPortal(
5255
<>
5356
<div
5457
style={overlayStyle}
55-
className={styles.ReactPortalDialog__Overlay}
58+
className="ReactPortalDialog__Overlay"
5659
onClick={closeHandler}
5760
/>
5861

5962
{isDraggable ? (
60-
<Draggable>{children}</Draggable>
63+
<Draggable bodyStyle={bodyStyle}>{children}</Draggable>
6164
) : (
6265
<div
63-
style={customStyles}
64-
className={styles.ReactPortalDialog__Body}
66+
style={bodyStyle}
67+
className="ReactPortalDialog__Body"
6568
>
6669
{children}
6770
</div>

src/style/style.module.css

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

src/style/styles.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
3+
export const ReactPortalDialog__Overlay: React.CSSProperties = {
4+
position: 'fixed',
5+
inset: '0',
6+
zIndex: '1000',
7+
};
8+
9+
export const ReactPortalDialog__Body: React.CSSProperties = {
10+
position: 'fixed',
11+
top: '50%',
12+
left: '50%',
13+
maxHeight: '200px',
14+
width: '400px',
15+
backgroundColor: 'rgb(223, 221, 221)',
16+
zIndex: '1000',
17+
transform: 'translate(-50%, -50%)',
18+
};
19+
20+
export const ReactPortalDialog__Move: React.CSSProperties = {
21+
backgroundColor: 'salmon',
22+
textAlign: 'center',
23+
padding: '5px',
24+
cursor: 'move',
25+
};

0 commit comments

Comments
 (0)