From ff50df6157864cd1b7621033947d758382827cb0 Mon Sep 17 00:00:00 2001 From: Gracjan Gorecki Date: Tue, 24 Mar 2020 11:46:53 +0100 Subject: [PATCH 1/4] fix: few fixes in the code and documentation found after tests --- apps/docs/src/app/core/api-files.ts | 6 +- .../button/button-docs.component.html | 2 +- .../button-icons-example.component.html | 1 - .../button-types-example.component.html | 2 +- .../segmented-button-docs.component.ts | 8 +-- .../segmented-button-docs.module.ts | 2 +- ...tton-programmatical-example.component.html | 4 +- ...button-programmatical-example.component.ts | 4 +- .../split-button-types-example.component.ts | 1 - libs/core/src/lib/button/button.component.ts | 65 ++++++++++++------- .../segmented-button.component.ts | 2 +- .../segmented-button.directive.spec.ts | 2 +- .../segmented-button.directive.ts | 19 ++++-- .../split-button/split-button.component.html | 2 +- .../split-button/split-button.component.ts | 27 ++++++-- 15 files changed, 94 insertions(+), 53 deletions(-) diff --git a/apps/docs/src/app/core/api-files.ts b/apps/docs/src/app/core/api-files.ts index 3a7845fb4d4..695fc91d61e 100644 --- a/apps/docs/src/app/core/api-files.ts +++ b/apps/docs/src/app/core/api-files.ts @@ -43,9 +43,9 @@ export const API_FILES = { button: [ 'ButtonComponent' ], - buttonGroup: [ - 'ButtonGroupComponent', - 'ButtonGroupedDirective', + segmentedButton: [ + 'SegmentedButtonComponent', + 'SegmentedButtonDirective', ], calendar: [ 'CalendarComponent', diff --git a/apps/docs/src/app/core/component-docs/button/button-docs.component.html b/apps/docs/src/app/core/component-docs/button/button-docs.component.html index 3c77ee1be04..e08fd2a184b 100644 --- a/apps/docs/src/app/core/component-docs/button/button-docs.component.html +++ b/apps/docs/src/app/core/component-docs/button/button-docs.component.html @@ -18,7 +18,7 @@ Button Sizes - Use [compact]="true" for the mobile button size. + Use (or skip) [compact]="false" for the mobile button size. diff --git a/apps/docs/src/app/core/component-docs/button/examples/button-icons-example.component.html b/apps/docs/src/app/core/component-docs/button/examples/button-icons-example.component.html index d783dd0f01f..dae652b105b 100644 --- a/apps/docs/src/app/core/component-docs/button/examples/button-icons-example.component.html +++ b/apps/docs/src/app/core/component-docs/button/examples/button-icons-example.component.html @@ -6,7 +6,6 @@ - diff --git a/apps/docs/src/app/core/component-docs/button/examples/button-types-example.component.html b/apps/docs/src/app/core/component-docs/button/examples/button-types-example.component.html index 7251a5fd8fc..5e025d80ce9 100644 --- a/apps/docs/src/app/core/component-docs/button/examples/button-types-example.component.html +++ b/apps/docs/src/app/core/component-docs/button/examples/button-types-example.component.html @@ -1,4 +1,4 @@ - + diff --git a/apps/docs/src/app/core/component-docs/segmented-button/segmented-button-docs.component.ts b/apps/docs/src/app/core/component-docs/segmented-button/segmented-button-docs.component.ts index 7609a8785c0..7a1eac08630 100644 --- a/apps/docs/src/app/core/component-docs/segmented-button/segmented-button-docs.component.ts +++ b/apps/docs/src/app/core/component-docs/segmented-button/segmented-button-docs.component.ts @@ -2,8 +2,8 @@ import { Component, OnInit } from '@angular/core'; import { Schema } from '../../../schema/models/schema.model'; import { SchemaFactoryService } from '../../../schema/services/schema-factory/schema-factory.service'; -import * as buttonGroupDefaultExample from '!raw-loader!./examples/segmented-button-default-example.component.html'; -import * as buttonGroupToggleExample from '!raw-loader!./examples/segmented-button-toggle-example.component.html'; +import * as segmentedDefaultExample from '!raw-loader!./examples/segmented-button-default-example.component.html'; +import * as segmentedToggleExample from '!raw-loader!./examples/segmented-button-toggle-example.component.html'; import { ExampleFile } from '../../../documentation/core-helpers/code-example/example-file'; import { Icons } from '../../../documentation/utilities/icons'; @@ -95,7 +95,7 @@ export class SegmentedButtonDocsComponent implements OnInit { defaultToggleHtml: ExampleFile[] = [ { language: 'html', - code: buttonGroupToggleExample, + code: segmentedToggleExample, fileName: 'segmented-button-toggle-example', } ]; @@ -103,7 +103,7 @@ export class SegmentedButtonDocsComponent implements OnInit { defaultSizeHtml: ExampleFile[] = [ { language: 'html', - code: buttonGroupDefaultExample, + code: segmentedDefaultExample, fileName: 'segmented-button-default-example', } ]; diff --git a/apps/docs/src/app/core/component-docs/segmented-button/segmented-button-docs.module.ts b/apps/docs/src/app/core/component-docs/segmented-button/segmented-button-docs.module.ts index 4197d5cd8cc..a8ed491458c 100644 --- a/apps/docs/src/app/core/component-docs/segmented-button/segmented-button-docs.module.ts +++ b/apps/docs/src/app/core/component-docs/segmented-button/segmented-button-docs.module.ts @@ -15,7 +15,7 @@ const routes: Routes = [ component: SegmentedButtonHeaderComponent, children: [ { path: '', component: SegmentedButtonDocsComponent }, - { path: 'api', component: ApiComponent, data: { content: API_FILES.buttonGroup } } + { path: 'api', component: ApiComponent, data: { content: API_FILES.segmentedButton } } ] } ]; diff --git a/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.html b/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.html index 3cfe2e0de0d..dd84c242f27 100644 --- a/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.html +++ b/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.html @@ -17,5 +17,5 @@ - - + + diff --git a/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.ts b/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.ts index 624bcd3182c..908ae1f4bc1 100644 --- a/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.ts +++ b/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.ts @@ -8,6 +8,9 @@ import { Component } from '@angular/core'; fd-split-button { margin-right: 12px; } + .programmable-button { + margin-right: 12px; + } ` ] }) @@ -21,5 +24,4 @@ export class ButtonSplitProgrammaticalExampleComponent { primaryButtonClicked() { alert('Primary Button Clicked!'); } - } diff --git a/apps/docs/src/app/core/component-docs/split-button/examples/split-button-types-example.component.ts b/apps/docs/src/app/core/component-docs/split-button/examples/split-button-types-example.component.ts index 72f1845db23..5f11ff19a99 100644 --- a/apps/docs/src/app/core/component-docs/split-button/examples/split-button-types-example.component.ts +++ b/apps/docs/src/app/core/component-docs/split-button/examples/split-button-types-example.component.ts @@ -19,5 +19,4 @@ export class ButtonSplitTypesExampleComponent { primaryButtonClicked() { alert('Primary Button Clicked!'); } - } diff --git a/libs/core/src/lib/button/button.component.ts b/libs/core/src/lib/button/button.component.ts index aec526bad3a..db13680d6a6 100644 --- a/libs/core/src/lib/button/button.component.ts +++ b/libs/core/src/lib/button/button.component.ts @@ -1,21 +1,30 @@ import { ChangeDetectionStrategy, Component, ElementRef, Input, ViewEncapsulation, OnInit } from '@angular/core'; import { applyCssClass, CssClassBuilder } from '../utils/public_api'; -export type ButtonType = '' | 'standard' | 'positive' | 'negative' | 'attention' | 'half' | 'ghost' | 'transparent' | 'emphasized' | 'menu'; +export type ButtonType = + | '' + | 'standard' + | 'positive' + | 'negative' + | 'attention' + | 'half' + | 'ghost' + | 'transparent' + | 'emphasized' + | 'menu'; export type ButtonOptions = 'light' | 'emphasized' | 'menu'; - -// TODO remove in 0.9.0 +// TODO remove in 0.17.0 function replaceLightWithTransparent(option: string): string { return option.replace('light', 'transparent'); } -// TODO remove in 0.9.0 +// TODO remove in 0.17.0 export function getOptionCssClass(options: ButtonOptions | ButtonOptions[]): string { if (Array.isArray(options)) { return options.map(option => `fd-button--${this.replaceLightWithTransparent(option)}`).join(' '); } - return `fd-button--${this.replaceLightWithTransparent(options)}` + return `fd-button--${this.replaceLightWithTransparent(options)}`; } /** @@ -29,7 +38,9 @@ export function getOptionCssClass(options: ButtonOptions | ButtonOptions[]): str // tslint:disable-next-line:component-selector selector: `button[fd-button], a[fd-button]`, exportAs: 'fd-button', - template: ``, + template: ` + + `, styleUrls: ['./button.component.scss'], encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush @@ -41,50 +52,58 @@ export class ButtonComponent implements OnInit, CssClassBuilder { this._change(); } // user's custom classes + private _glyph: string; /** The icon to include in the button. See the icon page for the list of icons. - * setter is used to control when css class have to be rebuilded + * Setter is used to control when css class have to be rebuilded. + * Default value is set to ''. */ - private _glyph: string @Input() set glyph(icon: string) { this._glyph = icon; this._change(); - }; + } - /** Whether to apply compact mode to the button. */ private _compact: boolean = false; + /** Whether to apply compact mode to the button. + * Default value is set to false + */ @Input() set compact(isComact: boolean) { this._compact = isComact; this._change(); } + private _type: ButtonType; /** The type of the button. Types include: * 'standard' | 'positive' | 'negative' | 'attention' | 'half' | 'ghost' | 'transparent' | 'emphasized' | 'menu'. - * Leave empty for default (Action button).'*/ - private _type: ButtonType; + * Leave empty for default (Standard button).' + */ @Input() set fdType(type: ButtonType) { this._type = type; this._change(); } - /** Whether to apply menu mode to the button.*/ private _menu: boolean = false; + /** Whether to apply menu mode to the button. + * Default value is set to false + */ @Input() set fdMenu(menu: boolean) { this._menu = menu; this._change(); } - /** Button options. Options include 'emphasized' and 'light'. Leave empty for default.' */ - private _options: ButtonOptions | ButtonOptions[] + private _options: ButtonOptions | ButtonOptions[]; + /** Button options. Options include 'emphasized' and 'light'. Leave empty for default.' + * @deprecated + * Will be removed in 0.17.0. + */ @Input() options(opt: ButtonOptions | ButtonOptions[]) { console.warn(`fd-button options property is deprecated and will be removed in 0.17.0. - Please follow the breaking changes.`) + Please follow the breaking changes.`); this._options = opt; this._change(); - }; + } /** @hidden */ - constructor(private _elementRef: ElementRef) { - } + constructor(private _elementRef: ElementRef) { } /** Function runs when component is initialized * function should build component css class @@ -108,11 +127,13 @@ export class ButtonComponent implements OnInit, CssClassBuilder { this._options ? getOptionCssClass(this._options) : '', this._glyph ? `sap-icon--${this._glyph}` : '', this._class - ].filter(x => x !== '').join(' '); + ] + .filter(x => x !== '') + .join(' '); } /** HasElementRef interface implementation - * function used by applyCssClass and applyCssStyle decorators + * function used by applyCssClass and applyCssStyle decorators */ elementRef(): ElementRef { return this._elementRef; @@ -121,6 +142,4 @@ export class ButtonComponent implements OnInit, CssClassBuilder { private _change(): void { this.buildComponentCssClass(); } - - } diff --git a/libs/core/src/lib/segmented-button/segmented-button.component.ts b/libs/core/src/lib/segmented-button/segmented-button.component.ts index 5f31f1f7e74..a82b17fcf5a 100644 --- a/libs/core/src/lib/segmented-button/segmented-button.component.ts +++ b/libs/core/src/lib/segmented-button/segmented-button.component.ts @@ -23,5 +23,5 @@ export class SegmentedButtonComponent { /** @hidden */ @HostBinding('class.fd-segmented-button') - fdButtonGroupClass: boolean = true; + fdsegmentedButtonClass: boolean = true; } diff --git a/libs/core/src/lib/segmented-button/segmented-button.directive.spec.ts b/libs/core/src/lib/segmented-button/segmented-button.directive.spec.ts index 0cafe5e05a5..2070376be51 100644 --- a/libs/core/src/lib/segmented-button/segmented-button.directive.spec.ts +++ b/libs/core/src/lib/segmented-button/segmented-button.directive.spec.ts @@ -44,7 +44,7 @@ describe('SegmentedButtonDirective', () => { }); it('should assign base class', () => { - expect(component.ref.nativeElement.className).toContain('fd-button--grouped'); + expect(component.ref.nativeElement.className).toContain('fd-segmented-button'); }); it('should support compact mode', () => { diff --git a/libs/core/src/lib/segmented-button/segmented-button.directive.ts b/libs/core/src/lib/segmented-button/segmented-button.directive.ts index 0c5a4b84d21..e4a107df855 100644 --- a/libs/core/src/lib/segmented-button/segmented-button.directive.ts +++ b/libs/core/src/lib/segmented-button/segmented-button.directive.ts @@ -17,12 +17,14 @@ export class SegmentedButtonDirective extends AbstractFdNgxClass { /** * @deprecated - * Will be removed in 0.13.0 + * Will be removed in 0.17.0 */ @Input() size: string; - /** Defines if there will be added fd-button class. Enabled by default. */ + /** Defines if there will be added fd-button class. + * Enabled by default. + */ @Input() fdButtonClass: boolean = true; /** Glyph (icon) of the button. */ @@ -33,24 +35,27 @@ export class SegmentedButtonDirective extends AbstractFdNgxClass { @Input() state: string; - /** Whether the button should be in compact form. */ + /** Whether the button should be in compact form. + * Default value is set to false + */ @Input() @HostBinding('class.fd-button--compact') compact: boolean = false; /** @hidden */ - @HostBinding('class.fd-button--grouped') - fdButtonGroupedClass: boolean = true; + @HostBinding('class.fd-segmented-button') + fdsegmentedButtonClass: boolean = true; /** @hidden */ constructor(private elementRef: ElementRef) { super(elementRef); - console.warn('SegmentedButtonDirective is not supported and will be removed in 0.17.0') + console.warn(`SegmentedButtonDirective is not supported and will be removed in 0.17.0. + Add styles directly to button instead`); } /** @hidden */ _setProperties() { - this._addClassToElement('fd-button--grouped'); + this._addClassToElement('fd-segmented-button'); if (this.fdButtonClass) { this._addClassToElement('fd-button'); } diff --git a/libs/core/src/lib/split-button/split-button.component.html b/libs/core/src/lib/split-button/split-button.component.html index 7efad0bd749..51b8e6fb029 100644 --- a/libs/core/src/lib/split-button/split-button.component.html +++ b/libs/core/src/lib/split-button/split-button.component.html @@ -7,7 +7,7 @@ [triggers]="triggers" [fillControlMode]="fillControlMode" > - +
- diff --git a/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.html b/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.html index dd84c242f27..a7e7f08ef32 100644 --- a/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.html +++ b/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.html @@ -17,5 +17,5 @@
- - + + diff --git a/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.ts b/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.ts index 908ae1f4bc1..9032a064e22 100644 --- a/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.ts +++ b/apps/docs/src/app/core/component-docs/split-button/examples/split-button-programmatical-example.component.ts @@ -8,7 +8,7 @@ import { Component } from '@angular/core'; fd-split-button { margin-right: 12px; } - .programmable-button { + .docs-button { margin-right: 12px; } ` diff --git a/libs/core/src/lib/button/button.component.ts b/libs/core/src/lib/button/button.component.ts index db13680d6a6..55002059cb9 100644 --- a/libs/core/src/lib/button/button.component.ts +++ b/libs/core/src/lib/button/button.component.ts @@ -36,7 +36,7 @@ export function getOptionCssClass(options: ButtonOptions | ButtonOptions[]): str */ @Component({ // tslint:disable-next-line:component-selector - selector: `button[fd-button], a[fd-button]`, + selector: 'button[fd-button], a[fd-button]', exportAs: 'fd-button', template: ` @@ -94,6 +94,7 @@ export class ButtonComponent implements OnInit, CssClassBuilder { /** Button options. Options include 'emphasized' and 'light'. Leave empty for default.' * @deprecated * Will be removed in 0.17.0. + * Use 'fdType' instead. */ @Input() options(opt: ButtonOptions | ButtonOptions[]) { console.warn(`fd-button options property is deprecated and will be removed in 0.17.0. From 9bb4e4dec8a904c5d57e9c023689462685743abc Mon Sep 17 00:00:00 2001 From: Gracjan Gorecki Date: Wed, 25 Mar 2020 10:40:15 +0100 Subject: [PATCH 3/4] workaround added to fix missing selector --- libs/core/src/lib/button/button.component.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/core/src/lib/button/button.component.ts b/libs/core/src/lib/button/button.component.ts index 55002059cb9..fb9743c2a32 100644 --- a/libs/core/src/lib/button/button.component.ts +++ b/libs/core/src/lib/button/button.component.ts @@ -29,9 +29,12 @@ export function getOptionCssClass(options: ButtonOptions | ButtonOptions[]): str /** * Button directive, used to enhance standard HTML buttons. - * + * + * ``` selector: button[fd-button], a[fd-button] ``` + * * ```html * + * Button Text * ``` */ @Component({ From fd08429bb766c18cedbae1f5d1ecee837b770674 Mon Sep 17 00:00:00 2001 From: Gracjan Gorecki Date: Wed, 25 Mar 2020 15:05:29 +0100 Subject: [PATCH 4/4] fix: addresing pr comments --- libs/core/src/lib/button/button.component.ts | 4 +++- .../src/lib/segmented-button/segmented-button.component.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/core/src/lib/button/button.component.ts b/libs/core/src/lib/button/button.component.ts index fb9743c2a32..7f4d06a2c02 100644 --- a/libs/core/src/lib/button/button.component.ts +++ b/libs/core/src/lib/button/button.component.ts @@ -50,10 +50,12 @@ export function getOptionCssClass(options: ButtonOptions | ButtonOptions[]): str }) export class ButtonComponent implements OnInit, CssClassBuilder { private _class: string = ''; + /** The property allows user to pass additional css classes + */ @Input() set class(userClass: string) { this._class = userClass; this._change(); - } // user's custom classes + } private _glyph: string; /** The icon to include in the button. See the icon page for the list of icons. diff --git a/libs/core/src/lib/segmented-button/segmented-button.component.ts b/libs/core/src/lib/segmented-button/segmented-button.component.ts index a82b17fcf5a..3c2d59860a3 100644 --- a/libs/core/src/lib/segmented-button/segmented-button.component.ts +++ b/libs/core/src/lib/segmented-button/segmented-button.component.ts @@ -23,5 +23,5 @@ export class SegmentedButtonComponent { /** @hidden */ @HostBinding('class.fd-segmented-button') - fdsegmentedButtonClass: boolean = true; + fdSegmentedButtonClass: boolean = true; }