[M] Split clamp function

This commit is contained in:
Azalea Gui
2023-02-09 21:35:49 -05:00
parent f25a7cb9d3
commit db4198c238
2 changed files with 6 additions and 2 deletions
+2 -2
View File
@@ -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
+4
View File
@@ -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)
}