Skip to content

Commit 4b9dc11

Browse files
committed
refactor: improve maintainability of dynamic calculations
1 parent 6e776cb commit 4b9dc11

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

web/src/components/RegistryCard/RegistryInfo.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ interface IListInfo {
1818
isListView?: boolean;
1919
}
2020

21+
const firstColWidthCalc = "calc(80px+(100-80)*(min(max(100vw,900px),1250px)-900px)/(1250-900))";
22+
const secondColWidthCalc = "calc(100px+(150-100)*(min(max(100vw,900px),1250px)-900px)/(1250-900))";
23+
2124
const ListInfo: React.FC<IListInfo> = ({ title, totalItems, logoURI, status, isListView = false }) => {
2225
const [imageLoaded, setImageLoaded] = useState(false);
2326
const [imageSrc, setImageSrc] = useState(getIpfsUrl(logoURI ?? DEFAULT_LIST_LOGO));
@@ -36,7 +39,7 @@ const ListInfo: React.FC<IListInfo> = ({ title, totalItems, logoURI, status, isL
3639
"w-full h-max lg:h-16 p-4",
3740
"[&_h3]:col-span-4 [&_img]:col-span-4",
3841
"lg:justify-between lg:grid-rows-[1fr] lg:px-8",
39-
"lg:grid-cols-[auto_1fr_calc(80px+(100-80)*(min(max(100vw,900px),1250px)-900px)/(1250-900))_calc(100px+(150-100)*(min(max(100vw,900px),1250px)-900px)/(1250-900))_max-content]",
42+
`lg:grid-cols-[auto_1fr_${firstColWidthCalc}_${secondColWidthCalc}_max-content]`,
4043
"lg:[&_img]:col-span-1 lg:[&_h3]:col-span-2",
4144
]
4245
)}

web/src/components/StatDisplay.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ interface IStatDisplay {
1111
color: IColors;
1212
}
1313

14+
const marginBottomCalc = "calc(16px+(30-16)*(min(max(100vw,375px),1250px)-375px)/(1250-375))";
15+
1416
const StatDisplay: React.FC<IStatDisplay> = ({ title, text, subtext, icon: Icon, color, ...props }) => {
1517
return (
16-
<div
17-
className={clsx(
18-
"flex items-center gap-2 max-w-[192px]",
19-
"lg:mb-[calc(16px+(30-16)*(min(max(100vw,375px),1250px)-375px)/(1250-375))]"
20-
)}
21-
{...props}
22-
>
18+
<div className={clsx("flex items-center gap-2 max-w-[192px]", `lg:mb-[${marginBottomCalc}]`)} {...props}>
2319
<div
2420
className={cn(
2521
"flex items-center justify-center h-12 w-12 rounded-[50%]",

web/src/layout/Header/navbar/DappList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ interface IDappList {
8282
toggleIsDappListOpen: () => void;
8383
}
8484

85+
const widthCalc = "calc(300px+(480-300)*(min(max(100vw,375px),1250px)-375px)/(1250-375))";
86+
8587
const DappList: React.FC<IDappList> = ({ toggleIsDappListOpen }) => {
8688
const containerRef = useRef(null);
8789
useClickAway(containerRef, () => toggleIsDappListOpen());
@@ -95,7 +97,7 @@ const DappList: React.FC<IDappList> = ({ toggleIsDappListOpen }) => {
9597
"bg-klerosUIComponentsWhiteBackground shadow-[0px_2px_3px_rgba(0,0,0,0.06)]",
9698
"[&_svg]:visible",
9799
"lg:mt-16 lg:top-0 lg:left-0 lg:right-auto lg:transform-none lg:translate-x-0 lg:max-h-[80vh]",
98-
"lg:w-[calc(300px+(480-300)*(min(max(100vw,375px),1250px)-375px)/(1250-375))]"
100+
`lg:w-[${widthCalc}]`
99101
)}
100102
>
101103
<h1 className="pt-6 text-2xl font-semibold leading-8">Kleros Solutions</h1>

web/src/layout/Header/navbar/Menu/Settings/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const TABS = [
1818
},
1919
];
2020

21+
const inlinePaddingCalc = "calc(8px+(32-8)*((100vw-300px)/(1250-300)))";
22+
const widthCalc = "calc(300px+(424-300)*((100vw-300px)/(1250-300)))";
23+
2124
const Settings: React.FC<ISettings> = ({ toggleIsSettingsOpen, initialTab }) => {
2225
const [currentTab, setCurrentTab] = useState<number>(initialTab || 0);
2326
const containerRef = useRef(null);
@@ -38,7 +41,7 @@ const Settings: React.FC<ISettings> = ({ toggleIsSettingsOpen, initialTab }) =>
3841
>
3942
<div className="flex justify-center text-2xl mt-6 text-klerosUIComponentsPrimaryText">Settings</div>
4043
<Tabs
41-
className="py-0 px-[calc(8px+(32-8)*((100vw-300px)/(1250-300)))] max-w-[660px] w-[86vw] lg:w-[calc(300px+(424-300)*((100vw-300px)/(1250-300)))]"
44+
className={clsx(`py-0 px-[${inlinePaddingCalc}]`, `max-w-[660px] w-[86vw] lg:w-[${widthCalc}]`)}
4245
currentValue={currentTab}
4346
items={TABS}
4447
callback={(n: number) => {

web/src/pages/Home/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import Header from "./Header";
66
import Stats from "./Stats";
77
import HighlightedLists from "./Highlights";
88

9+
const inlinePaddingCalc = "calc(0px+(132-0)*(min(max(100vw,375px),1250px)-375px)/(1250-375))";
10+
911
const Home: React.FC = () => {
1012
return (
1113
<>
1214
<HeroImage />
1315
<div
1416
className={clsx(
1517
"w-full max-w-[1400px] mx-auto bg-klerosUIComponentsLightBackground px-4 pt-4 pb-10",
16-
"lg:px-[calc(0px+(132-0)*(min(max(100vw,375px),1250px)-375px)/(1250-375))] lg:pb-[60px]"
18+
`lg:px-[${inlinePaddingCalc}] lg:pb-[60px]`
1719
)}
1820
>
1921
<Header />

0 commit comments

Comments
 (0)