Skip to content

Commit 5ea528f

Browse files
committed
refactor: migrate calc to clamp as tailwind utilities
1 parent 1854e11 commit 5ea528f

File tree

32 files changed

+106
-133
lines changed

32 files changed

+106
-133
lines changed

web/src/components/InformationCards/RegistryInformationCard/TopInfo.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { RegistryDetails } from "context/RegistryDetailsContext";
55
import StatusDisplay from "../StatusDisplay";
66
import { DEFAULT_CHAIN, SUPPORTED_CHAINS } from "src/consts/chains";
77
import { responsiveSize } from "src/styles/responsiveSize";
8-
import { cn, isUndefined } from "src/utils";
8+
import { isUndefined } from "src/utils";
99
import { DEFAULT_LIST_LOGO } from "src/consts";
1010
import { getIpfsUrl } from "utils/getIpfsUrl";
1111
import { shortenAddress } from "utils/shortenAddress";
1212
import { Link } from "react-router-dom";
13+
import clsx from "clsx";
1314

14-
const landscapeColumnGapCalc = "lg:gap-x-[calc(24px+(32-24)*(min(max(100vw,900px),1250px)-900px)/(1250-900))]";
1515
interface ITopInfo
1616
extends Pick<
1717
RegistryDetails,
@@ -60,10 +60,9 @@ const TopInfo: React.FC<ITopInfo> = ({
6060
)}
6161
</div>
6262
<div
63-
className={cn(
63+
className={clsx(
6464
"flex flex-row flex-wrap shrink gap-8 items-start pt-5",
65-
"lg:shrink-0 lg:gap-y-0",
66-
landscapeColumnGapCalc
65+
"lg:shrink-0 lg:gap-x-fluid-24-32-900 lg:gap-y-0"
6766
)}
6867
>
6968
{id !== "" ? (

web/src/components/ItemCard/index.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import ItemField from "./ItemField";
99
import { cn } from "src/utils";
1010
import clsx from "clsx";
1111

12-
const landscapeGridColsCalc =
13-
"lg:grid-cols-[1fr_calc(150px+(180-150)*(min(max(100vw,900px),1250px)-900px)/(1250-900))_max-content]";
14-
const landscapeGapCalc = "lg:gap-[calc(16px+(36-16)*(min(max(100vw,900px),1250px)-900px)/(1250-900))]";
12+
const landscapeGridColsCalc = "lg:grid-cols-[1fr_var(--spacing-fluid-150-180-900)_max-content]";
1513

1614
interface IItemCard extends ItemDetailsFragment {}
1715

@@ -37,10 +35,9 @@ const ItemCard: React.FC<IItemCard> = ({ id, status, disputed, props }) => {
3735
style={{ columnGap: responsiveSize(12, 32, 900) }}
3836
>
3937
<div
40-
className={cn(
38+
className={clsx(
4139
"flex flex-col justify-between items-start gap-4 w-fit col-span-2",
42-
"lg:flex-row lg:items-center lg:col-span-1",
43-
landscapeGapCalc
40+
"lg:flex-row lg:items-center lg:col-span-1 lg:gap-fluid-16-36-900"
4441
)}
4542
>
4643
{sortedProps.map((prop) => prop.isIdentifier && <ItemField key={prop.label} {...prop} />)}

web/src/components/RegistryCard/RegistryInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface IListInfo {
1919
}
2020

2121
const landscapeGridColsCalc =
22-
"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]";
22+
"lg:grid-cols-[auto_1fr_var(--spacing-fluid-80-100-900)_var(--spacing-fluid-100-150-900)_max-content]";
2323

2424
const ListInfo: React.FC<IListInfo> = ({ title, totalItems, logoURI, status, isListView = false }) => {
2525
const [imageLoaded, setImageLoaded] = useState(false);

web/src/components/StatDisplay.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ interface IStatDisplay {
1010
color: IColors;
1111
}
1212

13-
const landscapeMarginBottomCalc = "lg:mb-[calc(16px+(30-16)*(min(max(100vw,375px),1250px)-375px)/(1250-375))]";
14-
1513
const StatDisplay: React.FC<IStatDisplay> = ({ title, text, subtext, icon: Icon, color, ...props }) => {
1614
return (
17-
<div className={cn("flex items-center gap-2 max-w-[192px]", landscapeMarginBottomCalc)} {...props}>
15+
<div className="flex items-center gap-2 max-w-[192px] lg:mb-fluid-16-30" {...props}>
1816
<div
1917
className={cn(
2018
"flex items-center justify-center h-12 w-12 rounded-[50%]",

web/src/global.css

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,40 @@
2424
--max-width-landscape: 87.5rem;
2525
--shadow-custom: 0px 2px 3px rgba(0, 0, 0, 0.06);
2626
--leading-18px: 18px;
27+
28+
/*
29+
* Spacing utils for custom sizing
30+
* Default max screen width is 1250px
31+
* Default min screen width is 375px
32+
*/
33+
--spacing-scale-8-32-300: calc(8px + (32 - 8) * (100vw - 300px) / (1250 - 300));
34+
--spacing-scale-300-424-300: calc(300px + (424 - 300) * (100vw - 300px) / (1250 - 300));
35+
36+
/*
37+
* Spacing utils for resposive resizing
38+
* Default max screen width is 1250px
39+
* Default min screen width is 375px
40+
*/
41+
--spacing-fluid-0-32: clamp(0px, calc(0px + (132 - 0) * (100vw - 375px) / (1250 - 375)), 132px);
42+
--spacing-fluid-8-32-300: clamp(8px, calc(8px + (32 - 8) * (100vw - 300px) / (1250 - 300)), 32px);
43+
--spacing-fluid-16-30: clamp(16px, calc(16px + (30 - 16) * (100vw - 375px) / (1250 - 375)), 30px);
44+
--spacing-fluid-16-36-900: clamp(16px, calc(16px + (36 - 16) * (100vw - 900px) / (1250 - 900)), 36px);
45+
--spacing-fluid-16-54: clamp(16px, calc(16px + (54 - 16) * (100vw - 375px) / (1250 - 375)), 54px);
46+
--spacing-fluid-24-32: clamp(24px, calc(24px + (32 - 24) * (100vw - 375px) / (1250 - 375)), 32px);
47+
--spacing-fluid-24-32-900: clamp(24px, calc(24px + (32 - 24) * (100vw - 900px) / (1250 - 900)), 32px);
48+
--spacing-fluid-24-136: clamp(24px, calc(24px + (136 - 24) * (100vw - 375px) / (1250 - 375)), 136px);
49+
--spacing-fluid-25-65: clamp(25px, calc(25px + (65 - 25) * (100vw - 375px) / (1250 - 375)), 65px);
50+
--spacing-fluid-32-80: clamp(32px, calc(32px + (80 - 32) * (100vw - 375px) / (1250 - 375)), 80px);
51+
--spacing-fluid-76-96: clamp(76px, calc(76px + (96 - 76) * (100vw - 375px) / (1250 - 375)), 96px);
52+
--spacing-fluid-80-100-900: clamp(80px, calc(80px + (100 - 80) * (100vw - 900px) / (1250 - 900)), 100px);
53+
--spacing-fluid-100-150-900: clamp(100px, calc(100px + (150 - 100) * (100vw - 900px) / (1250 - 900)), 150px);
54+
--spacing-fluid-150-72: clamp(72px, calc(150px + (72 - 150) * (100vw - 375px) / (1250 - 375)), 150px);
55+
--spacing-fluid-150-180-900: clamp(150px, calc(150px + (180 - 150) * (100vw - 900px) / (1250 - 900)), 180px);
56+
--spacing-fluid-200-720: clamp(200px, calc(200px + (720 - 200) * (100vw - 375px) / (1250 - 375)), 720px);
57+
--spacing-fluid-300-480: clamp(300px, calc(300px + (480 - 300) * (100vw - 375px) / (1250 - 375)), 480px);
58+
--spacing-fluid-300-424-300: clamp(300px, calc(300px + (424 - 300) * (100vw - 300px) / (1250 - 300)), 424px);
59+
--spacing-fluid-342-618: clamp(342px, calc(342px + (618 - 342) * (100vw - 375px) / (1250 - 375)), 618px);
60+
--spacing-fluid-442-700-900: clamp(442px, calc(442px + (700 - 442) * (100vw - 900px) / (1250 - 900)), 700px);
2761
}
2862

2963
.dark {

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

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

85-
const landscapeWidthCalc = "lg:w-[calc(300px+(480-300)*(min(max(100vw,375px),1250px)-375px)/(1250-375))]";
86-
8785
const DappList: React.FC<IDappList> = ({ toggleIsDappListOpen }) => {
8886
const containerRef = useRef(null);
8987
useClickAway(containerRef, () => toggleIsDappListOpen());
@@ -97,17 +95,16 @@ const DappList: React.FC<IDappList> = ({ toggleIsDappListOpen }) => {
9795
"border border-klerosUIComponentsStroke rounded-[3px]",
9896
"bg-klerosUIComponentsWhiteBackground shadow-custom",
9997
"[&_svg]:visible",
100-
"lg:mt-16 lg:top-0 lg:left-0 lg:right-auto lg:transform-none lg:translate-x-0 lg:max-h-[80vh]",
101-
landscapeWidthCalc
98+
"lg:w-fluid-300-480 lg:mt-16 lg:top-0 lg:left-0 lg:right-auto lg:transform-none lg:translate-x-0 lg:max-h-[80vh]"
10299
)}
103100
>
104101
<h1 className="pt-6 mb-4">Kleros Solutions</h1>
105102
<div
106103
className={clsx(
107104
"grid grid-cols-[repeat(auto-fit,minmax(100px,1fr))]",
108-
"overflow-y-auto gap-y-2 gap-x-0.5 justify-items-center max-w-[480px] min-w-[300px]"
105+
"overflow-y-auto gap-y-2 gap-x-0.5 justify-items-center w-fluid-300-480"
109106
)}
110-
style={{ padding: `4px ${responsiveSize(8, 24)} 16px`, width: responsiveSize(300, 480) }}
107+
style={{ padding: `4px ${responsiveSize(8, 24)} 16px` }}
111108
>
112109
{ITEMS.map((item) => {
113110
return <Product {...item} key={item.text} />;

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import General from "./General";
55
import NotificationSettings from "./Notifications";
66
import { ISettings } from "../../index";
77
import { useLocation, useNavigate } from "react-router-dom";
8-
import { cn } from "src/utils";
8+
import clsx from "clsx";
99

1010
const TABS = [
1111
{
@@ -22,9 +22,6 @@ const TABS = [
2222
},
2323
];
2424

25-
const tabListInlinePaddingCalc = "[&>div:first-child]:px-[calc(8px+(32-8)*((100vw-300px)/(1250-300)))]";
26-
const landscapeWidthCalc = "lg:w-[calc(300px+(424-300)*((100vw-300px)/(1250-300)))]";
27-
2825
const Settings: React.FC<ISettings> = ({ toggleIsSettingsOpen }) => {
2926
const containerRef = useRef(null);
3027
const location = useLocation();
@@ -37,7 +34,7 @@ const Settings: React.FC<ISettings> = ({ toggleIsSettingsOpen }) => {
3734
return (
3835
<div
3936
ref={containerRef}
40-
className={cn(
37+
className={clsx(
4138
"flex flex-col absolute max-h-[80vh] overflow-y-auto",
4239
"top-[5%] left-1/2 transform -translate-x-1/2 z-1 rounded-[3px]",
4340
"bg-klerosUIComponentsWhiteBackground border border-solid border-klerosUIComponentsStroke",
@@ -46,7 +43,7 @@ const Settings: React.FC<ISettings> = ({ toggleIsSettingsOpen }) => {
4643
>
4744
<div className="flex justify-center text-2xl mt-6 text-klerosUIComponentsPrimaryText">Settings</div>
4845
<Tabs
49-
className={cn("py-0 max-w-[660px] w-[86vw]", landscapeWidthCalc, tabListInlinePaddingCalc)}
46+
className={clsx("py-0 max-w-[660px] w-[86vw] lg:w-scale-300-424-300", "[&>div:first-child]:px-scale-8-32-300")}
5047
items={[TABS[0], { ...TABS[1], content: <NotificationSettings {...{ toggleIsSettingsOpen }} /> }]}
5148
/>
5249
</div>

web/src/pages/AllLists/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ItemDisplay from "./ItemDisplay";
1010
import Breadcrumb from "./StyledBreadcrumb";
1111
import clsx from "clsx";
1212

13-
const landscapePaddingCalc = "lg:p-[48px_calc(0px+(132-0)*(min(max(100vw,375px),1250px)-375px)/(1250-375))_60px]";
13+
const landscapePaddingCalc = "lg:p-[48px_var(--spacing-fluid-0-32)_60px]";
1414

1515
const AllLists: React.FC = () => (
1616
<div

web/src/pages/AttachmentDisplay/index.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,19 @@ import NewTabIcon from "svgs/icons/new-tab.svg";
66

77
import Loader from "components/Loader";
88
import Header from "./Header";
9-
import { cn } from "src/utils";
9+
import clsx from "clsx";
1010

1111
const FileViewer = lazy(() => import("components/FileViewer"));
1212

13-
const paddingCalc = "p-[calc(24px+(136-24)*(min(max(100vw,375px),1250px)-375px)/875)]";
14-
const paddingTopCalc = "pt-[calc(32px+(80-32)*(min(max(100vw,375px),1250px)-375px)/875)]";
15-
const paddingBottomCalc = "pb-[calc(76px+(96-76)*(min(max(100vw,375px),1250px)-375px)/875)]";
16-
1713
const AttachmentDisplay: React.FC = () => {
1814
const [searchParams] = useSearchParams();
1915

2016
const url = searchParams.get("url");
2117
return (
2218
<div
23-
className={cn(
19+
className={clsx(
2420
"w-full max-w-landscape my-0 mx-auto bg-klerosUIComponentsLightBackground",
25-
paddingCalc,
26-
paddingTopCalc,
27-
paddingBottomCalc
21+
"p-fluid-24-136 pt-fluid-32-80 pb-fluid-76-96"
2822
)}
2923
>
3024
<div className="flex flex-col gap-2 w-full">

web/src/pages/Home/Stats/index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import PaperIcon from "svgs/icons/paper.svg";
55
import ListIcon from "svgs/icons/list.svg";
66
import DollarIcon from "svgs/icons/dollar.svg";
77
import JurorIcon from "svgs/icons/user.svg";
8-
import { responsiveSize } from "styles/responsiveSize";
98
import { useCoinPrice } from "hooks/useCoinPrice";
109
import { CoinIds } from "consts/coingecko";
1110
import { useCounter } from "hooks/queries/useCounter";
@@ -72,12 +71,9 @@ const Stats = () => {
7271
<Card
7372
className={clsx(
7473
"grid grid-cols-[repeat(auto-fit,minmax(190px,1fr))] gap-8",
75-
"w-full h-fit mb-16 pb-4! lg:gap-0 lg:pb-0!"
74+
"w-full h-fit mb-16 lg:gap-0",
75+
"p-fluid-16-30 pl-fluid-16-54 pb-4! lg:pb-0!"
7676
)}
77-
style={{
78-
padding: responsiveSize(16, 30),
79-
paddingLeft: responsiveSize(16, 54),
80-
}}
8177
>
8278
{stats.map(({ title, coinId, text, subtext, color, icon }, i) => {
8379
return <StatDisplay key={i} {...{ title, color, icon, text, subtext }} />;

0 commit comments

Comments
 (0)