Skip to content

Commit

Permalink
feat(ui): create metadata card component EBS-1516 (#234)
Browse files Browse the repository at this point in the history
* feat(ui): create metadata card component EBS-1516

* feat(ui): refactor metadata component styles and rename variable EBS-1516

* feat(ui): lint refactor EBS-1516

---------

Co-authored-by: Mihkel.Paloots <[email protected]>
  • Loading branch information
MihkelPaloots and Mihkel.Paloots authored Sep 10, 2024
1 parent e671e79 commit 62d8cac
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 0 deletions.
47 changes: 47 additions & 0 deletions apps/ui-e2e/src/component/metadata-card.component.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
describe('MetadataCardComponent', () => {
before(() => {
cy.visitStorybook();
});

it('Renders metadata card with default severity', () => {
cy.loadStory('Angular Metadata Card', 'Default');
cy.shouldHaveCSSVar(
'cvi-ng-metadata-card',
'--cvi-metadata-card-left-border-color',
'#005aa3'
);
});

it('Renders metadata card with success severity', () => {
cy.loadStory('Angular Metadata Card', 'Default')
.get('cvi-ng-metadata-card')
.changeArg('severity', 'success');
cy.shouldHaveCSSVar(
'cvi-ng-metadata-card',
'--cvi-metadata-card-left-border-color',
'#2c7a4c'
);
});

it('Renders metadata card with warning severity', () => {
cy.loadStory('Angular Metadata Card', 'Default')
.get('cvi-ng-metadata-card')
.changeArg('severity', 'warning');
cy.shouldHaveCSSVar(
'cvi-ng-metadata-card',
'--cvi-metadata-card-left-border-color',
'#ffb511'
);
});

it('Renders metadata card with error severity', () => {
cy.loadStory('Angular Metadata Card', 'Default')
.get('cvi-ng-metadata-card')
.changeArg('severity', 'error');
cy.shouldHaveCSSVar(
'cvi-ng-metadata-card',
'--cvi-metadata-card-left-border-color',
'#d73e3e'
);
});
});
4 changes: 4 additions & 0 deletions libs/styles/src/lib/scss/_apply.scss
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,7 @@
.cvi-labeled-item {
@include cvi-labeled-item;
}

.cvi-metadata-card {
@include cvi-metadata-card;
}
27 changes: 27 additions & 0 deletions libs/styles/src/lib/scss/components/_metadata-card.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@mixin cvi-metadata-card($base: &) {
--comment: 'A card with a coloured left border and content';

display: flex;
border-radius: var(--cvi-radius-s);
border-left: 6px solid var(--cvi-metadata-card-left-border-color);

@include cvi-breakpoint-up(sm) {
box-shadow: var(--cvi-shadow-beta);
}

#{$base}__content {
padding-inline: get-spacing('kuressaare');
padding-block: get-spacing('haapsalu');
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0;

@include cvi-breakpoint-down(sm) {
border: 1px solid get-color(black-coral-2);
border-left: none;
border-top-right-radius: var(--cvi-radius-s);
border-bottom-right-radius: var(--cvi-radius-s);
}
}
}

1 change: 1 addition & 0 deletions libs/styles/src/lib/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
@import 'components/table-responsive';
@import 'components/table-card';
@import 'components/labeled-item';
@import "components/metadata-card";

@import 'apply';

Expand Down
1 change: 1 addition & 0 deletions libs/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ export * from './lib/circle/circle.component';
export * from './lib/table-card/table-card.component';
export * from './lib/table-responsive/table-responsive.component';
export * from './lib/labeled-item/labeled-item.component';
export * from './lib/metadata-card/metadata-card.component';
5 changes: 5 additions & 0 deletions libs/ui/src/lib/metadata-card/metadata-card.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="cvi-metadata-card">
<div class="cvi-metadata-card__content">
<ng-content></ng-content>
</div>
</div>
18 changes: 18 additions & 0 deletions libs/ui/src/lib/metadata-card/metadata-card.component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## General description

Feature | Description
- | -
Selector | `cvi-ng-metadata-card`
Component name | `MetadataCardComponent`
Design system module | -
Content | no
Permitted parent/ancestors | any
Permitted children | -

## Where to use

Use if you need to display metadata information in a card-like format with coloured left border.

## How to use

Pass `--cvi-metadata-card-left-border-color` CSS variable to the Sass component. (See example colors in `metadata-card.ts`.)
21 changes: 21 additions & 0 deletions libs/ui/src/lib/metadata-card/metadata-card.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MetadataCardComponent } from '@egov/cvi-ng';

describe('MetadataCardComponent', () => {
let component: MetadataCardComponent;
let fixture: ComponentFixture<MetadataCardComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MetadataCardComponent],
}).compileComponents();

