Giter Club home page Giter Club logo

lw-range-slider's Introduction

Livewire Range Slider

Latest Stable Version Total Downloads License

An effortless blade component, noUiSlider, tailored for your Livewire Components.

Installation

You can install the package via composer:

composer require ysz/lw-range-slider

Register the script component to template after the @livewireScripts

<html>
    <body>
        <!-- @livewireScripts -->

        <x-livewire-range-slider::scripts />
    </body>
</html>

Requirements

This package is designed to be used in conjunction with Livewire components. Please ensure that you exclusively utilize it within Livewire projects.

How to use it!

Please add this properties inside your existing Livewire component.

public $options = [
    'start' => [
        20,
        50
    ],
    'range' => [
        'min' =>  [1],
        'max' => [100]
    ],
    'connect' => true,
    'behaviour' => 'tap-drag',
    'tooltips' => true,
    'pips' => [
        'mode' => 'steps',
        'stepped' => true,
        'density' => 4
    ],
    ...
];

public array $sliderValues;

The $options property represents the noUiSlider options that you provide to the component. For additional details and configurations, please refer to noUiSlider

The $sliderValues property is the model for the range slider values.

Livewire's default wire:model attribute

<x-range-slider :options="$options" wire:model="sliderValues" />

Deferred Updating

In cases where you don't need data updates to happen live, we have a .defer modifier that batches data updates with the next network request.

<x-range-slider :options="$options" wire:model.defer="sliderValues" />

Lazy Updating

You can also use .lazy modifier to update the data after the user has finished interacting with the slider.

<x-range-slider :options="$options" wire:model.lazy="sliderValues" />

Emitting events

To update the start or range values for noUiSlider, call the firePriceRangeChangedEvent method.

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use YsZ\LwRangeSlider\Contracts\CanFireEvents;

class AvailableUnits extends Component
{
    use CanFireEvents;
    
    public function updated($name, $value)
    {
        $this->firePriceRangeChangedEvent(min: 80, max: 150, minRange: 100, maxRange: 200);
    }
}

this will immediately update the range and start values for noUiSlider.

Customizing the slider

You can publish these blade file to resources/views/vendor/livewire-range-slider and customize it.

php artisan vendor:publish --tag=lw-range-slider-views

To customize the noUiSlider options from the published file, as certain options cannot be passed from the Livewire component due to them not being valid JSON when used as a callback function.

<div
    x-data='LivewireRangeSlider({
        options: {
            start: [{{ $this->minPrice }}, {{ $this->maxPrice }}],
            connect: true,
            tooltips: true,
            tooltips: {
                to: function (value) {
                    return window?.currencyFormat("site", value);
                },
                from: function (value) {
                    return window?.currencyFormat("site", value);
                }
            },
            range: {
                min: {{ $this->minPrice }},
                max: {{ $this->maxPrice }}
            }
        },
        models: {!! json_encode($getWireModel($attributes)) !!},
        modifier: "{{ $getWireModelModifier($attributes) }}"
    })'
    @focusout="setValue"
    {{ $attributes }}
    wire:ignore
>
    <div x-ref="range"></div>
    {{ $slot }}
</div>

lw-range-slider's People

Contributors

ghostza1209 avatar yoss1209 avatar jstnmthw avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.