Skip to content

Commit ed20ac1

Browse files
committed
fix: prefer extend of styled to make styles more predictable
1 parent 5084780 commit ed20ac1

File tree

9 files changed

+35
-20
lines changed

9 files changed

+35
-20
lines changed

src/common-elements/dropdown.ts

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

3-
import styled, { withProps } from '../styled-components';
3+
import styled, { withProps, StyledComponentClass } from '../styled-components';
44

55
export interface DropdownOption {
66
label: string;
@@ -87,9 +87,9 @@ export const StyledDropdown = withProps<DropdownProps>(styled(Dropdown))`
8787
background-color: rgba(38, 50, 56, 0.12)
8888
}
8989
}
90-
` as React.ComponentClass<DropdownProps>;
90+
` as StyledComponentClass<any, DropdownProps>;
9191

92-
export const SimpleDropdown = styled(StyledDropdown)`
92+
export const SimpleDropdown = StyledDropdown.extend`
9393
margin-left: 10px;
9494
text-transform: none;
9595
font-size: 0.929em;

src/common-elements/fields.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ export const FieldLabel = styled.span`
1212
line-height: 20px;
1313
`;
1414

15-
export const TypePrefix = styled(FieldLabel)`
15+
export const TypePrefix = FieldLabel.extend`
1616
color: ${props => transparentize(0.4, props.theme.colors.text)};
1717
`;
1818

19-
export const TypeName = styled(FieldLabel)`
19+
export const TypeName = FieldLabel.extend`
2020
color: ${props => transparentize(0.8, props.theme.colors.text)};
2121
`;
22-
export const TypeTitle = styled(FieldLabel)`
22+
export const TypeTitle = FieldLabel.extend`
2323
color: ${props => transparentize(0.5, props.theme.colors.text)};
2424
`;
2525

2626
export const TypeFormat = TypeName;
2727

28-
export const RequiredLabel = styled(FieldLabel.withComponent('div'))`
28+
export const RequiredLabel = FieldLabel.withComponent('div').extend`
2929
color: #e53935;
3030
font-size: 11px;
3131
font-weight: normal;
@@ -34,17 +34,17 @@ export const RequiredLabel = styled(FieldLabel.withComponent('div'))`
3434
font-weight: normal;
3535
`;
3636

37-
export const RecursiveLabel = styled(FieldLabel)`
37+
export const RecursiveLabel = FieldLabel.extend`
3838
color: #dd9900;
3939
font-size: 13px;
4040
`;
4141

42-
export const NullableLabel = styled(FieldLabel)`
42+
export const NullableLabel = FieldLabel.extend`
4343
color: #3195a6;
4444
font-size: 13px;
4545
`;
4646

47-
export const PatternLabel = styled(FieldLabel)`
47+
export const PatternLabel = FieldLabel.extend`
4848
color: #3195a6;
4949
&::before,
5050
&::after {
@@ -69,7 +69,7 @@ export const ExampleValue = styled.span`
6969
vertical-align: middle;
7070
`;
7171

72-
export const ConstraintItem = styled(FieldLabel)`
72+
export const ConstraintItem = FieldLabel.extend`
7373
background-color: ${props => transparentize(0.85, props.theme.colors.main)};
7474
color: ${props => transparentize(0.4, props.theme.colors.main)};
7575
margin-right: 6px;

src/common-elements/panels.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ export const RightPanel = styled.div`
2020
`};
2121
`;
2222

23-
export const DarkRightPanel = styled(RightPanel)`
23+
export const DarkRightPanel = RightPanel.extend`
2424
background-color: ${props => props.theme.rightPanel.backgroundColor};
2525
`;
2626

27-
export const EmptyDarkRightPanel = styled(DarkRightPanel)`
27+
export const EmptyDarkRightPanel = DarkRightPanel.extend`
2828
${media.lessThan('medium')`
2929
padding: 0
3030
`};

src/common-elements/tabs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const Tabs = styled(ReactTabs)`
6060
}
6161
`;
6262

63-
export const SmallTabs = styled(Tabs)`
63+
export const SmallTabs = Tabs.extend`
6464
> ul {
6565
display: block;
6666
> li {

src/components/Operation/Operation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { ResponseSamples } from '../ResponseSamples/ResponseSamples';
1818

1919
import { OperationModel as OperationType } from '../../services/models';
2020

21-
const OperationRow = styled(Row)`
21+
const OperationRow = Row.extend`
2222
backface-visibility: hidden;
2323
contain: content;
2424

src/components/PayloadSamples/styled.elements.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import styled from '../../styled-components';
22

3-
import { SimpleDropdown } from '../../common-elements';
3+
import { StyledDropdown } from '../../common-elements';
44

55
export const MimeLabel = styled.div`
66
border-bottom: 1px solid rgba(255, 255, 255, 0.9);
@@ -9,14 +9,22 @@ export const MimeLabel = styled.div`
99
color: rgba(255, 255, 255, 0.8);
1010
`;
1111

12-
export const InvertedSimpleDropdown = styled(SimpleDropdown)`
12+
export const InvertedSimpleDropdown = StyledDropdown.extend`
13+
margin-left: 10px;
14+
text-transform: none;
15+
font-size: 0.929em;
1316
border-bottom: 1px solid rgba(255, 255, 255, 0.9);
1417
margin: 0 0 10px 0;
1518
display: block;
1619
1720
.Dropdown-control,
1821
.Dropdown-control:hover {
22+
font-size: 1em;
23+
border: none;
24+
padding: 0 1.2em 0 0;
25+
background: transparent;
1926
color: rgba(255, 255, 255, 0.9);
27+
box-shadow: none;
2028
2129
.Dropdown-arrow {
2230
border-top-color: rgba(255, 255, 255, 0.9);

src/components/SecurityRequirement/SecuirityRequirement.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const SecuritiesColumn = styled.td`
4242
width: ${props => props.theme.schemaView.defaultDetailsWidth};
4343
`;
4444

45-
const AuthHeader = styled(UnderlinedHeader)`
45+
const AuthHeader = UnderlinedHeader.extend`
4646
display: inline-block;
4747
`;
4848

src/components/StickySidebar/StickyResponsiveSidebar.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ export class StickyResponsiveSidebar extends React.Component<StickySidebarProps>
9595
render() {
9696
const open = this.props.menu.sideBarOpened;
9797

98-
const height = `calc(100vh - ${top})`;
98+
const style = options => {
99+
const top = this.getScrollYOffset(options);
100+
return {
101+
top,
102+
height: `calc(100vh - ${top})`,
103+
};
104+
};
99105

100106
return (
101107
<OptionsContext.Consumer>
@@ -104,7 +110,7 @@ export class StickyResponsiveSidebar extends React.Component<StickySidebarProps>
104110
<StyledStickySidebar
105111
open={open}
106112
className={this.props.className}
107-
style={{ top: this.getScrollYOffset(options), height }}
113+
style={style(options)}
108114
// tslint:disable-next-line
109115
innerRef={el => {
110116
this.stickyElement = el;

src/styled-components.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ export const media = {
5050
};
5151

5252
export { css, injectGlobal, keyframes, ThemeProvider, withTheme, withProps };
53+
export { StyledComponentClass } from 'styled-components';
5354
export default styled;

0 commit comments

Comments
 (0)