Browse Source

Merge pull request #859 from mrfelton/feat/ui-menus

feat(ui): add Menu components
renovate/lint-staged-8.x
JimmyMow 6 years ago
committed by GitHub
parent
commit
2d4d3a3dde
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      app/components/UI/Menu.js
  2. 33
      app/components/UI/MenuItem.js
  3. 33
      app/components/UI/MenuItemGroup.js
  4. 1
      package.json
  5. 22
      stories/components/menu.stories.js
  6. 32
      test/unit/components/UI/Menu.spec.js
  7. 147
      test/unit/components/UI/__snapshots__/Menu.spec.js.snap
  8. 125
      yarn.lock

30
app/components/UI/Menu.js

@ -0,0 +1,30 @@
import React from 'react'
import system from '@rebass/components'
import styled from 'styled-components'
import MenuBase from 'rc-menu'
const SystemMenu = system(
{
extend: MenuBase,
mb: 2,
p: 0
},
'space'
)
const StyledMenu = styled(SystemMenu)`
outline: none;
`
/**
* @render react
* @name Menu
* @example
* <Menu>
<MenuItem>Menu item 1</MenuItem>
<MenuItem>Menu item 2</MenuItem>
</Menu>
*/
const Menu = props => <StyledMenu {...props} />
export default Menu

33
app/components/UI/MenuItem.js

@ -0,0 +1,33 @@
import React from 'react'
import { MenuItem as MenuItemBase } from 'rc-menu'
import system from '@rebass/components'
import styled from 'styled-components'
const SystemMenuItem = system(
{
extend: MenuItemBase,
py: 2
},
'space'
)
const StyledMenuItem = styled(SystemMenuItem)`
list-style-type: none;
&.rc-menu-item-active {
color: ${props => props.theme.colors.lightningOrange};
cursor: pointer;
}
&.rc-menu-item-selected {
color: ${props => props.theme.colors.lightningOrange};
}
`
/**
* @render react
* @name MenuItem
* @example
* <MenuItem>MenuItem item 1</MenuItem>
*/
const MenuItem = props => <StyledMenuItem {...props} />
export default MenuItem

33
app/components/UI/MenuItemGroup.js

@ -0,0 +1,33 @@
import React from 'react'
import system from '@rebass/components'
import styled from 'styled-components'
import { MenuItemGroup as MenuItemGroupBase } from 'rc-menu'
const SystemMenuItemGroup = system(
{
extend: MenuItemGroupBase,
mb: 3
},
'space'
)
const StyledMenuItemGroup = styled(SystemMenuItemGroup)`
list-style-type: none;
> .rc-menu-item-group-title {
font-weight: bold;
padding: ${props => props.theme.space[2]}px 0;
}
> .rc-menu-item-group-list {
padding: 0;
}
`
/**
* @render react
* @name MenuItemGroup
* @example
* <MenuItem>MenuItem item 1</MenuItem>
*/
const MenuItemGroup = props => <StyledMenuItemGroup {...props} />
export default MenuItemGroup

1
package.json

@ -324,6 +324,7 @@
"lodash.pick": "^4.4.0",
"prop-types": "^15.6.2",
"qrcode.react": "0.8.0",
"rc-menu": "^7.4.15",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-hot-loader": "^4.3.11",

22
stories/components/menu.stories.js

@ -0,0 +1,22 @@
import React from 'react'
import { storiesOf } from '@storybook/react'
import { action } from '@storybook/addon-actions'
import Menu from 'components/UI/Menu'
import MenuItem from 'components/UI/MenuItem'
import MenuItemGroup from 'components/UI/MenuItemGroup'
storiesOf('Components.Menu', module).add('Menu', () => (
<Menu onSelect={action('select')}>
<MenuItemGroup title="My Items">
<MenuItem key="item1">My item 1</MenuItem>
<MenuItem key="item2">My item 2</MenuItem>
<MenuItem key="item3">My item 3</MenuItem>
</MenuItemGroup>
<MenuItemGroup title="Other items">
<MenuItem key="item4">Other item 1</MenuItem>
<MenuItem key="item5">Other item 2</MenuItem>
<MenuItem key="item6">Other item 3</MenuItem>
</MenuItemGroup>
</Menu>
))

