From a7ce20f990f37553b3fde0f4add3bd03842d2bf6 Mon Sep 17 00:00:00 2001 From: Dan Bucholtz Date: Thu, 2 Mar 2017 14:48:16 -0600 Subject: [PATCH] refactor(fab): restructure fab component to separate modules restructure fab component to separate modules --- src/components/fab/fab-container.ts | 186 +++++++++++++++++++ src/components/fab/fab-list.ts | 89 +++++++++ src/components/fab/fab.ts | 269 +--------------------------- 3 files changed, 276 insertions(+), 268 deletions(-) create mode 100644 src/components/fab/fab-container.ts create mode 100644 src/components/fab/fab-list.ts diff --git a/src/components/fab/fab-container.ts b/src/components/fab/fab-container.ts new file mode 100644 index 0000000000..0c254a67d1 --- /dev/null +++ b/src/components/fab/fab-container.ts @@ -0,0 +1,186 @@ +import { Component, ContentChild, ContentChildren, QueryList, ElementRef } from '@angular/core'; + +import { Platform } from '../../platform/platform'; +import { UIEventManager } from '../../gestures/ui-event-manager'; +import { FabButton } from './fab'; +import { FabList } from './fab-list'; + +/** + * @name FabContainer + * @module ionic + * + * @description + * `` is not a FAB button by itself but a container that assist the fab button (` + * + * + * + * + * + * + * + * ``` + * + * Ionic's FAB also supports "material design's fab speed dial". It is a normal fab button + * that shows a list of related actions when clicked. + * + * The same `ion-fab` container can contain several `ion-fab-list` with different side values: + * `top`, `bottom`, `left` and `right`. For example, if you want to have a list of button that are + * on the top of the main button, you should use `side="top"` and so on. By default, if side is ommited, `side="bottom"`. + * + * ```html + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * ``` + * + * A FAB speed dial can also be closed programatically. + * + * ```html + * + * + * + * + * + * + * + * + * + * ``` + * + * ```ts + * share(socialNet: string, fab: FabContainer) { + * fab.close(); + * console.log("Sharing in", socialNet); + * } + * ``` + * + * @demo /docs/v2/demos/src/fab/ + * @see {@link /docs/v2/components#fabs FAB Component Docs} + */ +@Component({ + selector: 'ion-fab', + template: '' +}) +export class FabContainer { + + /** + * @private + */ + _events: UIEventManager; + + /** + * @private + */ + _listsActive: boolean = false; + + /** + * @private + */ + @ContentChild(FabButton) _mainButton: FabButton; + + /** + * @private + */ + @ContentChildren(FabList) _fabLists: QueryList; + + constructor(private _elementRef: ElementRef, plt: Platform) { + this._events = new UIEventManager(plt); + } + + /** + * @private + */ + ngAfterContentInit() { + const mainButton = this._mainButton; + if (!mainButton || !mainButton.getNativeElement()) { + console.error('FAB container needs a main + * + * + * + * + * + * + * + * + * + * ``` + * @module ionic + * + * @demo /docs/v2/demos/src/fab/ + * @see {@link /docs/v2/components#fab Fab Component Docs} + */ +@Directive({ + selector: 'ion-fab-list', +}) +export class FabList { + _visible: boolean = false; + _fabs: FabButton[] = []; + _mode: string; + + constructor( + private _elementRef: ElementRef, + private _renderer: Renderer, + config: Config, + private _plt: Platform + ) { + this._mode = config.get('mode'); + } + + @ContentChildren(FabButton) + set _setbuttons(query: QueryList) { + const fabs = this._fabs = query.toArray(); + const className = `fab-${this._mode}-in-list`; + for (var fab of fabs) { + fab.setElementClass('fab-in-list', true); + fab.setElementClass(className, true); + } + } + + /** + * @private + */ + setVisible(val: boolean) { + let visible = isTrueProperty(val); + if (visible === this._visible) { + return; + } + this._visible = visible; + + let fabs = this._fabs; + let i = 1; + if (visible) { + fabs.forEach(fab => { + this._plt.timeout(() => fab.setElementClass('show', true), i * 30); + i++; + }); + } else { + fabs.forEach(fab => fab.setElementClass('show', false)); + } + this.setElementClass('fab-list-active', visible); + } + + /** + * @internal + */ + setElementClass(className: string, add: boolean) { + this._renderer.setElementClass(this._elementRef.nativeElement, className, add); + } +} diff --git a/src/components/fab/fab.ts b/src/components/fab/fab.ts index 69d14c4e91..47af1d81ab 100755 --- a/src/components/fab/fab.ts +++ b/src/components/fab/fab.ts @@ -1,11 +1,7 @@ -import { Component, ContentChild, Input, ContentChildren, QueryList, ChangeDetectionStrategy, Directive, ElementRef, Renderer, ViewEncapsulation } from '@angular/core'; +import { Component, Input, ChangeDetectionStrategy, ElementRef, Renderer, ViewEncapsulation } from '@angular/core'; import { Config } from '../../config/config'; import { Ion } from '../ion'; -import { isTrueProperty } from '../../util/util'; -import { Platform } from '../../platform/platform'; -import { UIEventManager } from '../../gestures/ui-event-manager'; - /** * @name FabButton @@ -101,266 +97,3 @@ export class FabButton extends Ion { this.setElementClass('fab-close-active', closeVisible); } } - -/** - * @name FabList - * @description - * `ion-fab-list` is a container for multiple FAB buttons. They are components of `ion-fab` and allow you to specificy the buttons position, left, right, top, bottom. - * @usage - * - * ```html - * - * - * - * - * - * - * - * - * - * - * - * ``` - * @module ionic - * - * @demo /docs/v2/demos/src/fab/ - * @see {@link /docs/v2/components#fab Fab Component Docs} - */ -@Directive({ - selector: 'ion-fab-list', -}) -export class FabList { - _visible: boolean = false; - _fabs: FabButton[] = []; - _mode: string; - - constructor( - private _elementRef: ElementRef, - private _renderer: Renderer, - config: Config, - private _plt: Platform - ) { - this._mode = config.get('mode'); - } - - @ContentChildren(FabButton) - set _setbuttons(query: QueryList) { - const fabs = this._fabs = query.toArray(); - const className = `fab-${this._mode}-in-list`; - for (var fab of fabs) { - fab.setElementClass('fab-in-list', true); - fab.setElementClass(className, true); - } - } - - /** - * @private - */ - setVisible(val: boolean) { - let visible = isTrueProperty(val); - if (visible === this._visible) { - return; - } - this._visible = visible; - - let fabs = this._fabs; - let i = 1; - if (visible) { - fabs.forEach(fab => { - this._plt.timeout(() => fab.setElementClass('show', true), i * 30); - i++; - }); - } else { - fabs.forEach(fab => fab.setElementClass('show', false)); - } - this.setElementClass('fab-list-active', visible); - } - - /** - * @internal - */ - setElementClass(className: string, add: boolean) { - this._renderer.setElementClass(this._elementRef.nativeElement, className, add); - } - -} - -/** - * @name FabContainer - * @module ionic - * - * @description - * `` is not a FAB button by itself but a container that assist the fab button (` - * - * - * - * - * - * - * - * ``` - * - * Ionic's FAB also supports "material design's fab speed dial". It is a normal fab button - * that shows a list of related actions when clicked. - * - * The same `ion-fab` container can contain several `ion-fab-list` with different side values: - * `top`, `bottom`, `left` and `right`. For example, if you want to have a list of button that are - * on the top of the main button, you should use `side="top"` and so on. By default, if side is ommited, `side="bottom"`. - * - * ```html - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * ``` - * - * A FAB speed dial can also be closed programatically. - * - * ```html - * - * - * - * - * - * - * - * - * - * ``` - * - * ```ts - * share(socialNet: string, fab: FabContainer) { - * fab.close(); - * console.log("Sharing in", socialNet); - * } - * ``` - * - * @demo /docs/v2/demos/src/fab/ - * @see {@link /docs/v2/components#fabs FAB Component Docs} - */ -@Component({ - selector: 'ion-fab', - template: '' -}) -export class FabContainer { - - /** - * @private - */ - _events: UIEventManager; - - /** - * @private - */ - _listsActive: boolean = false; - - /** - * @private - */ - @ContentChild(FabButton) _mainButton: FabButton; - - /** - * @private - */ - @ContentChildren(FabList) _fabLists: QueryList; - - constructor(private _elementRef: ElementRef, plt: Platform) { - this._events = new UIEventManager(plt); - } - - /** - * @private - */ - ngAfterContentInit() { - const mainButton = this._mainButton; - if (!mainButton || !mainButton.getNativeElement()) { - console.error('FAB container needs a main