Skip to content

Commit

Permalink
refactor css styles (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikestarrdev authored Dec 15, 2023
1 parent dd0696b commit a13ab08
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 98 deletions.
83 changes: 43 additions & 40 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,53 +253,56 @@ function App() {
>
<div
className={twMerge(
'md:w-full lg:w-1/2 md:pt-4 md:pb-8 md:mr-2 bg-blueDark rounded-md pb-6 px-1',
'md:w-full lg:w-1/2',
'md:pt-4 md:pb-8 md:mr-2 bg-blueDark rounded-md pb-6 px-1',
'border border-blueGray shadow-sm shadow-grayDark'
)}
>
<Toggle
inputType={inputType}
clickTypeJson={() => {
setInputType(InputType.JSON);
setIsNoErrors(false);
setIsEnableCheck(false);
setErrors([]);
}}
clickTypeUrl={() => {
setInputType(InputType.URL);
setIsNoErrors(false);
// we need to reset the following 2 values because they affect the behavior of `decompressedJson` in Dilog.tsx
setUrlString(undefined);
setIsEnableCheck(false);
setErrors([]);
}}
/>

{inputType === InputType.JSON ? (
<JsonForm
handleSubmit={handleSubmit}
handleChangeTextArea={handleChangeTextAreaJson}
isEnableCheck={isEnableCheck}
isLoading={isLoadingCheck}
setIsEnableCheck={setIsEnableCheck}
setSelectedChainId={setSelectedChainId}
/>
) : (
<UrlForm
handleSubmit={handleSubmit}
handleChangeTextArea={handleChangeTextAreaUrl}
isEnableCheck={isEnableCheck}
isLoading={isLoadingCheck}
parsedJson={parsedJson}
decompressedJson={decompressedJson}
setDecompressedJson={setDecompressedJson}
<div className="w-full sm:w-4/5 md:w-full lg:w-[90%] m-auto">
<Toggle
inputType={inputType}
clickTypeJson={() => {
setInputType(InputType.JSON);
setIsNoErrors(false);
setIsEnableCheck(false);
setErrors([]);
}}
clickTypeUrl={() => {
setInputType(InputType.URL);
setIsNoErrors(false);
// reset the following 2 values because they affect the behavior of `decompressedJson` in Dialog.tsx
setUrlString(undefined);
setIsEnableCheck(false);
setErrors([]);
}}
/>
)}

{inputType === InputType.JSON ? (
<JsonForm
handleSubmit={handleSubmit}
handleChangeTextArea={handleChangeTextAreaJson}
isEnableCheck={isEnableCheck}
isLoading={isLoadingCheck}
setIsEnableCheck={setIsEnableCheck}
setSelectedChainId={setSelectedChainId}
/>
) : (
<UrlForm
handleSubmit={handleSubmit}
handleChangeTextArea={handleChangeTextAreaUrl}
isEnableCheck={isEnableCheck}
isLoading={isLoadingCheck}
parsedJson={parsedJson}
decompressedJson={decompressedJson}
setDecompressedJson={setDecompressedJson}
/>
)}
</div>
</div>
<div
className={twMerge(
'md:w-full md:pt-4 md:ml-2 md:mt-0',
'lg:w-1/2 mt-4 pt-4 pb-8 px-1 bg-blueDark text-lightGray',
'md:w-full lg:w-1/2 md:pt-4 md:ml-2 md:mt-0 mt-4 pt-4 pb-8 px-1',
'bg-blueDark text-lightGray',
'border border-blueGray rounded-md shadow-sm shadow-grayDark'
)}
>
Expand Down
11 changes: 10 additions & 1 deletion src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ export const Button = ({
text,
clickAction,
className,
variant,
}: {
text: string;
clickAction?: () => void;
className?: string;
variant: 'toggle' | 'dialog';
}) => {
const variants = {
toggle:
'flex flex-row space-x-2 w-full py-1.5 text-black text-sm font-semibold justify-center border-blueGray',
dialog:
'w-full mt-4 mx-auto py-3 px-4 text-white bg-blueGray border-darkgray border-1 rounded-sm font-medium text-lg uppercase',
};

return (
<button
onClick={clickAction}
className={twMerge(
'flex flex-row space-x-2 w-full py-1.5 text-black text-sm font-semibold justify-center border-blueGray',
variant === 'toggle' ? variants.toggle : variants.dialog,
className
)}
>
Expand Down
32 changes: 14 additions & 18 deletions src/components/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { Dispatch, SetStateAction, useEffect, useState } from 'react';
import { twMerge } from 'tailwind-merge';
import { ParsedJsonParams } from '../../types';
import { formatJsonString } from '../utilities/formatJsonString';
import { Button } from './Button';

export const Dialog = ({
inputButton,
Expand All @@ -23,10 +24,12 @@ export const Dialog = ({
if (!decompressedJson) {
return;
}

await navigator.clipboard.writeText(decompressedJson);
setOpen(false);
};

const handleClose = () => setOpen(false);

useEffect(() => {
if (!parsedJson) {
setDecompressedJson(undefined);
Expand Down Expand Up @@ -64,25 +67,18 @@ export const Dialog = ({
</AlertDialog.Description>
<div className="flex justify-end gap-[25px]">
<AlertDialog.Cancel asChild>
<button
onClick={() => handleCopyJson(decompressedJson)}
className={twMerge(
'w-full xs:w-[90%] sm:w-4/5 md:w-full lg:w-4/5',
'mt-4 mx-auto py-3 px-4 text-white bg-blueGray border-darkgray border-1 rounded-sm font-medium text-lg uppercase'
)}
>
Copy JSON
</button>
<Button
text="copy json"
clickAction={() => handleCopyJson(decompressedJson)}
variant="dialog"
/>
</AlertDialog.Cancel>
<AlertDialog.Action asChild>
<button
className={twMerge(
'w-full xs:w-[90%] sm:w-4/5 md:w-full lg:w-4/5',
'mt-4 mx-auto py-3 px-4 text-white bg-blueGray border-darkgray border-1 rounded-sm font-medium text-lg uppercase'
)}
>
Close
</button>
<Button
text="close"
clickAction={handleClose}
variant="dialog"
/>
</AlertDialog.Action>
</div>
</AlertDialog.Content>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Errors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export const Errors = ({
<div
id="errors-container"
className={twMerge(
'xs:w-[90%] sm:w-4/5 w-full',
'w-full sm:w-4/5 md:w-full lg:w-[90%]',
'mt-2 mx-auto p-4 lg:p-6 border bg-blueGray rounded-md',
errors.length < 1 && !isNoErrors && 'border-none',
errors.length > 0 && 'border-redAlert border-dashed',
errors.length > 0 && isNoErrors && 'border-white border-solid'
)}
>
{!isNoErrors ? (
<ul className="list-none">{renderedErrors}</ul>
<ul className="list-none break-words">{renderedErrors}</ul>
) : (
<h3 className="mb-1 text-lg font-semibold uppercase">
🎊 No errors found! 🎊
Expand Down
6 changes: 1 addition & 5 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ export const Header = ({
<img src={airswapLogo} alt="AirSwap logo" className="mr-3" />
<h1>Server Debugger</h1>
</div>
<div
className={twMerge(
'flex md:absolute md:right-0 mx-auto md:h-full md:py-2 text-sm font-light text-white uppercase'
)}
>
<div className="flex md:absolute md:right-0 mx-auto md:h-full md:py-2 text-sm font-light text-white uppercase">
Protocol fee:{' '}
{!isLoadingProtocolFee ? Number(protocolFee) || '7' : 'loading...'}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export const Select = ({
>
<RadixSelect.Trigger
className="flex items-center px-3 py-1 bg-blueGray border border-blueGray rounded-md font-semibold uppercase"
aria-label="chain"
aria-label="chain id"
>
<RadixSelect.Value placeholder="chain" />
<RadixSelect.Value placeholder="chain id" />
<RadixSelect.Icon className="ml-2">
<div
className={`${
Expand Down
4 changes: 3 additions & 1 deletion src/components/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ export const Toggle = ({
<h3 className="mt-2 mb-4 text-md sm:text-lg font-semibold uppercase">
Select server response type:
</h3>
<div className="flex flex-row w-full xs:w-[90%] sm:w-4/5 md:w-full lg:w-4/5 mx-auto rounded-sm">
<div className="flex flex-row mx-auto rounded-sm">
<Button
text="JSON"
clickAction={clickTypeJson}
variant="toggle"
className={`${
inputType === InputType.JSON
? 'text-white bg-blueGray'
Expand All @@ -28,6 +29,7 @@ export const Toggle = ({
<Button
text="URL"
clickAction={clickTypeUrl}
variant="toggle"
className={`${
inputType === InputType.URL
? 'bg-blueGray text-white'
Expand Down
19 changes: 3 additions & 16 deletions src/components/forms/JsonForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ChangeEvent, MouseEvent } from 'react';
import { textareaPlaceholder } from '../../placeholders/textareaJsonPlaceholder';
import { twMerge } from 'tailwind-merge';
import { Select } from '../Select';
import { chainIdOptions } from '../../utilities/chainIdOptions';

Expand All @@ -21,12 +20,7 @@ export const JsonForm = ({
}) => {
return (
<form onSubmit={handleSubmit} className="flex flex-col m-auto w-full">
<div
className={twMerge(
'xs:w-[90%] sm:w-4/5 md:w-full lg:w-4/5',
'flex flex-row w-full justify-between items-center py-2 m-auto '
)}
>
<div className="flex flex-row w-full justify-between items-center py-2 m-auto ">
<label
htmlFor="jsonInput"
className="ml-1 w-fit font-semibold uppercase "
Expand All @@ -47,11 +41,7 @@ export const JsonForm = ({
placeholder={textareaPlaceholder}
autoComplete="off"
onChange={handleChangeTextArea}
className={twMerge(
'w-full xs:w-[90%] sm:w-4/5 md:w-full lg:w-4/5',
'mb-2 mx-auto p-5 min-h-[325px] bg-blueExtraDark border-blueGray border rounded-sm',
'placeholder:text-sm'
)}
className="w-full mb-2 mx-auto p-5 min-h-[325px] bg-blueExtraDark border-blueGray border rounded-sm placeholder:text-sm"
/>
{isEnableCheck && (
<div className="md:hidden italic opacity-40 font-medium">
Expand All @@ -63,10 +53,7 @@ export const JsonForm = ({
type="submit"
value={!isLoading ? 'Check errors' : 'Loading...'}
disabled={isLoading}
className={twMerge(
'w-full xs:w-[90%] sm:w-4/5 md:w-full lg:w-4/5',
'mt-4 mx-auto py-3 px-4 text-white bg-blueAirSwap border-darkgray border-1 rounded-sm font-medium text-lg uppercase'
)}
className="w-full mt-4 mx-auto py-3 px-4 text-white bg-blueAirSwap border-darkgray border-1 rounded-sm font-medium text-lg uppercase"
/>
</form>
);
Expand Down
12 changes: 2 additions & 10 deletions src/components/forms/UrlForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ChangeEvent, Dispatch, MouseEvent, SetStateAction } from 'react';
import { twMerge } from 'tailwind-merge';
import { textareaUrlPlaceholder } from '../../placeholders/textareaUrlPlaceholder';
import { Dialog } from '../Dialog';
import { ParsedJsonParams } from '../../../types';
Expand Down Expand Up @@ -27,10 +26,7 @@ export const UrlForm = ({
type="submit"
value={!isLoading ? 'Check errors' : 'Loading...'}
disabled={isLoading}
className={twMerge(
'w-full xs:w-[90%] sm:w-4/5 md:w-full lg:w-4/5',
'mt-4 mx-auto py-3 px-4 text-white bg-blueAirSwap border-darkgray border-1 rounded-sm font-medium text-lg uppercase'
)}
className="w-full mt-4 mx-auto py-3 px-4 text-white bg-blueAirSwap border-darkgray border-1 rounded-sm font-medium text-lg uppercase"
/>
);

Expand All @@ -48,11 +44,7 @@ export const UrlForm = ({
placeholder={textareaUrlPlaceholder}
autoComplete="off"
onChange={handleChangeTextArea}
className={twMerge(
'w-full xs:w-[90%] sm:w-4/5 md:w-full lg:w-4/5',
'mb-2 mx-auto p-5 min-h-[325px] bg-blueExtraDark border-blueGray border rounded-sm',
'placeholder:text-sm'
)}
className="w-full mb-2 mx-auto p-5 min-h-[325px] bg-blueExtraDark border-blueGray border rounded-sm placeholder:text-sm"
/>
{isEnableCheck && (
<div className="md:hidden italic opacity-40 font-medium">
Expand Down
4 changes: 1 addition & 3 deletions src/utilities/validateJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ export const validateJson = ({
errorsList.push('swapContract: must be a valid ERC20 address');
// then check if address is correct
if (json['swapContract'] !== swapContractAddress) {
errorsList.push(
`swapContract: address is not valid. Check for deployed contracts on https://about.airswap.io/technology/deployments.`
);
errorsList.push(`swapContract: SwapERC20 address is not valid.`);
}
}
}
Expand Down

0 comments on commit a13ab08

Please sign in to comment.