32
test/unit/components/UI/Menu.spec.js

@ -0,0 +1,32 @@
import React from 'react'
import Menu from 'components/UI/Menu'
import MenuItem from 'components/UI/MenuItem'
import MenuItemGroup from 'components/UI/MenuItemGroup'
import renderer from 'react-test-renderer'
import { dark } from 'themes'
import { ThemeProvider } from 'styled-components'
describe('component.UI.Menu', () => {
it('should render correctly', () => {
const tree = renderer
.create(
<ThemeProvider theme={dark}>
<Menu>
<MenuItemGroup title="My Items">
<MenuItem key="item1">My item 1</MenuItem>
<MenuItem key="item2">My item 2</MenuItem>
<MenuItem key="item3">My item 3</MenuItem>
</MenuItemGroup>
<MenuItemGroup title="Other items">
<MenuItem key="item4">Other item 1</MenuItem>
<MenuItem key="item5">Other item 2</MenuItem>
<MenuItem key="item6">Other item 3</MenuItem>
</MenuItemGroup>
</Menu>
</ThemeProvider>
)
.toJSON()
expect(tree).toMatchSnapshot()
})
})

147
test/unit/components/UI/__snapshots__/Menu.spec.js.snap

@ -0,0 +1,147 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`component.UI.Menu should render correctly 1`] = `
.c0 {
margin-bottom: 8px;
padding: 0px;
outline: none;
}
.c2 {
padding-top: 8px;
padding-bottom: 8px;
list-style-type: none;
}
.c2.rc-menu-item-active {
color: #fd9800;
cursor: pointer;
}
.c2.rc-menu-item-selected {
color: #fd9800;
}
.c1 {
margin-bottom: 16px;
list-style-type: none;
}
.c1 > .rc-menu-item-group-title {
font-weight: bold;
padding: 8px 0;
}
.c1 > .rc-menu-item-group-list {
padding: 0;
}
<ul
className="rc-menu c0 rc-menu-root rc-menu-vertical"
mb={2}
onKeyDown={[Function]}
p={0}
role="menu"
style={Object {}}
tabIndex="0"
>
<li
className="c1 rc-menu-item-group"
mb={3}
>
<div
className="rc-menu-item-group-title"
style={Object {}}
title="My Items"
>
My Items
</div>
<ul
className="rc-menu-item-group-list"
>
<li
className="rc-menu-item c2"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
py={2}
role="menuitem"
style={Object {}}
>
My item 1
</li>
<li
className="rc-menu-item c2"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
py={2}
role="menuitem"
style={Object {}}
>
My item 2
</li>
<li
className="rc-menu-item c2"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
py={2}
role="menuitem"
style={Object {}}
>
My item 3
</li>
</ul>
</li>
<li
className="c1 rc-menu-item-group"
mb={3}
>
<div
className="rc-menu-item-group-title"
style={Object {}}
title="Other items"
>
Other items
</div>
<ul
className="rc-menu-item-group-list"
>
<li
className="rc-menu-item c2"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
py={2}
role="menuitem"
style={Object {}}
>
Other item 1
</li>
<li
className="rc-menu-item c2"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
py={2}
role="menuitem"
style={Object {}}
>
Other item 2
</li>
<li
className="rc-menu-item c2"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
py={2}
role="menuitem"
style={Object {}}
>
Other item 3
</li>
</ul>
</li>
</ul>
`;

125
yarn.lock

