From d714e53cfa88da22a6fc75473455d57be7bac497 Mon Sep 17 00:00:00 2001 From: Meier Lukas Date: Mon, 10 Mar 2025 20:29:50 +0100 Subject: [PATCH] fix(downloads): improve responsive styles (#2552) --- packages/widgets/src/downloads/component.tsx | 191 +++++++------------ packages/widgets/src/widgets-common.css | 37 ---- 2 files changed, 71 insertions(+), 157 deletions(-) diff --git a/packages/widgets/src/downloads/component.tsx b/packages/widgets/src/downloads/component.tsx index 10c98ba8a..588cdf608 100644 --- a/packages/widgets/src/downloads/component.tsx +++ b/packages/widgets/src/downloads/component.tsx @@ -24,7 +24,6 @@ import { Tooltip, } from "@mantine/core"; import { useDisclosure } from "@mantine/hooks"; -import type { IconProps } from "@tabler/icons-react"; import { IconAlertTriangle, IconCirclesRelation, @@ -75,16 +74,6 @@ const columnsRatios: Record = { upSpeed: 3, }; -const actionIconIconStyle: IconProps["style"] = { - height: "var(--ai-icon-size)", - width: "var(--ai-icon-size)", -}; - -const standardIconStyle: IconProps["style"] = { - height: "var(--icon-size)", - width: "var(--icon-size)", -}; - export default function DownloadClientsWidget({ isEditMode, integrationIds, @@ -307,72 +296,41 @@ export default function DownloadClientsWidget({ upSpeed: options.columns.includes("upSpeed") && integrationTypes.includes("torrent"), } satisfies Record; - //Set a relative width using ratio table - const totalWidth = options.columns.reduce( - (count: number, column) => (columnVisibility[column] ? count + columnsRatios[column] : count), - 0, - ); - //Default styling behavior for stopping interaction when editing. (Applied everywhere except the table header) const editStyle: MantineStyleProp = { pointerEvents: isEditMode ? "none" : undefined, }; - //General style sizing as vars that should apply or be applied to all elements - const baseStyle: MantineStyleProp = { - "--total-width": totalWidth, - "--ratio-width": "calc(100cqw / var(--total-width))", - "--space-size": "calc(var(--ratio-width) * 0.1)", //Standard gap and spacing value - "--text-fz": "calc(var(--ratio-width) * 0.45)", //General Font Size - "--button-fz": "var(--text-fz)", - "--icon-size": "calc(var(--ratio-width) * 2 / 3)", //Normal icon size - "--ai-icon-size": "calc(var(--ratio-width) * 0.5)", //Icon inside action icons size - "--button-size": "calc(var(--ratio-width) * 0.75)", //Action Icon, button and avatar size - "--image-size": "var(--button-size)", - "--mrt-base-background-color": "transparent", - }; - //Base element in common with all columns const columnsDefBase = useCallback( ({ key, showHeader, - align, }: { key: keyof ExtendedDownloadClientItem; showHeader: boolean; - align?: "center" | "left" | "right" | "justify" | "char"; }): MRT_ColumnDef => { - const style: MantineStyleProp = { - minWidth: 0, - width: "var(--column-width)", - height: "var(--ratio-width)", - padding: "var(--space-size)", - transition: "unset", - "--key-width": columnsRatios[key], - "--column-width": "calc((var(--key-width)/var(--total-width) * 100cqw))", - }; return { id: key, accessorKey: key, header: key, size: columnsRatios[key], - mantineTableBodyCellProps: { style, align }, - mantineTableHeadCellProps: { - style, - align: isEditMode ? "center" : align, - }, - Header: () => (showHeader && !isEditMode ? {t(`items.${key}.columnTitle`)} : ""), + Header: () => + showHeader ? ( + + {t(`items.${key}.columnTitle`)} + + ) : null, }; }, - [isEditMode, t], + [t], ); //Make columns and cell elements, Memoized to data with deps on data and EditMode const columns = useMemo[]>( () => [ { - ...columnsDefBase({ key: "actions", showHeader: false, align: "center" }), + ...columnsDefBase({ key: "actions", showHeader: false }), enableSorting: false, Cell: ({ cell, row }) => { const actions = cell.getValue(); @@ -380,19 +338,15 @@ export default function DownloadClientsWidget({ const [opened, { open, close }] = useDisclosure(false); return actions ? ( - + - - {pausedAction === "resume" ? ( - - ) : ( - - )} + + {pausedAction === "resume" ? : } - - + + @@ -423,68 +377,68 @@ export default function DownloadClientsWidget({ ) : ( - - + + ); }, }, { - ...columnsDefBase({ key: "added", showHeader: true, align: "center" }), + ...columnsDefBase({ key: "added", showHeader: true }), sortUndefined: "last", Cell: ({ cell }) => { const added = cell.getValue(); - return {added !== undefined ? dayjs(added).fromNow() : "unknown"}; + return {added !== undefined ? dayjs(added).fromNow() : "unknown"}; }, }, { - ...columnsDefBase({ key: "category", showHeader: false, align: "center" }), + ...columnsDefBase({ key: "category", showHeader: false }), sortUndefined: "last", Cell: ({ cell }) => { const category = cell.getValue(); return ( category !== undefined && ( - + ) ); }, }, { - ...columnsDefBase({ key: "downSpeed", showHeader: true, align: "right" }), + ...columnsDefBase({ key: "downSpeed", showHeader: true }), sortUndefined: "last", Cell: ({ cell }) => { const downSpeed = cell.getValue(); - return downSpeed && {humanFileSize(downSpeed, "/s")}; + return downSpeed ? {humanFileSize(downSpeed, "/s")} : null; }, }, { - ...columnsDefBase({ key: "id", showHeader: false, align: "center" }), + ...columnsDefBase({ key: "id", showHeader: false }), enableSorting: false, Cell: ({ cell }) => { const id = cell.getValue(); return ( - + ); }, }, { - ...columnsDefBase({ key: "index", showHeader: true, align: "center" }), + ...columnsDefBase({ key: "index", showHeader: true }), Cell: ({ cell }) => { const index = cell.getValue(); - return {index}; + return {index}; }, }, { - ...columnsDefBase({ key: "integration", showHeader: false, align: "center" }), + ...columnsDefBase({ key: "integration", showHeader: false }), Cell: ({ cell }) => { const integration = cell.getValue(); return ( - + ); }, @@ -494,62 +448,61 @@ export default function DownloadClientsWidget({ Cell: ({ cell }) => { const name = cell.getValue(); return ( - + {name} ); }, }, { - ...columnsDefBase({ key: "progress", showHeader: true, align: "center" }), + ...columnsDefBase({ key: "progress", showHeader: true }), Cell: ({ cell, row }) => { const progress = cell.getValue(); return ( - - + + {new Intl.NumberFormat("en", { style: "percent", notation: "compact", unitDisplay: "narrow" }).format( progress, )} - + ); }, }, { - ...columnsDefBase({ key: "ratio", showHeader: true, align: "center" }), + ...columnsDefBase({ key: "ratio", showHeader: true }), sortUndefined: "last", Cell: ({ cell }) => { const ratio = cell.getValue(); - return ratio !== undefined && {ratio.toFixed(ratio >= 100 ? 0 : ratio >= 10 ? 1 : 2)}; + return ratio !== undefined && {ratio.toFixed(ratio >= 100 ? 0 : ratio >= 10 ? 1 : 2)}; }, }, { - ...columnsDefBase({ key: "received", showHeader: true, align: "right" }), + ...columnsDefBase({ key: "received", showHeader: true }), Cell: ({ cell }) => { const received = cell.getValue(); - return {humanFileSize(received)}; + return {humanFileSize(received)}; }, }, { - ...columnsDefBase({ key: "sent", showHeader: true, align: "right" }), + ...columnsDefBase({ key: "sent", showHeader: true }), sortUndefined: "last", Cell: ({ cell }) => { const sent = cell.getValue(); - return sent && {humanFileSize(sent)}; + return sent && {humanFileSize(sent)}; }, }, { - ...columnsDefBase({ key: "size", showHeader: true, align: "right" }), + ...columnsDefBase({ key: "size", showHeader: true }), Cell: ({ cell }) => { const size = cell.getValue(); - return {humanFileSize(size)}; + return {humanFileSize(size)}; }, }, { @@ -557,25 +510,25 @@ export default function DownloadClientsWidget({ enableSorting: false, Cell: ({ cell }) => { const state = cell.getValue(); - return {t(`states.${state}`)}; + return {t(`states.${state}`)}; }, }, { - ...columnsDefBase({ key: "time", showHeader: true, align: "center" }), + ...columnsDefBase({ key: "time", showHeader: true }), Cell: ({ cell }) => { const time = cell.getValue(); - return time === 0 ? : {dayjs().add(time).fromNow()}; + return time === 0 ? : {dayjs().add(time).fromNow()}; }, }, { ...columnsDefBase({ key: "type", showHeader: true }), Cell: ({ cell }) => { const type = cell.getValue(); - return {type}; + return {type}; }, }, { - ...columnsDefBase({ key: "upSpeed", showHeader: true, align: "right" }), + ...columnsDefBase({ key: "upSpeed", showHeader: true }), sortUndefined: "last", Cell: ({ cell }) => { const upSpeed = cell.getValue(); @@ -604,17 +557,17 @@ export default function DownloadClientsWidget({ mantineTableContainerProps: { style: { height: "100%" } }, mantineTableProps: { className: "downloads-widget-table", - style: { - "--sortButtonSize": "var(--button-size)", - "--dragButtonSize": "var(--button-size)", - }, }, mantineTableBodyProps: { style: editStyle }, + mantineTableHeadCellProps: { + p: 4, + }, mantineTableBodyCellProps: ({ cell, row }) => ({ onClick: () => { setClickedIndex(row.index); if (cell.column.id !== "actions") open(); }, + p: 4, }), onColumnOrderChange: (order) => { //Order has a tendency to add the disabled column at the end of the the real ordered array @@ -666,26 +619,25 @@ export default function DownloadClientsWidget({ if (options.columns.length === 0) return (
- {t("errors.noColumns")} + {t("errors.noColumns")}
); //The actual widget return ( - + {integrationTypes.includes("torrent") && ( - - {`${t("globalRatio")}:`} - {(globalTraffic.up / globalTraffic.down).toFixed(2)} + + {`${t("globalRatio")}:`} + {(globalTraffic.up / globalTraffic.down).toFixed(2)} )} - - + + - + {t("items.integration.columnTitle")} - + {clients.map((client) => ( ))} @@ -847,37 +799,37 @@ const ClientsControl = ({ clients, filters, setFilters, availableStatuses }: Cli {someInteract && ( mutateResumeQueue({ integrationIds: integrationsStatuses.paused })} > - + )} {someInteract && ( mutatePauseQueue({ integrationIds: integrationsStatuses.active })} > - + )} @@ -967,9 +919,8 @@ const ClientAvatar = ({ client }: ClientAvatarProps) => { key={client.integration.id} src={getIconUrl(client.integration.kind)} style={{ filter: !isConnected ? "grayscale(100%)" : undefined }} - size={30} + size="sm" p={5} - bd={`calc(var(--space-size)*0.5) solid ${client.status ? "transparent" : "var(--mantine-color-red-filled)"}`} /> ); }; diff --git a/packages/widgets/src/widgets-common.css b/packages/widgets/src/widgets-common.css index 5bcacd11f..7c75ebf0a 100644 --- a/packages/widgets/src/widgets-common.css +++ b/packages/widgets/src/widgets-common.css @@ -1,40 +1,3 @@ -.downloads-widget-table { - /*Set Header static and overflow body instead*/ - display: flex; - height: 100%; - flex-direction: column; - .mantine-Table-tbody { - overflow-y: auto; - flex: 1; - scrollbar-width: 0; - } - /*Hide scrollbar until I can apply an overlay scrollbar instead*/ - .mantine-Table-tbody::-webkit-scrollbar { - width: 0; - } - /*Properly size header*/ - .mrt-table-head-cell-labels { - min-height: var(--ratioWidth); - gap: 0; - padding: 0; - } - /*Properly size controls*/ - .mrt-grab-handle-button { - margin: unset; - width: var(--dragButtonSize); - min-width: var(--dragButtonSize); - height: var(--dragButtonSize); - min-height: var(--dragButtonSize); - } - .mrt-table-head-sort-button { - margin: unset; - width: var(--sortButtonSize); - min-width: var(--sortButtonSize); - height: var(--sortButtonSize); - min-height: var(--sortButtonSize); - } -} - /*Make background of component different on hover, depending on base var*/ .hoverable-component { &:hover {