Skip to content

Commit 56834fe

Browse files
committed
Fix zoom input step size and default value
1 parent c36c4dd commit 56834fe

2 files changed

Lines changed: 9 additions & 21 deletions

File tree

packages/imagekit-editor-dev/src/components/common/ZoomInput.tsx

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,26 @@ type ZoomInputFieldProps = {
1919
defaultValue?: number
2020
}
2121

22-
/**
23-
* Calculate the step size based on the current zoom value
24-
* If zoom >= 100: step = 50
25-
* If zoom < 100: step = 10
26-
*/
27-
function getStepSize(value: number, zoomMode: "in" | "out"): number {
28-
if (zoomMode === "in") {
29-
return value >= 100 ? 50 : 10
30-
} else {
31-
return value > 100 ? 50 : 10
32-
}
33-
}
22+
const STEP_SIZE = 10
23+
3424

3525
/**
3626
* Calculate the next zoom value when zooming in
3727
* Rounds up to the next step value
3828
*/
3929
function calculateZoomIn(currentValue: number): number {
40-
const step = getStepSize(currentValue, "in")
41-
return (Math.floor(currentValue / step) * step) + step
30+
return (Math.floor(currentValue / STEP_SIZE) * STEP_SIZE) + STEP_SIZE
4231
}
4332

4433
/**
4534
* Calculate the next zoom value when zooming out
4635
* Rounds down to the previous step value
4736
*/
4837
function calculateZoomOut(currentValue: number): number {
49-
const step = getStepSize(currentValue, "out")
50-
return (Math.ceil(currentValue / step) * step) - step
38+
return (Math.ceil(currentValue / STEP_SIZE) * STEP_SIZE) - STEP_SIZE
5139
}
5240

53-
export const ZoomInputField: React.FC<ZoomInputFieldProps> = ({
41+
export const ZoomInput: React.FC<ZoomInputFieldProps> = ({
5442
id,
5543
onChange,
5644
defaultValue = 100,
@@ -138,4 +126,4 @@ export const ZoomInputField: React.FC<ZoomInputFieldProps> = ({
138126
)
139127
}
140128

141-
export default ZoomInputField
129+
export default ZoomInput

packages/imagekit-editor-dev/src/components/sidebar/transformation-config-sidebar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import { SidebarFooter } from "./sidebar-footer"
5656
import { SidebarHeader } from "./sidebar-header"
5757
import { SidebarRoot } from "./sidebar-root"
5858
import PaddingInputField from "../common/PaddingInput"
59-
import ZoomInputField from "../common/ZoomInput"
59+
import ZoomInput from "../common/ZoomInput"
6060

6161
export const TransformationConfigSidebar: React.FC = () => {
6262
const {
@@ -575,10 +575,10 @@ export const TransformationConfigSidebar: React.FC = () => {
575575
/>
576576
) : null}
577577
{field.fieldType === "zoom" ? (
578-
<ZoomInputField
578+
<ZoomInput
579579
value={watch(field.name) as string}
580580
onChange={(value) => setValue(field.name, value)}
581-
defaultValue={field.fieldProps?.defaultValue as number ?? 0}
581+
defaultValue={field.fieldProps?.defaultValue as number ?? 100}
582582
{...field.fieldProps}
583583
/>
584584
) : null}

0 commit comments

Comments
 (0)