Started on grid layout

This commit is contained in:
Gregory Schier
2023-02-22 19:44:44 -08:00
parent 6c549dc086
commit 00a7d9a180
7 changed files with 98 additions and 62 deletions

View File

@@ -7,6 +7,9 @@ import { WindowDragRegion } from './components/WindowDragRegion';
import { IconButton } from './components/IconButton'; import { IconButton } from './components/IconButton';
import { Sidebar } from './components/Sidebar'; import { Sidebar } from './components/Sidebar';
import { UrlBar } from './components/UrlBar'; import { UrlBar } from './components/UrlBar';
import { Input } from './components/Input';
import { Button } from './components/Button';
import { Grid } from './components/Grid';
interface Response { interface Response {
url: string; url: string;
@@ -63,44 +66,49 @@ function App() {
</DropdownMenuRadio> </DropdownMenuRadio>
</HStack> </HStack>
</Sidebar> </Sidebar>
<VStack className="w-full"> <Grid cols={2}>
<HStack as={WindowDragRegion} items="center" className="pl-4 pr-1"> <VStack className="w-full">
<h5 className="pointer-events-none text-gray-800">Send Request</h5> <HStack as={WindowDragRegion} items="center" className="px-3">
<IconButton icon="gear" className="ml-auto" /> <UrlBar
</HStack> method={method}
<VStack className="p-4 max-w-[50rem] mx-auto" space={3}> url={url}
<UrlBar onMethodChange={setMethod}
method={method} onUrlChange={setUrl}
url={url} sendRequest={sendRequest}
onMethodChange={setMethod} />
onUrlChange={setUrl} </HStack>
sendRequest={sendRequest}
/>
{error && <div className="text-white bg-red-500 px-4 py-1 rounded">{error}</div>}
{response !== null && (
<>
<div className="my-1 italic text-gray-500 text-sm">
{response?.method.toUpperCase()}
&nbsp;&bull;&nbsp;
{response?.status}
&nbsp;&bull;&nbsp;
{response?.elapsed}ms &nbsp;&bull;&nbsp;
{response?.elapsed2}ms
</div>
{contentType.includes('html') ? (
<iframe
title="Response preview"
srcDoc={response.body}
sandbox="allow-scripts allow-same-origin"
className="h-[70vh] w-full rounded-lg"
/>
) : response?.body ? (
<Editor value={response?.body} contentType={contentType} />
) : null}
</>
)}
</VStack> </VStack>
</VStack> <VStack className="w-full">
<HStack as={WindowDragRegion} items="center" className="pl-3 pr-1">
<div className="my-1 italic text-gray-500 text-sm w-full">
{response?.method.toUpperCase()}
&nbsp;&bull;&nbsp;
{response?.status}
&nbsp;&bull;&nbsp;
{response?.elapsed}ms &nbsp;&bull;&nbsp;
{response?.elapsed2}ms
</div>
<IconButton icon="gear" className="ml-auto" size="sm" />
</HStack>
<VStack className="px-3 py-3" space={3}>
{error && <div className="text-white bg-red-500 px-3 py-1 rounded">{error}</div>}
{response !== null && (
<>
{contentType.includes('html') ? (
<iframe
title="Response preview"
srcDoc={response.body}
sandbox="allow-scripts allow-same-origin"
className="h-full w-full rounded-lg"
/>
) : response?.body ? (
<Editor value={response?.body} contentType={contentType} />
) : null}
</>
)}
</VStack>
</VStack>
</Grid>
</div> </div>
</> </>
); );

View File

@@ -4,7 +4,7 @@ import { Icon } from './Icon';
export type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & { export type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
color?: 'primary' | 'secondary'; color?: 'primary' | 'secondary';
size?: 'sm' | 'md'; size?: 'xs' | 'sm' | 'md';
justify?: 'start' | 'center'; justify?: 'start' | 'center';
forDropdown?: boolean; forDropdown?: boolean;
}; };
@@ -31,6 +31,7 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button
justify === 'center' && 'justify-center', justify === 'center' && 'justify-center',
size === 'md' && 'h-10 px-4', size === 'md' && 'h-10 px-4',
size === 'sm' && 'h-8 px-3 text-sm', size === 'sm' && 'h-8 px-3 text-sm',
size === 'xs' && 'h-6 px-2 text-sm',
color === undefined && color === undefined &&
'hover:bg-gray-500/[0.1] active:bg-gray-500/[0.15] text-gray-800 hover:text-gray-900', 'hover:bg-gray-500/[0.1] active:bg-gray-500/[0.15] text-gray-800 hover:text-gray-900',
color === 'primary' && 'bg-blue-500 hover:bg-blue-500/90 active:bg-blue-500/80 text-white', color === 'primary' && 'bg-blue-500 hover:bg-blue-500/90 active:bg-blue-500/80 text-white',

View File

@@ -1,12 +1,28 @@
.cm-editor { .cm-wrapper {
height: 100%;
width: 100%; width: 100%;
overflow: hidden; position: relative;
}
.cm-editor {
position: absolute !important;
left: 0;
right: 0;
top: 0;
bottom: 0;
border-radius: var(--border-radius-lg); border-radius: var(--border-radius-lg);
border: 1px solid hsl(var(--color-gray-50));
font-size: 0.9rem;
}
.cm-editor.cm-focused {
outline: none !important;
border-color: hsl(var(--color-gray-100));
} }
.cm-editor .cm-scroller { .cm-editor .cm-scroller {
border-radius: var(--border-radius-lg); border-radius: var(--border-radius-lg);
background-color: hsl(var(--color-gray-50) / 0.5); background-color: hsl(var(--color-gray-50));
} }
.cm-editor .cm-line { .cm-editor .cm-line {
@@ -16,7 +32,7 @@
} }
.cm-editor .cm-gutters { .cm-editor .cm-gutters {
background-color: transparent; background-color: hsl(var(--color-gray-50));
border-right: 0; border-right: 0;
color: hsl(var(--color-gray-300)); color: hsl(var(--color-gray-300));
} }

