Skip to content

Commit ea48b8e

Browse files
SaraVieiraCompuIves
authored andcommitted
make search responsive (codesandbox#1185)
1 parent 160af7a commit ea48b8e

File tree

13 files changed

+125
-29
lines changed

13 files changed

+125
-29
lines changed

packages/app/src/app/pages/Dashboard/Content/Sandboxes/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Content extends React.Component {
4949
<DelayedAnimation
5050
delay={0.6}
5151
style={{
52+
textAlign: 'center',
5253
marginTop: '2rem',
5354
fontWeight: 600,
5455
color: 'rgba(255, 255, 255, 0.5)',

packages/app/src/app/pages/Search/Filters/Filter/elements.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import styled from 'styled-components';
1+
import styled, { css } from 'styled-components';
22

33
export const Container = styled.div`
44
padding: 1rem;
@@ -19,10 +19,37 @@ export const Container = styled.div`
1919
font-size: 0.875rem;
2020
padding-left: 2.5em;
2121
}
22+
23+
@media (max-width: 768px) {
24+
${props =>
25+
!props.open &&
26+
css`
27+
height: 30px;
28+
overflow: hidden;
29+
`};
30+
}
2231
`;
2332

2433
export const Title = styled.div`
2534
font-weight: 300;
2635
font-size: 1.25rem;
2736
margin-bottom: 1rem;
37+
display: flex;
38+
justify-content: space-between;
39+
align-items: center;
40+
41+
svg {
42+
display: none;
43+
width: 30px;
44+
height: 30px;
45+
@media (max-width: 768px) {
46+
display: block;
47+
}
48+
}
49+
`;
50+
51+
export const Button = styled.button`
52+
border: none;
53+
background: inherit;
54+
color: ${props => props.theme.white};
2855
`;
Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1-
import React from 'react';
2-
1+
import React, { Component } from 'react';
2+
import Down from 'react-icons/lib/md/expand-more';
3+
import Up from 'react-icons/lib/md/expand-less';
34
import { RefinementList } from 'react-instantsearch/dom';
45

5-
import { Container, Title } from './elements';
6+
import { Container, Title, Button } from './elements';
67

7-
function Filter({ title, attributeName, operator, noSearch }) {
8-
return (
9-
<Container>
10-
<Title>{title}</Title>
11-
<RefinementList
12-
withSearchBox={!noSearch}
13-
showMore={!noSearch}
14-
operator={operator}
15-
attributeName={attributeName}
16-
/>
17-
</Container>
18-
);
19-
}
8+
class Filter extends Component {
9+
state = { open: false };
2010

11+
toggle = () => this.setState(({ open }) => ({ open: !open }));
12+
render() {
13+
const { title, attributeName, operator, noSearch } = this.props;
14+
const { open } = this.state;
15+
return (
16+
<Container open={open}>
17+
<Title>
18+
<span>{title}</span>
19+
<Button onClick={this.toggle}>{open ? <Up /> : <Down />}</Button>
20+
</Title>
21+
<RefinementList
22+
withSearchBox={!noSearch}
23+
showMore={!noSearch}
24+
operator={operator}
25+
attributeName={attributeName}
26+
/>
27+
</Container>
28+
);
29+
}
30+
}
2131
export default Filter;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import styled from 'styled-components';
2+
3+
export const Container = styled.aside`
4+
flex: 1;
5+
@media (max-width: 768px) {
6+
width: 100%;
7+
}
8+
`;

packages/app/src/app/pages/Search/Filters/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react';
22

33
import Filter from './Filter';
4+
import { Container } from './elements';
45

56
function Filters() {
67
return (
7-
<div style={{ flex: 1 }}>
8+
<Container>
89
<Filter
910
title="Templates"
1011
operator="or"
@@ -17,7 +18,7 @@ function Filters() {
1718
attributeName="npm_dependencies.dependency"
1819
/>
1920
<Filter title="Tags" operator="or" attributeName="tags" />
20-
</div>
21+
</Container>
2122
);
2223
}
2324

packages/app/src/app/pages/Search/Results/elements.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@ export const Container = styled.div`
77
padding-top: 1rem;
88
99
color: rgba(255, 255, 255, 0.6);
10+
11+
@media (max-width: 768px) {
12+
margin-right: 0;
13+
order: 1;
14+
15+
width: 100%;
16+
}
1017
`;

packages/app/src/app/pages/Search/SandboxCard/SandboxInfo/elements.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export const CenteredText = styled.div`
1010

1111
export const UpdatedAt = styled.em`
1212
font-size: 0.75rem;
13+
14+
@media (max-width: 768px) {
15+
display: none;
16+
}
1317
`;
1418

1519
export const Stats = styled.div`

packages/app/src/app/pages/Search/SandboxCard/elements.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import styled from 'styled-components';
22
import { Link } from 'react-router-dom';
3+
import Row from 'common/components/flex/Row';
34
import getTemplateDefinition from 'common/templates';
45

56
export const Container = styled.div`
@@ -51,4 +52,14 @@ export const Description = styled.p`
5152
export const TagContainer = styled.div`
5253
font-size: 0.75rem;
5354
width: 30%;
55+
56+
@media (max-width: 768px) {
57+
width: auto;
58+
}
59+
`;
60+
61+
export const Header = styled(Row)`
62+
@media (max-width: 768px) {
63+
flex-direction: column;
64+
}
5465
`;

packages/app/src/app/pages/Search/SandboxCard/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Highlight } from 'react-instantsearch/dom';
44
import Tags from 'app/components/Tags';
55

66
import { sandboxUrl } from 'common/utils/url-generator';
7-
import Row from 'common/components/flex/Row';
87

98
import SandboxInfo from './SandboxInfo';
109

@@ -14,13 +13,14 @@ import {
1413
Title,
1514
Description,
1615
TagContainer,
16+
Header,
1717
} from './elements';
1818

1919
function SandboxCard({ hit }) {
2020
return (
2121
<StyledLink to={sandboxUrl({ id: hit.objectID, git: hit.git })}>
2222
<Container template={hit.template}>
23-
<Row alignItems="flex-start">
23+
<Header alignItems="flex-start">
2424
<Title>
2525
{hit.title ? (
2626
<Highlight attributeName="title" hit={hit} />
@@ -35,7 +35,7 @@ function SandboxCard({ hit }) {
3535
tags={(hit.tags || []).filter(tag => tag.length < 20)}
3636
/>
3737
</TagContainer>
38-
</Row>
38+
</Header>
3939
<Description>
4040
<Highlight attributeName="description" hit={hit} />
4141
</Description>

packages/app/src/app/pages/Search/elements.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import styled from 'styled-components';
22
import Title from 'app/components/Title';
3+
import Row from 'common/components/flex/Row';
34

45
export const Content = styled.div`
56
margin-top: 5%;
@@ -11,4 +12,20 @@ export const StyledTitle = styled(Title)`
1112
display: inline-block;
1213
text-align: left;
1314
font-size: 2rem;
15+
16+
/* Algolia Icon */
17+
+ div {
18+
@media (max-width: 768px) {
19+
float: none;
20+
margin-top: -10px;
21+
padding: 0;
22+
margin-bottom: 1.5rem;
23+
}
24+
}
25+
`;
26+
27+
export const Main = styled(Row)`
28+
@media (max-width: 768px) {
29+
flex-direction: column;
30+
}
1431
`;

0 commit comments

Comments
 (0)