Skip to content

Commit

Permalink
fix(types): inputValue type
Browse files Browse the repository at this point in the history
  • Loading branch information
limonte committed Aug 20, 2023
1 parent 676f6f9 commit 671fbc2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
9 changes: 4 additions & 5 deletions sandbox/index.html
@@ -1,13 +1,12 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
@import url('https://fonts.googleapis.com/css?family=Montserrat');

* {
font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell,
'Helvetica Neue', Helvetica, Arial, sans-serif;
font-family: Montserrat, sans-serif;
}
</style>
</head>
Expand All @@ -27,9 +26,9 @@
icon: 'success',
showCloseButton: true,
showCancelButton: true,
preConfirm: (value) => {
inputValidator: (value) => {
if (!value) {
Swal.showValidationMessage('Should not be empty!')
return 'Should not be empty!'
}
},
didOpen: (modal) => {
Expand Down
2 changes: 1 addition & 1 deletion src/buttons-handlers.js
Expand Up @@ -68,7 +68,7 @@ const handleConfirmOrDenyWithInput = (instance, type) => {

/**
* @param {SweetAlert} instance
* @param {string | number | File | FileList | null} inputValue
* @param {SweetAlertInputValue | null} inputValue
* @param {'confirm' | 'deny'} type
*/
const handleInputValidator = (instance, inputValue, type) => {
Expand Down
1 change: 1 addition & 0 deletions src/types.js
Expand Up @@ -4,6 +4,7 @@
* @typedef { import('sweetalert2').SweetAlertIcon } SweetAlertIcon
* @typedef { import('sweetalert2').SweetAlertInput } SweetAlertInput
* @typedef { import('sweetalert2').SweetAlertResult } SweetAlertResult
* @typedef { import('sweetalert2').SweetAlertOptions['inputValue'] } SweetAlertInputValue
*/

/**
Expand Down
8 changes: 2 additions & 6 deletions src/utils/dom/inputUtils.js
Expand Up @@ -4,10 +4,6 @@ import { asPromise, error, hasToPromiseFn, isPromise } from '../utils.js'
import { getDirectChildByClass } from './domUtils.js'
import * as dom from './index.js'

/**
* @typedef { string | number | boolean | undefined } InputValue
*/

/**
* @param {SweetAlert} instance
* @param {SweetAlertOptions} params
Expand All @@ -27,7 +23,7 @@ export const handleInputOptionsAndValue = (instance, params) => {
/**
* @param {SweetAlert} instance
* @param {SweetAlertOptions} innerParams
* @returns {string | number | File | FileList | null}
* @returns {SweetAlertInputValue}
*/
export const getInputValue = (instance, innerParams) => {
const input = instance.getInput()
Expand Down Expand Up @@ -235,7 +231,7 @@ const formatInputOptions = (inputOptions) => {

/**
* @param {string} optionValue
* @param {InputValue | Promise<InputValue> | { toPromise: () => InputValue }} inputValue
* @param {SweetAlertInputValue} inputValue
* @returns {boolean}
*/
const isSelected = (optionValue, inputValue) => {
Expand Down
2 changes: 1 addition & 1 deletion sweetalert2.d.ts
Expand Up @@ -1011,7 +1011,7 @@ declare module 'sweetalert2' {
*
* @default ''
*/
inputValue?: SyncOrAsync<string | number | boolean>
inputValue?: SyncOrAsync<string | number | File | FileList>

/**
* If the `input` parameter is set to `'select'` or `'radio'`, you can provide options.
Expand Down

0 comments on commit 671fbc2

Please sign in to comment.