Skip to content

Commit

Permalink
feat: add loaderHtml support (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
limonte committed Nov 7, 2022
1 parent 4859142 commit 5b8e21f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The following options can be React elements:
- footer
- closeButtonHtml
- iconHtml
- loaderHtml

## Installation

Expand Down
4 changes: 4 additions & 0 deletions src/mounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ export const mounts = [
key: 'iconHtml',
getter: swal => swal.getIcon().querySelector('.swal2-icon-content'),
},
{
key: 'loaderHtml',
getter: swal => swal.getLoader(),
},
]
1 change: 1 addition & 0 deletions src/sweetalert2-react-content.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface ReactOptions {
footer?: ReactElementOr<'footer'>;
closeButtonHtml?: ReactElementOr<'closeButtonHtml'>;
iconHtml?: ReactElementOr<'iconHtml'>;
loaderHtml?: ReactElementOr<'loaderHtml'>;
}

// Overwrite<T, U> will take the properties of U and add to it the properties of T that are not in U.
Expand Down
2 changes: 2 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('integration', () => {
title: <span>title</span>,
html: <span>html</span>,
iconHtml: <span>@</span>,
loaderHtml: <span>%</span>,
confirmButtonText: <span>confirmButtonText</span>,
denyButtonText: <span>denyButtonText</span>,
cancelButtonText: <span>cancelButtonText</span>,
Expand All @@ -58,6 +59,7 @@ describe('integration', () => {
expect(MySwal.getIcon().innerHTML).toEqual('<div class="swal2-icon-content"><span>@</span></div>')
expect(MySwal.getFooter().innerHTML).toEqual('<span>footer</span>')
expect(MySwal.getCloseButton().innerHTML).toEqual('<span>closeButtonHtml</span>')
expect(MySwal.getLoader().innerHTML).toEqual('<span>%</span>')
}
})
it('can mix React and non-React params', async () => {
Expand Down
1 change: 1 addition & 0 deletions test/test-build.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
await MySwal.fire({
icon: 'success',
iconHtml: React.createElement('b', {key: 'iconHtml'}, ['P']),
loaderHtml: React.createElement('b', {key: 'iconHtml'}, ['@']),
title: React.createElement('i', {key: 'title'}, ['Hello World']),
didOpen: (popup) => {
console.log('didOpen', popup)
Expand Down

0 comments on commit 5b8e21f

Please sign in to comment.