Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / Controls

CompareSlider

Two versions of the same thing, one over the other, split by a divider people move to compare them.

Before and after split by adivider

When to useLink to "When to use"

  • Before and after of an image edit, a redesign or a render, where the difference is in the detail.

Use something else when:

UsageLink to "Usage"

tsx
Copy
import { CompareSlider } from "@arshad-shah/cynosure";

<CompareSlider before={<img src={original} alt="Original" />} after={<img src={edited} alt="Edited" />} />

before and after should be the same size. Control the divider with value and onChange (percent of the width showing before).

Controlled

PropsLink to "Props"

Every prop of CompareSlider
PropWhat it doesTypeDefault
beforeRequired
Shown on the start side of the divider (e.g. the original image).ReactNode
afterRequired
Shown on the other side (e.g. the edited image). Both should be the same size.ReactNode
value
Divider position: percent of the width showing before.number
defaultValue
The divider's starting position when uncontrolled, 0 to 100. Default 50.number50
onChange
Called as the divider moves (drag, click or keys), with the new position, 0 to 100.((value: number) => void)
showTags
Show the Before and After tags. Default true.booleantrue
labels
Replace the built-in English text: the divider's name, its spoken position and the two tags.Partial<CompareSliderLabels>
className
Added to the root element, for layout.string
style
Layout only. Restyle through --cy-compare-slider-* tokens.CSSProperties

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

  • Role: the divider is a slider named "Comparison", read as "40% before". Rename it and the tags with labels.
  • Pointer: press anywhere on the picture to jump the divider there (and focus it), then drag; Escape mid-drag puts it back.
  • Keyboard: arrows move 1%, Shift+arrows and Page Up/Down 10%, Home and End go to the ends.
  • Touch: a sideways drag moves the divider at once and a tap jumps it; an upward or downward swipe scrolls the page. The divider's hit area is 44px on touch screens.
Keyboard moves the divider

ThemingLink to "Theming"

Tokens: --cy-compare-slider-divider and --cy-compare-slider-grip-size.

Slider · SplitPane · SelectionFrame

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog