Skip to content

Commit

Permalink
Merge pull request #163 from MaibornWolff/#162-card-improvements
Browse files Browse the repository at this point in the history
#162-card-improvements
  • Loading branch information
Fuasmattn authored Jun 23, 2023
2 parents 7062037 + adcfb17 commit 26bf1e6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
8 changes: 8 additions & 0 deletions mwui-stencil/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ export namespace Components {
* Alt text for the image
*/
alt: string;
/**
* Height of image
*/
height?: string;
/**
* Image source
*/
Expand Down Expand Up @@ -1364,6 +1368,10 @@ declare namespace LocalJSX {
* Alt text for the image
*/
alt?: string;
/**
* Height of image
*/
height?: string;
/**
* Image source
*/
Expand Down
1 change: 1 addition & 0 deletions mwui-stencil/src/components/mw-card-body/mw-card-body.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
:host {
display: block;
padding: 0 var(--mw-component-card-padding-components-x-default);
flex: 1;
}
14 changes: 13 additions & 1 deletion mwui-stencil/src/components/mw-card-image/mw-card-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,35 @@ export class MwCardImage {
* Alt text for the image
*/
@Prop() alt: string;
/**
* Height of image
*/
@Prop() height?: string;

private isFirstChild: boolean;
private isLastChild: boolean;
private isOnlyChild: boolean;
private styles;

componentWillLoad(): void {
const card = this.hostElement.parentNode;
this.isOnlyChild = card.childElementCount === 1;
this.isFirstChild = !this.isOnlyChild && this.hostElement.isSameNode(card.firstElementChild);
this.isLastChild = !this.isOnlyChild && this.hostElement.isSameNode(card.lastElementChild);
if (this.height) {
this.styles = {
"height": this.height,
"object-fit": "cover",
"width": "100%",
};
}
}

render() {
return (
<Host>
<div class={{ "card-image": true, "top": this.isFirstChild, "bottom": this.isLastChild, "single": this.isOnlyChild }}>
<img src={this.src} alt={this.alt} />
<img src={this.src} alt={this.alt} style={this.styles} />
</div>
</Host>
);
Expand Down
2 changes: 2 additions & 0 deletions mwui-stencil/src/components/mw-card/mw-card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
-moz-border-radius: var(--mw-component-card-border-radius);
color: var(--mw-component-card-fg-default);
border: none;
height: 100%;
box-sizing: border-box;
transition: all 0.4 ease;

&:first-child {
Expand Down
6 changes: 3 additions & 3 deletions mwui-stencil/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,13 @@ <h3>CardTitle</h3>
</mw-card>
</div>
<h3>CardImage</h3>
<div style="display: flex; gap: 20px">
<div style="display: grid; gap: 20px; grid-template-columns: 1fr 1fr">
<mw-card elevated>
<mw-card-header header="Header" subheader="Subheader"><mw-avatar slot="icon" alt="John Doe" /></mw-card-header>
<mw-card-image src="https://placedog.net/500/280?id=3" alt="card image"></mw-card-image>
<mw-card-image src="https://placedog.net/500/280?id=3" alt="card image" height="170px"></mw-card-image>
</mw-card>
<mw-card elevated>
<mw-card-image src="https://placedog.net/500/280?id=3" alt="card image"></mw-card-image>
<mw-card-image src="https://placedog.net/500/280?id=3" alt="card image" height="250px"></mw-card-image>
<mw-card-title title="Peter Pan" subtitle="DTD" metadata="Last updated: 2 days ago"></mw-card-title>
<mw-card-body>I am the body section of this card.</mw-card-body>
<mw-card-footer>
Expand Down

0 comments on commit 26bf1e6

Please sign in to comment.