Skip to content

Commit

Permalink
fix: basic responsiveness
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Jan 30, 2018
1 parent a66de6c commit a29c3cc
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 23 deletions.
1 change: 1 addition & 0 deletions demo/playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ReDoc</title>
<style>
body {
Expand Down
20 changes: 19 additions & 1 deletion src/common-elements/panels.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
import styled from '../styled-components';
import styled, { media } from '../styled-components';

export const MiddlePanel = styled.div`
width: ${props => 100 - props.theme.rightPanel.width}%;
padding: ${props => props.theme.spacingUnit * 2}px;
${media.lessThan('medium')`
width: 100%;
`};
`;

export const RightPanel = styled.div`
width: ${props => props.theme.rightPanel.width}%;
color: #fafbfc;
bckground-color: ${props => props.theme.rightPanel.backgroundColor};
padding: ${props => props.theme.spacingUnit * 2}px;
${media.lessThan('medium')`
width: 100%;
`};
`;

export const DarkRightPanel = styled(RightPanel)`
background-color: ${props => props.theme.rightPanel.backgroundColor};
`;

export const EmptyDarkRightPanel = styled(DarkRightPanel)`
${media.lessThan('medium')`
padding: 0
`};
`;

export const Row = styled.div`
display: flex;
width: 100%;
${media.lessThan('medium')`
flex-direction: column;
`};
`;
4 changes: 2 additions & 2 deletions src/components/ApiInfo/ApiInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';

import { AppStore } from '../../services/AppStore';

import { DarkRightPanel, MiddlePanel, Row } from '../../common-elements/';
import { MiddlePanel, Row, EmptyDarkRightPanel } from '../../common-elements/';
import { Markdown } from '../Markdown/Markdown';
import { SecurityDefs } from '../SecuritySchemes/SecuritySchemes';

Expand Down Expand Up @@ -110,7 +110,7 @@ export class ApiInfo extends React.Component<ApiInfoProps> {
/>
</div>
</MiddlePanel>
<DarkRightPanel />
<EmptyDarkRightPanel />
</Row>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/ContentItems/ContentItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from 'react';
import { SECTION_ATTR } from '../../services/MenuStore';
import { Markdown } from '../Markdown/Markdown';

import { DarkRightPanel, H1, MiddlePanel, Row, ShareLink } from '../../common-elements';
import { EmptyDarkRightPanel, H1, MiddlePanel, Row, ShareLink } from '../../common-elements';
import { ContentItemModel } from '../../services/MenuBuilder';
import { OperationModel } from '../../services/models';
import { Operation } from '../Operation/Operation';
Expand Down Expand Up @@ -70,7 +70,7 @@ export class TagItem extends React.Component<ContentItemProps> {
</H1>
{description !== undefined && <Markdown source={description} />}
</MiddlePanel>
<DarkRightPanel key="right" />
<EmptyDarkRightPanel key="right" />
</Row>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Operation/Operation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { OperationModel as OperationType } from '../../services/models';
const OperationRow = styled(Row)`
transform: translateZ(0);
overflow: hidden;
positioin: relative;
position: relative;
&:after {
position: absolute;
Expand Down
5 changes: 4 additions & 1 deletion src/components/Redoc/elements.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hoverColor } from '../../common-elements/mixins';
import styled from '../../styled-components';
import styled, { media } from '../../styled-components';
export { ClassAttributes } from 'react';

export const RedocWrap = styled.div`
Expand Down Expand Up @@ -38,4 +38,7 @@ export const ApiContent = styled.div`
z-index: 10;
position: relative;
width: calc(100% - ${props => props.theme.menu.width});
${media.lessThan('small')`
width: 100%;
`};
`;
28 changes: 14 additions & 14 deletions src/components/SecurityRequirement/SecuirityRequirement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@ export class SecurityRequirement extends React.PureComponent<SecurityRequirement
}
}

const AuthHeaderColumn = styled.div`
display: inline-block;
width: calc(100% - ${props => props.theme.schemaView.defaultDetailsWidth});
`;
const AuthHeaderColumn = styled.td``;

const SecuritiesColumn = styled.div`
const SecuritiesColumn = styled.td`
width: ${props => props.theme.schemaView.defaultDetailsWidth};
display: inline-block;
`;

const AuthHeader = styled(UnderlinedHeader)`
Expand All @@ -61,14 +57,18 @@ export class SecurityRequirements extends React.PureComponent<SecurityRequiremen
return null;
}
return (
<div>
<AuthHeaderColumn>
<AuthHeader>Authorizations: </AuthHeader>
</AuthHeaderColumn>
<SecuritiesColumn>
{securities.map((security, idx) => <SecurityRequirement key={idx} security={security} />)}
</SecuritiesColumn>
</div>
<table>
<tr>
<AuthHeaderColumn>
<AuthHeader>Authorizations: </AuthHeader>
</AuthHeaderColumn>
<SecuritiesColumn>
{securities.map((security, idx) => (
<SecurityRequirement key={idx} security={security} />
))}
</SecuritiesColumn>
</tr>
</table>
);
}
}
2 changes: 1 addition & 1 deletion src/services/MenuStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action, computed } from 'mobx';
import { action, computed, observable } from 'mobx';
import { querySelector } from '../utils/dom';
import { GroupModel, OperationModel, SpecStore } from './models';

Expand Down
30 changes: 29 additions & 1 deletion src/styled-components.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as styledComponents from 'styled-components';

import { ThemeInterface } from './theme';
import theme, { ThemeInterface } from './theme';

export type StyledFunction<T> = styledComponents.ThemedStyledFunction<T, ThemeInterface>;

Expand All @@ -21,5 +21,33 @@ const {
any
>) as styledComponents.ThemedStyledComponentsModule<ThemeInterface>;

export const media = {
lessThan(breakpoint) {
return (...args) => css`
@media (max-width: ${theme.breakpoints[breakpoint]}) {
${(css as any)(...args)};
}
`;
},

greaterThan(breakpoint) {
return (...args) => css`
@media (min-width: ${theme.breakpoints[breakpoint]}) {
${(css as any)(...args)};
}
`;
},

between(firstBreakpoint, secondBreakpoint) {
return (...args) => css`
@media (min-width: ${theme.breakpoints[firstBreakpoint]}) and (max-width: ${theme.breakpoints[
secondBreakpoint
]}) {
${(css as any)(...args)};
}
`;
},
};

export { css, injectGlobal, keyframes, ThemeProvider, withTheme, withProps };
export default styled;
5 changes: 5 additions & 0 deletions src/theme.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const theme = {
spacingUnit: 20,
breakpoints: {
small: '50rem',
medium: '85rem',
large: '105rem',
},
colors: {
main: '#32329f',
success: '#00aa13',
Expand Down

0 comments on commit a29c3cc

Please sign in to comment.