forked from rajun/ar-test
feat: clamp custom button sizes for the live preview
This commit is contained in:
parent
8034b851d0
commit
a72f76f814
21
app/lib/projects/button-size.ts
Normal file
21
app/lib/projects/button-size.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { BUTTON_CUSTOM_DEFAULT, BUTTON_CUSTOM_LIMITS } from '~/data/projects/constants';
|
||||
import type { ButtonCustomSize } from '~/types/project';
|
||||
|
||||
function fit(key: keyof typeof BUTTON_CUSTOM_LIMITS, value: number | null): number | null {
|
||||
if (typeof value !== 'number' || !Number.isFinite(value)) return null;
|
||||
const { min, max } = BUTTON_CUSTOM_LIMITS[key];
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
|
||||
// Custom measurements as they are being typed, made safe to draw: each held within its range, and an empty box
|
||||
// falls back to the default (an empty width fits the label). The preview follows every keystroke this way.
|
||||
export function fitButtonCustom(custom: ButtonCustomSize): ButtonCustomSize {
|
||||
return {
|
||||
height: fit('height', custom.height) ?? BUTTON_CUSTOM_DEFAULT.height,
|
||||
width: fit('width', custom.width),
|
||||
paddingX: fit('paddingX', custom.paddingX) ?? BUTTON_CUSTOM_DEFAULT.paddingX,
|
||||
radius: fit('radius', custom.radius) ?? BUTTON_CUSTOM_DEFAULT.radius,
|
||||
borderWidth: fit('borderWidth', custom.borderWidth) ?? BUTTON_CUSTOM_DEFAULT.borderWidth,
|
||||
borderColor: custom.borderColor,
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user