-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
105 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
<script lang="ts"> | ||
export let disabled = false; | ||
export let minimal = false; | ||
</script> | ||
|
||
<div | ||
class="flex w-full items-center gap-2 rounded px-2 py-2 outline outline-2 outline-gray-400 focus-within:outline-emerald-500" | ||
class="flex w-full items-center gap-2 rounded px-2 py-2 outline focus-within:outline-emerald-500" | ||
class:outline-red-500={disabled} | ||
class:outline-1={minimal} | ||
class:outline-zinc-300={minimal} | ||
class:dark:outline-zinc-700={minimal} | ||
class:dark:outline-zinc-500={!minimal} | ||
class:outline-2={!minimal} | ||
class:outline-zinc-400={!minimal} | ||
> | ||
<slot /> | ||
</div> |
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
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,22 @@ | ||
import { clamp } from '$lib/utils/numbers/clamp'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
describe('clamp', () => { | ||
it('should return the correct val', () => { | ||
expect(clamp(0, 5, 10)).toBe(5); | ||
expect(clamp(0, -1, 10)).toBe(0); | ||
expect(clamp(0, 11, 10)).toBe(10); | ||
}); | ||
|
||
it('should handle negative ranges correctly', () => { | ||
expect(clamp(-10, -5, 0)).toBe(-5); | ||
}); | ||
|
||
it('should handle equal min and max values', () => { | ||
expect(clamp(5, 5, 5)).toBe(5); | ||
}); | ||
|
||
it('should throw an error if min is greater than max', () => { | ||
expect(() => clamp(10, 5, 0)).toThrow('min cannot be greater than max'); | ||
}); | ||
}); |
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,16 @@ | ||
/** | ||
* Clamps a number within the inclusive range specified by the given minimum and maximum values. | ||
* | ||
* @param min The minimum value. | ||
* @param desired The number to clamp. | ||
* @param max The maximum value. | ||
* @returns The clamped value. | ||
* @throws {Error} Will throw an error if min is greater than max. | ||
*/ | ||
export function clamp(min: number, desired: number, max: number) { | ||
if (min > max) throw new Error('min cannot be greater than max'); | ||
if (desired > max) return max; | ||
if (desired < min) return min; | ||
|
||
return desired; | ||
} |
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