Skip to content

Commit

Permalink
feat: account card (#805)
Browse files Browse the repository at this point in the history
* feat: account card

* resolve package-lock

* Update libs/web-components/account-card/src/styles.scss

Co-authored-by: dorsaf frigui <[email protected]>

* document account card

Co-authored-by: dorsaf frigui <[email protected]>
  • Loading branch information
Pi5rr5 and dorsaffrigui authored Jul 27, 2022
1 parent 12bb01d commit 4b1aea2
Show file tree
Hide file tree
Showing 13 changed files with 369 additions and 14 deletions.
36 changes: 24 additions & 12 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,6 @@
},
"tags": []
},
"wc:breadcrumb": {
"root": "libs/web-components/breadcrumb",
"architect": {
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": ["libs/web-components/breadcrumb/src/**/*.ts"]
}
}
},
"tags": ["web-components"]
},
"button-toggle": {
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"root": "libs/web-components/button-toggle",
Expand Down Expand Up @@ -1520,6 +1508,18 @@
},
"tags": []
},
"wc-account-card": {
"root": "libs/web-components/account-card",
"architect": {
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": ["libs/web-components/account-card/src/**/*.ts"]
}
}
},
"tags": ["web-components"]
},
"wc-avatar": {
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"root": "libs/web-components/avatar",
Expand Down Expand Up @@ -1594,6 +1594,18 @@
},
"tags": ["web-components"]
},
"wc:breadcrumb": {
"root": "libs/web-components/breadcrumb",
"architect": {
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": ["libs/web-components/breadcrumb/src/**/*.ts"]
}
}
},
"tags": ["web-components"]
},
"wizard": {
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
Expand Down
17 changes: 17 additions & 0 deletions libs/web-components/account-card/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"parserOptions": {
"project": ["libs/web-components/account-card/tsconfig.*?.json"]
},
"rules": {}
},
{
"files": ["*.html"],
"rules": {}
}
]
}
8 changes: 8 additions & 0 deletions libs/web-components/account-card/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.tsbuildinfo
tsconfig.json
.eslintignore
*.tgz
images/*
test/*
*.ts
!*.d.ts
31 changes: 31 additions & 0 deletions libs/web-components/account-card/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Account Card

Account Card is a use case of card using the [Accounts and Balances](https://developer.fusionfabric.cloud/api/corporate-accounteinfo-me-v1-831cb09d-cc10-4772-8ed5-8a6b72ec8e01/docs#operation/getAccountsForCustomerUser) APIs.

> This component is based on [base-card](./src/base-card.ts). See `fds-card` documentation for more details.
[![See it on NPM!](https://img.shields.io/npm/v/@finastra/account-card?style=for-the-badge)](https://www.npmjs.com/package/@finastra/account-card)
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@finastra/account-card?style=for-the-badge)](https://bundlephobia.com/result?p=@finastra/account-card')
[![Storybook](https://shields.io/badge/-Play%20with%20this%20web%20component-2a0481?logo=storybook&style=for-the-badge)](https://finastra.github.io/finastra-design-system/?path=/story/components-account-card--default)

## Usage

### Import

```
npm i @finastra/account-card
```

```ts
import '@finastra/account-card';
...
<fds-account-card name="France" balance="50000" currency="EUR" number="DE89 3704 0044 0532 0130 00"></fds-account-card>
```

### Pure HTML pages

```html
<script type="module" src="https://unpkg.com/@finastra/account-card@latest/dist/src/account-card.js?module"></script>

<fds-account-card name="France" balance="50000" currency="EUR" number="DE89 3704 0044 0532 0130 00"></fds-account-card>
```
9 changes: 9 additions & 0 deletions libs/web-components/account-card/demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script type="module" src="node_modules/@finastra/account-card/dist/src/account-card.js"></script>

<div style="display: flex; flex-direction: column; gap: 16px;">
<fds-account-card name="France" balance="50000" currency="EUR" number="DE89 3704 0044 0532 0130 00"></fds-account-card>

<fds-account-card name="France" balance="50000" currency="EUR" number="DE89 3704 0044 0532 0130 00" selectable></fds-account-card>

<fds-account-card name="France" balance="50000" currency="EUR" number="DE89 3704 0044 0532 0130 00" disabled></fds-account-card>
</div>
26 changes: 26 additions & 0 deletions libs/web-components/account-card/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@finastra/account-card",
"displayName": "AccountCard",
"version": "1.0.0",
"description": "AccountCard Web Component",
"keywords": [
"Finastra Design System",
"Web Components",
"AccountCard"
],
"license": "MIT",
"main": "dist/src/account-card.js",
"module": "dist/src/account-card.js",
"scripts": {
"build:style": "node ../../../scripts/sass-to-lit-css/index.js src/styles.scss"
},
"dependencies": {
"lit": "^2.0.0",
"tslib": "^2.0.1",
"@finastra/divider": "^0.0.34",
"@material/mwc-icon": "^0.26.1"
},
"publishConfig": {
"access": "public"
}
}
62 changes: 62 additions & 0 deletions libs/web-components/account-card/src/account-card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { BaseCard } from "@finastra/card";
import '@finastra/divider';
import { html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { styles } from './styles.css';

/**
* @attr {string} [name='Account'] - Account Name.
* @attr {number} [balance=0] - Account balance.
* @attr {string} [currency='USD'] - Account currency ISO format.
* @attr {string} [number='XXXX XXXX XXXX XXXX XXXX XX'] - Account number.
* @attr {string} [icon=credit_card] - Change card icon.
* @attr {boolean} [iconAriaLabel='Credit Card'] - Change the card icon aria label.
* @attr {boolean} [selectable=false] - Change the card style to an action card.
* @attr {boolean} [disabled=false] - Disabled style of the card.
*/

