Skip to content

Commit 9991843

Browse files
authored
Merge pull request #11 from mbrookson/feature/portal-refactor
v1 Portal refactor
2 parents 90fe93b + f04cc6a commit 9991843

File tree

10 files changed

+627
-1383
lines changed

10 files changed

+627
-1383
lines changed

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ yarn add react-simple-hook-modal
3030
- Modals are rendered after allthe children in side `<ModalProvider/>`
3131
- Use the `useModal` hook to control your modal's state
3232
- Use the `ModalTransition` enum to optionally set the transition animation
33-
- Currently there are 3 to select from, or choose NONE to disable the transitions
33+
- Currently there are 3 to select from, or choose `NONE` to disable the transitions
3434

35-
```
36-
import { ModalProvider, Modal, useModal, ModalTransition } from 'react-simple-hook-modal';
35+
```tsx
36+
import {
37+
ModalProvider,
38+
Modal,
39+
useModal,
40+
ModalTransition,
41+
} from 'react-simple-hook-modal';
3742

3843
const MyComponent = () => {
3944
const { isModalOpen, openModal, closeModal } = useModal();
@@ -43,34 +48,33 @@ const MyComponent = () => {
4348
<button onClick={openModal}>Open</button>
4449
<Modal
4550
id="any-unique-identifier"
46-
content={(
47-
// Any React node can be used as content
48-
<button onClick={openModal}>Open</button>
49-
)}
5051
isOpen={isModalOpen}
5152
transition={ModalTransition.BOTTOM_UP}
52-
/>
53+
>
54+
<button onClick={openModal}>Open</button>
55+
</Modal>
5356
</>
5457
);
55-
}
58+
};
5659

5760
const App = () => (
5861
<ModalProvider>
5962
<MyComponent />
6063
</ModalProvider>
61-
)
62-
64+
);
6365
```
6466

6567
## Styles
6668

6769
`react-simple-hook-modal` uses a subset of [tailwindcss][tailwind] under the hood. The tailwind classes used have a prefix of `rsm` added to avoid potential conflicts with your own styles. You can import the default styles using:
6870

69-
```
71+
```css
7072
import 'react-simple-hook-modal/dist/styles.css';
7173
```
7274

73-
`ModalProvider` also takes an optional `backdropClassName` which can contain one or more classes to append and override the default styles (e.g. Changing the backdrop colour can be done by adding the class `bg-blue-800`).
75+
`ModalProvider` also takes optional props:
76+
77+
- `backdropClassName` which can contain one or more classes to append and override the default styles (e.g. Changing the backdrop colour can be done by adding the class `bg-blue-800`).
7478

7579
# Example
7680

@@ -84,7 +88,7 @@ See the `example` directory in the repository for a full example including multi
8488

8589
If you have any issues, please create an issue here on GitHub.
8690

87-
### Thanks!
91+
### Thanks and enjoy!
8892

8993
[publish]: https://github.com/mbrookson/react-simple-hook-modal/workflows/Publish%20CI/badge.svg?branch=master
9094
[ci]: https://github.com/mbrookson/react-simple-hook-modal/workflows/CI/badge.svg?branch=master

example/package-lock.json

Lines changed: 417 additions & 1278 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
},
1111
"dependencies": {
1212
"@fullhuman/postcss-purgecss": "^2.1.2",
13-
"components": "^0.1.0",
1413
"autoprefixer": "^9.7.6",
14+
"components": "^0.1.0",
1515
"cssnano": "^4.1.10",
1616
"parcel-bundler": "^1.12.4",
1717
"postcss-cli": "^7.1.0",
18-
"tailwindcss": "^1.3.5",
19-
"typescript": "^3.4.5",
2018
"react-app-polyfill": "^1.0.0",
21-
"react-icons-kit": "^1.3.1"
19+
"react-icons-kit": "^1.3.1",
20+
"tailwindcss": "^1.4.6",
21+
"typescript": "^3.9.6"
2222
},
2323
"alias": {
2424
"react": "../node_modules/react",
@@ -29,4 +29,4 @@
2929
"@types/react": "^16.9.11",
3030
"@types/react-dom": "^16.8.4"
3131
}
32-
}
32+
}

example/src/Example.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ const ModalContent = ({ transition, onCloseClicked }) => {
1616
</button>
1717
<Modal
1818
id="2"
19-
content={<p>This modal can be closed by clicking the backdrop.</p>}
2019
isOpen={isModalOpen}
2120
onBackdropClick={closeModal}
2221
transition={transition}
23-
/>
22+
>
23+
<p>This modal can be closed by clicking the backdrop.</p>
24+
</Modal>
2425
<div className="mt-8">
2526
Open another modal which will appear stacked on top of the current
2627
modal.
@@ -67,14 +68,9 @@ export const Example = ({ transition }) => {
6768
>
6869
Open modal
6970
</button>
70-
<Modal
71-
id="1"
72-
content={
73-
<ModalContent transition={transition} onCloseClicked={closeModal} />
74-
}
75-
isOpen={isModalOpen}
76-
transition={transition}
77-
/>
71+
<Modal id="1" isOpen={isModalOpen} transition={transition}>
72+
<ModalContent transition={transition} onCloseClicked={closeModal} />
73+
</Modal>
7874
</div>
7975
);
8076
};

package-lock.json

Lines changed: 142 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.2.0",
2+
"version": "1.0.0",
33
"license": "MIT",
44
"name": "react-simple-hook-modal",
55
"description": "A simple React modal with hook based API",
@@ -52,10 +52,10 @@
5252
"react": "^16.13.1",
5353
"react-dom": "^16.13.1",
5454
"rollup-plugin-postcss": "^2.8.2",
55-
"tailwindcss": "^1.3.5",
55+
"tailwindcss": "^1.4.6",
5656
"tsdx": "^0.13.2",
5757
"tslib": "^1.11.1",
58-
"typescript": "^3.8.3"
58+
"typescript": "^3.9.6"
5959
},
6060
"keywords": [
6161
"react",
@@ -65,6 +65,7 @@
6565
"simple"
6666
],
6767
"dependencies": {
68+
"hooks": "^0.3.2",
6869
"react-spring": "^8.0.27"
6970
}
7071
}

src/ModalContext.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from 'react';
22

33
export interface Context {
4+
addOrUpdate(id: string): void;
45
remove(id: string): void;
5-
addOrUpdate(modal: React.ReactNode): void;
6+
getStaggerPixels(id: string): number;
67
}
78

89
export const ModalContext = React.createContext({} as Context);

0 commit comments

Comments
 (0)