Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Next from peer dependencies #38

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@ You can also pass a `Wrapper` to the `<URLModal>` component which will wrap all
/>
```

By default, this package uses the default `history` API used by browsers. If you want to use a custom router either from `react-router` or `Next.js`, you render the `URLModal` component as follows:

```tsx
import Router from 'next/router';
import { URLModal } from 'react-url-modal';
import { CreateAccount, EditAccount } from './Modals';

const customRouterAction = ({ href, replace }) => {
if (replace) {
Router.replace(href, undefined, { shallow: true });
} else {
Router.push(href, undefined, { shallow: true });
}
};

export const App = () => (
<URLModal
modals={{
createAccount: CreateAccount,
editAccount: EditAccount,
}}
customRouterAction={customRouterAction}
/>
);
```

To see all the available props, please check the API reference below.

## API Reference
Expand All @@ -106,13 +132,13 @@ To see all the available props, please check the API reference below.
/>
```

| Parameter | Type | Description |
| :-------------- | :------------------------------------------------------ | :-------------------------------------------------------------- |
| `modals` | `[name: string]: React Component or Promise<Component>` | **Required** |
| `Wrapper` | `React Component` | A component to wrap each modal with |
| `usePortal` | `boolean` | Should this modal be mounted on a portal |
| `portalElement` | `HTML Element` | A component to mount the modals in, defaults to body |
| `adapter` | `null or "nextjs"` | If set to NextJS it will use next router instead of history API |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was what we had before @donaminos

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it's what our platform uses.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any user trying to use this package without Next.js was going to get a build error as optionalDeps are not a thing on modern JS bundlers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just check the existing issues for this project.

| Parameter | Type | Description |
| :------------------- | :------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------- |
| `modals` | `[name: string]: React Component or Promise<Component>` | **Required** |
| `Wrapper` | `React Component` | A component to wrap each modal with |
| `usePortal` | `boolean` | Should this modal be mounted on a portal |
| `portalElement` | `HTML Element` | A component to mount the modals in, defaults to body |
| `customRouterAction` | `(params: { href: string; replace?: boolean; }) => void` | A custom function that can be used to override the default URL behavior. Use this to integrate with routers from Next.js or Remix |

#### openModal

Expand Down Expand Up @@ -189,7 +215,7 @@ Go to the project directory
Install dependencies

```bash
yarn && yarn add next --peer
yarn
```

Start the server
Expand Down
28 changes: 14 additions & 14 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"name": "example-react-url-modal",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite --port 3002",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"@tailwindcss/forms": "^0.4.0",
"autoprefixer": "^10.4.2",
"classnames": "^2.3.1",
"@tailwindcss/forms": "^0.5.6",
"autoprefixer": "^10.4.16",
"classnames": "^2.3.2",
"clipboard-copy": "^4.0.1",
"postcss": "^8.4.5",
"prism-react-renderer": "^1.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"tailwindcss": "^3.0.18"
"postcss": "^8.4.30",
"prism-react-renderer": "^2.0.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwindcss": "^3.3.3"
},
"devDependencies": {
"@types/react": "^17.0.33",
"@types/react-dom": "^17.0.10",
"@vitejs/plugin-react": "^1.0.7",
"typescript": "^4.4.4",
"vite": "^2.7.2"
"@types/react": "^18.2.22",
"@types/react-dom": "^18.2.7",
"@vitejs/plugin-react": "^4.0.4",
"typescript": "^5.2.2",
"vite": "^4.4.9"
}
}
5 changes: 2 additions & 3 deletions example/src/components/Code.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Highlight, { defaultProps } from 'prism-react-renderer';
import theme from 'prism-react-renderer/themes/nightOwl';
import { Highlight, themes } from 'prism-react-renderer';
import clipboardCopy from 'clipboard-copy';
import { CopyIcon } from './Icons';

Expand All @@ -13,7 +12,7 @@ export const Code = ({ code }: { code: string }) => (
>
<CopyIcon />
</button>
<Highlight {...defaultProps} code={code} theme={theme} language="jsx">
<Highlight code={code} theme={themes.nightOwl} language="jsx">
{({ className, tokens, getLineProps, getTokenProps }) => (
<pre className={`${className} p-4 text-sm`}>
{tokens.map((line, i) => (
Expand Down
1 change: 1 addition & 0 deletions example/src/components/Examples.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { openModal, URLModal } from 'react-url-modal';
import { Modal } from 'react-url-modal/Modal';

const StandardModalContent = () => <>No params! Simple stuff</>;

const ModalWithParams = ({ params }: { params: { [key: string]: string } }) => (
Expand Down
2 changes: 1 addition & 1 deletion example/src/components/Modals/Modal3.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Modal } from 'react-url-modal/Modal';

export default function Modal3(props: unknown) {
export default function Modal3(props: any) {
return <Modal {...props}>I am loaded from another file</Modal>;
}
2 changes: 1 addition & 1 deletion example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
Expand Down
8 changes: 0 additions & 8 deletions example/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ export default defineConfig({
},
],
},
optimizeDeps: {
exclude: ['next/router'],
},
build: {
rollupOptions: {
external: ['next/router'],
},
},
server: {
fs: {
// Allow serving files from one level up to the project root
Expand Down
Loading
Loading