Coder Social home page Coder Social logo

199ocero / radio-deck Goto Github PK

View Code? Open in Web Editor NEW
58.0 1.0 10.0 686 KB

Turn filament default radio button into a selectable card with icons, title and description.

Home Page: https://filamentphp.com/plugins/jaocero-radio-deck

License: MIT License

JavaScript 7.47% PHP 69.73% CSS 0.26% Blade 22.54%
filament-form filamentphp filamentphp-plugin

radio-deck's Introduction

Radio Deck

Header

Latest Version on Packagist Total Downloads

Turn filament default radio button into a selectable card with icons, title and description.

Installation

You can install the package via composer:

composer require jaocero/radio-deck

To adhere to Filament's theming approach, you'll be required to employ a personalized theme in order to utilize this plugin.

Custom Theme Installation Filament Docs

Add the plugin's views to your tailwind.config.js file.

content: [
    ...
    './vendor/jaocero/radio-deck/resources/views/**/*.blade.php',
]

Usage

use JaOcero\RadioDeck\Forms\Components\RadioDeck;
use Filament\Support\Enums\IconSize;
use Filament\Support\Enums\Alignment;
use Filament\Support\Enums\IconPosition;

public static function form(Form $form): Form
{
    return $form
        ->schema([
            RadioDeck::make('name')
                ->options([
                    'ios' => 'iOS',
                    'android' => 'Android',
                    'web' => 'Web',
                    'windows' => 'Windows',
                    'mac' => 'Mac',
                    'linux' => 'Linux',
                ])
                ->descriptions([
                    'ios' => 'iOS Mobile App',
                    'android' => 'Android Mobile App',
                    'web' => 'Web App',
                    'windows' => 'Windows Desktop App',
                    'mac' => 'Mac Desktop App',
                    'linux' => 'Linux Desktop App',
                ])
                ->icons([
                    'ios' => 'heroicon-m-device-phone-mobile',
                    'android' => 'heroicon-m-device-phone-mobile',
                    'web' => 'heroicon-m-globe-alt',
                    'windows' => 'heroicon-m-computer-desktop',
                    'mac' => 'heroicon-m-computer-desktop',
                    'linux' => 'heroicon-m-computer-desktop',
                ])
                ->required()
                ->iconSize(IconSize::Large) // Small | Medium | Large | (string - sm | md | lg)
                ->iconSizes([ // Customize the values for each icon size
                    'sm' => 'h-12 w-12',
                    'md' => 'h-14 w-14',
                    'lg' => 'h-16 w-16',
                ])
                ->iconPosition(IconPosition::Before) // Before | After | (string - before | after)
                ->alignment(Alignment::Center) // Start | Center | End | (string - start | center | end)
                ->gap('gap-5') // Gap between Icon and Description (Any TailwindCSS gap-* utility)
                ->padding('px-4 px-6') // Padding around the deck (Any TailwindCSS padding utility)
                ->direction('column') // Column | Row (Allows to place the Icon on top)
                ->extraCardsAttributes([ // Extra Attributes to add to the card HTML element
                    'class' => 'rounded-xl'
                ])
                ->extraOptionsAttributes([ // Extra Attributes to add to the option HTML element
                    'class' => 'text-3xl leading-none w-full flex flex-col items-center justify-center p-4'
                ])
                ->extraDescriptionsAttributes([ // Extra Attributes to add to the description HTML element
                    'class' => 'text-sm font-light text-center'
                ])
                ->color('primary') // supports all color custom or not
                ->multiple() // Select multiple card (it will also returns an array of selected card values)
                ->columns(3)
        ])
        ->columns('full');
}

You can also utilize an Enum class for ->options(), ->descriptions(), and ->icons() . Here's an example of how to create a simple enum class for this purpose:

<?php

namespace App\Filament\Enums;

use Filament\Support\Contracts\HasLabel;
use JaOcero\RadioDeck\Contracts\HasDescriptions;
use JaOcero\RadioDeck\Contracts\HasIcons;