@ -1838,6 +1838,13 @@ add-asset-html-webpack-plugin@^3.0.1:
micromatch "^3.1.3"
p-each-series "^1.0.0"
add-dom-event-listener@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/add-dom-event-listener/-/add-dom-event-listener-1.1.0.tgz#6a92db3a0dd0abc254e095c0f1dc14acbbaae310"
integrity sha512-WCxx1ixHT0GQU9hb0KI/mhgRQhnU+U3GvwY6ZvVjYq8rsihIGoaIOUbY0yMPBxLH5MDtr0kz3fisWGNcbWW7Jw==
dependencies:
object-assign "4.x"
address@1.0.3, address@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/address/-/address-1.0.3.tgz#b5f50631f8d6cec8bd20c963963afb55e06cbce9"
@ -3652,7 +3659,7 @@ babel-register@^6.26.0:
mkdirp "^0.5.1"
source-map-support "^0.4.15"
babel-runtime@6.26.0, babel-runtime@6.x.x, babel-runtime@^6.11.6, babel-runtime@^6.18.0, babel-runtime@^6.2.0, babel-runtime@^6.22.0, babel-runtime@^6.23.0, babel-runtime@^6.26.0, babel-runtime@^6.5.0, babel-runtime@^6.9.2:
babel-runtime@6.26.0, babel-runtime@6.x, babel-runtime@6.x.x, babel-runtime@^6.11.6, babel-runtime@^6.18.0, babel-runtime@^6.2.0, babel-runtime@^6.22.0, babel-runtime@^6.23.0, babel-runtime@^6.26.0, babel-runtime@^6.5.0, babel-runtime@^6.9.2:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
integrity sha1-llxwWGaOgrVde/4E/yM3vItWR/4=
@ -4659,7 +4666,7 @@ class-utils@^0.3.5:
isobject "^3.0.0"
static-extend "^0.1.1"
classnames@^2.2.5:
classnames@2.x, classnames@^2.2.5, classnames@^2.2.6:
version "2.2.6"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.6.tgz#43935bffdd291f326dad0a205309b38d00f650ce"
integrity sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q==
@ -4967,11 +4974,23 @@ compare-version@^0.1.2:
resolved "https://registry.yarnpkg.com/compare-version/-/compare-version-0.1.2.tgz#0162ec2d9351f5ddd59a9202cba935366a725080"
integrity sha1-AWLsLZNR9d3VmpICy6k1NmpyUIA=
component-classes@^1.2.5:
version "1.2.6"
resolved "https://registry.yarnpkg.com/component-classes/-/component-classes-1.2.6.tgz#c642394c3618a4d8b0b8919efccbbd930e5cd691"
integrity sha1-xkI5TDYYpNiwuJGe/Mu9kw5c1pE=
dependencies:
component-indexof "0.0.3"
component-emitter@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6"
integrity sha1-E3kY1teCg/ffemt8WmPhQOaUJeY=
component-indexof@0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/component-indexof/-/component-indexof-0.0.3.tgz#11d091312239eb8f32c8f25ae9cb002ffe8d3c24"
integrity sha1-EdCRMSI5648yyPJa6csAL/6NPCQ=
compress-commons@^1.2.0:
version "1.2.2"
resolved "https://registry.yarnpkg.com/compress-commons/-/compress-commons-1.2.2.tgz#524a9f10903f3a813389b0225d27c48bb751890f"
@ -5354,6 +5373,14 @@ csp-html-webpack-plugin@^2.3.0:
cheerio "^1.0.0-rc.2"
lodash "^4.17.10"
css-animation@^1.3.2:
version "1.4.1"
resolved "https://registry.yarnpkg.com/css-animation/-/css-animation-1.4.1.tgz#5b8813125de0fbbbb0bbe1b472ae84221469b7a8"
integrity sha1-W4gTEl3g+7uwu+G0cq6EIhRpt6g=
dependencies:
babel-runtime "6.x"
component-classes "^1.2.5"
css-color-keywords@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/css-color-keywords/-/css-color-keywords-1.0.0.tgz#fea2616dc676b2962686b3af8dbdbe180b244e05"
@ -5980,6 +6007,11 @@ doctrine@^2.0.0, doctrine@^2.1.0:
dependencies:
esutils "^2.0.2"
dom-align@^1.7.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/dom-align/-/dom-align-1.8.0.tgz#c0e89b5b674c6e836cd248c52c2992135f093654"
integrity sha512-B85D4ef2Gj5lw0rK0KM2+D5/pH7yqNxg2mB+E8uzFaolpm7RQmsxEfjyEuNiF8UBBkffumYDeKRzTzc3LePP+w==
dom-converter@~0.2:
version "0.2.0"
resolved "https://registry.yarnpkg.com/dom-converter/-/dom-converter-0.2.0.tgz#6721a9daee2e293682955b6afe416771627bb768"
@ -5992,6 +6024,11 @@ dom-helpers@^3.3.1:
resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-3.3.1.tgz#fc1a4e15ffdf60ddde03a480a9c0fece821dd4a6"
integrity sha512-2Sm+JaYn74OiTM2wHvxJOo3roiq/h25Yi69Fqk269cNUwIXsCvATB6CRSFC9Am/20G2b28hGv/+7NiWydIrPvg==
dom-scroll-into-view@1.x:
version "1.2.1"
resolved "https://registry.yarnpkg.com/dom-scroll-into-view/-/dom-scroll-into-view-1.2.1.tgz#e8f36732dd089b0201a88d7815dc3f88e6d66c7e"
integrity sha1-6PNnMt0ImwIBqI14Fdw/iObWbH4=
dom-serializer@0, dom-serializer@~0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.0.tgz#073c697546ce0780ce23be4a28e293e40bc30c82"
@ -11182,6 +11219,16 @@ mini-css-extract-plugin@^0.4.4:
schema-utils "^1.0.0"
webpack-sources "^1.1.0"
mini-store@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/mini-store/-/mini-store-2.0.0.tgz#0843c048d6942ce55e3e78b1b67fc063022b5488"
integrity sha512-EG0CuwpQmX+XL4QVS0kxNwHW5ftSbhygu1qxQH0pipugjnPkbvkalCdQbEihMwtQY6d3MTN+MS0q+aurs+RfLQ==
dependencies:
hoist-non-react-statics "^2.3.1"
prop-types "^15.6.0"
react-lifecycles-compat "^3.0.4"
shallowequal "^1.0.2"
minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7"
@ -11356,6 +11403,11 @@ murmurhash3js@^3.0.1:
resolved "https://registry.yarnpkg.com/murmurhash3js/-/murmurhash3js-3.0.1.tgz#3e983e5b47c2a06f43a713174e7e435ca044b998"
integrity sha1-Ppg+W0fCoG9DpxMXTn5DXKBEuZg=
mutationobserver-shim@^0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/mutationobserver-shim/-/mutationobserver-shim-0.3.2.tgz#f4d5dae7a4971a2207914fb5a90ebd514b65acca"
integrity sha1-9NXa56SXGiIHkU+1qQ69UUtlrMo=
mute-stream@0.0.7, mute-stream@~0.0.4:
version "0.0.7"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"
@ -11968,7 +12020,7 @@ oauth-sign@~0.9.0:
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.9.0.tgz#47a7b016baa68b5fa0ecf3dee08a85c679ac6455"
integrity sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==
object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
object-assign@4.x, object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
@ -13276,7 +13328,7 @@ promzard@^0.3.0:
dependencies:
read "1"
prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.8, prop-types@^15.5.9, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2:
prop-types@15.x, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.6, prop-types@^15.5.8, prop-types@^15.5.9, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2:
version "15.6.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102"
integrity sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==
@ -13560,6 +13612,66 @@ raw-loader@^0.5.1:
resolved "https://registry.yarnpkg.com/raw-loader/-/raw-loader-0.5.1.tgz#0c3d0beaed8a01c966d9787bf778281252a979aa"
integrity sha1-DD0L6u2KAclm2Xh793goElKpeao=
rc-align@^2.4.0:
version "2.4.3"
resolved "https://registry.yarnpkg.com/rc-align/-/rc-align-2.4.3.tgz#b9b3c2a6d68adae71a8e1d041cd5e3b2a655f99a"
integrity sha512-h5KgyB5IXYR7iKpYFcMr54cuQ2eozPCZ11kbXPG5+6CWvmyJ+c0R/yjndVndiNk2G3MKcTMbJNdDv5DIckLAxQ==
dependencies:
babel-runtime "^6.26.0"
dom-align "^1.7.0"
prop-types "^15.5.8"
rc-util "^4.0.4"
rc-animate@2.x:
version "2.5.4"
resolved "https://registry.yarnpkg.com/rc-animate/-/rc-animate-2.5.4.tgz#3b308c42e137a2e3fb578650fdb145c2100fcc35"
integrity sha512-aYisNYRuOvH+r5/nxEHHUzk1celxPg4nMUOuBGHd77c6NZbZ5fcjHFgWF3/nPdRPbLaqY4Z7Q317EcLO41fOvQ==
dependencies:
babel-runtime "6.x"
classnames "^2.2.6"
css-animation "^1.3.2"
prop-types "15.x"
raf "^3.4.0"
react-lifecycles-compat "^3.0.4"
rc-menu@^7.4.15:
version "7.4.15"
resolved "https://registry.yarnpkg.com/rc-menu/-/rc-menu-7.4.15.tgz#18304e8b837514eccc0cc6d171fc15b9a6f3822f"
integrity sha512-xEUlCWYiK1lw1SxcQZuSgaoJwjsnK5qJPM1HxiI8uUCvD3djM4eegAIC7E6PG79Xl0Zq2V4KZZj5T5hWJA3qNA==
dependencies:
babel-runtime "6.x"
classnames "2.x"
dom-scroll-into-view "1.x"
mini-store "^2.0.0"
mutationobserver-shim "^0.3.2"
prop-types "^15.5.6"
rc-animate "2.x"
rc-trigger "^2.3.0"
rc-util "^4.1.0"
resize-observer-polyfill "^1.5.0"
rc-trigger@^2.3.0:
version "2.6.2"
resolved "https://registry.yarnpkg.com/rc-trigger/-/rc-trigger-2.6.2.tgz#a9c09ba5fad63af3b2ec46349c7db6cb46657001"
integrity sha512-op4xCu95/gdHVaysyxxiYxbY+Z+UcIBSUY9nQfLqm1FlitdtnAN+owD5iMPfnnsRXntgcQ5+RdYKNUFQT5DjzA==
dependencies:
babel-runtime "6.x"
classnames "^2.2.6"
prop-types "15.x"
rc-align "^2.4.0"
rc-animate "2.x"
rc-util "^4.4.0"
rc-util@^4.0.4, rc-util@^4.1.0, rc-util@^4.4.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/rc-util/-/rc-util-4.6.0.tgz#ba33721783192ec4f3afb259e182b04e55deb7f6"
integrity sha512-rbgrzm1/i8mgfwOI4t1CwWK7wGe+OwX+dNa7PVMgxZYPBADGh86eD4OcJO1UKGeajIMDUUKMluaZxvgraQIOmw==
dependencies:
add-dom-event-listener "^1.1.0"
babel-runtime "6.x"
prop-types "^15.5.10"
shallowequal "^0.2.2"
rc@^1.0.1, rc@^1.1.6, rc@^1.2.1, rc@^1.2.7:
version "1.2.8"
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed"
@ -14608,6 +14720,11 @@ reselect@^4.0.0:
resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.0.0.tgz#f2529830e5d3d0e021408b246a206ef4ea4437f7"
integrity sha512-qUgANli03jjAyGlnbYVAV5vvnOmJnODyABz51RdBN7M4WaVu8mecZWgyQNkG8Yqe3KRGRt0l4K4B3XVEULC4CA==
resize-observer-polyfill@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.0.tgz#660ff1d9712a2382baa2cad450a4716209f9ca69"
integrity sha512-M2AelyJDVR/oLnToJLtuDJRBBWUGUvvGigj1411hXhAdyFWqMaqHp7TixW3FpiLuVaikIcR1QL+zqoJoZlOgpg==
resolve-cwd@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"

Loading…
Cancel
Save