[M] Split clamp function
This commit is contained in:
+2
-2
@@ -10,7 +10,7 @@ import 'tippy.js/animations/shift-away.css';
|
||||
import './app.sass';
|
||||
|
||||
import { Icon } from '@iconify-icon/solid';
|
||||
import { sizeFmt } from './utils';
|
||||
import { clamp, sizeFmt } from './utils';
|
||||
|
||||
interface File {
|
||||
name: string
|
||||
@@ -51,7 +51,7 @@ export default function App() {
|
||||
function wheel(e: WheelEvent)
|
||||
{
|
||||
let direction = (e.detail < 0 || e.deltaY > 0) ? 1 : -1
|
||||
setBcLeft(Math.max(Math.min(bcLeft() + direction * 20, bcMax), 0))
|
||||
setBcLeft(clamp(bcLeft() + direction * 20, 0, bcMax))
|
||||
}
|
||||
|
||||
// Set initial breadcrumb wheel to show the end path
|
||||
|
||||
@@ -7,4 +7,8 @@
|
||||
export function sizeFmt(size: number): string {
|
||||
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
|
||||
return (size / Math.pow(1024, i)).toFixed(1) + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
||||
}
|
||||
|
||||
export function clamp(num: number, min: number, max: number) {
|
||||
return Math.max(Math.min(num, max), min)
|
||||
}
|
||||
Reference in New Issue
Block a user