Skip to content

Commit fae574f

Browse files
authored
Fix/responsive docs pages (#1174)
* Support showing navbar in mobile * More minor responsive fixes * Fix margin top in navbar on mobile
1 parent 8fd9809 commit fae574f

File tree

12 files changed

+153
-58
lines changed

12 files changed

+153
-58
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
3+
import menuIcon from '../../images/newDesign/menu.svg';
4+
import './index.scss';
5+
6+
export default ({onClick}) => {
7+
return (
8+
<button className="fab" onClick={onClick}>
9+
<img src={menuIcon} />
10+
</button>
11+
);
12+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@import 'src/styles/constants';
2+
3+
.fab {
4+
position: fixed;
5+
display: flex;
6+
align-items: center;
7+
justify-content: center;
8+
border: none;
9+
10+
bottom: 20px;
11+
right: 20px;
12+
padding: 10px;
13+
background-color: $dark80;
14+
box-shadow: 1px 1px 5px rgba($dark10, 0.2);
15+
z-index: 200;
16+
17+
18+
@include desktop {
19+
display: none;
20+
}
21+
}

uilib-docs/src/components/layout.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ const Layout = ({children, location}) => {
2121
}
2222
}
2323
}
24-
`);
24+
`
25+
);
2526

2627
const {pathname} = location;
27-
const {site: {siteMetadata}} = data;
28-
28+
const {
29+
site: {siteMetadata}
30+
} = data;
31+
2932
const metaTitle = siteMetadata.title;
3033
const metaDescription = siteMetadata.description;
3134
const pathPrefix = `/${siteMetadata.domain}`;
32-
35+
3336
const showSidebar = _.replace(pathname, pathPrefix, '') !== '/';
3437
return (
3538
<div className="layout">
@@ -43,8 +46,17 @@ const Layout = ({children, location}) => {
4346
<meta property="twitter:title" content={metaTitle} />
4447
<meta property="twitter:description" content={metaDescription} />
4548
<link rel="canonical" href="https://wix.github.io/react-native-ui-lib/" />
46-
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.22.0/prism.min.js" integrity="sha512-9+422Bs3A87UkWfp+qV80Nfv9arhbCXKY1rxrF2seorI36mIIstMiuBfyKLF1yH1nnzQkEWq2xrzT4XU3Z+vrA==" crossorigin="anonymous"></script>
47-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.22.0/themes/prism-tomorrow.min.css" integrity="sha512-vswe+cgvic/XBoF1OcM/TeJ2FW0OofqAVdCZiEYkd6dwGXthvkSFWOoGGJgS2CW70VK5dQM5Oh+7ne47s74VTg==" crossorigin="anonymous" />
49+
<script
50+
src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.22.0/prism.min.js"
51+
integrity="sha512-9+422Bs3A87UkWfp+qV80Nfv9arhbCXKY1rxrF2seorI36mIIstMiuBfyKLF1yH1nnzQkEWq2xrzT4XU3Z+vrA=="
52+
crossorigin="anonymous"
53+
></script>
54+
<link
55+
rel="stylesheet"
56+
href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.22.0/themes/prism-tomorrow.min.css"
57+
integrity="sha512-vswe+cgvic/XBoF1OcM/TeJ2FW0OofqAVdCZiEYkd6dwGXthvkSFWOoGGJgS2CW70VK5dQM5Oh+7ne47s74VTg=="
58+
crossorigin="anonymous"
59+
/>
4860
</Helmet>
4961
<Header githubDomain={siteMetadata.github} />
5062
{/* <div className={`main ${!showSidebar ? 'fill' : ''}`}> */}

uilib-docs/src/components/layout.scss

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
display: flex;
1313
flex: 1;
1414
height: 100%;
15+
width: 100%;
1516
border-top: 0;
1617
// overflow-y: auto;
1718
// overflow-x: hidden;
18-
width: 80%;
1919
min-width: 50vw;
20+
21+
@include desktop {
22+
width: 80%;
23+
}
2024
}
2125

2226
.content {
@@ -25,7 +29,9 @@
2529
width: 100%;
2630

2731
&.with-navbar {
28-
padding-left: $navbarWidth;
32+
@include desktop {
33+
padding-left: $navbarWidth;
34+
}
2935
}
3036
}
3137
}

