From b53eb683bf63e0874ed13ccb29d82940f5fd40b2 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Thu, 25 May 2023 18:29:00 -0300 Subject: [PATCH] Hotfix for Import Flows modal --- .../modals/importModal/buttonBox/index.tsx | 150 +++++++----------- src/frontend/src/modals/importModal/index.tsx | 2 +- src/frontend/tailwind.config.js | 8 + 3 files changed, 64 insertions(+), 96 deletions(-) diff --git a/src/frontend/src/modals/importModal/buttonBox/index.tsx b/src/frontend/src/modals/importModal/buttonBox/index.tsx index 2e8978597..b8e51e388 100644 --- a/src/frontend/src/modals/importModal/buttonBox/index.tsx +++ b/src/frontend/src/modals/importModal/buttonBox/index.tsx @@ -1,4 +1,4 @@ -import React, { ReactNode, useEffect } from "react"; +import React, { ReactNode, useEffect, useRef, useState } from "react"; import { DocumentDuplicateIcon } from "@heroicons/react/solid"; import { classNames } from "../../../utils"; import Tooltip from "../../../components/TooltipComponent"; @@ -33,89 +33,48 @@ export default function ButtonBox({ let textHeight: number; let textWidth: number; switch (size) { - case "small": - bigCircle = "h-12 w-12"; - smallCircle = "h-8 w-8"; - titleFontSize = "text-sm"; - descriptionFontSize = "text-xs"; - padding = "p-2 py-3"; - marginTop = "mt-2"; - height = "h-36"; - textHeight = 70; - textWidth = 80; - width = "w-32"; - break; - case "medium": - bigCircle = "h-16 w-16"; - smallCircle = "h-12 w-12"; - titleFontSize = "text-base"; - descriptionFontSize = "text-sm"; - padding = "p-4 py-5"; - marginTop = "mt-3"; - textHeight = 112; - textWidth = 162; - height = "h-44"; - width = "w-36"; - break; - case "big": - bigCircle = "h-20 w-20"; - smallCircle = "h-16 w-16"; - titleFontSize = "text-lg"; - descriptionFontSize = "text-sm"; - padding = "p-8 py-10"; - marginTop = "mt-6"; - height = "h-56"; - width = "w-44"; - break; - default: - bigCircle = "h-20 w-20"; - smallCircle = "h-16 w-16"; - titleFontSize = "text-lg"; - descriptionFontSize = "text-sm"; - padding = "p-8 py-10"; - marginTop = "mt-6"; - height = "h-56"; - width = "w-44"; - break; - } - - const titleRef = React.useRef(null); - - useEffect(() => { - const resizeFont = () => { - const titleElement = titleRef.current; - if (titleElement) { - const containerWidth = titleElement.offsetWidth; - const containerHeight = titleElement.offsetHeight; - - const titleComputedStyle = window.getComputedStyle(titleElement); - const titleWidth = titleElement.getBoundingClientRect().width; - - const currentFontSize = parseFloat(titleComputedStyle.fontSize); - - const desiredWidth = textWidth - 10; // Subtracting the desired padding - - // Calculate the desired font size based on the adjusted width - let desiredFontSize = currentFontSize * (desiredWidth / titleWidth); - - // Adjust the desired font size to fit within the container height, if needed - const maxHeight = containerHeight - 10; // Subtracting the desired top padding - const maxHeightFontSize = maxHeight * 0.8; // Adjust the scaling factor as needed - desiredFontSize = Math.min(desiredFontSize, maxHeightFontSize); - - // Apply the desired font size and padding to the title element - titleElement.style.fontSize = `${desiredFontSize}px`; - titleElement.style.paddingLeft = "5px"; - titleElement.style.paddingRight = "5px"; - } - }; - - resizeFont(); - window.addEventListener("resize", resizeFont); - return () => { - window.removeEventListener("resize", resizeFont); - }; - }, []); + case "small": + bigCircle = "h-12 w-12"; + smallCircle = "h-8 w-8"; + titleFontSize = "text-sm"; + descriptionFontSize = "text-xs"; + padding = "p-2 py-3"; + marginTop = "mt-2"; + height = "h-36"; + width = "w-32"; + break; + case "medium": + bigCircle = "h-16 w-16"; + smallCircle = "h-12 w-12"; + titleFontSize = "text-base"; + descriptionFontSize = "text-sm"; + padding = "p-4 py-5"; + marginTop = "mt-3"; + height = "h-44"; + width = "w-36"; + break; + case "big": + bigCircle = "h-20 w-20"; + smallCircle = "h-16 w-16"; + titleFontSize = "text-lg"; + descriptionFontSize = "text-sm"; + padding = "p-8 py-10"; + marginTop = "mt-6"; + height = "h-56"; + width = "w-44"; + break; + default: + bigCircle = "h-20 w-20"; + smallCircle = "h-16 w-16"; + titleFontSize = "text-lg"; + descriptionFontSize = "text-sm"; + padding = "p-8 py-10"; + marginTop = "mt-6"; + height = "h-56"; + width = "w-44"; + break; + } + return ( ); diff --git a/src/frontend/src/modals/importModal/index.tsx b/src/frontend/src/modals/importModal/index.tsx index ba7136bd1..2d3ef979a 100644 --- a/src/frontend/src/modals/importModal/index.tsx +++ b/src/frontend/src/modals/importModal/index.tsx @@ -177,7 +177,7 @@ export default function ImportModal() { !loadingExamples && examples.map((example, index) => { return ( -
+
{" "}