-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scale factor buttons to the editor component
- Loading branch information
1 parent
0279eb9
commit 807c322
Showing
6 changed files
with
123 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { FunctionComponent } from 'react'; | ||
import { clamp } from '../../utils/clamp'; | ||
|
||
type Props = { | ||
min?: number; | ||
max?: number; | ||
step?: number; | ||
value: number; | ||
onChange: (value: number) => void; | ||
}; | ||
|
||
export const ZoomPaneComponent: FunctionComponent<Props> = (props) => { | ||
const { min = 0.5, max = 5, step = 0.5, value, onChange } = props; | ||
|
||
return ( | ||
<div style={{ position: 'absolute', left: '0.75em', bottom: '0.75em' }}> | ||
<button | ||
style={{ marginRight: '0.5em' }} | ||
className="button-rounded" | ||
onClick={() => onChange(clamp(value + step, min, max))} | ||
> | ||
+ | ||
</button> | ||
<button className="button-rounded" onClick={() => onChange(clamp(value - step, min, max))}> | ||
- | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export const ZoomPane = ZoomPaneComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Clamp a given value to an allowed range | ||
* @param value The value that should be clamped | ||
* @param min The minimum allowed value | ||
* @param max The maximum allowed value | ||
*/ | ||
export const clamp = (value: number, min: number, max: number): number => { | ||
return Math.max(min, Math.min(value, max)); | ||
}; |