Absolutely! Let's enhance the slider component to be more elegant and suited for dark mode, with some additional pizzazz like dimming icons or shimmer effects based on the selection.
Step 1: Update Tailwind Configuration
Ensure your tailwind.config.js is set up for dark mode:
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./pages/**/*.{js,ts,jsx,tsx}",
"./components/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
darkMode: 'class', // Enable dark mode
}
Step 2: Create the Enhanced Slider Component
Create or update the components/Slider.js file:
import { useState } from 'react';
const Slider = () => {
const [selected, setSelected] = useState(0);
const choices = ['Dim', 'Bright', 'Superbright'];
const icons = ['🌑', '🌕', '✨'];
const handleSlide = (direction) => {
if (direction === 'left' && selected > 0) {
setSelected(selected - 1);
} else if (direction === 'right' && selected < choices.length - 1) {
setSelected(selected + 1);
}
};
return (
<div className="w-64 mx-auto mt-10">
<div className="relative w-full h-20 bg-gray-800 rounded-lg overflow-hidden">
<div
className="absolute top-0 left-0 flex transition-transform duration-500"
style={{ transform: `translateX(-${selected * 100}%)` }}
>
{choices.map((choice, index) => (
<div
key={index}
className="flex-none w-full h-full flex items-center justify-center bg-gray-900"
>
<div className="text-center">
<span className="text-lg font-semibold text-gray-300">
{icons[index]}
</span>
<h3 className="mt-2 text-lg font-semibold text-gray-300">
{choice}
</h3>
</div>
</div>
))}
</div>
</div>
<div className="flex justify-between mt-4">
<button
onClick={() => handleSlide('left')}
className="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50"
>
Left
</button>
<button
onClick={() => handleSlide('right')}
className="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50"
>
Right
</button>
</div>
</div>
);
};
export default Slider;
Step 3: Add Dark Mode and Shimmer Effects
To add shimmer effects and dim the icons based on the selection, we can use some custom styles and conditional classes.
Update your components/Slider.js to include these effects: