Skip to content

Commit

Permalink
added status chip to storybook (#1514)
Browse files Browse the repository at this point in the history
  • Loading branch information
pflopez committed May 14, 2024
1 parent 20a8fcc commit 5f0fd5e
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 2 deletions.
176 changes: 174 additions & 2 deletions src/interface/src/styleguide/docs/documentation.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,145 @@
}
},
"templateData": "<mat-icon *ngIf=\"icon\">{{ icon }}</mat-icon>\n<ng-content></ng-content>\n"
},
{
"name": "StatusChipComponent",
"id": "component-StatusChipComponent-2b86b4ec02ea586989a688f308c425033d867782f2d7a548a8d410071345f96b04847a74cd077844dc90b6a480f8169359da251fc8236e2f9d2e067b91b4ca13",
"file": "src/styleguide/status-chip/status-chip.component.ts",
"encapsulation": [],
"entryComponents": [],
"inputs": [],
"outputs": [],
"providers": [],
"selector": "sg-status-chip",
"styleUrls": [],
"styles": [],
"templateUrl": [
"./status-chip.component.html"
],
"viewProviders": [],
"hostDirectives": [],
"inputsClass": [
{
"name": "label",
"defaultValue": "''",
"deprecated": false,
"deprecationMessage": "",
"rawdescription": "\n\nOptional label\n",
"description": "<p>Optional label</p>\n",
"line": 25,
"type": "string",
"decorators": []
},
{
"name": "status",
"defaultValue": "'inProgress'",
"deprecated": false,
"deprecationMessage": "",
"rawdescription": "\n\nThe status\n",
"description": "<p>The status</p>\n",
"line": 21,
"type": "StatusChipStatus",
"decorators": []
}
],
"outputsClass": [],
"propertiesClass": [],
"methodsClass": [],
"deprecated": false,
"deprecationMessage": "",
"hostBindings": [
{
"name": "class.failed",
"deprecated": false,
"deprecationMessage": "",
"line": 48,
"type": "boolean",
"decorators": []
},
{
"name": "class.in-progress",
"deprecated": false,
"deprecationMessage": "",
"line": 38,
"type": "boolean",
"decorators": []
},
{
"name": "class.running",
"deprecated": false,
"deprecationMessage": "",
"line": 53,
"type": "boolean",
"decorators": []
},
{
"name": "class.success",
"deprecated": false,
"deprecationMessage": "",
"line": 43,
"type": "boolean",
"decorators": []
}
],
"hostListeners": [],
"standalone": true,
"imports": [
{
"name": "NgIf"
},
{
"name": "NgSwitch"
}
],
"description": "<p>Status chip to display status inline.\nTakes optional label or displays the status styled accordingly.</p>\n",
"rawdescription": "\n\nStatus chip to display status inline.\nTakes optional label or displays the status styled accordingly.\n",
"type": "component",
"sourceCode": "import { Component, HostBinding, Input } from '@angular/core';\nimport { NgIf, NgSwitch } from '@angular/common';\n\nexport type StatusChipStatus = 'inProgress' | 'success' | 'failed' | 'running';\n\n/**\n * Status chip to display status inline.\n * Takes optional label or displays the status styled accordingly.\n */\n@Component({\n selector: 'sg-status-chip',\n standalone: true,\n imports: [NgIf, NgSwitch],\n templateUrl: './status-chip.component.html',\n styleUrl: './status-chip.component.scss',\n})\nexport class StatusChipComponent {\n /**\n * The status\n */\n @Input() status: StatusChipStatus = 'inProgress';\n /**\n * Optional label\n */\n @Input() label? = '';\n\n /**\n * @ignore\n */\n readonly defaultTextByStatus: Record<StatusChipStatus, string> = {\n inProgress: 'In Progress',\n success: 'Success',\n failed: 'Failed',\n running: 'Running',\n };\n\n @HostBinding('class.in-progress')\n get isInProgress() {\n return this.status === 'inProgress';\n }\n\n @HostBinding('class.success')\n get isSuccess() {\n return this.status === 'success';\n }\n\n @HostBinding('class.failed')\n get isFailed() {\n return this.status === 'failed';\n }\n\n @HostBinding('class.running')\n get isRunning() {\n return this.status === 'running';\n }\n}\n",
"styleUrl": "./status-chip.component.scss",
"assetsDirs": [],
"styleUrlsData": "",
"stylesData": "",
"extends": [],
"accessors": {
"isInProgress": {
"name": "isInProgress",
"getSignature": {
"name": "isInProgress",
"type": "",
"returnType": "",
"line": 38
}
},
"isSuccess": {
"name": "isSuccess",
"getSignature": {
"name": "isSuccess",
"type": "",
"returnType": "",
"line": 43
}
},
"isFailed": {
"name": "isFailed",
"getSignature": {
"name": "isFailed",
"type": "",
"returnType": "",
"line": 48
}
},
"isRunning": {
"name": "isRunning",
"getSignature": {
"name": "isRunning",
"type": "",
"returnType": "",
"line": 53
}
}
},
"templateData": "<ng-container *ngIf=\"label; else defaultByStatus\">\n {{ label }}\n</ng-container>\n<ng-template #defaultByStatus>{{ defaultTextByStatus[status] }}</ng-template>\n"
}
],
"modules": [],
Expand All @@ -213,6 +352,17 @@
"deprecationMessage": "",
"description": "",
"kind": 192
},
{
"name": "StatusChipStatus",
"ctype": "miscellaneous",
"subtype": "typealias",
"rawtype": "\"inProgress\" | \"success\" | \"failed\" | \"running\"",
"file": "src/styleguide/status-chip/status-chip.component.ts",
"deprecated": false,
"deprecationMessage": "",
"description": "",
"kind": 192
}
],
"enumerations": [],
Expand All @@ -232,13 +382,26 @@
"description": "",
"kind": 192
}
],
"src/styleguide/status-chip/status-chip.component.ts": [
{
"name": "StatusChipStatus",
"ctype": "miscellaneous",
"subtype": "typealias",
"rawtype": "\"inProgress\" | \"success\" | \"failed\" | \"running\"",
"file": "src/styleguide/status-chip/status-chip.component.ts",
"deprecated": false,
"deprecationMessage": "",
"description": "",
"kind": 192
}
]
}
},
"routes": [],
"coverage": {
"count": 20,
"status": "low",
"count": 31,
"status": "medium",
"files": [
{
"filePath": "src/styleguide/button/button.component.ts",
Expand All @@ -248,6 +411,15 @@
"coveragePercent": 20,
"coverageCount": "2/10",
"status": "low"
},
{
"filePath": "src/styleguide/status-chip/status-chip.component.ts",
"type": "component",
"linktype": "component",
"name": "StatusChipComponent",
"coveragePercent": 42,
"coverageCount": "3/7",
"status": "medium"
}
]
}
Expand Down
1 change: 1 addition & 0 deletions src/interface/src/styleguide/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './button/button.component';
export * from './status-chip/status-chip.component';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<ng-container *ngIf="label; else defaultByStatus">
{{ label }}
</ng-container>
<ng-template #defaultByStatus>{{ defaultTextByStatus[status] }}</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@import "mixins";
@import "colors";