uilib-docs/src/components/navbar/index.js

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import './index.scss';
77
import searchIcon from '../../images/search.svg';
88
import clearIcon from '../../images/delete.svg';
99
import Item from './item';
10+
import Fab from '../fab';
1011

1112
class Navbar extends Component {
1213
state = {
14+
showNavbar: false,
1315
filter: ''
1416
};
1517

@@ -28,7 +30,7 @@ class Navbar extends Component {
2830
return _.flow(
2931
p => _.split(p, '/'),
3032
items => _.filter(items, i => !_.isEmpty(i)),
31-
_.last,
33+
_.last
3234
)(path);
3335
}
3436
};
@@ -57,6 +59,12 @@ class Navbar extends Component {
5759
return filteredComponents;
5860
}
5961

62+
toggleNavbar = value => {
63+
this.setState({
64+
showNavbar: _.isBoolean(value) ? value : !this.state.showNavbar
65+
});
66+
};
67+
6068
renderSearch = () => {
6169
const {filter} = this.state;
6270
const clearButtonClassName = classnames('clear-button', {
@@ -65,11 +73,7 @@ class Navbar extends Component {
6573
return (
6674
<div className="search">
6775
<img src={searchIcon} />
68-
<input
69-
placeholder="Search..."
70-
onChange={this.setFilter}
71-
value={filter}
72-
/>
76+
<input placeholder="Search..." onChange={this.setFilter} value={filter} />
7377
<button className={clearButtonClassName} onClick={this.resetSearch}>
7478
<img src={clearIcon} />
7579
</button>
@@ -79,37 +83,42 @@ class Navbar extends Component {
7983

8084
renderNavbar = data => {
8185
const currentPage = this.getCurrentPage();
82-
const {filter} = this.state;
86+
const {filter, showNavbar} = this.state;
8387
const markdowns = this.getMarkdownPages(data);
8488
const components = this.getNavbarComponents(data);
8589
const filteredComponents = _.filter(components, component =>
8690
_.includes(_.lowerCase(component.node.displayName), _.lowerCase(filter))
8791
);
8892

89-
const componentsByGroups = _.groupBy(
90-
filteredComponents,
91-
c => _.split(c.node.displayName, '.')[0]
92-
);
93+
const componentsByGroups = _.groupBy(filteredComponents, c => _.split(c.node.displayName, '.')[0]);
94+
95+
const navbarClassName = classnames('navbar', {
96+
visible: showNavbar
97+
});
9398

9499
return (
95-
<div className="navbar">
96-
{this.renderSearch()}
97-
<ul>
98-
{_.map(markdowns, page => {
99-
return <Item id={page.title} link={page.path} />;
100-
})}
101-
<li className="separator" />
102-
{_.map(componentsByGroups, (components, key) => {
103-
return (
104-
<Item
105-
id={key}
106-
components={components}
107-
currentPage={currentPage}
108-
></Item>
109-
);
110-
})}
111-
</ul>
112-
</div>
100+
<>
101+
<div className={navbarClassName}>
102+
{this.renderSearch()}
103+
<ul>
104+
{_.map(markdowns, page => {
105+
return <Item id={page.title} link={page.path} onLinkClick={() => this.toggleNavbar(false)} />;
106+
})}
107+
<li className="separator" />
108+
{_.map(componentsByGroups, (components, key) => {
109+
return (
110+
<Item
111+
id={key}
112+
components={components}
113+
currentPage={currentPage}
114+
onLinkClick={() => this.toggleNavbar(false)}
115+
></Item>
116+
);
117+
})}
118+
</ul>
119+
</div>
120+
<Fab onClick={this.toggleNavbar} />
121+
</>
113122
);
114123
};
115124

@@ -125,7 +134,12 @@ class Navbar extends Component {
125134
}
126135
}
127136
}
128-
allFile(filter: {sourceInstanceName: {eq: "markdown-pages"}, childMarkdownRemark: {frontmatter: {path: {ne: null}}}}) {
137+
allFile(
138+
filter: {
139+
sourceInstanceName: {eq: "markdown-pages"}
140+
childMarkdownRemark: {frontmatter: {path: {ne: null}}}
141+
}
142+
) {
129143
edges {
130144
node {
131145
childMarkdownRemark {

uilib-docs/src/components/navbar/index.scss

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
@import 'src/styles/constants';
22

33
.navbar {
4+
display: none;
45
position: fixed;
5-
width: $navbarWidth;
66
height: calc(100% - #{$headerHeight});
7+
width: 100%;
8+
background-color: $white;
79
overflow-y: auto;
810
overflow-x: hidden;
911
padding: 20px;
1012
padding-top: 0;
1113
border-radius: 2px;
12-
margin-top: 20px;
1314
border-right: 2px solid $dark80;
15+
z-index: 100;
16+
17+
&.visible {
18+
display: initial;
19+
}
20+
21+
@include desktop {
22+
opacity: 1;
23+
display: initial;
24+
width: $navbarWidth;
25+
background-color: initial;
26+
margin-top: 20px;
27+
}
1428

1529
.search {
1630
position: sticky;

uilib-docs/src/components/navbar/item.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@ import classnames from 'classnames';
55

66
const undocumentedGroups = ['Incubator'];
77

8-
export default ({id, link, components, currentPage}) => {
8+
export default ({id, link, components, currentPage, onLinkClick}) => {
99
const hasChildren = _.size(components) > 1;
1010

1111
if (!hasChildren) {
12-
return <ItemEntry id={id} link={link} currentPage={currentPage} />;
12+
return <ItemEntry id={id} link={link} currentPage={currentPage} onLinkClick={onLinkClick} />;
1313
} else {
1414
return (
1515
<li key={id}>
1616
{undocumentedGroups.includes(id) ? (
1717
<span class={classnames('entry', {selected: id === currentPage})}>{id}</span>
1818
) : (
19-
<Link key={id} to={`/docs/${id}/`}>
19+
<Link key={id} to={`/docs/${id}/`} onClick={onLinkClick}>
2020
<span class={classnames('entry', {selected: id === currentPage})}>{id}</span>
2121
</Link>
2222
)}
2323

2424
<ul class="nested">
2525
{_.map(_.filter(components, c => c.node.displayName !== id), c => {
2626
return (
27-
<ItemEntry id={c.node.displayName} currentPage={currentPage} />
27+
<ItemEntry id={c.node.displayName} currentPage={currentPage} onLinkClick={onLinkClick}/>
2828
);
2929
})}
3030
</ul>
@@ -33,10 +33,10 @@ export default ({id, link, components, currentPage}) => {
3333
}
3434
};
3535

36-
const ItemEntry = ({id, link, currentPage}) => {
36+
const ItemEntry = ({id, link, currentPage, onLinkClick}) => {
3737
return (
3838
<li key={id}>
39-
<Link key={id} to={link || `/docs/${id}/`}>
39+
<Link key={id} to={link || `/docs/${id}/`} onClick={onLinkClick}>
4040
<span class={classnames('entry', {selected: id === currentPage})}>
4141
{id}
4242
</span>
Lines changed: 3 additions & 0 deletions
Loading

uilib-docs/src/pages/index.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
flex-direction: column;
4040
margin: auto;
4141
align-items: center;
42+
padding: 0 20px;
4243

4344
.main-section {
4445
position: relative;
@@ -144,7 +145,7 @@
144145

145146
code {
146147
display: inline-block;
147-
white-space: pre;
148+
white-space: break-spaces;
148149
text-align: left;
149150
background: $dark10;
150151
padding: 10px;

uilib-docs/src/pages/sections/LibrariesSection.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
.libraries-section {
44
width: 100vw;
5-
padding: 0 20%;
5+
padding: 0 40px;
66
height: 250px;
77
display: flex;
88
flex-direction: column;
@@ -13,6 +13,7 @@
1313
flex-direction: row;
1414
justify-content: space-between;
1515
align-items: center;
16+
padding: 0 20%;
1617
}
1718

1819
.headline {

uilib-docs/src/templates/components.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ $tabletOfContentWidth: 20vw;
215215
flex-direction: row;
216216
flex: 1;
217217
justify-content: center;
218-
width: $containerWidth;
218+
219+
@include desktop {
220+
width: $containerWidth;
221+
}
219222

220223
div {
221224
display: block;
@@ -228,6 +231,7 @@ $tabletOfContentWidth: 20vw;
228231
}
229232

230233
.sidebar {
234+
display: none;
231235
position: fixed;
232236
right: 0;
233237
bottom: 0;
@@ -240,6 +244,10 @@ $tabletOfContentWidth: 20vw;
240244

241245
@include tabletOfContent();
242246
@include visuals();
247+
248+
@include desktop {
249+
display: initial;
250+
}
243251
}
244252

245253
.component-header {

0 commit comments

Comments
 (0)