Skip to content

Commit

Permalink
feat(button): add fullWidth mode (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnixaa authored Jul 30, 2018
1 parent aed2099 commit 13014d4
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/framework/theme/components/button/button.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
&:hover, &:focus {
text-decoration: none;
}

&.btn-full-width {
width: 100%;
}
}
15 changes: 15 additions & 0 deletions src/framework/theme/components/button/button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import { convertToBoolProperty } from '../helpers';
* and `a`:
* @stacked-example(Button Elements, button/button-types.component.html)
*
* Button can be made `fullWidth`:
* @stacked-example(Full Width Button, button/button-full-width.component.html)
*
* @styles
*
* btn-fg:
Expand Down Expand Up @@ -192,6 +195,9 @@ export class NbButtonComponent {
return this.disabled ? '-1' : '0';
}

@HostBinding('class.btn-full-width')
fullWidth = false;

/**
* Button size, available sizes:
* `xxsmall`, `xsmall`, `small`, `medium`, `large`
Expand Down Expand Up @@ -239,6 +245,15 @@ export class NbButtonComponent {
this.disabled = convertToBoolProperty(val);
}

/**
* If set element will fill its container
* @param {boolean}
*/
@Input('fullWidth')
set setFullWidth(value) {
this.fullWidth = convertToBoolProperty(value);
}

/**
* Adds `outline` styles
* @param {boolean} val
Expand Down
9 changes: 9 additions & 0 deletions src/framework/theme/components/button/button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,13 @@ describe('Component: NbButton', () => {
.debugElement.nativeElement.classList.contains('btn-semi-round'))
.toBeTruthy()
});

it('should set full-width class', () => {
button.fullWidth = true;
fixture.detectChanges();
expect(
fixture
.debugElement.nativeElement.classList.contains('btn-full-width'))
.toBeTruthy()
});
});
10 changes: 10 additions & 0 deletions src/playground/button/button-full-width.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<nb-card>
<nb-card-header>Button Full Width</nb-card-header>
<nb-card-body>
<button nbButton fullWidth status="primary">Primary</button>
<button nbButton fullWidth status="success">Success</button>
<button nbButton fullWidth status="info">Info</button>
<button nbButton fullWidth status="warning">Warning</button>
<button nbButton fullWidth status="danger">Danger</button>
</nb-card-body>
</nb-card>
20 changes: 20 additions & 0 deletions src/playground/button/button-full-width.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license
* Copyright Akveo. All Rights Reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import { ChangeDetectionStrategy, Component } from '@angular/core';

@Component({
selector: 'nb-button-full-width',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './button-full-width.component.html',
styles: [`
[nbButton] {
margin-bottom: 1rem;
}
`],
})
export class NbButtonFullWidthComponent {
}
5 changes: 5 additions & 0 deletions src/playground/playground-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ import { NbButtonHeroComponent } from './button/button-hero.component';
import { NbButtonOutlineComponent } from './button/button-outline.component';
import { NbButtonSizesComponent } from './button/button-sizes.component';
import { NbButtonTypesComponent } from './button/button-types.component';
import { NbButtonFullWidthComponent } from './button/button-full-width.component';
import { NbInputsShowcaseComponent } from './input/input-showcase.component';
import { NbInputColorsComponent } from './input/input-colors.component';
import { NbInputSizesComponent } from './input/input-sizes.component';
Expand Down Expand Up @@ -206,6 +207,10 @@ export const routes: Routes = [
path: 'button-types.component',
component: NbButtonTypesComponent,
},
{
path: 'button-full-width.component',
component: NbButtonFullWidthComponent,
},
],
},
{
Expand Down
2 changes: 2 additions & 0 deletions src/playground/playground.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ import { NbButtonHeroComponent } from './button/button-hero.component';
import { NbButtonOutlineComponent } from './button/button-outline.component';
import { NbButtonSizesComponent } from './button/button-sizes.component';
import { NbButtonTypesComponent } from './button/button-types.component';
import { NbButtonFullWidthComponent } from './button/button-full-width.component';
import { NbInputsShowcaseComponent } from './input/input-showcase.component';
import { NbInputColorsComponent } from './input/input-colors.component';
import { NbInputSizesComponent } from './input/input-sizes.component';
Expand Down Expand Up @@ -323,6 +324,7 @@ export const NB_EXAMPLE_COMPONENTS = [
NbButtonOutlineComponent,
NbButtonSizesComponent,
NbButtonTypesComponent,
NbButtonFullWidthComponent,
NbInputsShowcaseComponent,
NbInputColorsComponent,
NbInputSizesComponent,
Expand Down

0 comments on commit 13014d4

Please sign in to comment.