Skip to content

Commit a331c59

Browse files
committed
fix(api): be a normal enhancer, require the Swal argument (no default)
BREAKING CHANGE: no default value for the `Swal` argument
1 parent b661367 commit a331c59

File tree

4 files changed

+6
-9
lines changed

4 files changed

+6
-9
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import Swal from 'sweetalert2'
2525
import withReactContent from 'sweetalert2-react-content'
2626

2727
const MySwal = withReactContent(Swal)
28-
// or just `const MySwal = withReactContent()`
2928

3029
MySwal.fire({
3130
title: <p>Hello World</p>,

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
"zenflowConfig": {
8787
"build": {
8888
"globals": {
89-
"sweetalert2": "swal",
9089
"react": "React",
9190
"react-dom": "ReactDOM"
9291
}

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import Swal from 'sweetalert2'
21
import React from 'react'
32
import ReactDOM from 'react-dom'
43
import { mounts } from './mounts'
54

65
const noop = () => {}
76

8-
export default function withReactContent(ParentSwal = Swal) {
7+
export default function withReactContent(ParentSwal) {
98
return class extends ParentSwal {
109
static argsToParams(args) {
1110
if (React.isValidElement(args[0]) || React.isValidElement(args[1])) {

test/tests/integration.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { timeout } from '../util/util'
1111
describe('integration', () => {
1212
it('renders React elements for each supported option', async () => {
1313
await cleanSwalState()
14-
const MySwal = withReactContent()
14+
const MySwal = withReactContent(Swal)
1515
await MySwal.fire({
1616
animation: false,
1717
title: <span>title</span>,
@@ -35,7 +35,7 @@ describe('integration', () => {
3535
})
3636
it('can mix React and non-React params', async () => {
3737
await cleanSwalState()
38-
const MySwal = withReactContent()
38+
const MySwal = withReactContent(Swal)
3939
await MySwal.fire({
4040
animation: false,
4141
title: <span>React element</span>,
@@ -50,7 +50,7 @@ describe('integration', () => {
5050
})
5151
})
5252
it('returns a class with the same instance & static properties as Swal', async () => {
53-
const MySwal = withReactContent()
53+
const MySwal = withReactContent(Swal)
5454
Object.keys(Swal).forEach(key => {
5555
expect(typeof MySwal[key]).toBe(typeof Swal[key])
5656
})
@@ -60,7 +60,7 @@ describe('integration', () => {
6060
})
6161
it('works with shorthand Swal calls', async () => {
6262
await cleanSwalState()
63-
const MySwal = withReactContent()
63+
const MySwal = withReactContent(Swal)
6464
const swal = MySwal.fire(<span>title</span>, <span>html</span>, 'info')
6565
await timeout(100)
6666
expect(MySwal.getTitle().innerHTML).toEqual('<span>title</span>')
@@ -71,7 +71,7 @@ describe('integration', () => {
7171
})
7272
it('has no effect on normal shorthand Swal calls', async () => {
7373
await cleanSwalState()
74-
const MySwal = withReactContent()
74+
const MySwal = withReactContent(Swal)
7575
const swal = MySwal.fire('my title', 'my html', 'error')
7676
await timeout(100)
7777
expect(MySwal.getTitle().innerHTML).toEqual('my title')

0 commit comments

Comments
 (0)