enum AssetType: string implements HasLabel, HasDescriptions, HasIcons
{
    case iOs = 'ios';
    case Android = 'android';
    case Web = 'web';
    case Windows = 'windows';
    case Mac = 'mac';
    case Linux = 'linux';

    public function getLabel(): ?string
    {
        return match ($this) {
            self::iOs => 'iOS',
            self::Android => 'Android',
            self::Web => 'Web',
            self::Windows => 'Windows',
            self::Mac => 'Mac',
            self::Linux => 'Linux',
        };
    }

    public function getDescriptions(): ?string
    {
        return match ($this) {
            self::iOs => 'iOS Mobile App',
            self::Android => 'Android Mobile App',
            self::Web => 'Web App',
            self::Windows => 'Windows Desktop App',
            self::Mac => 'Mac Desktop App',
            self::Linux => 'Linux Desktop App',
        };
    }

    public function getIcons(): ?string
    {
        return match ($this) {
            self::iOs => 'heroicon-m-device-phone-mobile',
            self::Android => 'heroicon-m-device-phone-mobile',
            self::Web => 'heroicon-m-globe-alt',
            self::Windows => 'heroicon-m-computer-desktop',
            self::Mac => 'heroicon-m-computer-desktop',
            self::Linux => 'heroicon-m-computer-desktop',
        };
    }
}

After that, in your form, you can set it up like this:

public static function form(Form $form): Form
{
    return $form
        ->schema([
            RadioDeck::make('name')
                ->options(AssetType::class)
                ->descriptions(AssetType::class)
                ->icons(AssetType::class)
                ->required()
                ->iconSize(IconSize::Large)
                ->iconPosition(IconPosition::Before)
                ->alignment(Alignment::Center)
                ->color('danger')
                ->columns(3),
        ])
        ->columns('full');
}

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.

radio-deck's People

Contributors

199ocero avatar alexisserneels avatar atmonshi avatar codewithdennis avatar dmason30 avatar juliangums avatar orangejuiced avatar stvtk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

radio-deck's Issues

[Bug]: Enun support not working

What happened?

When using enuns, the description and icon are not recognized. The enum value is used instead

How to reproduce the bug

// Resource form

RadioDeck::make('export_type')
    ->label('Tipo de exportação')
    ->options(ExportType::class)
    ->descriptions(ExportType::class)
    ->icons(ExportType::class)
    ->iconSize(IconSize::Large)
    ->iconPosition(IconPosition::Before)
    ->alignment(Alignment::Center)
    ->color('danger')
    ->columns(3)
// enum

enum ExportType: int implements HasDescription, HasIcon, HasLabel
{
    case PERSONAL_DATA = 1;

    case JUST_TOTAL_NUMBERS = 2;

    public function getLabel(): string
    {
        return match ($this) {
            self::PERSONAL_DATA => 'Dados pessoais',
            self::JUST_TOTAL_NUMBERS => 'Quantitativo',
        };
    }

    public function getDescription(): string
    {
        return match ($this) {
            self::PERSONAL_DATA => 'Nome, e-mail, etc.',
            self::JUST_TOTAL_NUMBERS => 'Apenas o número de registros encontrados.',
        };
    }

    public function getIcon(): ?string
    {
        return match ($this) {
            self::PERSONAL_DATA => 'heroicon-m-finger-print',
            self::JUST_TOTAL_NUMBERS => 'heroicon-o-chart-pie',
        };
    }
}

Package Version

1.2.4

PHP Version

8.3.6

Laravel Version

11.5.0

Which operating systems does with happen with?

Windows

Notes

No response

Support for Enums

What happened?

Great plugin! Well done. I'm trying to add a radio deck for predefined enums. I think this plugin should support enums.

How to reproduce the bug

Here's an example Enum class:

<?php

namespace App\Enums;

use Filament\Support\Contracts\HasLabel;
use Filament\Support\Contracts\HasIcon;

enum ClientType: string implements HasLabel, HasIcon
{
	case Individual = 'Individual';
	case Organisation = 'Organisation';

