Skip to content

Commit

Permalink
fix(select): cssClass + strong typed
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Apr 27, 2018
1 parent c0ec02e commit 826e02b
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 55 deletions.
5 changes: 3 additions & 2 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
RouterOutletOptions,
RouteWrite,
SelectInputChangeEvent,
SelectInterface,
SelectPopoverOption,
StyleEvent,
ToastOptions,
Expand Down Expand Up @@ -5674,7 +5675,7 @@ declare global {
/**
* The interface the select should use: `action-sheet`, `popover` or `alert`. Default: `alert`.
*/
'interface': string;
'interface': SelectInterface;
/**
* Any additional options that the `alert`, `action-sheet` or `popover` interface can take. See the [AlertController API docs](../../alert/AlertController/#create), the [ActionSheetController API docs](../../action-sheet/ActionSheetController/#create) and the [PopoverController API docs](../../popover/PopoverController/#create) for the create options for each interface.
*/
Expand Down Expand Up @@ -5736,7 +5737,7 @@ declare global {
/**
* The interface the select should use: `action-sheet`, `popover` or `alert`. Default: `alert`.
*/
'interface'?: string;
'interface'?: SelectInterface;
/**
* Any additional options that the `alert`, `action-sheet` or `popover` interface can take. See the [AlertController API docs](../../alert/AlertController/#create), the [ActionSheetController API docs](../../action-sheet/ActionSheetController/#create) and the [PopoverController API docs](../../popover/PopoverController/#create) for the create options for each interface.
*/
Expand Down
4 changes: 2 additions & 2 deletions core/src/components/action-sheet/action-sheet-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export interface ActionSheetOptions {
header?: string;
subHeader?: string;
cssClass?: string;
cssClass?: string | string[];
buttons: (ActionSheetButton | string)[];
enableBackdropDismiss?: boolean;
translucent?: boolean;
Expand All @@ -12,7 +12,7 @@ export interface ActionSheetButton {
text?: string;
role?: 'cancel' | 'destructive' | 'selected' | string;
icon?: string;
cssClass?: string;
cssClass?: string | string[];
handler?: () => boolean | void;
}

1 change: 0 additions & 1 deletion core/src/components/input/input-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface InputBaseComponent {

clearOnEdit: boolean;
didBlurAfterEdit: boolean;
styleTmr?: number;

// Shared Attributes
autocapitalize?: string;
Expand Down
1 change: 1 addition & 0 deletions core/src/components/select/select-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type SelectInterface = 'action-sheet' | 'popover' | 'alert';
85 changes: 42 additions & 43 deletions core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component, Element, Event, EventEmitter, Listen, Prop, State, Watch } from '@stencil/core';
import { ActionSheetButton, ActionSheetOptions, AlertOptions, CssClassMap,
Mode, PopoverOptions, SelectInputChangeEvent, SelectPopoverOption, StyleEvent
import { ActionSheetButton, ActionSheetOptions, AlertInput, AlertOptions,
CssClassMap, Mode, PopoverOptions, SelectInputChangeEvent, SelectInterface, SelectPopoverOption, StyleEvent
} from '../../interface';
import { deferEvent } from '../../utils/helpers';


@Component({
Expand All @@ -20,7 +21,7 @@ export class Select {
private selectId = `ion-sel-${selectIds++}`;
private labelId?: string;
private overlay?: HTMLIonActionSheetElement | HTMLIonAlertElement | HTMLIonPopoverElement;
private styleTmr: any;

mode!: Mode;

@Element() el!: HTMLIonSelectElement;
Expand Down Expand Up @@ -71,7 +72,7 @@ export class Select {
/**
* The interface the select should use: `action-sheet`, `popover` or `alert`. Default: `alert`.
*/
@Prop() interface = 'alert';
@Prop() interface: SelectInterface = 'alert';

/**
* Any additional options that the `alert`, `action-sheet` or `popover` interface
Expand Down Expand Up @@ -231,6 +232,8 @@ export class Select {
}

componentDidLoad() {
this.ionStyle = deferEvent(this.ionStyle);

const label = this.getLabel();
if (label) {
this.labelId = label.id = this.name + '-lbl';
Expand Down Expand Up @@ -292,9 +295,11 @@ export class Select {
}

private async openPopover(ev: UIEvent) {
const interfaceOptions = {...this.interfaceOptions};
const interfaceOptions = this.interfaceOptions;

const popoverOpts: PopoverOptions = {
...interfaceOptions,

const popoverOpts: PopoverOptions = Object.assign(interfaceOptions, {
component: 'ion-select-popover',
componentProps: {
header: interfaceOptions.header,
Expand All @@ -314,9 +319,9 @@ export class Select {
} as SelectPopoverOption;
})
},
cssClass: 'select-popover' + (interfaceOptions.cssClass ? ' ' + interfaceOptions.cssClass : ''),
cssClass: ['select-popover', interfaceOptions.cssClass],
ev: ev
});
};

const popover = this.overlay = await this.popoverCtrl.create(popoverOpts);
await popover.present();
Expand All @@ -325,8 +330,6 @@ export class Select {
}

private async openActionSheet() {
const interfaceOptions = {...this.interfaceOptions};

const actionSheetButtons = this.childOpts.map(option => {
return {
role: (option.selected ? 'selected' : ''),
Expand All @@ -345,10 +348,13 @@ export class Select {
}
});

const actionSheetOpts: ActionSheetOptions = Object.assign(interfaceOptions, {
const interfaceOptions = this.interfaceOptions;
const actionSheetOpts: ActionSheetOptions = {
...interfaceOptions,

buttons: actionSheetButtons,
cssClass: 'select-action-sheet' + (interfaceOptions.cssClass ? ' ' + interfaceOptions.cssClass : '')
});
cssClass: ['select-action-sheet', interfaceOptions.cssClass]
};

const actionSheet = this.overlay = await this.actionSheetCtrl.create(actionSheetOpts);
await actionSheet.present();
Expand All @@ -358,12 +364,14 @@ export class Select {
}

private async openAlert() {
const interfaceOptions = {...this.interfaceOptions};

const label = this.getLabel();
const labelText = (label) ? label.textContent : null;

const alertOpts: AlertOptions = Object.assign(interfaceOptions, {
const interfaceOptions = this.interfaceOptions;
const alertOpts: AlertOptions = {
...interfaceOptions,

header: interfaceOptions.header ? interfaceOptions.header : labelText,
inputs: this.childOpts.map(o => {
return {
Expand All @@ -372,27 +380,23 @@ export class Select {
value: o.value,
checked: o.selected,
disabled: o.disabled
};
} as AlertInput;
}),
buttons: [
{
text: this.cancelText,
role: 'cancel',
handler: () => {
this.ionCancel.emit();
}
},
{
text: this.okText,
handler: (selectedValues: any) => {
this.value = selectedValues;
}
buttons: [{
text: this.cancelText,
role: 'cancel',
handler: () => {
this.ionCancel.emit();
}
],
cssClass: 'select-alert ' +
(this.multiple ? 'multiple-select-alert' : 'single-select-alert') +
(interfaceOptions.cssClass ? ' ' + interfaceOptions.cssClass : '')
});
}, {
text: this.okText,
handler: (selectedValues: any) => {
this.value = selectedValues;
}
}],
cssClass: ['select-alert', interfaceOptions.cssClass,
(this.multiple ? 'multiple-select-alert' : 'single-select-alert')]
};

const alert = this.overlay = await this.alertCtrl.create(alertOpts);
await alert.present();
Expand All @@ -412,7 +416,6 @@ export class Select {

const overlay = this.overlay;
this.overlay = undefined;

this.isExpanded = false;

return overlay.dismiss();
Expand All @@ -439,14 +442,10 @@ export class Select {
}

private emitStyle() {
clearTimeout(this.styleTmr);

this.styleTmr = setTimeout(() => {
this.ionStyle.emit({
'select': true,
'select-disabled': this.disabled,
'input-has-value': this.hasValue()
});
this.ionStyle.emit({
'select': true,
'select-disabled': this.disabled,
'input-has-value': this.hasValue()
});
}

Expand Down
1 change: 0 additions & 1 deletion core/src/components/textarea/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class Textarea implements TextareaComponent {
color!: string;

didBlurAfterEdit = false;
styleTmr?: number;

@Element() el!: HTMLElement;

Expand Down
1 change: 1 addition & 0 deletions core/src/interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './components/loading/loading-interface';
export * from './components/popover/popover-interface';
export * from './components/nav/nav-interface';
export * from './components/router/utils/interface';
export * from './components/select/select-interface';
export * from './components/select-popover/select-popover-interface';
export * from './components/toast/toast-interface';

Expand Down
11 changes: 5 additions & 6 deletions core/src/utils/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ export function getButtonClassMap(buttonType: string, mode: Mode): CssClassMap {

export function getClassList(classes: string | string[] | undefined): string[] {
if (classes) {
if (Array.isArray(classes)) {
return classes;
}
return classes
.split(' ')
.filter(c => c.trim() !== '');
const array = Array.isArray(classes) ? classes : classes.split(' ');
return array
.filter(c => c != null)
.map(c => c.trim())
.filter(c => c !== '');
}
return [];
}
Expand Down

0 comments on commit 826e02b

Please sign in to comment.