Skip to content

Commit aa2204e

Browse files
committed
Fix Send card header layout by replacing all pill margins with flex gap
Previously we used left/right margins to manage spacing, which doesn't work well with the new layout that can go in either direction. In general though, using margins like this isn't very nice. This change drops the margins on generic pills entirely, putting them in only on the few spots where they're really required, and simplifying various places en route.
1 parent 836a95e commit aa2204e

File tree

9 files changed

+63
-62
lines changed

9 files changed

+63
-62
lines changed

src/components/common/card.tsx

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@ import { observer } from 'mobx-react';
55
import { styled, Theme, ThemeProps, css } from '../../styles';
66
import { Icon } from '../../icons';
77

8+
interface CollapseIconProps extends ThemeProps<Theme> {
9+
className?: string;
10+
onClick: () => void;
11+
collapsed: boolean;
12+
headerAlignment: 'left' | 'right';
13+
}
14+
15+
const CollapseIcon = styled((props: CollapseIconProps) =>
16+
<Icon
17+
className={props.className}
18+
icon={['fas', props.collapsed ? 'chevron-down' : 'chevron-up']}
19+
onClick={props.onClick}
20+
/>
21+
)`
22+
cursor: pointer;
23+
user-select: none;
24+
25+
padding: 4px 10px;
26+
27+
${p => p.headerAlignment === 'right'
28+
? 'margin: 0 -10px 0 -3px;'
29+
: 'margin: 0 -3px 0 -10px;'
30+
}
31+
32+
&:hover {
33+
color: ${p => p.theme.popColor};
34+
}
35+
`;
36+
837
interface CardProps extends React.HTMLAttributes<HTMLElement> {
938
className?: string;
1039
disabled?: boolean;
@@ -56,6 +85,8 @@ const Card = styled.section.attrs((p: CardProps) => ({
5685
${p => p.headerAlignment === 'left' && `
5786
flex-direction: row-reverse;
5887
`}
88+
89+
gap: 8px;
5990
}
6091
`;
6192

@@ -200,35 +231,6 @@ export class CollapsibleCard extends React.Component<
200231

201232
}
202233

203-
interface CollapseIconProps extends ThemeProps<Theme> {
204-
className?: string;
205-
onClick: () => void;
206-
collapsed: boolean;
207-
headerAlignment: 'left' | 'right';
208-
}
209-
210-
const CollapseIcon = styled((props: CollapseIconProps) =>
211-
<Icon
212-
className={props.className}
213-
icon={['fas', props.collapsed ? 'chevron-down' : 'chevron-up']}
214-
onClick={props.onClick}
215-
/>
216-
)`
217-
cursor: pointer;
218-
user-select: none;
219-
220-
padding: 4px 10px;
221-
222-
${p => p.headerAlignment === 'right'
223-
? 'margin: 0 -10px 0 5px;'
224-
: 'margin: 0 5px 0 -10px;'
225-
}
226-
227-
&:hover {
228-
color: ${p => p.theme.popColor};
229-
}
230-
`;
231-
232234
// Bit of redundancy here, but just because the TS styled plugin
233235
// gets super confused if you use variables in property names.
234236
const cardDirectionCss = (direction?: string) =>

src/components/common/pill.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ const pillStyles = css`
4242
border-radius: 4px;
4343
padding: 4px 8px;
4444
45-
margin: 0 8px 0 0;
46-
* + & {
47-
margin-left: 8px;
48-
}
49-
& + & {
50-
margin-left: 0;
51-
}
52-
5345
text-align: center;
5446
text-transform: none;
5547
font-weight: bold;
@@ -93,10 +85,6 @@ const Select = styled(Pill.withComponent('select'))`
9385
font-size: ${p => p.theme.textSize};
9486
font-family: ${p => p.theme.fontFamily};
9587
96-
${Pill} + & {
97-
margin-left: 0;
98-
}
99-
10088
${interactiveMouseoverStyles}
10189
10290
* {

src/components/editor/body-card-components.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export const EditorCardContent = styled.div`
4949
min-height: 0;
5050
`;
5151

52+
export const ContainerSizedEditorCardContent = styled(EditorCardContent)`
53+
flex-shrink: 1;
54+
`;
55+
5256
export function getBodyDownloadFilename(url: string, headers: Headers | RawHeaders): string | undefined {
5357
const contentDisposition = getHeaderValue(headers, 'content-disposition') || "";
5458
const filenameMatch = / filename="([^"]+)"/.exec(contentDisposition);

src/components/intercept/intercept-option.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ const LoadingOverlay = styled.div`
146146

147147
export const StatusPill = styled(Pill)`
148148
white-space: normal; /* Useful for layout in tiny screens, e.g. the 'proxy port' badge */
149-
&& { margin: auto 0 0 0; }
149+
150+
margin-top: auto;
150151
`;
151152

152153
function getStatusPill(interceptor: Interceptor) {

src/components/send/send-request-body-card.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import { EditableContentType, EditableContentTypes } from '../../model/events/co
1212
import { CollapsibleCardProps } from '../common/card';
1313
import { SendBodyCardSection } from './send-card-section';
1414
import { ContainerSizedEditor } from '../editor/base-editor';
15-
import { EditableBodyCardHeader, EditorCardContent } from '../editor/body-card-components';
15+
import {
16+
EditableBodyCardHeader,
17+
ContainerSizedEditorCardContent
18+
} from '../editor/body-card-components';
1619

1720
export interface SendRequestBodyProps extends CollapsibleCardProps {
1821
body: Buffer;
@@ -24,10 +27,6 @@ export interface SendRequestBodyProps extends CollapsibleCardProps {
2427
editorNode: portals.HtmlPortalNode<typeof ContainerSizedEditor>;
2528
}
2629

27-
export const SendRequestEditorContent = styled(EditorCardContent)`
28-
flex-shrink: 1;
29-
`;
30-
3130
@observer
3231
export class SendRequestBodyCard extends React.Component<SendRequestBodyProps> {
3332

@@ -82,7 +81,7 @@ export class SendRequestBodyCard extends React.Component<SendRequestBodyProps> {
8281
onChangeContentType={this.onChangeContentType}
8382
/>
8483
</header>
85-
<SendRequestEditorContent>
84+
<ContainerSizedEditorCardContent>
8685
<portals.OutPortal<typeof ContainerSizedEditor>
8786
node={editorNode}
8887

@@ -91,7 +90,7 @@ export class SendRequestBodyCard extends React.Component<SendRequestBodyProps> {
9190
value={bodyString}
9291
onChange={this.updateBody}
9392
/>
94-
</SendRequestEditorContent>
93+
</ContainerSizedEditorCardContent>
9594
</SendBodyCardSection>;
9695
}
9796
}

src/components/send/sent-response-body.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { CollapsibleCardProps } from '../common/card';
1616
import { LoadingCard } from '../common/loading-card';
1717

1818
import {
19-
EditorCardContent,
19+
ContainerSizedEditorCardContent,
2020
ReadonlyBodyCardHeader,
2121
getBodyDownloadFilename,
2222
BodyDecodingErrorBanner
@@ -35,10 +35,6 @@ export interface SentResponseBodyProps extends CollapsibleCardProps {
3535
editorNode: portals.HtmlPortalNode<typeof ContainerSizedEditor>;
3636
}
3737

38-
export const SentResponseEditorContent = styled(EditorCardContent)`
39-
flex-shrink: 1;
40-
`;
41-
4238
// A selection of content types you might want to try out, to explore your encoded data:
4339
const ENCODED_DATA_CONTENT_TYPES = ['text', 'raw', 'base64', 'image'] as const;
4440

@@ -127,7 +123,7 @@ export class SentResponseBodyCard extends React.Component<{
127123
isPaidUser={isPaidUser}
128124
/>
129125
</header>
130-
<SentResponseEditorContent>
126+
<ContainerSizedEditorCardContent>
131127
<ContentViewer
132128
contentId={message.id}
133129
editorNode={this.props.editorNode}
@@ -138,7 +134,7 @@ export class SentResponseBodyCard extends React.Component<{
138134
>
139135
{decodedBody}
140136
</ContentViewer>
141-
</SentResponseEditorContent>
137+
</ContainerSizedEditorCardContent>
142138
</SendBodyCardSection>;
143139
} else if (!decodedBody && message.body.decodingError) {
144140
// We have failed to decode the body content! Show the error & raw encoded data instead:
@@ -179,7 +175,7 @@ export class SentResponseBodyCard extends React.Component<{
179175
headers={message.rawHeaders}
180176
/>
181177
{ encodedBody &&
182-
<SentResponseEditorContent>
178+
<ContainerSizedEditorCardContent>
183179
<ContentViewer
184180
contentId={message.id}
185181
editorNode={this.props.editorNode}
@@ -189,7 +185,7 @@ export class SentResponseBodyCard extends React.Component<{
189185
>
190186
{ encodedBody }
191187
</ContentViewer>
192-
</SentResponseEditorContent>
188+
</ContainerSizedEditorCardContent>
193189
}
194190
</SendBodyCardSection>;
195191
} else {

src/components/view/http/http-export-card.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ const SnippetDescriptionContainer = styled.div`
4444
}
4545
`;
4646

47+
const SnippetDetailButtons = styled.div`
48+
display: flex;
49+
align-items: center;
50+
51+
gap: 10px;
52+
margin-bottom: 10px;
53+
`;
54+
4755
const SnippetEditorContainer = styled.div`
4856
margin: 0 -20px -20px -20px;
4957
border-top: solid 1px ${p => p.theme.containerBorder};
@@ -82,13 +90,14 @@ const ExportSnippetEditor = observer((p: {
8290
getCodeSnippetFormatName(p.exportOption)
8391
}</strong>: { description }
8492
</p>
85-
<p>
93+
<SnippetDetailButtons>
8694
<DocsLink href={link}>
8795
Find out more
88-
</DocsLink> <CopyButtonPill content={snippet}>
96+
</DocsLink>
97+
<CopyButtonPill content={snippet}>
8998
{' '}Copy snippet
9099
</CopyButtonPill>
91-
</p>
100+
</SnippetDetailButtons>
92101
</SnippetDescriptionContainer>
93102
<SnippetEditorContainer>
94103
<SelfSizedEditor

src/components/view/http/http-performance-card.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ const CompressionResultsContainer = styled.div`
139139

140140
const CompressionResultsPill = styled(Pill)`
141141
flex-shrink: 0;
142-
margin: 0;
143142
`;
144143

145144
const CompressionOptions = observer((p: {

src/components/view/stream-message-rows.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ const EditorRowHeader = styled.div<{ messageDirection: 'left' | 'right' }>`
311311
display: flex;
312312
flex-direction: row;
313313
align-items: center;
314+
gap: 8px;
314315
315316
padding: 4px 15px 4px 0;
316317
@@ -327,6 +328,8 @@ const EditorRowHeader = styled.div<{ messageDirection: 'left' | 'right' }>`
327328
flex-grow: 1;
328329
text-overflow: ellipsis;
329330
overflow: hidden;
331+
332+
margin-left: -8px;
330333
}
331334
332335
> ${IconButton} {

0 commit comments

Comments
 (0)