fixture = TestBed.createComponent(MetadataCardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
77 changes: 77 additions & 0 deletions libs/ui/src/lib/metadata-card/metadata-card.component.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { Meta, StoryObj } from '@storybook/angular';
import notes from './metadata-card.component.md';
import { MetadataCardComponent } from './metadata-card.component';

export default {
title: 'Angular/Metadata Card',
component: MetadataCardComponent,
parameters: {
docs: {
description: {
component: notes,
},
},
},
argTypes: {
severity: {
name: 'Severity style',
control: { type: 'select' },
},
},
args: {
severity: 'info',
},
} as Meta<MetadataCardComponent>;

type Story = StoryObj<MetadataCardComponent>;

export const Default: Story = {
render: (args: MetadataCardComponent) => ({
props: {
...args,
html: '<div class="cvi-html-section__content-elements"><cvi-web-track gap="4" layout="flex" flex-direction="vertical"><a href="https://www.siseministeerium.ee/maakonnakeskuse-kohalikud-omavalitsused-rahvastiku-toimingute-valdkonnas" target="_blank" class="external-link" rel="noopener noreferrer">Maakonnakeskuse kohalikud omavalitsused</a><a href="https://www.notar.ee/et/notarid/nimekiri" target="_blank" class="external-link" rel="noopener noreferrer">Notarid</a><a href="https://www.siseministeerium.ee/abielu-solmimise-oigust-omavad-vaimulikud" target="_blank" class="external-link" rel="noopener noreferrer">Abielu sõlmimise õigust omavad vaimulikud</a></cvi-web-track></div></div>',
},
template: `
<cvi-ng-track [gap]="4" [flexIsMultiline]="true" horizontalAlignment="left">
<div style="width: 300px">
<cvi-ng-metadata-card [severity]="severity">
<cvi-ng-labeled-item label="Item 1">How do you do?</cvi-ng-labeled-item>
<cvi-ng-labeled-item
label="Item 2, so long it does not fit ever even one line. needs breaking into next line in order to fit">
Hello!
</cvi-ng-labeled-item>
<cvi-ng-labeled-item label="Item 3">Some text</cvi-ng-labeled-item>
</cvi-ng-metadata-card>
</div>
<div>
<cvi-ng-metadata-card [severity]="severity">
<cvi-ng-html-section html="{{html}}">
</cvi-ng-html-section>
</cvi-ng-metadata-card>
</div>
</cvi-ng-track>
`,
}),
};

export const WithCustomStyle: Story = {
render: (args: MetadataCardComponent) => ({
props: args,
template: `
<cvi-ng-metadata-card style="--cvi-metadata-card-left-border-color: var(--cvi-color-sea-green-10)">
<cvi-ng-labeled-item label="Item 1">How do you do?</cvi-ng-labeled-item>
<cvi-ng-labeled-item label="Item 2">Hello!</cvi-ng-labeled-item>
<cvi-ng-labeled-item label="Item 3">Some text</cvi-ng-labeled-item>
</cvi-ng-metadata-card>
`,
}),
};

export const Mobile: Story = {
...Default,
parameters: {
viewport: {
defaultViewport: 'iphone12mini',
},
},
};
41 changes: 41 additions & 0 deletions libs/ui/src/lib/metadata-card/metadata-card.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
ChangeDetectionStrategy,
Component,
HostBinding,
Input,
} from '@angular/core';
import {
MetadataCardCustomProperties,
MetadataCardCustomPropertyGroup,
metadataCardCustomPropertyGroups,
MetadataCardSeverity,
} from './metadata-card';

@Component({
selector: 'cvi-ng-metadata-card',
templateUrl: './metadata-card.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MetadataCardComponent {
@Input() severity: MetadataCardSeverity = 'info';

@HostBinding('style.--cvi-metadata-card-left-border-color')
get hostStyleLeftBorderColor(): string | null {
return this.getCustomProperty('--cvi-metadata-card-left-border-color');
}

getCustomProperty(
propName: keyof MetadataCardCustomProperties
): string | null {
const item = metadataCardCustomPropertyGroups.find(
(group: MetadataCardCustomPropertyGroup) =>
group.severity === this.severity
);
if (item) {
return `var(${
item.customProperties[propName as keyof MetadataCardCustomProperties]
})`;
}
return null;
}
}
39 changes: 39 additions & 0 deletions libs/ui/src/lib/metadata-card/metadata-card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export type MetadataCardSeverity = 'info' | 'success' | 'warning' | 'error';

export const metadataCardCustomPropertyGroups: MetadataCardCustomPropertyGroup[] =
[
{
severity: 'info',
customProperties: {
'--cvi-metadata-card-left-border-color': '--cvi-color-sapphire-blue-10',
},
},
{
severity: 'success',
customProperties: {
'--cvi-metadata-card-left-border-color': '--cvi-color-sea-green-11',
},
},
{
severity: 'warning',
customProperties: {
'--cvi-metadata-card-left-border-color':
'--cvi-color-dark-tangerine-10',
},
},
{
severity: 'error',
customProperties: {
'--cvi-metadata-card-left-border-color': '--cvi-color-jasper-10',
},
},
];

export type MetadataCardCustomPropertyGroup = {
severity: MetadataCardSeverity;
customProperties: MetadataCardCustomProperties;
};

export type MetadataCardCustomProperties = {
'--cvi-metadata-card-left-border-color': string;
};
2 changes: 2 additions & 0 deletions libs/ui/src/lib/ui.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import { FormMessageSeverityToHeaderIconPipe } from './form-message/form-message
import { TableCardComponent } from './table-card/table-card.component';
import { TableResponsiveComponent } from './table-responsive/table-responsive.component';
import { LabeledItemComponent } from './labeled-item/labeled-item.component';
import { MetadataCardComponent } from './metadata-card/metadata-card.component';

const components = [
TrackComponent,
Expand Down Expand Up @@ -172,6 +173,7 @@ const components = [
TableCardComponent,
TableResponsiveComponent,
LabeledItemComponent,
MetadataCardComponent,
];

const pipes = [
Expand Down

0 comments on commit 62d8cac

Please sign in to comment.