	public function getLabel(): ?string
	{
		$label = match ($this) {
			self::Individual => 'Individual',
			self::Organisation => 'Organisation',
		};

		return $label;
	}

	public function getIcon(): ?string
	{
		return match ($this) {
			self::Individual => 'heroicon-m-user',
			self::Organisation => 'heroicon-m-building-office',
		};
	}
	
}

And the use case should be like this:

RadioDeck::make('client_type')
            ->options(ClientType::class)

And that would automatically load ->descriptions() and ->icons() unless there is a way already to do this?

Package Version

1.1.1

PHP Version

8.2.1

Laravel Version

10.39.0

Which operating systems does with happen with?

macOS

Notes

No response

[New Feature]: Having field description

What happened?

Hey.. Thanks for this plugin. It'd be great if we could add a description for the field.

How to reproduce the bug

Not a bug. Trying to access github's submit idea for this repo throws a 404

Package Version

2

PHP Version

8.2

Laravel Version

11

Which operating systems does with happen with?

No response

Notes

No response

[Bug]: Can't Click Option

What happened?

I can not click one of options listed

How to reproduce the bug

Just install, add assets config in tailwind config, and use it

Package Version

1.2

PHP Version

8.3

Laravel Version

10

Which operating systems does with happen with?

No response

Notes

No response

[Question]: How can I add a space between options?

What happened?

If I use your example code, the options are all withour space between. Is it possible to add a space between the options?

image

How to reproduce the bug

                RadioDeck::make('name')
                    ->options([
                        'ios' => 'iOS',
                        'android' => 'Android',
                        'web' => 'Web',
                        'windows' => 'Windows',
                        'mac' => 'Mac',
                        'linux' => 'Linux',
                    ])
                    ->required()
                    ->padding('px-4 px-6') // Padding around the deck (Any TailwindCSS padding utility)
                    ->direction('column') // Column | Row (Allows to place the Icon on top)
                    ->extraCardsAttributes([ // Extra Attributes to add to the card HTML element
                        'class' => 'rounded-xl'
                    ])
                    ->extraOptionsAttributes([ // Extra Attributes to add to the option HTML element
                        'class' => 'text-3xl leading-none w-full flex flex-col items-center justify-center p-4'
                    ])
                    ->extraDescriptionsAttributes([ // Extra Attributes to add to the description HTML element
                        'class' => 'text-sm font-light text-center'
                    ])
                    ->color('primary') // supports all color custom or not
                    ->multiple() // Select multiple card (it will also returns an array of selected card values)
                    ->columns(3),

Package Version

newest

PHP Version

8.3

Laravel Version

11

Which operating systems does with happen with?

No response

Notes

No response

[Bug]: Border outline color not working again

What happened?

I'm having the same problem as described at #2.

How to reproduce the bug

Trying with any color reproduces the bug. I already verified and my tailwind.config.js content list is correct.

Maybe some breaking change with Filament v3.2?

Package Version

1.2.1

PHP Version

8.2

Laravel Version

10

Which operating systems does with happen with?

Linux

[Bug]: Cards broken

What happened?

I followed the installation steps, but there is an issue with the space between cards and the outline doesn't change on hover and the cards are not clickable. is this package working with the latest Filament? Or is there something I'm doing wrong?
image

How to reproduce the bug

Install it with latest versions

Package Version

latest

PHP Version

latest

Laravel Version

latest

Which operating systems does with happen with?

Linux

Notes

No response

[Bug]: Border outline color not working

What happened?

In the new version the following method does not add a outline color to the options anymore ->color('primary'). Downgrading to v1.0.0-beta does work.

How to reproduce the bug

Add ->color('primary') to the field. (or any other color)

Package Version

v1.1.0

PHP Version

v8.2

Laravel Version

v10.39

Which operating systems does with happen with?

No response

Notes

What is happening:
Scherm­afbeelding 2024-01-02 om 14 37 47

Expected behavior:
Scherm­afbeelding 2024-01-02 om 14 38 27

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.