Skip to content

Commit

Permalink
feat: add dashboard stats component
Browse files Browse the repository at this point in the history
  • Loading branch information
phkel committed Jul 10, 2023
1 parent 3bdb785 commit 51fe20d
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/cxl-lumo-styles/scss/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ html {
--cxl-content-width: 36em;
--cxl-wrap-width: 72rem;
--cxl-wrap-padding: var(--lumo-space-m);
--cxl-color-light-gray: hsla(0, 0%, 96%, 1);
--cxl-color-black-50pct: hsla(0, 0%, 0%, 0.5);

/**
* Lumo Icons have a documented 4px "safe area" around them. Vaadin Icons don't, for unknown reasons.
Expand Down
17 changes: 17 additions & 0 deletions packages/cxl-ui/scss/cxl-stats.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@use "~@conversionxl/cxl-lumo-styles/scss/mq";

:host {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: var(--lumo-space-m);
padding: var(--lumo-space-xl) var(--lumo-space-m) var(--lumo-space-m);
border-bottom: 1px solid var(--cxl-color-light-gray);

@media #{mq.$small} {
padding: var(--lumo-space-xl) var(--lumo-space-l) var(--lumo-space-l);
}

@media #{mq.$medium} {
grid-template-columns: repeat(4, 1fr);
}
}
16 changes: 16 additions & 0 deletions packages/cxl-ui/scss/global/cxl-stats.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cxl-stats {
.stats-title {
margin-top: 0;
font-size: var(--lumo-font-size-xs);
font-weight: 400;
line-height: 1;
color: var(--cxl-color-black-50pct);
text-transform: uppercase;
}

.stats-count {
margin: 0;
font-size: var(--lumo-font-size-xxl);
font-weight: 700;
}
}
28 changes: 28 additions & 0 deletions packages/cxl-ui/src/components/cxl-stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { LitElement, html } from 'lit';
// eslint-disable-next-line import/no-extraneous-dependencies
import { customElement } from 'lit/decorators.js';
import { registerGlobalStyles } from '@conversionxl/cxl-lumo-styles/src/utils';
import '@conversionxl/cxl-lumo-styles';
import cxlStatsStyles from '../styles/cxl-stats-css.js';
import cxlStatsGlobalStyles from '../styles/global/cxl-stats-css.js';

@customElement('cxl-stats')
export class CXLStatsElement extends LitElement {
static get styles() {
return [cxlStatsStyles];
}

render() {
return html`<slot></slot>`;
}

firstUpdated(_changedProperties) {
super.firstUpdated(_changedProperties);

// Global styles.
registerGlobalStyles(cxlStatsGlobalStyles, {
moduleId: 'cxl-stats',
});
}
}
1 change: 1 addition & 0 deletions packages/cxl-ui/src/index-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export { CXLCardElement } from './components/cxl-card.js';
export { CXLCheckoutDetailsElement } from './components/cxl-checkout-details.js';
export { CXLMarketingNavElement } from './components/cxl-marketing-nav.js';
export { CXLSectionElement } from './components/cxl-section.js';
export { CXLStatsElement } from './components/cxl-stats.js';
export { CXLTabsSliderElement } from './components/cxl-tabs-slider.js';
export { CXLNotification } from './components/cxl-notification.js';

Expand Down
1 change: 1 addition & 0 deletions packages/cxl-ui/src/index-storybook.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export { CXLAppLayoutElement } from './components/cxl-app-layout.js';
export { CXLCardElement } from './components/cxl-card.js';
export { CXLMarketingNavElement } from './components/cxl-marketing-nav.js';
export { CXLSectionElement } from './components/cxl-section.js';
export { CXLStatsElement } from './components/cxl-stats.js';
export { CXLTabsSliderElement } from './components/cxl-tabs-slider.js';

// Order matters.
Expand Down
18 changes: 18 additions & 0 deletions packages/storybook/cxl-ui/cxl-stats/cxl-stats.data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"title": "Categories<br>completed",
"count": "1"
},
{
"title": "Courses<br>completed",
"count": "30"
},
{
"title": "Lessons<br>completed",
"count": "95"
},
{
"title": "Complete<br>library",
"count": "12%"
}
]
42 changes: 42 additions & 0 deletions packages/storybook/cxl-ui/cxl-stats/default.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { html } from 'lit';
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
import '@conversionxl/cxl-lumo-styles';
import '@conversionxl/cxl-ui/src/components/cxl-stats.js';
import statsData from './cxl-stats.data.json';

export default {
title: 'CXL UI/cxl-stats',
};

export const CXLStats = ({ statsCount }) => {

for (let i = 0; i < statsCount; i += 1) {
const newItem = {
title: 'Complete<br>library',
count: '12%'
};

statsData.push(newItem);
}

return html`
<cxl-stats class="stats">
${statsData
.slice(0, statsCount)
.map((el) => html`
<div>
<h4 class="stats-title">${unsafeHTML(el.title)}</h4>
<p class="h3 stats-count">${el.count}</p>
</div>
`
)}
</cxl-stats>
`
};

Object.assign(CXLStats, {
args: {
statsCount: 4
},
storyName: 'CXL Stats'
});

0 comments on commit 51fe20d

Please sign in to comment.