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

Fix Button Interface Typings #774

Merged
merged 6 commits into from
Dec 14, 2017
Merged
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
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