Skip to content

Commit

Permalink
feat(design): create <daff-flat-button> variant (#2448)
Browse files Browse the repository at this point in the history
  • Loading branch information
xelaint committed Jul 6, 2023
1 parent 6d6067f commit ed4a52d
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 55 deletions.
19 changes: 19 additions & 0 deletions libs/design/button/examples/src/examples.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { BasicButtonComponent } from './basic-button/basic-button.component';
import { FlatButtonComponent } from './flat-button/flat-button.component';
import { IconButtonComponent } from './icon-button/icon-button.component';
import { RaisedButtonComponent } from './raised-button/raised-button.component';
import { SizeableButtonComponent } from './sizeable-button/sizeable-button.component';
import { StatusableButtonComponent } from './statusable-button/statusable-button.component';
import { StrokedButtonComponent } from './stroked-button/stroked-button.component';
import { UnderlineButtonComponent } from './underline-button/underline-button.component';

export const BUTTON_EXAMPLES = [
BasicButtonComponent,
IconButtonComponent,
RaisedButtonComponent,
SizeableButtonComponent,
StatusableButtonComponent,
StrokedButtonComponent,
UnderlineButtonComponent,
FlatButtonComponent,
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<button daff-flat-button>Default</button>
<button daff-flat-button color="primary">Primary</button>
<button daff-flat-button color="secondary">Secondary</button>
<button daff-flat-button color="tertiary">Tertiary</button>
<button daff-flat-button color="black">Black</button>
<button daff-flat-button color="white">White</button>
<button daff-flat-button color="theme">Theme</button>
<button daff-flat-button color="theme-contrast">Theme Contrast</button>
<button daff-flat-button><fa-icon [icon]="faChevronLeft" size="sm" daffPrefix></fa-icon>Button</button>
<button daff-flat-button><fa-icon [icon]="faChevronRight" size="sm" daffSuffix></fa-icon>Button</button>
<button daff-flat-button disabled>Disabled</button>
<button daff-flat-button loading="true">Default</button>
<a href="#" daff-flat-button>Link</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
ChangeDetectionStrategy,
Component,
} from '@angular/core';
import {
faChevronLeft,
faChevronRight,
} from '@fortawesome/free-solid-svg-icons';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: 'flat-button',
templateUrl: './flat-button.component.html',
styles: [`
:host {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
`],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FlatButtonComponent {
faChevronLeft = faChevronLeft;
faChevronRight = faChevronRight;
}
20 changes: 20 additions & 0 deletions libs/design/button/examples/src/flat-button/flat-button.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NgModule } from '@angular/core';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';

import { DaffButtonModule } from '@daffodil/design';

import { FlatButtonComponent } from './flat-button.component';

@NgModule({
declarations: [
FlatButtonComponent,
],
exports: [
FlatButtonComponent,
],
imports: [
DaffButtonModule,
FontAwesomeModule,
],
})
export class FlatButtonModule { }
38 changes: 11 additions & 27 deletions libs/design/button/examples/src/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
import { BasicButtonComponent } from './basic-button/basic-button.component';
export { BUTTON_EXAMPLES } from './examples';

export { BasicButtonComponent } from './basic-button/basic-button.component';
export { BasicButtonModule } from './basic-button/basic-button.module';
import { IconButtonComponent } from './icon-button/icon-button.component';
export { FlatButtonComponent } from './flat-button/flat-button.component';
export { FlatButtonModule } from './flat-button/flat-button.module';
export { IconButtonComponent } from './icon-button/icon-button.component';
export { IconButtonModule } from './icon-button/icon-button.module';
import { RaisedButtonComponent } from './raised-button/raised-button.component';
export { RaisedButtonComponent } from './raised-button/raised-button.component';
export { RaisedButtonModule } from './raised-button/raised-button.module';
import { SizeableButtonComponent } from './sizeable-button/sizeable-button.component';
export { SizeableButtonComponent } from './sizeable-button/sizeable-button.component';
export { SizeableButtonModule } from './sizeable-button/sizeable-button.module';
import { StatusableButtonComponent } from './statusable-button/statusable-button.component';
export { StatusableButtonComponent } from './statusable-button/statusable-button.component';
export { StatusableButtonModule } from './statusable-button/statusable-button.module';
import { StrokedButtonComponent } from './stroked-button/stroked-button.component';
export { StrokedButtonComponent } from './stroked-button/stroked-button.component';
export { StrokedButtonModule } from './stroked-button/stroked-button.module';
import { UnderlineButtonComponent } from './underline-button/underline-button.component';
export { UnderlineButtonComponent } from './underline-button/underline-button.component';
export { UnderlineButtonModule } from './underline-button/underline-button.module';

