-
Notifications
You must be signed in to change notification settings - Fork 381
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
13 changed files
with
134 additions
and
28 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
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
82 changes: 82 additions & 0 deletions
82
src/interfaces/assistants_web/src/components/UI/Slider.tsx
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,82 @@ | ||
'use client'; | ||
|
||
import { ChangeEvent, useEffect, useMemo } from 'react'; | ||
|
||
import { InputLabel, Text } from '@/components/UI'; | ||
import { cn } from '@/utils'; | ||
|
||
type Props = { | ||
label: string; | ||
min: number; | ||
max: number; | ||
step: number; | ||
value: number; | ||
onChange: (value: number) => void; | ||
sublabel?: string; | ||
className?: string; | ||
tooltipLabel?: React.ReactNode; | ||
formatValue?: (value: number) => string; | ||
}; | ||
|
||
/** | ||
* | ||
* Renders a slider with a label, a minimum, maximum and step value, and optional subLabel and tooltip. | ||
* Styling for the thumb is located in main.css | ||
*/ | ||
export const Slider: React.FC<Props> = ({ | ||
label, | ||
sublabel, | ||
min, | ||
max, | ||
step, | ||
value, | ||
onChange, | ||
tooltipLabel, | ||
formatValue, | ||
className = '', | ||
}) => { | ||
// if `max` is changed dynamically don't allow the value to surpass it | ||
useEffect(() => { | ||
if (value > max) onChange(Math.min(value, max)); | ||
}, [max, onChange, value]); | ||
|
||
// if `min` is changed dynamically don't allow the value to go below it | ||
useEffect(() => { | ||
if (value < min) onChange(Math.max(value, min)); | ||
}, [min, onChange, value]); | ||
|
||
const handleChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
const value = Number(e.target.value); | ||
|
||
onChange(value); | ||
}; | ||
|
||
const ticks = useMemo(() => { | ||
return Array.from({ length: (max - min) / step + 1 }, (_, i) => { | ||
return i * step + min; | ||
}); | ||
}, [max, min, step]); | ||
|
||
return ( | ||
<div className={cn('flex flex-col space-y-4', className)}> | ||
<div className="flex w-full items-center justify-between"> | ||
<InputLabel label={label} tooltipLabel={tooltipLabel} sublabel={sublabel} /> | ||
<Text>{formatValue ? formatValue(value) : value}</Text> | ||
</div> | ||
<div className="flex items-center"> | ||
<input | ||
type="range" | ||
value={value} | ||
max={max} | ||
min={min} | ||
step={step} | ||
onChange={handleChange} | ||
className={cn( | ||
'flex w-full cursor-pointer appearance-none items-center rounded-lg border outline-none active:cursor-grabbing', | ||
'focus-visible:outline focus-visible:outline-1 focus-visible:outline-offset-4 focus-visible:outline-volcanic-100' | ||
)} | ||
/> | ||
</div> | ||
</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
4 changes: 2 additions & 2 deletions
4
src/interfaces/assistants_web/src/stores/slices/paramsSlice.ts
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