/
githubmirror
/
tabler
Обзор
Документация
Войти
/
githubmirror
/
tabler
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
shared/ui/Range.astro
59 строк
2 KB
Paweł Kuna
Narrow component prop types, remove unused props and dead code (#2838)
10 авг 2026, 00:14
Не верифицирован
10 авг 2026, 00:14
4f7beec
Код
Авторство
О чём код?
--- // With an id → a noUiSlider div + init script; without an id → a native <input type=range>. import CaptureScript from '../components/CaptureScript.astro'; interface Props { min?: number; max?: number; value?: string | number; id?: string; connect?: boolean; class?: string; } const { min = 0, max = 100, value = 50, id, connect = false, class: className } = Astro.props; const step = 10; const values = String(value).split(','); const size = values.length; const numericValues = values.map(Number); const startValue = size > 1 ? numericValues : numericValues[0]; // Connect array: alternate false/true for mid segments, then true, false. let connectValue; if (size > 1 || connect) { const parts: boolean[] = []; for (let i = 2; i <= size; i++) parts.push((i - 2) % 2 !== 0); connectValue = [...parts, true, false]; } const rangeId = `range-${id}`; --- { id ? ( <div class:list={['form-range mb-2', className]} id={rangeId} /> ) : ( <input type="range" class:list={['form-range mb-2', className]} value={value} min={min} max={max} step={step} /> ) } { id && ( <CaptureScript> <!-- BEGIN RANGE --> <script is:inline define:vars={{ rangeId, startValue, connectValue, step, min, max }}> function initRange() { window.noUiSlider && noUiSlider.create(document.getElementById(rangeId), { start: startValue, ...(connectValue ? { connect: connectValue } : {}), step, range: { min, max }, }); } document.readyState !== 'loading' ? initRange() : document.addEventListener('DOMContentLoaded', initRange, { once: true }); </script> <!-- END RANGE --> </CaptureScript> ) }