export const BUTTON_EXAMPLES = [
BasicButtonComponent,
IconButtonComponent,
RaisedButtonComponent,
SizeableButtonComponent,
StatusableButtonComponent,
StrokedButtonComponent,
UnderlineButtonComponent,
];

export {
BasicButtonComponent,
IconButtonComponent,
RaisedButtonComponent,
SizeableButtonComponent,
StatusableButtonComponent,
StrokedButtonComponent,
UnderlineButtonComponent,
};
83 changes: 58 additions & 25 deletions libs/design/src/atoms/button/button-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@use './button-theme-variants/raised';
@use './button-theme-variants/stroked';
@use './button-theme-variants/underline';
@use './button-theme-variants/focus';
@use './button-theme-variants/flat';

@mixin daff-button-theme($theme) {
$primary: map.get($theme, primary);
Expand Down Expand Up @@ -437,66 +437,99 @@ z
}
}

.daff-underline-button {
@include underline.daff-underline-button-theme-variant(
theming.daff-illuminate($base, $gray, 7)
);
.daff-flat-button {
color: theming.daff-text-contrast($base);

&:after {
background-color: theming.daff-illuminate($base, $gray, 2);
}

&:active {
&:after {
background-color: theming.daff-illuminate($base, $gray, 3);
}
}

&.daff-primary {
@include underline.daff-underline-button-theme-variant(
theming.daff-color($primary)
@include flat.daff-flat-button-theme-variant(
theming.daff-color($primary),
theming.daff-color($primary, 70)
);
}

&.daff-secondary {
@include underline.daff-underline-button-theme-variant(
theming.daff-color($secondary)
@include flat.daff-flat-button-theme-variant(
theming.daff-color($secondary),
theming.daff-color($secondary, 70)
);
}

&.daff-tertiary {
@include underline.daff-underline-button-theme-variant(
theming.daff-color($tertiary)
@include flat.daff-flat-button-theme-variant(
theming.daff-color($tertiary),
theming.daff-color($tertiary, 70)
);
}

&.daff-black {
@include underline.daff-underline-button-theme-variant($black);
@include flat.daff-flat-button-theme-variant(
$black,
theming.daff-color($gray, 100)
);
}

&.daff-white {
@include underline.daff-underline-button-theme-variant($white);
@include flat.daff-flat-button-theme-variant(
$white,
theming.daff-color($gray, 20)
);
}

&.daff-theme {
@include underline.daff-underline-button-theme-variant($base);
@include flat.daff-flat-button-theme-variant(
$base,
theming.daff-illuminate($base, $gray, 2)
);
}

&.daff-theme-contrast {
@include underline.daff-underline-button-theme-variant($base-contrast);
@include flat.daff-flat-button-theme-variant(
$base-contrast,
theming.daff-illuminate($base-contrast, $gray, 2)
);
}

&[disabled] {
@include underline.daff-underline-button-theme-variant(
theming.daff-illuminate($base, $gray, 4)
);
&[disabled],
&.daff-button--disabled {
color: theming.daff-illuminate($base, $gray, 5);

&:hover,
&:focus,
&:active {
&:after {
background: transparent;
}
}
}

&.daff-warn {
@include underline.daff-underline-button-theme-variant(
theming.daff-color(theming.$daff-bronze, 60)
@include flat.daff-flat-button-theme-variant(
theming.daff-color(theming.$daff-bronze, 60),
theming.daff-color(theming.$daff-bronze, 70)
);
}

&.daff-danger {
@include underline.daff-underline-button-theme-variant(
theming.daff-color(theming.$daff-red, 60)
@include flat.daff-flat-button-theme-variant(
theming.daff-color(theming.$daff-red, 60),
theming.daff-color(theming.$daff-red, 70)
);
}

&.daff-success {
@include underline.daff-underline-button-theme-variant(
theming.daff-color(theming.$daff-green, 60)
@include flat.daff-flat-button-theme-variant(
theming.daff-color(theming.$daff-green, 60),
theming.daff-color(theming.$daff-green, 70)
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion libs/design/src/atoms/button/button.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@

.daff-button,
.daff-raised-button,
.daff-stroked-button {
.daff-stroked-button,
.daff-flat-button {
@include daff-button();
@include daff-button-animation();
@include prefix-suffix();
Expand Down
21 changes: 20 additions & 1 deletion libs/design/src/atoms/button/button.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import {
<a daff-raised-button [color]="color" [size]="size" [status]="status" [loading]="loading" [tabindex]="tabindex">Raised Link Button</a>
<a daff-icon-button [color]="color" [size]="size" [status]="status" [loading]="loading" [tabindex]="tabindex">Icon Link Button</a>
<a daff-underline-button [color]="color" [size]="size" [status]="status" [loading]="loading" [tabindex]="tabindex">Underline Link Button</a>
<a daff-flat-button [color]="color" [size]="size" [status]="status" [loading]="loading" [tabindex]="tabindex">Flat Link Button</a>
<button daff-button [color]="color" [size]="size" [status]="status" [loading]="loading" [tabindex]="tabindex">Basic Button</button>
<button daff-stroked-button [color]="color" [size]="size" [status]="status" [loading]="loading" [tabindex]="tabindex">Stroked Button</button>
<button daff-raised-button [color]="color" [size]="size" [status]="status" [loading]="loading" [tabindex]="tabindex">Raised Button</button>
<button daff-icon-button [color]="color" [size]="size" [status]="status" [loading]="loading" [tabindex]="tabindex">Icon Button</button>
<button daff-underline-button [color]="color" [size]="size" [status]="status" [loading]="loading" [tabindex]="tabindex">Underline Button</button>
<button daff-flat-button [color]="color" [size]="size" [status]="status" [loading]="loading" [tabindex]="tabindex">Flat Button</button>
`,
})

Expand Down Expand Up @@ -125,7 +127,7 @@ describe('DaffButtonComponent', () => {
});
});

describe('<daff-icon-butto>n', () => {
describe('<daff-icon-button>', () => {
beforeEach(() => {
buttonDE = fixture.debugElement.query(By.css('button[daff-icon-button]'));
anchorDE = fixture.debugElement.query(By.css('a[daff-icon-button]'));
Expand Down Expand Up @@ -159,6 +161,23 @@ describe('DaffButtonComponent', () => {
});
});

describe('<daff-flat-button>', () => {
beforeEach(() => {
buttonDE = fixture.debugElement.query(By.css('button[daff-flat-button]'));
anchorDE = fixture.debugElement.query(By.css('a[daff-flat-button]'));
});

it('should add a class of `daff-flat-button` to the host element', () => {
expect(buttonDE.classes).toEqual(jasmine.objectContaining({
'daff-flat-button': true,
}));

expect(anchorDE.classes).toEqual(jasmine.objectContaining({
'daff-flat-button': true,
}));
});
});

describe('using the color property of a button', () => {
it('should not set a default color', () => {
expect(component.color).toBeFalsy();
Expand Down
13 changes: 12 additions & 1 deletion libs/design/src/atoms/button/button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const BUTTON_HOST_ATTRIBUTES: DaffButtonType[] = [
'daff-button',
'daff-stroked-button',
'daff-raised-button',
'daff-flat-button',
'daff-icon-button',
'daff-underline-button',
];
Expand All @@ -51,7 +52,7 @@ class DaffButtonBase{

const _daffButtonBase = daffArticleEncapsulatedMixin(daffPrefixableMixin(daffSuffixableMixin(daffColorMixin(daffStatusMixin(daffSizeMixin<DaffButtonSize>(DaffButtonBase, 'md'))))));

export type DaffButtonType = 'daff-button' | 'daff-stroked-button' | 'daff-raised-button' | 'daff-icon-button' | 'daff-underline-button' | undefined;
export type DaffButtonType = 'daff-button' | 'daff-stroked-button' | 'daff-raised-button' | 'daff-flat-button' | 'daff-icon-button' | 'daff-underline-button' | undefined;

/**
* The DaffSizeable types that the DaffButtonComponent can implement
Expand All @@ -62,6 +63,7 @@ enum DaffButtonTypeEnum {
Default = 'daff-button',
Stroked = 'daff-stroked-button',
Raised = 'daff-raised-button',
Flat = 'daff-flat-button',
Icon = 'daff-icon-button',
Underline = 'daff-underline-button'
}
Expand All @@ -75,11 +77,13 @@ enum DaffButtonTypeEnum {
'button[daff-button]' + ',' +
'button[daff-stroked-button]' + ',' +
'button[daff-raised-button]' + ',' +
'button[daff-flat-button]' + ',' +
'button[daff-icon-button]' + ',' +
'button[daff-underline-button]' + ',' +
'a[daff-button]' + ',' +
'a[daff-stroked-button]' + ',' +
'a[daff-raised-button]' + ',' +
'a[daff-flat-button]' + ',' +
'a[daff-icon-button]' + ',' +
'a[daff-underline-button]',
templateUrl: './button.component.html',
Expand Down Expand Up @@ -138,6 +142,13 @@ export class DaffButtonComponent
return this.buttonType === DaffButtonTypeEnum.Raised;
}

/**
* @docs-private
*/
@HostBinding('class.daff-flat-button') get flat() {
return this.buttonType === DaffButtonTypeEnum.Flat;
}

/**
* @docs-private
*/
Expand Down

0 comments on commit ed4a52d

Please sign in to comment.