Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: maf-img component #19

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/pages/components/mf-img.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
meta:
title: Mf Img
description:
layout: component
---

```html:preview
<mf-img src="https://www.dev.mallgiftcard.ae/assets/maf-logo-header.svg" alt="MAF" ></mf-img>
```

## Examples

### Only image

```html:preview
<mf-img src="https://www.dev.mallgiftcard.ae/assets/maf-logo-header.svg" alt="MAF" ></mf-img>
```

### Image and Link

```html:preview
<mf-img src="https://www.dev.mallgiftcard.ae/assets/maf-logo-header.svg" alt="MAF" href="https://google.com"></mf-img>
```

[component-metadata:mf-logo]
64 changes: 64 additions & 0 deletions src/components/mf-img/mf-img.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { classMap } from 'lit/directives/class-map.js';
import { html } from 'lit';
import { LocalizeController } from '../../utilities/localize.js';
import { property } from 'lit/decorators.js';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import styles from './mf-img.styles.js';
import type { CSSResultGroup } from 'lit';

/**
* @summary Short summary of the component's intended use.
* @documentation https://shoelace.style/components/mf-img
* @status experimental
* @since 2.0
*
* @csspart base - The component's base wrapper.
* @csspart image - The component's image part.
*
*/
export default class MfImg extends ShoelaceElement {
static styles: CSSResultGroup = [componentStyles, styles];

private readonly localize = new LocalizeController(this);

/** Logo href value. */
@property() href = '';

/** Logo src value. */
@property() src = '';

/** Logo Alt value. */
@property() alt = '';

/** image width value. */
@property() width = '';

/** image height value. */
@property() height = '';

/** anchor target value. */
@property() target: '_blank' | '_parent' | '_self' | '_top' = '_self';

render() {
const isRtl = this.localize.dir() === 'rtl';
if (this.href) {
return html` <a
class=${classMap({
img: true,
'img--rtl': isRtl,
'img--anchor': this.href
})}
part="base"
href="${this.href}"
target="${this.target}"
>
<img src="${this.src}" alt="${this.alt}" width="${this.width}" height="${this.height}" part="image" />
</a>`;
} else {
return html`
<img src="${this.src}" alt="${this.alt}" width="${this.width}" height="${this.height}" part="image" />
`;
}
}
}
22 changes: 22 additions & 0 deletions src/components/mf-img/mf-img.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { css } from 'lit';

export default css`
:host {
display: block;
}
:host a {
display: block;
text-decoration: none;
}

:host img {
display: block;
text-decoration: none;
}

a img {
carlos-verdes marked this conversation as resolved.
Show resolved Hide resolved
display: block;
width: 100%;
height: 100%;
}
`;
10 changes: 10 additions & 0 deletions src/components/mf-img/mf-img.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import '../../../dist/shoelace.js';
import { expect, fixture, html } from '@open-wc/testing';

describe('<mf-img>', () => {
it('should render a component', async () => {
const el = await fixture(html` <mf-img></mf-img> `);

expect(el).to.exist;
});
});
12 changes: 12 additions & 0 deletions src/components/mf-img/mf-img.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import MfImg from './mf-img.component.js';

export * from './mf-img.component.js';
export default MfImg;

MfImg.define('mf-img');

declare global {
interface HTMLElementTagNameMap {
'mf-img': MfImg;
}
}
2 changes: 2 additions & 0 deletions src/shoelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export { default as SlTree } from './components/tree/tree.js';
export { default as SlTreeItem } from './components/tree-item/tree-item.js';
export { default as SlVisuallyHidden } from './components/visually-hidden/visually-hidden.js';
export { default as MfNavigation } from './components/mf-navigation/mf-navigation.js';
export { default as MfNavItem } from './components/mf-nav-item/mf-nav-item.js';
carlos-verdes marked this conversation as resolved.
Show resolved Hide resolved
export { default as MFLogo } from './components/mf-img/mf-img.js';
/* plop:component */

// Utilities
Expand Down