Skip to content

Commit

Permalink
Merge pull request t4t5#774 from alex-osman/fix-typings
Browse files Browse the repository at this point in the history
Fix Button Interface Typings
  • Loading branch information
t4t5 authored Dec 14, 2017
2 parents 1086356 + 0b5a6a6 commit ea032a7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/modules/init/buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const initButtons = (buttons: ButtonList, dangerMode: boolean): void => {
const footerEl: Element = injectElIntoModal(footerMarkup);

for (let key in buttons) {
const buttonOpts: ButtonOptions = buttons[key];
const buttonOpts: ButtonOptions = buttons[key] as ButtonOptions;
const buttonEl: Node = getButton(key, buttonOpts, dangerMode);

if (buttonOpts.visible) {
Expand Down
8 changes: 3 additions & 5 deletions src/modules/init/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ const addInputEvents = (input: HTMLElement): void => {

/*
* FIXME (this is a bit hacky)
* Set the focus to the input
* Overwrite the submit value with the
* value of the input element ("" or value/defaultValue)
* We're overwriting the default value of confirm button,
* as well as overwriting the default focus on the button
*/
setTimeout(() => {
input.focus();
const defaultValue = (input as HTMLInputElement).value;
setActionValue(defaultValue)
setActionValue('');
}, 0);

};
Expand Down
3 changes: 2 additions & 1 deletion src/modules/init/modal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ButtonList } from './../options/buttons';
import { stringToNode, getNode } from '../utils';
import { modalMarkup } from '../markup';
import { SwalOptions } from '../options';
Expand Down Expand Up @@ -54,7 +55,7 @@ export const initModalContent = (opts: SwalOptions): void => {
initTitle(opts.title);
initText(opts.text);
initContent(opts.content);
initButtons(opts.buttons, opts.dangerMode);
initButtons(opts.buttons as ButtonList, opts.dangerMode);
};

const initModalOnce = (): void => {
Expand Down
12 changes: 6 additions & 6 deletions src/modules/options/buttons.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { isPlainObject, throwErr } from '../utils';

export interface ButtonOptions {
visible: boolean,
text: string,
value: any,
className: string | Array<string>,
closeModal: boolean,
visible?: boolean,
text?: string,
value?: any,
className?: string | Array<string>,
closeModal?: boolean,
};

export interface ButtonList {
[buttonNamespace: string]: ButtonOptions,
[buttonNamespace: string]: ButtonOptions | boolean,
};

export const CONFIRM_KEY = 'confirm';
Expand Down
2 changes: 1 addition & 1 deletion src/modules/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface SwalOptions {
title: string,
text: string,
icon: string,
buttons: ButtonList,
buttons: ButtonList | Array<string | boolean>,
content: ContentOptions,
className: string,
closeOnClickOutside: boolean,
Expand Down
12 changes: 6 additions & 6 deletions typings/modules/options/buttons.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export interface ButtonOptions {
visible: boolean;
text: string;
value: any;
className: string | Array<string>;
closeModal: boolean;
visible?: boolean;
text?: string;
value?: any;
className?: string | Array<string>;
closeModal?: boolean;
}
export interface ButtonList {
[buttonNamespace: string]: ButtonOptions;
[buttonNamespace: string]: ButtonOptions | boolean;
}
export declare const CONFIRM_KEY = "confirm";
export declare const CANCEL_KEY = "cancel";
Expand Down
2 changes: 1 addition & 1 deletion typings/modules/options/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface SwalOptions {
title: string;
text: string;
icon: string;
buttons: ButtonList;
buttons: ButtonList | Array<string | boolean>;
content: ContentOptions;
className: string;
closeOnClickOutside: boolean;
Expand Down

0 comments on commit ea032a7

Please sign in to comment.