Slider
Page through a row of items with arrows, dots, horizontal scroll, or swipe gestures.
Slider is a client component that lays its children out in a horizontal track and animates between pages with a motion spring. Use it for plan cards, testimonials and other short rows of items. Controls render below the track. It reads theme tokens and should render inside DesignSystemProvider.
Import#
import { Slider } from "@reactberry/system/blocks";
Usage#
import { Slider } from "@reactberry/system/blocks";
import { Box, Text } from "@reactberry/system/elements";
const plans = ["Starter", "Team", "Business", "Enterprise"];
export default function PlanSlider() {
return (
<Slider
config={{ slidesToShow: 1, spacing: 8 }}
responsiveConfig={[
{ breakpoint: 1024, settings: { slidesToShow: 3 } },
{ breakpoint: 640, settings: { slidesToShow: 2 } },
]}
>
{plans.map((plan) => (
<Box key={plan} p="l" skin="surface" shape="rounded">
<Text>{plan}</Text>
</Box>
))}
</Slider>
);
}
Examples#
Arrows only#
Set dots: false to hide the page dots and keep the arrow controls.
Responsive slides#
responsiveConfig merges settings when the window is wider than a breakpoint. List entries from largest to smallest breakpoint. Resize the window to see it change.
API#
Slider#
| Prop | Type | Default | Description |
|---|---|---|---|
config | SliderConfig | — | Settings merged over the defaults. See |
responsiveConfig | ResponsiveConfig[] | [] | Breakpoint overrides, each |
children* | ReactNode[] | — | Slides. Must be an array; each element is wrapped in its own slide container. |
No other props are accepted and nothing is spread.
SliderConfig#
Fields of config and of each responsiveConfig entry's settings:
| Prop | Type | Default | Description |
|---|---|---|---|
slidesToShow | number | 1 | Slides visible per page. Page count is |
dots | boolean | true | Shows one dot per page; clicking a dot jumps to that page. |
arrows | boolean | true | Shows previous and next arrow controls. |
spacing | number | 0 | Horizontal padding in pixels applied to each side of every slide. |
paddingX | number | 0 | Horizontal padding in pixels on the root. |
paddingY | number | 0 | Vertical padding in pixels on the root. |
maxItemWidth | number | 300 | Maximum slide width in pixels, applied only when there are fewer children than |
infinite | boolean | false | Keeps both arrows enabled at all times. Navigation still stops at the first and last page. |
slidesToScroll | number | 1 | Declared but not used; paging always moves by |
Accessibility#
- Arrow controls and dots are
divelements without a button role, accessible label, or keyboard focus.
Notes#
- Controls render only when there is more than one page.
- Navigation: arrow controls, dots, horizontal wheel or trackpad scroll (one page per gesture), and dragging. A drag changes page when it travels more than 50px with a velocity above 500.
responsiveConfigis evaluated on mount and on every window resize. The first entry whosebreakpointis less thanwindow.innerWidthis merged into the current settings. Matched settings persist; they are not reverted when the viewport shrinks below every breakpoint.- The page transition is a spring (
visualDuration0.3,bounce0.2). No reduced-motion check is performed. - The
SliderConfigandResponsiveConfigtypes and the internalSliderControlscomponent are not exported from@reactberry/system/blocks.