Reputation: 6257
I trying to create a carrousel component that would take 100% width & height of a parent container (it should be able to go fullscreen). I have added a custom-arrow but I can't style it.
How to achieve such a result?
Here is my code and a sandbox:
const ArrowLeft = (props) => (
<button style={{background:"red", border: 0}} {...props} className={'prev'}>
back
</button>
);
const settings = {
dots: true,
infinite: true,
speed: 1000,
slidesToShow: 1,
slidesToScroll: 1,
autoplay: true,
lazyLoad: true,
centerMode: true,
adaptiveHeight: true,
fade: true,
arrows: true,
prevArrow: <ArrowLeft />,
autoplaySpeed: 5000,
className: "slides"
};
const images = [
"https://static.toiimg.com/photo/72975551.cms",
"https://www.gettyimages.fr/gi-resources/images/500px/983794168.jpg",
"https://www.freedigitalphotos.net/images/img/homepage/394230.jpg"
];
const StyledSlider = styled(Slider)``;
const Image = styled.div`
background-size: cover;
background: ${(props) => `url(${props.src}) no-repeat center`};
width: 100%;
height: 500px; // how to add an auto 100% width?
`;
export default function App() {
return (
<StyledSlider {...settings}>
{images.map((image, i) => {
return (
<div key={i}>
<Image src={image} alt="img" />
</div>
);
})}
</StyledSlider>
);
}
https://codesandbox.io/s/cranky-noether-1hdhr?file=/src/App.js
Any help would be greatly appreciated!
Upvotes: 3
Views: 8170
Reputation: 7355
react-slick is passing in its own styles which you can spread into the style object of the <Button>
(see: https://react-slick.neostack.com/docs/example/custom-arrows). You can then add or override any styles you wish.
The fix below uses the code from your Code Sandbox (working fork here: https://codesandbox.io/s/lucid-roentgen-bie3j?file=/src/App.js).
const Arrow = ({ className, style, onClick }) => (
<Button style={{...style, left: 0, backgroundColor: 'red'}} onClick={onClick} className={className}>
<div>back</div>
</Button>
);
const settings = {
...
prevArrow: <Arrow />
};
Upvotes: 2