Skip to content

Commit f045214

Browse files
committed
[PR feedback] EuiAspectRatio changes
1 parent 5f98d22 commit f045214

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed

src/components/aspect_ratio/aspect_ratio.test.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,36 @@ describe('EuiAspectRatio', () => {
3131
expect(container.firstChild).toMatchSnapshot();
3232
});
3333

34-
it('merges child styles', () => {
34+
it('merges all styles', () => {
3535
const { getByTestSubject } = render(
36-
<EuiAspectRatio height={4} width={9}>
36+
<EuiAspectRatio height={4} width={9} style={{ color: 'bronze' }}>
3737
<div data-test-subj="child" style={{ backgroundColor: 'salmon' }} />
3838
</EuiAspectRatio>
3939
);
4040

4141
expect(getByTestSubject('child')).toHaveStyle({
42+
color: 'bronze',
4243
'background-color': 'salmon',
44+
'inline-size': '100%', // jsdom doesn't know how to interpret `aspect-ratio` CSS, so we just check for something it does know how to render
4345
});
4446
});
4547

48+
it('merges all classNames', () => {
49+
const { getByTestSubject } = render(
50+
<EuiAspectRatio height={4} width={9} className="hello">
51+
<div data-test-subj="child" className="world" />
52+
</EuiAspectRatio>
53+
);
54+
55+
const finalDiv = getByTestSubject('child');
56+
expect(finalDiv).toHaveClass('euiAspectRatio');
57+
expect(finalDiv).toHaveClass('hello');
58+
expect(finalDiv).toHaveClass('world');
59+
});
60+
4661
test('maxWidth', () => {
4762
const { getByTestSubject } = render(
48-
<EuiAspectRatio height={16} width={9} maxWidth={500} {...requiredProps}>
63+
<EuiAspectRatio height={16} width={9} maxWidth={500}>
4964
<div data-test-subj="child" />
5065
</EuiAspectRatio>
5166
);

src/components/aspect_ratio/aspect_ratio.tsx

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,47 @@
88

99
import React, {
1010
FunctionComponent,
11+
HTMLAttributes,
1112
ReactElement,
1213
CSSProperties,
1314
useMemo,
1415
} from 'react';
1516
import classNames from 'classnames';
1617

18+
import { CommonProps } from '../common';
1719
import { logicalStyles } from '../../global_styling';
1820

19-
export type EuiAspectRatioProps = {
20-
/**
21-
* Aspect ratio height. For example 9 would be widescreen video.
22-
*/
23-
height: number;
24-
/**
25-
* Aspect ratio width. For example 16 would be widescreen video.
26-
*/
27-
width: number;
28-
/**
29-
* The maximum width you want the child to stretch to.
30-
*/
31-
maxWidth?: CSSProperties['width'];
32-
children: ReactElement<any>;
33-
};
21+
export type EuiAspectRatioProps = HTMLAttributes<HTMLDivElement> &
22+
CommonProps & {
23+
/**
24+
* Aspect ratio height. For example 9 would be widescreen video.
25+
*/
26+
height: number;
27+
/**
28+
* Aspect ratio width. For example 16 would be widescreen video.
29+
*/
30+
width: number;
31+
/**
32+
* The maximum width you want the child to stretch to.
33+
*/
34+
maxWidth?: CSSProperties['width'];
35+
children: ReactElement<any>;
36+
};
3437

3538
export const EuiAspectRatio: FunctionComponent<EuiAspectRatioProps> = ({
3639
children,
40+
className,
41+
style,
3742
height,
3843
width,
3944
maxWidth,
45+
...rest
4046
}) => {
41-
const classes = classNames('euiAspectRatio', children.props.className);
47+
const classes = classNames(
48+
'euiAspectRatio',
49+
className,
50+
children.props.className
51+
);
4252

4353
const euiAspectRatioStyle = useMemo(
4454
() =>
@@ -52,7 +62,8 @@ export const EuiAspectRatio: FunctionComponent<EuiAspectRatioProps> = ({
5262
);
5363

5464
return React.cloneElement(children, {
65+
...rest,
5566
className: classes,
56-
style: { ...children.props.style, ...euiAspectRatioStyle },
67+
style: { ...children.props.style, ...euiAspectRatioStyle, ...style },
5768
});
5869
};

0 commit comments

Comments
 (0)