From 5140c13696c2a3a1eb455bd1d94652e274a68344 Mon Sep 17 00:00:00 2001 From: Alex Krolick Date: Tue, 16 Jul 2019 17:39:52 -0700 Subject: [PATCH] feat(media): create media object component (#1383) * feat(media): create media object component * feat(media): add menu elements * chore(media): rename media.img to media.figure * docs(media): add layout examples * docs(media): add form elements to media object example * docs(media): add titles to examples * feat(media): add aria-label prop to media.menu * style(media): change to arrow fns from function keyword * style(media): use defaultProps for everything * fix(media): adjust composition of body + figure content * refactor(media): remove menu wrapper div, pass props to button * fix(media): remove unneeded css attr * refactor(media): scss shorthand declaration * fix(media): ie11 proofing * refactor(media): use flex shorthand * fix(media): revert change to dropdownmenu, add dropdownProps instead --- scripts/styleguide.config.js | 13 ++ src/components/media/Media.js | 35 +++++ src/components/media/Media.md | 148 ++++++++++++++++++ src/components/media/Media.scss | 42 +++++ src/components/media/MediaBody.js | 19 +++ src/components/media/MediaBody.md | 30 ++++ src/components/media/MediaFigure.js | 28 ++++ src/components/media/MediaFigure.md | 28 ++++ src/components/media/MediaMenu.js | 41 +++++ src/components/media/MediaMenu.md | 30 ++++ src/components/media/__tests__/Media-test.js | 40 +++++ .../media/__tests__/MediaFigure-test.js | 12 ++ .../media/__tests__/MediaMenu-test.js | 18 +++ .../__snapshots__/Media-test.js.snap | 38 +++++ src/components/media/index.js | 2 + 15 files changed, 524 insertions(+) create mode 100644 src/components/media/Media.js create mode 100644 src/components/media/Media.md create mode 100644 src/components/media/Media.scss create mode 100644 src/components/media/MediaBody.js create mode 100644 src/components/media/MediaBody.md create mode 100644 src/components/media/MediaFigure.js create mode 100644 src/components/media/MediaFigure.md create mode 100644 src/components/media/MediaMenu.js create mode 100644 src/components/media/MediaMenu.md create mode 100644 src/components/media/__tests__/Media-test.js create mode 100644 src/components/media/__tests__/MediaFigure-test.js create mode 100644 src/components/media/__tests__/MediaMenu-test.js create mode 100644 src/components/media/__tests__/__snapshots__/Media-test.js.snap create mode 100644 src/components/media/index.js diff --git a/scripts/styleguide.config.js b/scripts/styleguide.config.js index c4886bd2f2..dbb2286537 100644 --- a/scripts/styleguide.config.js +++ b/scripts/styleguide.config.js @@ -103,6 +103,19 @@ const allSections = [ description: 'Box UI Elements components implement the reusable building blocks of the Box Design Language', sectionDepth: 2, usageMode: 'expand', + sections: [ + { + name: 'Media', + components: [ + '../src/components/media/Media.js', + '../src/components/media/MediaFigure.js', + '../src/components/media/MediaBody.js', + '../src/components/media/MediaMenu.js', + ], + description: 'Implements the "media object" layout', + usageMode: 'expand', + }, + ], }, { name: 'Icons', diff --git a/src/components/media/Media.js b/src/components/media/Media.js new file mode 100644 index 0000000000..0a314a0e4a --- /dev/null +++ b/src/components/media/Media.js @@ -0,0 +1,35 @@ +// @flow +import * as React from 'react'; +import classnames from 'classnames'; +import MediaFigure from './MediaFigure'; +import MediaBody from './MediaBody'; +import MediaMenu from './MediaMenu'; +import './Media.scss'; + +type Props = { + /** Component to use as outermost element, e.g., 'li' */ + as: React.ElementType, + /** Child elements */ + children: React.ChildrenArray>, + /** Additional class names */ + className?: string, +}; + +const Media = ({ as: Wrapper, children, className, ...rest }: Props) => ( + + {children} + +); + +// Use this instead of default value because of param destructuring bug in Flow +// that affects union types +// https://github.com/facebook/flow/issues/5461 +Media.defaultProps = { + as: 'div', +}; + +Media.Body = MediaBody; +Media.Menu = MediaMenu; +Media.Figure = MediaFigure; + +export default Media; diff --git a/src/components/media/Media.md b/src/components/media/Media.md new file mode 100644 index 0000000000..a88e50fb19 --- /dev/null +++ b/src/components/media/Media.md @@ -0,0 +1,148 @@ +> **Note** +> +> `Media` is a compound component, the inner elements are not meant to be used outside of the Media container + +Implements the "media object" element + +```plaintext +import Media from 'box-ui-elements/es/components/media' +``` + +```js +const { MenuItem } = require('../menu'); + + + + + + + + + Edit + Delete + +
+ Yo Yo Ma commented on this file +
+
+ Please review the notes +
a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 + 9 0 1 2 3 4 5 6 7 8 9 +
+
+
; +``` + +```js +const { MenuItem } = require('../menu'); + +<> + + Media{' '} + Media.Figure{' '} + Media.Body{' '} + Media.Menu + +
+
+ + + + + + + + Edit + Delete + +
+ Yo Yo Ma commented on this file +
+
+ Please review the notes +
a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 + 8 9 0 1 2 3 4 5 6 7 8 9 +
+
+
+; +``` + +## Nesting Media Components + +```js +const { MenuItem } = require('../menu'); + + + + + + + + + Edit + Delete + +
+ Yo Yo Ma commented on this file +
+
This is a nested media object
+
    + + + + + + +
    + Bjork replied +
    +
    I must agree!
    + + + + + + +
    + Bono replied +
    +
    Me too!
    +
    +
    +
    +
    +
+
+
; +``` + +## With Form Elements + +```js +const { MenuItem } = require('../menu'); + + + + + + + + + Edit + Delete + +
+ W.A. Mozart commented on this file +
+
Everyone get ready to perform the symphony tonight!
+
+ + +