Coder Social home page Coder Social logo

filament-range-field's Introduction

The missing range field for the Filament forms.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

"repositories": [
    {
        "type":"package",
        "package": {
            "name": "ashwin-nath-m/filament-range-field",
            "version":"v1.0.0",
            "source": {
                "url": "https://github.com/ashwin-nath-m/filament-range-field.git",
                "type": "git",
                "reference":"v1.0.0"
            }
        }
    }
],
    "require": {
          "ashwin-nath-m/filament-range-field": "v1.0.0"
    }

Publish the assets:

php artisan vendor:publish --tag="filament-range-field-assets"

Optionally, you can publish the views using

php artisan vendor:publish --tag="filament-range-field-views"

Basic usage

By default the range is used to get value from 0 to 100.

use Yepsua\Filament\Forms\Components\RangeSlider

...
    protected function getFormSchema(): array
    {
        return [
            ...
            RangeSlider::make('range')
            ...
        ];
    }
...

Defining the steps:

use Yepsua\Filament\Forms\Components\RangeSlider

...
    protected function getFormSchema(): array
    {
        return [
            ...
            RangeSlider::make('range')->steps([
                'A', // should get value: 1 for the A
                'B', // should get value: 2 for the B
                'C', // should get value: 3 for the C
                'D'  // should get value: 4 for the D
            ])
            ...
        ];
    }
...

Associative Array:

use Yepsua\Filament\Forms\Components\RangeSlider

...
    protected function getFormSchema(): array
    {
        return [
            ...
            RangeSlider::make('range')->steps([
                '25'  => 'A', // should get value: 25  for the A
                '50'  => 'B', // should get value: 50  for the B
                '75'  => 'C', // should get value: 75  for the C
                '100' => 'D'  // should get value: 100 for the D
            ])
            ...
        ];
    }
...

Hide the Step List:

use Yepsua\Filament\Forms\Components\RangeSlider

...
    protected function getFormSchema(): array
    {
        return [
            ...
            RangeSlider::make('range')->steps([
                'A',
                'B',
                'C',
                'D'
            ])->displaySteps(false)
            ...
        ];
    }
...

📕 Note: The step value is defined by the first item in the steps array, Ex. => [25, 50, 75, 100] the step value should be 25. However if you need to define any other step value you can use the setter step.

    RangeSlider::make('range')->steps([
        0 => '0',
        25 => '25',
        50 => '50',
        75 => '75',
        100 => '100'
    ])->step(25)
    ...

The same case applies for the min and max setters:

    RangeSlider::make('range')->min(25)->max(75)->step(5)

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

filament-range-field's People

Contributors

oyepez003 avatar francescomugnai avatar devadattas avatar mohamedsabil83 avatar ashwin-nath-m avatar dependabot[bot] avatar github-actions[bot] 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.