From 4096943e5330d2e82f30c0873349554a2e34fb6b Mon Sep 17 00:00:00 2001 From: "dave.snider@gmail.com" Date: Thu, 21 Nov 2019 11:54:12 -0800 Subject: [PATCH] Aspect ratio component (#2535) EuiAspectRatio provides a way to responsively resize a single block level child element to a specified ratio. This is useful for things like YouTube iframes that initially have a fixed size. --- CHANGELOG.md | 1 + .../templates/stateless_function.tsx | 4 +- src-docs/src/routes.js | 3 + .../src/views/aspect_ratio/aspect_ratio.js | 56 +++++++++++++++++ .../aspect_ratio/aspect_ratio_example.js | 62 +++++++++++++++++++ src-docs/src/views/image/image.js | 2 +- .../__snapshots__/aspect_ratio.test.tsx.snap | 43 +++++++++++++ .../aspect_ratio/_aspect_ratio.scss | 12 ++++ src/components/aspect_ratio/_index.scss | 1 + .../aspect_ratio/aspect_ratio.test.tsx | 51 +++++++++++++++ src/components/aspect_ratio/aspect_ratio.tsx | 53 ++++++++++++++++ src/components/aspect_ratio/index.ts | 1 + src/components/index.js | 2 + src/components/index.scss | 1 + 14 files changed, 289 insertions(+), 3 deletions(-) create mode 100644 src-docs/src/views/aspect_ratio/aspect_ratio.js create mode 100644 src-docs/src/views/aspect_ratio/aspect_ratio_example.js create mode 100644 src/components/aspect_ratio/__snapshots__/aspect_ratio.test.tsx.snap create mode 100644 src/components/aspect_ratio/_aspect_ratio.scss create mode 100644 src/components/aspect_ratio/_index.scss create mode 100644 src/components/aspect_ratio/aspect_ratio.test.tsx create mode 100644 src/components/aspect_ratio/aspect_ratio.tsx create mode 100644 src/components/aspect_ratio/index.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c3d93f3eda..bd5bfbdb53e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Added new keyboard shortcuts for the data grid component: `Home` (same row, first column), `End` (same row, last column), `Ctrl+Home` (first row, first column), `Ctrl+End` (last row, last column), `Page Up` (next page) and `Page Down` (previous page) ([#2519](https://github.com/elastic/eui/pull/2519)) - Added `disabled` prop to the `EuiCheckboxGroup` definition ([#2545](https://github.com/elastic/eui/pull/2545)) - Added `disabled` option to the `option` attribute of the `options` object that is passed to the `EuiCheckboxGroup` so that checkboxes in a group can be individually disabled ([#2548](https://github.com/elastic/eui/pull/2548)) +- Added `EuiAspectRatio` component that allows for responsively resizing embeds ([#2535](https://github.com/elastic/eui/pull/2535)) **Bug fixes** diff --git a/generator-eui/component/templates/stateless_function.tsx b/generator-eui/component/templates/stateless_function.tsx index 17a009510b7..a85b766c170 100644 --- a/generator-eui/component/templates/stateless_function.tsx +++ b/generator-eui/component/templates/stateless_function.tsx @@ -1,4 +1,4 @@ -import React, { HTMLAttributes, SFC } from 'react'; +import React, { HTMLAttributes, FunctionComponent } from 'react'; import { CommonProps } from '../common'; import classNames from 'classnames'; @@ -6,7 +6,7 @@ export type <%= componentName %>Props = HTMLAttributes & CommonP }; -export const <%= componentName %>: React.SFC<<%= componentName %>Props> = ({ +export const <%= componentName %>: FunctionComponent<<%= componentName %>Props> = ({ children, className, ...rest diff --git a/src-docs/src/routes.js b/src-docs/src/routes.js index b366166d992..b3aec97f6ff 100644 --- a/src-docs/src/routes.js +++ b/src-docs/src/routes.js @@ -39,6 +39,8 @@ import { AccessibilityExample } from './views/accessibility/accessibility_exampl import { AccordionExample } from './views/accordion/accordion_example'; +import { AspectRatioExample } from './views/aspect_ratio/aspect_ratio_example'; + import { AvatarExample } from './views/avatar/avatar_example'; import { BadgeExample } from './views/badge/badge_example'; @@ -334,6 +336,7 @@ const navigation = [ { name: 'Display', items: [ + AspectRatioExample, AvatarExample, BadgeExample, CallOutExample, diff --git a/src-docs/src/views/aspect_ratio/aspect_ratio.js b/src-docs/src/views/aspect_ratio/aspect_ratio.js new file mode 100644 index 00000000000..8bac7081423 --- /dev/null +++ b/src-docs/src/views/aspect_ratio/aspect_ratio.js @@ -0,0 +1,56 @@ +import React, { Fragment } from 'react'; + +import { + EuiAspectRatio, + EuiSpacer, + EuiTitle, +} from '../../../../src/components'; + +export default () => ( + + +

16x9 aspect

+
+ + +