:host {
@include xs-label();
display: inline-flex;
padding: 8px 12px;
justify-content: center;
align-items: center;
border-radius: 4px;

&.in-progress {
color: $color-main-blue;
background-color: $color-soft-light-blue;
}

&.success {
color: $color-brand-green;
background-color: $color-brand-soft-green;
}

&.failed {
color: $color-dark-red;
background-color: $color-light-red
}

&.running {
color: $color-dark-yellow;
background-color: $color-brand-soft-yellow;
}
}
56 changes: 56 additions & 0 deletions src/interface/src/styleguide/status-chip/status-chip.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Component, HostBinding, Input } from '@angular/core';
import { NgIf, NgSwitch } from '@angular/common';

export type StatusChipStatus = 'inProgress' | 'success' | 'failed' | 'running';

/**
* Status chip to display status inline.
* Takes optional label or displays the status styled accordingly.
*/
@Component({
selector: 'sg-status-chip',
standalone: true,
imports: [NgIf, NgSwitch],
templateUrl: './status-chip.component.html',
styleUrl: './status-chip.component.scss',
})
export class StatusChipComponent {
/**
* The status
*/
@Input() status: StatusChipStatus = 'inProgress';
/**
* Optional label
*/
@Input() label? = '';

/**
* @ignore
*/
readonly defaultTextByStatus: Record<StatusChipStatus, string> = {
inProgress: 'In Progress',
success: 'Success',
failed: 'Failed',
running: 'Running',
};

@HostBinding('class.in-progress')
get isInProgress() {
return this.status === 'inProgress';
}

@HostBinding('class.success')
get isSuccess() {
return this.status === 'success';
}

@HostBinding('class.failed')
get isFailed() {
return this.status === 'failed';
}

@HostBinding('class.running')
get isRunning() {
return this.status === 'running';
}
}
48 changes: 48 additions & 0 deletions src/interface/src/styleguide/status-chip/status-chip.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { Meta, StoryObj } from '@storybook/angular';
import { argsToTemplate } from '@storybook/angular';
import { StatusChipComponent } from './status-chip.component';

const meta: Meta<StatusChipComponent> = {
title: 'Components/Status Chip',
component: StatusChipComponent,
tags: ['autodocs'],
render: (args) => ({
props: args,
template: `<sg-status-chip ${argsToTemplate(args)}></sg-status-chip>`,
}),
};

export default meta;
type Story = StoryObj<StatusChipComponent>;

export const Default: Story = {
args: {},
};

export const InProgress: Story = {
args: {
status: 'inProgress',
},
};
export const Success: Story = {
args: {
status: 'success',
},
};
export const Failed: Story = {
args: {
status: 'failed',
},
};
export const Running: Story = {
args: {
status: 'running',
},
};

export const AnyLabel: Story = {
args: {
status: 'success',
label: 'done deal',
},
};
4 changes: 4 additions & 0 deletions src/interface/src/styles/_colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ $color-brand-soft-green: #DFEDE6;
$color-brand-soft-orange: #EB8573;
$color-brand-soft-yellow: #EDD9A4;
$color-drop-shadow: #00000040;
$color-dark-red: #9E0000;
$color-light-red: #FEE2E2;
$color-dark-yellow: #614100;
$color-soft-light-blue: #E9F1FF;
5 changes: 5 additions & 0 deletions src/interface/src/styles/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ Declare mixins based on styleguide and apply to classes
@include defToStyles(map.get($styleguide, 'standard-label-sm'))
}

@mixin xs-label {
@include defToStyles(map.get($styleguide, 'xs-label'))
}


@mixin standard-input-label {
@include defToStyles(map.get($styleguide, 'standard-input-label'))
}
Expand Down

0 comments on commit 5f0fd5e

Please sign in to comment.