Skip to content

Commit d1348db

Browse files
authored
Merge pull request #49 from ssi02014/dev
chore: Support cjs, esm
2 parents 9fef678 + 920c653 commit d1348db

File tree

11 files changed

+297
-350
lines changed

11 files changed

+297
-350
lines changed

README.md

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -146,48 +146,6 @@ const App = () => {
146146
}
147147
```
148148

149-
<br />
150-
151-
## How to use Next(v13) 😊
152-
### STEP 1️⃣
153-
- Install Package
154-
```
155-
yarn add react-thumbnail-generator next-transpile-modules
156-
or
157-
npm install react-thumbnail-generator next-transpile-modules
158-
```
159-
160-
<br />
161-
162-
### STEP 2️⃣
163-
- Modify `next.config`
164-
```js
165-
/** @type {import('next').NextConfig} */
166-
const nextConfig = {
167-
reactStrictMode: true,
168-
transpilePackages: ["react-thumbnail-generator"], // (*)
169-
};
170-
171-
module.exports = nextConfig;
172-
```
173-
174-
<br />
175-
176-
### STEP 3️⃣
177-
- Add `<ThumbnailGenerator>` component.
178-
179-
```jsx
180-
import ThumbnailGenerator from 'react-thumbnail-generator';
181-
182-
export default function Home() {
183-
return (
184-
<ThumbnailGenerator />
185-
);
186-
}
187-
188-
```
189-
190-
191149
<br />
192150

193151
## How to add Web fonts 😊

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ module.exports = {
33
['@babel/preset-env', { useBuiltIns: 'usage', corejs: 3 }],
44
'@babel/preset-typescript',
55
'@babel/preset-react',
6+
'@emotion/babel-preset-css-prop',
67
],
7-
plugins: ['@emotion/babel-plugin'],
88
};

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"name": "react-thumbnail-generator",
3-
"version": "3.0.4",
3+
"version": "3.1.0",
44
"description": "react-thumbnail-generator",
5-
"main": "dist/index.js",
6-
"module": "dist/index.js",
5+
"main": "dist/cjs/index.js",
6+
"module": "dist/esm/index.js",
7+
"files": [
8+
"dist"
9+
],
710
"scripts": {
811
"test": "echo \"Error: no test specified\" && exit 1",
912
"build": "rm -rf dist && rollup -c",
@@ -26,7 +29,8 @@
2629
"@babel/preset-env": "^7.22.4",
2730
"@babel/preset-react": "^7.22.3",
2831
"@babel/preset-typescript": "^7.21.5",
29-
"@emotion/babel-plugin": "^11.11.0",
32+
"@devgrace/react": "^0.1.2",
33+
"@emotion/babel-preset-css-prop": "^11.11.0",
3034
"@emotion/react": "^11.11.1",
3135
"@emotion/styled": "^11.11.0",
3236
"@rollup/plugin-alias": "^5.0.0",

rollup.config.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ export default {
1818
output: [
1919
{
2020
file: pkg.main,
21-
format: 'esm',
2221
sourcemap: false,
22+
format: 'cjs',
23+
},
24+
{
25+
file: pkg.module,
26+
sourcemap: false,
27+
format: 'esm',
2328
},
2429
],
2530
external: ['react', 'react-dom'],
@@ -34,7 +39,7 @@ export default {
3439
extensions,
3540
include: ['src/**/*'],
3641
}),
37-
typescript({ tsconfig: './tsconfig.json' }),
42+
typescript({ tsconfig: './tsconfig.json', exclude: ['**/*.stories.tsx'] }),
3843
alias({
3944
entries: [{ find: '@', replacement: path.resolve(__dirname, './src') }],
4045
}),

src/components/ColorPicker/index.tsx

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React, {
88
} from 'react';
99
import { Color, ColorPicker as PaletteColorPicker } from 'react-color-palette';
1010
import { IconButton } from '../Icon/styled';
11+
import { Portal } from '@devgrace/react';
1112

1213
interface ColorPickerProps {
1314
children: React.ReactNode;
@@ -24,6 +25,7 @@ const ColorPicker = ({
2425
}: ColorPickerProps) => {
2526
const [isOpenColorPicker, setIsOpenColorPicker] = useState(false);
2627
const colorRef = useRef<HTMLDivElement>(null);
28+
const [coordinates, setCoordinates] = useState({ x: 0, y: 0 });
2729

2830
const handleCloseColorPicker = useCallback(
2931
(e: any) => {
@@ -39,10 +41,16 @@ const ColorPicker = ({
3941
[isOpenColorPicker, toggleIsBlockEvent]
4042
);
4143

42-
const handleOpenColorPicker = useCallback(() => {
43-
setIsOpenColorPicker((prev) => !prev);
44-
toggleIsBlockEvent();
45-
}, [toggleIsBlockEvent]);
44+
const handleOpenColorPicker = useCallback(
45+
(e: React.MouseEvent<HTMLButtonElement>) => {
46+
const { x, y } = e.currentTarget.getBoundingClientRect();
47+
48+
setCoordinates({ x, y });
49+
setIsOpenColorPicker((prev) => !prev);
50+
toggleIsBlockEvent();
51+
},
52+
[toggleIsBlockEvent]
53+
);
4654

4755
useEffect(() => {
4856
document.addEventListener('mousedown', handleCloseColorPicker);
@@ -61,11 +69,12 @@ const ColorPicker = ({
6169
const colorPickerWrapperStyle: CSSProperties = useMemo(() => {
6270
return {
6371
position: 'absolute',
64-
left: '50%',
65-
bottom: '40px',
72+
left: `${coordinates.x}px`,
73+
top: `${coordinates.y - 300}px`,
6674
transform: 'translateX(-50%)',
75+
zIndex: '9999',
6776
};
68-
}, []);
77+
}, [coordinates]);
6978

7079
return (
7180
<div style={wrapperStyle}>
@@ -75,19 +84,21 @@ const ColorPicker = ({
7584
isBorder={true}>
7685
{children}
7786
</IconButton>
78-
{isOpenColorPicker && (
79-
<div ref={colorRef} style={colorPickerWrapperStyle}>
80-
<PaletteColorPicker
81-
width={250}
82-
height={150}
83-
color={color}
84-
onChange={setColor}
85-
hideHSV
86-
hideRGB
87-
dark
88-
/>
89-
</div>
90-
)}
87+
<Portal>
88+
{isOpenColorPicker && (
89+
<div ref={colorRef} style={colorPickerWrapperStyle}>
90+
<PaletteColorPicker
91+
width={250}
92+
height={150}
93+
color={color}
94+
onChange={setColor}
95+
hideHSV
96+
hideRGB
97+
dark
98+
/>
99+
</div>
100+
)}
101+
</Portal>
91102
</div>
92103
);
93104
};

src/components/Layout/styled.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ export const BodyWrapper = styled.section<{
2929
min-width: ${({ isFullWidth }) => (isFullWidth ? '100%' : '600px')};
3030
border-radius: 7px;
3131
box-shadow: 1px 1px 10px #cccccc;
32-
z-index: 9999;
32+
z-index: 100;
3333
background-color: #ffffff;
3434
flex-direction: column;
35-
overflow: hidden;
36-
3735
font-family: Arial;
38-
3936
* {
4037
box-sizing: border-box;
4138
}

src/components/Portal/index.tsx

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

0 commit comments

Comments
 (0)