All files / webview-app/src/components/CanvasComponent minSizes.ts

40% Statements 2/5
0% Branches 0/6
0% Functions 0/1
40% Lines 2/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33              2x   2x                                              
import type { CanvasComponent } from "@/types/canvas";
 
export interface ComponentMinSize {
  minWidth: number;
  minHeight: number;
}
 
export const FALLBACK_MIN_SIZE: ComponentMinSize = { minWidth: 48, minHeight: 28 };
 
export const MIN_SIZE_BY_TYPE: Partial<Record<CanvasComponent["type"], ComponentMinSize>> = {
  Label: { minWidth: 24, minHeight: 20 },
  Button: { minWidth: 72, minHeight: 28 },
  TextField: { minWidth: 88, minHeight: 28 },
  TextArea: { minWidth: 88, minHeight: 52 },
  CheckBox: { minWidth: 72, minHeight: 24 },
  RadioButton: { minWidth: 72, minHeight: 24 },
  ComboBox: { minWidth: 92, minHeight: 28 },
  List: { minWidth: 96, minHeight: 60 },
  ProgressBar: { minWidth: 96, minHeight: 16 },
  Slider: { minWidth: 96, minHeight: 24 },
  Spinner: { minWidth: 72, minHeight: 28 },
  Separator: { minWidth: 24, minHeight: 6 },
  Panel: { minWidth: 72, minHeight: 48 },
};
 
export function getComponentMinSize(component: CanvasComponent): ComponentMinSize {
  if (component.type === "Separator" && component.orientation === "vertical") {
    return { minWidth: 6, minHeight: 24 };
  }
 
  return MIN_SIZE_BY_TYPE[component.type] ?? FALLBACK_MIN_SIZE;
}