@customElement('fds-account-card')
export class AccountCard extends BaseCard {
static styles = styles;

@property({ type: String }) name = 'Account';
@property({ type: Number }) balance = 0;
@property({ type: String }) currency = 'USD';
@property({ type: String }) number = 'XXXX XXXX XXXX XXXX XXXX XX';
@property({ type: String }) icon = 'credit_card';
@property({ type: String }) iconAriaLabel = 'Credit Card';



renderCardContent() {
return html`
<fds-card-content class="account-content">
<div class="account-icon">
<mwc-icon aria-label="${this.iconAriaLabel}">${this.icon}</mwc-icon>
</div>
<div>
<div class="account-name">${this.name}</div>
<div class="account-balance">${this.renderBalance()}</div>
</div>
</fds-card-content>
<fds-card-footer>
<fds-divider></fds-divider>
<div class="account-number">${this.number}</div>
</fds-card-footer>
`;
}

renderBalance() {
const dollarUSLocale = Intl.NumberFormat('en-US', {
style: 'currency',
currency: this.currency,
});
return dollarUSLocale.format(this.balance);
}
}

declare global {
interface HTMLElementTagNameMap {
'fds-account-card': AccountCard;
}
}
59 changes: 59 additions & 0 deletions libs/web-components/account-card/src/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@use "@finastra/card/src" as base-card;
@use '@finastra/fds-theme' as fds;

:host {
min-width: 230px;
@include base-card.core-styles();

.account-content {
display: flex;
gap: var(--fds-spacing-2, 8px);
}

.account-icon {
@include fds.margin(1, top);
border-radius: 50%;
width: 38px;
height: 38px;
display: flex;
justify-content: center;
align-items: center;
@include fds.bg-color(primary-lighter);

mwc-icon {
@include fds.text-color(primary);
}
}

.account-name {
@include fds.typography(body-1);
@include fds.text-color(on-surface);
}

.account-balance {
@include fds.typography(headline-5);
@include fds.text-color(on-surface);
@include fds.margin(4, top);
}

.account-number {
@include fds.typography(body-3);
@include fds.text-color(on-surface-medium);
@include fds.padding(2, top, bottom);
@include fds.padding(3, right, left);
}

.mdc-card--disabled .account-name,
.mdc-card--disabled .account-balance,
.mdc-card--disabled .account-number {
@include fds.text-color(on-surface-disabled);
}

.mdc-card--disabled .account-icon {
@include fds.bg-color(surface-disabled);

mwc-icon {
@include fds.text-color(on-surface-disabled);
}
}
}
50 changes: 50 additions & 0 deletions libs/web-components/account-card/stories/account-card.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const README = require('../README.md');
import '@finastra/account-card';
import type { AccountCard } from '@finastra/account-card';
import { Meta, Story } from '@storybook/web-components';
import { html } from 'lit-html';
import { argTypes, cssprops } from './sb-generated/fds-account-card.json';

export default {
title: 'DATA DISPLAY/Cards/Account Card',
component: 'fds-account-card',
argTypes,
args: {
name: 'France',
balance: 50000,
currency: "EUR",
number: "DE89 3704 0044 0532 0130 00"
},
parameters: {
docs: {
description: { component: README }
},
design: {
type: 'figma',
url: 'https://www.figma.com/file/6BBm9XAsO9lQZQ4xBM4cGr/Patterns-%26-apps?node-id=407%3A17290'
},
cssprops
},
decorators: []
} as Meta;

const Template: Story<AccountCard> = ({ name, balance, currency, number, icon, iconAriaLabel, outlined, selectable, disabled}) => {
return html`<fds-account-card name=${name} balance=${balance} currency=${currency} number=${number} icon=${icon} iconAriaLabel=${iconAriaLabel} ?outlined=${outlined} ?selectable=${selectable} ?disabled=${disabled}></fsd-account-card>`;
};

export const Default: Story<AccountCard> = Template.bind({});

export const Selectable: Story<AccountCard> = Template.bind({});
Selectable.args = {
selectable: true
};

export const Outlined: Story<AccountCard> = Template.bind({});
Outlined.args = {
outlined: true
};

export const Disabled: Story<AccountCard> = Template.bind({});
Disabled.args = {
disabled: true
};
12 changes: 12 additions & 0 deletions libs/web-components/account-card/test/account-card.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { html, fixture, expect, elementUpdated } from '@open-wc/testing';
import { AccountCard } from '../src/account-card.js';
import '../src/account-card.js';

describe('AccountCard', () => {
it('loads accessibly', async () => {
const el: AccountCard = await fixture(html`<fds-account-card></fds-account-card>`);

await elementUpdated(el);
await expect(el).to.be.accessible();
});
});
10 changes: 10 additions & 0 deletions libs/web-components/account-card/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"composite": true,
"rootDir": "./",
"outDir": "./dist",
"tsBuildInfoFile": "./dist/.tsbuildinfo"
},
"include": ["src/**/*.ts", "test/**/*.ts"]
}
7 changes: 5 additions & 2 deletions libs/web-components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,25 @@
"path": "fab"
},
{
"path": "icon-button"
"path": "icon-button"
},
{
"path": "expansion-panel"
},
{
"path": "badge"
},
{
{
"path": "menu"
},
{
"path": "dialog"
},
{
"path": "breadcrumb"
},
{
"path": "account-card"
}
]
}
Loading

0 comments on commit 4b1aea2

Please sign in to comment.