Skip to content

Commit

Permalink
feat: updated slider component, now the label can be a ReactNode
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepat0 committed Nov 7, 2024
1 parent c324473 commit 2b0c360
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 96 deletions.
188 changes: 95 additions & 93 deletions src/components/ui/Slider.css
Original file line number Diff line number Diff line change
@@ -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;
}
}
.slider-thumb {
width: 20px;
height: 20px;
}
}
5 changes: 2 additions & 3 deletions src/components/ui/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface Props {
max?: number;
step?: number;
defaultValue?: number;
label?: string;
label?: string | React.ReactNode;
onChange?: (value: number) => void;
}

Expand Down Expand Up @@ -44,8 +44,7 @@ const CustomSlider = ({
return (
<div className="slider-container" style={{ '--percentage': `${percentage}%` } as React.CSSProperties}>
<div className="slider-header">
<span className="slider-label">{label}</span>
{/* <span className="slider-value">{value}</span> */}
{label}
</div>

<div className="slider-track-container" onClick={handleSliderClick}>
Expand Down

0 comments on commit 2b0c360

Please sign in to comment.