UNPKG

@wordpress/widget-dashboard

Version:

Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.

35 lines (34 loc) • 909 B
// packages/widget-dashboard/src/utils/row-height-presets/row-height-presets.ts var ROW_HEIGHT_PRESETS = { small: 200, medium: 300, large: 400 }; var DEFAULT_ROW_HEIGHT = ROW_HEIGHT_PRESETS.medium; var PRESET_ENTRIES = Object.entries(ROW_HEIGHT_PRESETS); function rowHeightToPreset(rowHeight) { let closest = "medium"; let minDistance = Infinity; for (const [preset, value] of PRESET_ENTRIES) { const distance = Math.abs(rowHeight - value); if (distance < minDistance) { minDistance = distance; closest = preset; } } return closest; } function presetToRowHeight(preset) { return ROW_HEIGHT_PRESETS[preset]; } function snapRowHeight(rowHeight) { return presetToRowHeight(rowHeightToPreset(rowHeight)); } export { DEFAULT_ROW_HEIGHT, ROW_HEIGHT_PRESETS, presetToRowHeight, rowHeightToPreset, snapRowHeight }; //# sourceMappingURL=row-height-presets.mjs.map