Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
fix: text margin top (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbt1 authored Nov 3, 2023
1 parent a0c1f50 commit 5c85bdf
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/pivot-table/__tests__/test-with-providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from "react";
import type { App, Model } from "../../types/QIX";
import type { ExtendedSelections } from "../../types/types";
import type { RootProps } from "../Root";
import { DEFAULT_CELL_HEIGHT } from "../constants";
import { CELL_PADDING_HEIGHT, DEFAULT_CELL_HEIGHT } from "../constants";
import BaseProvider from "../contexts/BaseProvider";
import SelectionsProvider from "../contexts/SelectionsProvider";
import StyleProvider from "../contexts/StyleProvider";
Expand Down Expand Up @@ -77,6 +77,8 @@ const TestWithProvider = (props: Props) => {
},
headerCellHeight: DEFAULT_CELL_HEIGHT,
contentCellHeight: DEFAULT_CELL_HEIGHT,
contentRowHeight: DEFAULT_CELL_HEIGHT,
contentTextHeight: DEFAULT_CELL_HEIGHT - CELL_PADDING_HEIGHT,
},
app = { getField: () => Promise.resolve() } as unknown as App,
model = { applyPatches: () => Promise.resolve(), getLayout: () => Promise.resolve({}) } as unknown as Model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const ExpandOrCollapseIcon = ({ cell, dataModel, isLeftColumn, isCellSelected }:
const disableOnClickHandler = !interactions.active || isActive || !dataModel;
const color = getColor({ cell, styleService, isCellSelected });
const opacity = isActive ? 0.4 : 1.0;
const halfCellHeight = styleService.contentCellHeight / 2;
const halfCellHeight = styleService.contentRowHeight / 2;
const Icon = cell.ref.qCanExpand ? PlusOutlineIcon : MinusOutlineIcon;
let expandOrCollapse: ExpandOrCollapser | undefined;

Expand Down
9 changes: 3 additions & 6 deletions src/pivot-table/components/cells/DimensionValue/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { type ReactNode } from "react";
import type { Cell, StyleService } from "../../../../types/types";
import { DEFAULT_LINE_CLAMP, LINE_HEIGHT_COEFFICIENT } from "../../../constants";
import { DEFAULT_LINE_CLAMP } from "../../../constants";
import { CELL_PADDING, getLineClampStyle, textStyle } from "../../shared-styles";
import { getColor, getFontStyle, getFontWeight, getTextDecoration } from "./utils/get-style";

Expand All @@ -12,11 +12,8 @@ type Props = {
children: ReactNode;
};

const getMarginTop = (styleService: StyleService) => {
const textHeight = parseInt(styleService.dimensionValues.fontSize, 10) * LINE_HEIGHT_COEFFICIENT;

return styleService.contentCellHeight / 2 - textHeight / 2;
};
const getMarginTop = (styleService: StyleService) =>
styleService.contentRowHeight / 2 - styleService.contentTextHeight / 2;

const Text = ({ children, cell, styleService, isCellSelected, isLeftColumn }: Props): JSX.Element => (
<span
Expand Down
2 changes: 2 additions & 0 deletions src/pivot-table/contexts/__mocks__/StyleProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const useStyleContext = (): StyleService => ({
},
headerCellHeight: 24,
contentCellHeight: 24,
contentRowHeight: 24,
contentTextHeight: 16,
});

const StyleProvider = (): JSX.Element => <div />;
Expand Down
6 changes: 6 additions & 0 deletions src/services/__tests__/style-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ describe("style-service", () => {
},
headerCellHeight: 32,
contentCellHeight: 48,
contentRowHeight: 24,
contentTextHeight: 16,
} as StyleService);
});

Expand Down Expand Up @@ -207,6 +209,8 @@ describe("style-service", () => {
},
headerCellHeight: 32,
contentCellHeight: 56,
contentRowHeight: 28,
contentTextHeight: 20,
} as StyleService);
});

Expand Down Expand Up @@ -274,6 +278,8 @@ describe("style-service", () => {
},
headerCellHeight: 32,
contentCellHeight: 24,
contentRowHeight: 24,
contentTextHeight: 16,
} as StyleService);
});
});
4 changes: 4 additions & 0 deletions src/services/style-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ const createStyleService = (theme: ExtendedTheme, layoutService: LayoutService):
DEFAULT_CELL_HEIGHT,
);

styleService.contentRowHeight = styleService.contentCellHeight / lineClamp;

styleService.contentTextHeight = styleService.contentRowHeight - CELL_PADDING_HEIGHT;

return styleService;
};

Expand Down
2 changes: 2 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ export type StyleService = ThemeStyling & {
header: CellStyling & { hoverBackground: string; activeBackground: string };
headerCellHeight: number;
contentCellHeight: number;
contentRowHeight: number;
contentTextHeight: number;
};

export type ActivelySortedColumn = {
Expand Down

0 comments on commit 5c85bdf

Please sign in to comment.