diff --git a/src/components/aspect_ratio/aspect_ratio.stories.tsx b/src/components/aspect_ratio/aspect_ratio.stories.tsx new file mode 100644 index 00000000000..78a4c0a41b7 --- /dev/null +++ b/src/components/aspect_ratio/aspect_ratio.stories.tsx @@ -0,0 +1,42 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import React from 'react'; +import type { Meta, StoryObj } from '@storybook/react'; +import { disableStorybookControls } from '../../../.storybook/utils'; + +import { EuiAspectRatio, EuiAspectRatioProps } from './aspect_ratio'; + +const meta: Meta = { + title: 'EuiAspectRatio', + component: EuiAspectRatio, +}; + +export default meta; +type Story = StoryObj; + +export const Playground: Story = { + args: { + height: 9, + width: 16, + maxWidth: '100%', + children: ( +
+ Resize the demo window +
+ ), + }, + argTypes: disableStorybookControls(['children']), +}; diff --git a/src/components/aspect_ratio/aspect_ratio.test.tsx b/src/components/aspect_ratio/aspect_ratio.test.tsx index 67ff1d5e40b..b2954867bd5 100644 --- a/src/components/aspect_ratio/aspect_ratio.test.tsx +++ b/src/components/aspect_ratio/aspect_ratio.test.tsx @@ -53,6 +53,19 @@ describe('EuiAspectRatio', () => { expect(container.firstChild).toMatchSnapshot(); }); + test('inherits child styles', () => { + const { getByTestSubject } = render( + +
+ + ); + + expect(getByTestSubject('child')).toHaveStyle({ + 'background-color': 'salmon', + color: 'gray', + }); + }); + describe('props', () => { describe('maxWidth', () => { test('is rendered', () => { diff --git a/src/components/aspect_ratio/aspect_ratio.tsx b/src/components/aspect_ratio/aspect_ratio.tsx index 901216050dc..af707c1660a 100644 --- a/src/components/aspect_ratio/aspect_ratio.tsx +++ b/src/components/aspect_ratio/aspect_ratio.tsx @@ -44,6 +44,7 @@ export const EuiAspectRatio: FunctionComponent = ({ const classes = classNames('euiAspectRatio', className); const euiAspectRatioStyle = { + ...children.props.style, aspectRatio: `${width} / ${height}`, height: 'auto', width: '100%',