-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] Add mobile navigation menu #908
Closed
Closed
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6bf30da
Allow links to be tabbed through for a11y
13e3861
Set appropriate scaling so example works on mobile
4f1440f
Create mobile navigation that switches layout when less than 650px
2361a45
Improve a11y and experience of mobile of filter
a463382
Merge remote-tracking branch 'storybooks/master' into feature/mobile-…
7158a74
Remove MenuMobile component that wasn't being used
c619e1d
Move common layout styles to separate module
da5fc3b
Resolve linting errors
6716e15
Resolve review comments and linting errrors
4dfbc88
Merge remote-tracking branch 'storybooks/master' into feature/mobile-…
2a97b17
Merge remote-tracking branch 'storybooks/master' into feature/mobile-…
a9fa8b5
Merge in master and resolve conflicts
79d0c6d
Merge remote-tracking branch 'storybooks/master' into feature/mobile-…
dd69e1e
Revert 2a97b17
2721e51
Remove .cache files from PR
6377e4a
Revert the Revert of 2a97b17 (o god)
7eb1491
Remove unnecessary changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// IMPORTANT | ||
// --------- | ||
// This is an auto generated file with React CDK. | ||
// Do not modify this file. | ||
// Use `.scripts/user/pretest.js instead`. | ||
|
||
require('babel-core/register'); | ||
require('babel-polyfill'); | ||
|
||
// Add jsdom support, which is required for enzyme. | ||
var jsdom = require('jsdom').jsdom; | ||
// Adds window.matchMedia support | ||
var matchMedia = require('matchmedia'); | ||
|
||
var exposedProperties = ['window', 'navigator', 'document']; | ||
|
||
global.document = jsdom(''); | ||
global.window = document.defaultView; | ||
Object.keys(document.defaultView).forEach((property) => { | ||
if (typeof global[property] === 'undefined') { | ||
exposedProperties.push(property); | ||
global[property] = document.defaultView[property]; | ||
} | ||
}); | ||
global.window.matchMedia = matchMedia; | ||
global.navigator = { | ||
userAgent: 'node.js' | ||
}; | ||
|
||
process.on('unhandledRejection', function (error) { | ||
console.error('Unhandled Promise Rejection:'); | ||
console.error(error && error.stack || error); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
packages/storybook-ui/src/modules/ui/components/collapsible.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React, { PropTypes } from 'react'; | ||
import { baseFonts } from './theme'; | ||
|
||
const wrapperStyles = { | ||
display: 'block', | ||
paddingTop: '10px', | ||
marginBottom: '15px', | ||
listStyle: 'none', | ||
fontSize: '18px', | ||
fontWeight: 'bold', | ||
...baseFonts, | ||
}; | ||
|
||
const iconStyles = { | ||
float: 'right', | ||
fontWeight: 'normal', | ||
fontSize: '150%', | ||
lineHeight: '0.65', | ||
}; | ||
|
||
class Collapsible extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
// Collapsible will be closed by default but | ||
// allows props to be passed in to override initialState | ||
this.state = { isActive: props.isActive || false }; | ||
this.handleClick = this.handleClick.bind(this); | ||
this.focusToContent = this.focusToContent.bind(this); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
// Allow controlled toggling of active state | ||
if (nextProps.active !== this.props.active) { | ||
this.setState({ | ||
isActive: nextProps.active, | ||
}); | ||
} | ||
} | ||
|
||
focusToContent() { | ||
const content = this.collapsibleBody; | ||
if (content) { | ||
content.focus(); | ||
} | ||
} | ||
|
||
handleClick(e) { | ||
e.preventDefault(); | ||
this.setState({ | ||
isActive: !this.state.isActive, | ||
}, this.focusToContent); | ||
// We will execute any additional onClick handlers that are passed | ||
// to the component | ||
const { onClick } = this.props; | ||
if (onClick) { | ||
onClick(); | ||
} | ||
} | ||
|
||
render() { | ||
const { | ||
tagName = 'div', | ||
children, | ||
title, | ||
id = encodeURI(title), | ||
} = this.props; | ||
const { isActive } = this.state; | ||
const headingStyles = { | ||
...wrapperStyles, | ||
textDecoration: isActive ? 'underline' : 'none', | ||
}; | ||
const Element = tagName; | ||
|
||
return ( | ||
<Element> | ||
<a | ||
href={`#${id}`} | ||
onClick={this.handleClick} | ||
aria-label={isActive ? `${title} - hides content` : `${title} - shows more content`} | ||
style={headingStyles} | ||
> | ||
{title} | ||
<span style={iconStyles}> | ||
{isActive ? '-' : '+'} | ||
</span> | ||
</a> | ||
{isActive && | ||
<div | ||
id={id} | ||
ref={c => this.collapsibleBody = c} // eslint-disable-line no-return-assign | ||
tabIndex="-1" | ||
> | ||
{children} | ||
</div>} | ||
</Element> | ||
); | ||
} | ||
} | ||
|
||
Collapsible.propTypes = { | ||
tagName: PropTypes.string, | ||
children: PropTypes.node.isRequired, | ||
title: PropTypes.string.isRequired, | ||
id: PropTypes.string, | ||
isActive: PropTypes.bool, | ||
onClick: PropTypes.func, | ||
}; | ||
|
||
export default Collapsible; |
19 changes: 19 additions & 0 deletions
19
packages/storybook-ui/src/modules/ui/components/layout/commonLayoutStyles.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const rootStyle = { | ||
height: '100%', | ||
backgroundColor: '#F7F7F7', | ||
}; | ||
|
||
export const fullScreenPreviewStyle = { | ||
position: 'fixed', | ||
left: '0px', | ||
right: '0px', | ||
top: '0px', | ||
zIndex: 1, | ||
backgroundColor: '#FFF', | ||
height: '100%', | ||
width: '100%', | ||
border: 0, | ||
margin: 0, | ||
padding: 0, | ||
overflow: 'hidden', | ||
}; |
122 changes: 122 additions & 0 deletions
122
packages/storybook-ui/src/modules/ui/components/layout/desktop.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
|
||
import VSplit from './vsplit'; | ||
import HSplit from './hsplit'; | ||
import SplitPane from '@kadira/react-split-pane'; | ||
|
||
import { rootStyle, fullScreenPreviewStyle } from './commonLayoutStyles'; | ||
|
||
const leftPanelStyle = { | ||
position: 'absolute', | ||
width: '100%', | ||
height: '100%', | ||
}; | ||
|
||
const downPanelStyle = { | ||
display: 'flex', | ||
position: 'absolute', | ||
width: '100%', | ||
height: '100%', | ||
padding: '5px 10px 10px 0', | ||
boxSizing: 'border-box', | ||
}; | ||
|
||
const contentPanelStyle = { | ||
position: 'absolute', | ||
boxSizing: 'border-box', | ||
width: '100%', | ||
height: '100%', | ||
padding: '10px 10px 10px 0', | ||
}; | ||
|
||
const normalPreviewStyle = { | ||
width: '100%', | ||
height: '100%', | ||
backgroundColor: '#FFF', | ||
border: '1px solid #ECECEC', | ||
borderRadius: 4, | ||
}; | ||
|
||
const vsplit = <VSplit />; | ||
const hsplit = <HSplit />; | ||
|
||
const onDragStart = function () { | ||
document.body.classList.add('dragging'); | ||
}; | ||
|
||
const onDragEnd = function () { | ||
document.body.classList.remove('dragging'); | ||
}; | ||
|
||
class Layout extends Component { | ||
render() { | ||
const { | ||
goFullScreen, | ||
showLeftPanel, | ||
showDownPanel, | ||
downPanelInRight, | ||
downPanel, | ||
leftPanel, | ||
preview, | ||
} = this.props; | ||
let previewStyle = normalPreviewStyle; | ||
|
||
if (goFullScreen) { | ||
previewStyle = fullScreenPreviewStyle; | ||
} | ||
|
||
const leftPanelDefaultSize = showLeftPanel ? 250 : 1; | ||
let downPanelDefaultSize = 1; | ||
if (showDownPanel) { | ||
downPanelDefaultSize = downPanelInRight ? 400 : 200; | ||
} | ||
|
||
return ( | ||
<div style={rootStyle}> | ||
<SplitPane | ||
split="vertical" | ||
minSize={leftPanelDefaultSize} | ||
defaultSize={leftPanelDefaultSize} | ||
resizerChildren={vsplit} | ||
onDragStarted={onDragStart} | ||
onDragFinished={onDragEnd} | ||
> | ||
<div style={leftPanelStyle}> | ||
{showLeftPanel ? leftPanel() : null} | ||
</div> | ||
|
||
<SplitPane | ||
split={downPanelInRight ? 'vertical' : 'horizontal'} | ||
primary="second" | ||
minSize={downPanelInRight ? 200 : 100} | ||
defaultSize={downPanelDefaultSize} | ||
resizerChildren={downPanelInRight ? vsplit : hsplit} | ||
onDragStarted={onDragStart} | ||
onDragFinished={onDragEnd} | ||
> | ||
<div style={contentPanelStyle}> | ||
<div style={previewStyle}> | ||
{preview()} | ||
</div> | ||
</div> | ||
<div style={downPanelStyle}> | ||
{showDownPanel ? downPanel() : null} | ||
</div> | ||
</SplitPane> | ||
</SplitPane> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Layout.propTypes = { | ||
showLeftPanel: PropTypes.bool.isRequired, | ||
showDownPanel: PropTypes.bool.isRequired, | ||
goFullScreen: PropTypes.bool.isRequired, | ||
leftPanel: PropTypes.func.isRequired, | ||
preview: PropTypes.func.isRequired, | ||
downPanel: PropTypes.func.isRequired, | ||
downPanelInRight: PropTypes.bool.isRequired, | ||
}; | ||
|
||
export default Layout; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
React.PropTypes
is deprecated. Should beimport PropTypes from 'prop-types'
across all changes AFAIK?