Skip to content

Commit

Permalink
feat(cxl-ui): refactor cxl-light-card component based on `cxl-base-…
Browse files Browse the repository at this point in the history
  • Loading branch information
kertuilves committed Aug 7, 2023
1 parent 1a688fa commit 4989403
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 104 deletions.
76 changes: 25 additions & 51 deletions packages/cxl-ui/scss/cxl-light-card.scss
Original file line number Diff line number Diff line change
@@ -1,47 +1,33 @@
:host {
display: block;
max-width: 300px;
height: auto;
min-height: auto;
padding: var(--lumo-space-m);
border: 1px solid var(--lumo-contrast-10pct);
border-radius: var(--lumo-border-radius-l);
box-shadow: var(--lumo-box-shadow-xs);

.entry-header {
display: flex;
align-items: flex-start;
justify-content: space-between;

.thumbnail {
width: calc(var(--lumo-icon-size-s) * 4);
height: calc(var(--lumo-icon-size-s) * 4);
margin: 0 0 0 var(--lumo-space-s);
border-radius: 100%;
}
.container > .attributes {
display: none;
}

.entry-title {
margin-bottom: var(--lumo-space-s);
font-weight: 600;
}

.entry-byline {
font-size: var(--lumo-font-size-s);
color: var(--lumo-contrast-70pct);
row-gap: calc(var(--lumo-space-s) / 2);

> div {
display: flex;
align-items: center;
header {
.info {
.name {
font-size: var(--lumo-font-size-m);
font-weight: 600;
}

.attributes {
display: flex;
flex-direction: column;
padding-top: var(--lumo-space-xs);
padding-bottom: 0;
gap: var(--lumo-space-xs);
}
}

vaadin-icon {
margin-right: var(--lumo-space-xs);
font-size: var(--lumo-font-size-m);
.instructor-image {
height: 80px;
}
}

::slotted(.entry-footer) {
margin-top: var(--lumo-space-l);
}
}

:host([completed]) {
Expand All @@ -54,20 +40,8 @@
}
}

:host([new]) {
position: relative;
overflow: initial;

[icon="cxl:new"] {
position: absolute;
top: calc(var(--lumo-space-m) * -1);
right: 0;
display: block;
width: calc(var(--lumo-space-m) * 2);
height: calc(var(--lumo-space-m) * 2);
padding: 6px;
color: var(--lumo-primary-contrast-color);
background-color: var(--lumo-primary-color);
border-radius: 100%;
}
::slotted(footer) {
display: flex;
flex-wrap: wrap;
gap: var(--lumo-space-xs);
}
47 changes: 12 additions & 35 deletions packages/cxl-ui/src/components/cxl-light-card.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,27 @@
/* eslint-disable import/no-extraneous-dependencies */
import { LitElement, html, nothing } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { html } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import '@conversionxl/cxl-lumo-styles';
import cxlLightCardStyles from '../styles/cxl-light-card-css.js';
import { CXLBaseCardElement } from './cxl-base-card.js';

@customElement('cxl-light-card')
export class CXLLightCardElement extends LitElement {
export class CXLLightCardElement extends CXLBaseCardElement {
static get styles() {
return [cxlLightCardStyles];
return [...super.styles, cxlLightCardStyles];
}

@property({ type: String }) id = '';
@state() showTags = false;

@property({ type: String }) theme = 'light-card';
@property({ type: String }) title = '';
@property({ type: String }) time = '';
@property({ type: String }) instructorPrefix = 'By:';
@property({ type: String }) instructor = '';
@property({ type: String }) avatar = '';

@property({ type: Boolean, reflect: true }) new = false;

@property({ type: Boolean, reflect: true }) completed = false;
@state() showTimeIcon = true;

render() {
return html`
<header class="entry-header">
${this.new ? html`<vaadin-icon icon="cxl:new"></vaadin-icon>` : nothing}
<div>
<div class="entry-title">
${this.title}
${this.completed ? html`<vaadin-icon icon="lumo:checkmark"></vaadin-icon>` : nothing}
</div>
<div class="entry-byline">
<div><vaadin-icon icon="lumo:clock"></vaadin-icon>${this.time}</div>
<div>${this.instructorPrefix}&nbsp;${this.instructor}</div>
</div>
</div>
<img class="thumbnail" src="${this.avatar}" alt="${this.instructor}" />
</header>
<slot name="footer"></slot>
<div class="container">
${this._renderHeader()}
<slot name="footer"></slot>
<vaadin-icon class="badge-new" icon="cxl:new"></vaadin-icon>
</div>
`;
}
}
14 changes: 4 additions & 10 deletions packages/storybook/cxl-ui/cxl-light-card/default.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,32 @@ export default {
const Template = (card) => html`
<cxl-light-card
theme="${card.theme}"
title="${card.title}"
name="${card.name}"
time="${card.time}"
instructor="${card.instructor}"
avatar="${card.avatar}"
.new="${card.new}"
.completed="${card.completed}"
>
${card.footer
? html`card.
<footer slot="footer" class="entry-footer">${unsafeHTML(card.footer)}</footer>`
: nothing}
${card.footer ? html` <footer slot="footer">${unsafeHTML(card.footer)}</footer>` : nothing}
</cxl-light-card>
`;

export const CXLLightCard = Template.bind({});
export const CXLLightCardFooter = Template.bind({});

CXLLightCard.args = {
theme: 'light-card',
new: false,
completed: false,
title: 'Account based marketing',
name: 'Account based marketing',
time: '3h 00min',
instructor: 'Ton Wesseling',
avatar:
'https://cxl.com/institute/wp-content/uploads/2020/05/48192546_10156982340630746_8127333122065825792_n-wpv_400pxx400px_center_center.jpg',
footer: '',
};

CXLLightCard.story = {
name: '[theme=light-card]',
};

CXLLightCardFooter.args = {
...CXLLightCard.args,
footer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ export default {
};

const Template = ({ numberOfCards }) => html`
<style>
vaadin-tab {
max-width: calc(var(--cxl-content-width) / 2);
}
</style>
<cxl-tabs-slider theme="cxl-course-slider minimal">
${Array.from(
{ length: numberOfCards },
Expand All @@ -37,8 +31,7 @@ LightCardSlider.args = {

CXLLightCard.args = {
theme: 'light-card',
hasBadges: false,
title: 'Account based marketing',
name: 'Account based marketing',
time: '3h 00min',
instructor: 'Ton Wesseling',
avatar:
Expand Down

0 comments on commit 4989403

Please sign in to comment.