Skip to content

Commit

Permalink
feat(medium): add image part
Browse files Browse the repository at this point in the history
  • Loading branch information
dpellier committed Feb 4, 2025
1 parent 4e00af2 commit fd2de1d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class OdsMedium {
<img
alt={ this.alt }
height={ this.height }
part="image"
src={ this.src }
width={ this.width } />
</Host>
Expand Down
12 changes: 12 additions & 0 deletions packages/ods/src/components/medium/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,17 @@
src="https://corporate.ovhcloud.com/sites/default/files/2022-03/ovhcloud-logo2.png"
width="300">
</ods-medium>

<p>Custom CSS</p>
<ods-medium alt="OVHcloud logo"
class="custom-image"
src="https://corporate.ovhcloud.com/sites/default/files/2022-03/ovhcloud-logo2.png"
height="100">
</ods-medium>
<style>
.custom-image::part(image) {
max-height: 30px;
}
</style>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { E2EElement, E2EPage } from '@stencil/core/testing';
import { newE2EPage } from '@stencil/core/testing';
import { type E2EElement, type E2EPage, newE2EPage } from '@stencil/core/testing';

describe('ods-medium rendering', () => {
let el: E2EElement;
Expand All @@ -10,7 +9,7 @@ describe('ods-medium rendering', () => {
page = await newE2EPage();

await page.setContent(content);
await page.evaluate(() => document.body.style.setProperty('margin', '0px'));
await page.evaluate(() => document.body.style.setProperty('margin', '0'));

if (customStyle) {
await page.addStyleTag({ content: customStyle });
Expand All @@ -26,4 +25,15 @@ describe('ods-medium rendering', () => {
expect(el.shadowRoot).not.toBeNull();
expect(medium).not.toBeNull();
});

describe('part', () => {
it('should render with custom style applied', async() => {
const customMaxHeight = '50px';
await setup('<ods-medium></ods-medium>', `ods-medium::part(image) { max-height: ${customMaxHeight}; }`);

const tagStyle = await medium.getComputedStyle();

expect(tagStyle.getPropertyValue('max-height')).toBe(customMaxHeight);
});
});
});
15 changes: 15 additions & 0 deletions packages/storybook/stories/components/medium/medium.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ export const Demo: StoryObj = {
},
};

export const CustomCSS: StoryObj = {
tags: ['isHidden'],
render: () => html`
<ods-medium alt="${exampleAlt}"
class="my-medium"
src="${exampleSrc}">
</ods-medium>
<style>
.my-medium::part(image) {
max-width: 100px;
}
</style>
`,
};

export const Overview: StoryObj = {
tags: ['isHidden'],
parameters: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import * as MediumStories from './medium.stories';

<TechnicalSpecification data={ SpecificationsMedium } />

<Heading label="Style customization" level={ 2 } />

You can update the component style using a class on the web-component directly or access the internal image using the part `image`.

Custom CSS:

<Canvas of={ MediumStories.CustomCSS } sourceState="shown" />

<Heading label="Examples" level={ 2 } />

<Heading label="Default" level={ 3 } />
Expand Down

0 comments on commit fd2de1d

Please sign in to comment.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy