svelte-range-slider-pips

repository·main·Indexed 19 days ago

https://github.com/simeydotme/svelte-range-slider-pips

A reactive, accessible, multi-thumb range slider with customizable pips (notches) and floating labels. Designed for Svelte 4 and 5, it also supports vanilla JavaScript, Vue, and React via JS modules. Features include range picker mode with draggable areas, spring animations, keyboard navigation, and extensive formatting options via props like rangeFormatter and handleFormatter. Version 4.1.1 introduces rs-prefixed CSS classes to prevent framework conflicts.

Tokens
5.4K
Snippets
23
Records
30
Agent score
67%

What's inside svelte-range-slider-pips

  1. Keyboard Navigation in v4

    main

    Keyboard navigation has been refined for better precision and alignment with the step value:

    • Ctrl/Cmd + Arrow: Moves the handle by 1% of the total range.
    • Shift + Arrow or PageUp/PageDown: Moves the handle by 10% of the total range.
    • PageUp: Moves the handle up/right.
    • PageDown: Moves the handle down/left.

    All movements respect the step and precision settings.

    <RangeSlider
      min={0}
      max={100}
      step={1}
      // Ctrl/Cmd + Arrow moves by 1 unit
      // Shift + Arrow or PageUp/PageDown moves by 10 units
    />
  2. Hover State Behavior with Disabled Sliders

    main

    Hover effects are now strictly controlled by both the hoverable and disabled properties. Hover effects (on handles or the range bar) will only be visible if hoverable is true AND disabled is false.

    <RangeSlider
      hoverable={true}
      disabled={true}  // Hover effects will not show
    />
    
    <RangeSlider
      hoverable={true}
      disabled={false} // Hover effects will show
    />
  3. Upgrade from v3 to v4

    main

    To upgrade to version 4, update your package manager dependencies. Note that v4 introduces breaking changes regarding CSS class names, which are now prefixed with rs to prevent conflicts. If you use custom CSS selectors or JavaScript to manipulate component classes, you must update them. All previous CSS variable names remain valid.

    npm install svelte-range-slider-pips@4
    # or
    yarn add svelte-range-slider-pips@4
    # or
    pnpm add svelte-range-slider-pips@4
  4. Update custom CSS for handle and range bar positioning (v4)

    main

    In v4, handles and range bars use CSS translate instead of left/right positioning. The component now uses internal CSS custom properties to control positions:

    • Handles: --handle-pos
    • Range: --range-start, --range-end, and --range-size.

    If you have written custom CSS to position these elements, you will need to update your code to use these properties or the new translate logic.

  5. Update custom CSS for float positioning (v4)

    main

    In v4, the component switched from transform: translate() to the modern translate property and added 3D transforms for hardware acceleration. If you have custom CSS targeting float elements, you must update your selectors.

    Example Update:

    /* Before (v3) */
    .rangeSlider .rangeHandle.active .rangeFloat {
      transform: translate(-50%, -10px);
    }
    
    /* After (v4) */
    .rangeSlider .rangeHandle.rsActive .rangeFloat {
      translate: -50% -10px 0.01px;
    }
    /* After (v4) */
    .rangeSlider .rangeHandle.rsActive .rangeFloat {
      translate: -50% -10px 0.01px;
    }
  6. Style the range slider with CSS

    main

    Styling is primarily handled via CSS. The slider is horizontally fluid, and its overall scale is controlled by the font-size property on the .rangeSlider base element.

    Key styling methods:

    • Colors: Use the provided CSS variables to control element colors.
    • Scaling: Adjust the font-size of the .rangeSlider element to scale the entire component.
    • Fine Control: For specific width or height overrides, use the id prop to assign a unique ID to your slider, making it easier to target with specific CSS selectors.
    • Labels: Label values can be styled with CSS, and their display format can be customized using the formatter() function prop.
    • Animations: Handle movement animations via the springValues object prop.

    Note for v4 users: Most CSS class names are now prefixed with rs (e.g., .rs-something) to prevent conflicts with CSS frameworks like DaisyUI or UnoCSS.

  7. Use version 2.3.1 for Svelte 3 projects

    main

    The current version of svelte-range-slider-pips is incompatible with Svelte 3. If your project is stuck on Svelte 3 and you cannot upgrade to Svelte 4 or 5, you should use version 2.3.1. This version is considered robust and will not receive further updates.

    To install the compatible version, use the following commands:

    yarn add svelte-range-slider-pips@2.3.1 --dev          # or
    npm install svelte-range-slider-pips@2.3.1 --save-dev  # if you prefer npm
  8. Migrate from v3 to v4

    main

    When upgrading from v3 to v4, follow these steps to ensure your custom styles and logic remain functional:

    1. Update CSS Selectors: Change any custom CSS targeting component state or modifier classes to use the new rs prefixed names (e.g., .pip.selected becomes .rsPip.rsSelected).
    2. Update JavaScript Queries: If you use JS to query or manipulate component elements, update the class names in your queries to include the rs prefix.
    3. Review CSS Frameworks: Check if any CSS framework configurations were targeting the old, non-prefixed class names.
    4. Test Component: Thoroughly test the slider to ensure all styles and animations behave as expected.
  9. Use svelte-range-slider-pips as a JS module (Vue, React, etc.)

    main

    In modern JavaScript applications using ES modules, you can import the .mjs distribution file. Initialize the slider by calling the RangeSlider constructor with a target (a DOM element reference) and a props object.

    import RangeSlider from './node_modules/svelte-range-slider-pips/dist/svelte-range-slider-pips.mjs';
    
    var mySlider = new RangeSlider({
      target: node, // js reference to a DOM element
      props: { values: [50], pips: true }
    });