Skip to content
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
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .jestrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|scss)$": "<rootDir>/__mocks__/styleMock.js"
},
"testPathIgnorePatterns": ["/node_modules/", "/dist/"],
"roots": ["packages"],
"collectCoverage": false,
"collectCoverageFrom": [
Expand Down
1 change: 1 addition & 0 deletions packages/storybook-ui/example/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Storybook UI Demo</title>
<style>
body {
Expand Down
2 changes: 2 additions & 0 deletions packages/storybook-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"fuzzysearch": "^1.0.3",
"json-stringify-safe": "^5.0.1",
"keycode": "^2.1.8",
"lodash.isstring": "^4.0.1",
"lodash.pick": "^4.4.0",
"lodash.sortby": "^4.7.0",
"mantra-core": "^1.7.0",
Expand All @@ -32,6 +33,7 @@
"react-fuzzy": "^0.3.3",
"react-inspector": "^1.1.2",
"react-komposer": "^2.0.0",
"react-media": "^1.5.1",
"react-modal": "^1.7.6",
"react-split-pane": "^0.1.63",
"redux": "^3.6.0"
Expand Down
108 changes: 108 additions & 0 deletions packages/storybook-ui/src/modules/ui/components/collapsible.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import React from 'react';
import PropTypes from 'prop-types';
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;
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',
};
Loading