View File

@@ -8,5 +8,5 @@ interface Props {
export default function Editor(props: Props) { export default function Editor(props: Props) {
const { ref } = useCodeMirror({ value: props.value, contentType: props.contentType }); const { ref } = useCodeMirror({ value: props.value, contentType: props.contentType });
return <div ref={ref} className="m-0 text-sm overflow-hidden" />; return <div ref={ref} className="cm-wrapper" />;
} }

View File

@@ -1,5 +1,5 @@
import classnames from 'classnames'; import classnames from 'classnames';
import {HTMLAttributes} from 'react'; import { HTMLAttributes } from 'react';
const colsClasses = { const colsClasses = {
none: 'grid-cols-none', none: 'grid-cols-none',
@@ -28,7 +28,12 @@ type Props = HTMLAttributes<HTMLElement> & {
export function Grid({ className, cols, gap, ...props }: Props) { export function Grid({ className, cols, gap, ...props }: Props) {
return ( return (
<div <div
className={classnames(className, 'grid', cols && colsClasses[cols], gap && gapClasses[gap])} className={classnames(
className,
'grid w-full',
cols && colsClasses[cols],
gap && gapClasses[gap],
)}
{...props} {...props}
/> />
); );

View File

@@ -2,20 +2,24 @@ import { InputHTMLAttributes, ReactNode } from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
import { HStack, VStack } from './Stacks'; import { HStack, VStack } from './Stacks';
interface Props extends InputHTMLAttributes<HTMLInputElement> { interface Props extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'> {
name: string; name: string;
label: string; label: string;
hideLabel?: boolean; hideLabel?: boolean;
labelClassName?: string; labelClassName?: string;
containerClassName?: string;
leftSlot?: ReactNode; leftSlot?: ReactNode;
rightSlot?: ReactNode; rightSlot?: ReactNode;
size?: 'sm' | 'md';
} }
export function Input({ export function Input({
label, label,
labelClassName,
hideLabel, hideLabel,
className, className,
containerClassName,
labelClassName,
size = 'md',
name, name,
leftSlot, leftSlot,
rightSlot, rightSlot,
@@ -23,15 +27,12 @@ export function Input({
}: Props) { }: Props) {
const id = `input-${name}`; const id = `input-${name}`;
return ( return (
<HStack items="center" className="w-full bg-gray-50 h-10 rounded-md text-sm "> <HStack
items="center"
className={classnames(containerClassName, 'w-full bg-gray-50 rounded-md text-sm')}
>
{leftSlot} {leftSlot}
<VStack <VStack className={classnames('w-full border-gray-100/50')}>
className={classnames(
'w-full border-gray-100/50',
leftSlot && 'border-l ml-0.5',
rightSlot && 'border-r mr-0.5',
)}
>
<label <label
htmlFor={name} htmlFor={name}
className={classnames( className={classnames(
@@ -46,7 +47,11 @@ export function Input({
id={id} id={id}
className={classnames( className={classnames(
className, className,
'bg-transparent min-w-0 pl-3 pr-2 w-full h-full focus:outline-none', 'bg-transparent min-w-0 pl-3 pr-2 w-full focus:outline-none',
leftSlot && 'pl-1',
rightSlot && 'pr-1',
size === 'md' && 'h-10',
size === 'sm' && 'h-8',
)} )}
{...props} {...props}
/> />

View File

@@ -28,12 +28,13 @@ export function UrlBar({ sendRequest, onMethodChange, method, onUrlChange, url }
}; };
return ( return (
<HStack as="form" className="items-end" onSubmit={handleSendRequest} space={2}> <form onSubmit={handleSendRequest} className="w-full flex items-center">
<Input <Input
hideLabel hideLabel
size="sm"
name="url" name="url"
label="Enter URL" label="Enter URL"
className="font-mono pr-12" className="font-mono"
onChange={(e) => onUrlChange(e.currentTarget.value)} onChange={(e) => onUrlChange(e.currentTarget.value)}
value={url} value={url}
placeholder="Enter a URL..." placeholder="Enter a URL..."
@@ -47,7 +48,7 @@ export function UrlBar({ sendRequest, onMethodChange, method, onUrlChange, url }
{ label: 'POST', value: 'POST' }, { label: 'POST', value: 'POST' },
]} ]}
> >
<Button disabled={loading} forDropdown size="sm" className="ml-1 w-22" justify="start"> <Button disabled={loading} size="xs" className="ml-1" justify="start">
{method.label} {method.label}
</Button> </Button>
</DropdownMenuRadio> </DropdownMenuRadio>
@@ -57,11 +58,11 @@ export function UrlBar({ sendRequest, onMethodChange, method, onUrlChange, url }
icon={loading ? 'update' : 'paper-plane'} icon={loading ? 'update' : 'paper-plane'}
spin={loading} spin={loading}
disabled={loading} disabled={loading}
size="sm" size="xs"
className="w-10 mr-1" className="mr-1"
/> />
} }
/> />
</HStack> </form>
); );
} }