From 2b0c3603a135aa58b573cb526a2569791417aed1 Mon Sep 17 00:00:00 2001 From: andrepat0 Date: Thu, 7 Nov 2024 17:42:43 +0100 Subject: [PATCH] feat: updated slider component, now the label can be a ReactNode --- src/components/ui/Slider.css | 188 ++++++++++++++++++----------------- src/components/ui/Slider.tsx | 5 +- 2 files changed, 97 insertions(+), 96 deletions(-) diff --git a/src/components/ui/Slider.css b/src/components/ui/Slider.css index dd38e20a..5ad98e36 100644 --- a/src/components/ui/Slider.css +++ b/src/components/ui/Slider.css @@ -1,109 +1,111 @@ .slider-container { - width: 100%; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; - } + width: 100%; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; +} - .slider-header { - display: flex; - justify-content: space-between; - align-items: center; - margin-bottom: 8px; - } +.slider-header { + display: flex; + align-items: center; + justify-content: space-between; + margin-bottom: 8px; + position: absolute; +} - .slider-label { - font-size: 14px; - font-weight: 500; - color: #333; - } +.slider-label { + color: #333; + font-size: 14px; + font-weight: 500; +} - .slider-value { - font-size: 14px; - color: #666; - } +.slider-value { + color: #666; + font-size: 14px; +} - .slider-track-container { - position: relative; - height: 48px; - display: flex; - align-items: center; - cursor: pointer; - } +.slider-track-container { + position: relative; + display: flex; + height: 48px; + align-items: center; + cursor: pointer; + margin-top: 8px; +} - .slider-track { - position: absolute; - width: 100%; - height: 8px; - background-color: #e5e5e5; - border-radius: 4px; - overflow: hidden; - } +.slider-track { + position: absolute; + overflow: hidden; + width: 100%; + height: 8px; + border-radius: 4px; + background-color: #e5e5e5; +} - .slider-track-fill { - position: absolute; - height: 100%; - width: var(--percentage); - background-color: var(--memori-primary); - border-radius: 4px; - transition: width 0.2s ease; - } +.slider-track-fill { + position: absolute; + width: var(--percentage); + height: 100%; + border-radius: 4px; + background-color: var(--memori-primary); + transition: width 0.2s ease; +} - .slider-marks { - position: absolute; - width: 100%; - display: flex; - justify-content: space-between; - padding: 0 4px; - pointer-events: none; - padding-top: 15px; - } +.slider-marks { + position: absolute; + display: flex; + width: 100%; + justify-content: space-between; + padding: 0 4px; + padding-top: 15px; + pointer-events: none; +} - .slider-mark { - display: flex; - flex-direction: column; - align-items: center; - } +.slider-mark { + display: flex; + flex-direction: column; + align-items: center; +} - .slider-mark-line { - height: 4px; - width: 2px; - background-color: #9ca3af; - margin-bottom: 4px; - } +.slider-mark-line { + width: 2px; + height: 4px; + margin-bottom: 4px; + background-color: #9ca3af; +} - .slider-mark-value { - font-size: 12px; - color: #666; - } +.slider-mark-value { + color: #666; + font-size: 12px; +} - .slider-thumb { - position: absolute; - height: 24px; - width: 24px; - border-radius: 50%; - background-color: white; - border: 2px solid var(--memori-primary); - box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); - left: var(--percentage); - transform: translateX(-50%); - transition: transform 0.2s ease; - z-index: 1; - } +.slider-thumb { + position: absolute; + z-index: 1; + left: var(--percentage); + width: 24px; + height: 24px; + border: 2px solid var(--memori-primary); + border-radius: 50%; + background-color: white; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); + transform: translateX(-50%); + transition: transform 0.2s ease; +} - .slider-thumb:hover { - transform: translateX(-50%) scale(1.1); - } +.slider-thumb:hover { + transform: translateX(-50%) scale(1.1); +} - @media (max-width: 640px) { - .slider-container { - padding: 12px; - } +@media (max-width: 640px) { + .slider-container { + padding: 12px; + } - .slider-track { - height: 6px; - } + .slider-track { + height: 6px; + } - .slider-thumb { - height: 20px; - width: 20px; - } - } \ No newline at end of file + .slider-thumb { + width: 20px; + height: 20px; + } +} \ No newline at end of file diff --git a/src/components/ui/Slider.tsx b/src/components/ui/Slider.tsx index 4ed5b1b7..b5b73158 100644 --- a/src/components/ui/Slider.tsx +++ b/src/components/ui/Slider.tsx @@ -7,7 +7,7 @@ export interface Props { max?: number; step?: number; defaultValue?: number; - label?: string; + label?: string | React.ReactNode; onChange?: (value: number) => void; } @@ -44,8 +44,7 @@ const CustomSlider = ({ return (
- {label} - {/* {value} */} + {label}