From e4a22ade305fd6ea962648b86ff88431d77ea41e Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Mon, 11 Mar 2019 13:58:25 -0700 Subject: [PATCH] feat: add dimension type (#117) --- packages/superset-ui-dimension/src/computeMaxFontSize.ts | 5 +++-- packages/superset-ui-dimension/src/getTextDimension.ts | 6 +++--- packages/superset-ui-dimension/src/types.ts | 5 +++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/superset-ui-dimension/src/computeMaxFontSize.ts b/packages/superset-ui-dimension/src/computeMaxFontSize.ts index dacf45ead..462ee7504 100644 --- a/packages/superset-ui-dimension/src/computeMaxFontSize.ts +++ b/packages/superset-ui-dimension/src/computeMaxFontSize.ts @@ -1,9 +1,10 @@ import getTextDimension, { GetTextDimensionInput } from './getTextDimension'; +import { Dimension } from './types'; function decreaseSizeUntil( startSize: number, - computeDimension: (size: number) => { height: number; width: number }, - condition: (dimension: { height: number; width: number }) => boolean, + computeDimension: (size: number) => Dimension, + condition: (dimension: Dimension) => boolean, ): number { let size = startSize; let dimension = computeDimension(size); diff --git a/packages/superset-ui-dimension/src/getTextDimension.ts b/packages/superset-ui-dimension/src/getTextDimension.ts index f486bfaeb..f3181fb00 100644 --- a/packages/superset-ui-dimension/src/getTextDimension.ts +++ b/packages/superset-ui-dimension/src/getTextDimension.ts @@ -1,4 +1,4 @@ -import { TextStyle } from './types'; +import { TextStyle, Dimension } from './types'; const SVG_NS = 'http://www.w3.org/2000/svg'; const STYLE_FIELDS: (keyof TextStyle)[] = [ @@ -21,8 +21,8 @@ const DEFAULT_DIMENSION = { height: 20, width: 100 }; export default function getTextDimension( input: GetTextDimensionInput, - defaultDimension = DEFAULT_DIMENSION, -) { + defaultDimension: Dimension = DEFAULT_DIMENSION, +): Dimension { const { text, className, style = {}, container = document.body } = input; const textNode = document.createElementNS(SVG_NS, 'text'); diff --git a/packages/superset-ui-dimension/src/types.ts b/packages/superset-ui-dimension/src/types.ts index 445bc52cd..472b74740 100644 --- a/packages/superset-ui-dimension/src/types.ts +++ b/packages/superset-ui-dimension/src/types.ts @@ -15,3 +15,8 @@ export interface Margin { bottom: number; right: number; } + +export interface Dimension { + width: number; + height: number; +}