Giter VIP home page Giter VIP logo

filament-announce's Introduction

Filament Announce

Latest Version on Packagist GitHub Tests Action Status Total Downloads

The easiest way to shout announcements in filament!

Installation

You can install the package via composer:

composer require rupadana/filament-announce
php artisan make:notifications-table
php artisan migrate

Optionally, you can publish the views using

php artisan vendor:publish --tag="filament-announce-views"

publish config

php artisan vendor:publish --tag="filament-announce-config"
return [
    'navigation' => [
        'group' => '',
        'sort' => 1
    ],
    'can_access' => [
        'role' => ['super_admin']
    ]
];

Usage

You must enable Announce by adding FilamentAnnouncePlugin class to your Filament Panel's plugin() or plugins([]) method:

use Rupadana\FilamentAnnounce\FilamentAnnouncePlugin;
use Filament\Support\Colors\Color;
class CustomersPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ...
            ->plugin(
                FilamentAnnouncePlugin::make()
                    ->pollingInterval('30s') // optional, by default it is set to null
                    ->defaultColor(Color::Blue) // optional, by default it is set to "primary"

            )
    }
}

To override the plugins announcementResource with your own custom resource, you should append usingResource method when registering the plugin:

use Rupadana\FilamentAnnounce\FilamentAnnouncePlugin;
use Filament\Support\Colors\Color;
class CustomersPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ...
            ->plugin(
                FilamentAnnouncePlugin::make()
                    ->usingResource(MyCustomAnnouncementResource::class)
                    ->pollingInterval('30s') // optional, by default it is set to null
                    ->defaultColor(Color::Blue) // optional, by default it is set to "primary"

            )
    }
}

Now you can announce whatever to users:

use App\Models\User;
use Rupadana\FilamentAnnounce\Announce;

Announce::make()
    ->title('Big News!')
    ->icon('heroicon-o-megaphone')
    ->body('Filament can now show very important message to specific users!')
    ->disableCloseButton() // Optional, if you want ur announcement discloseable
    ->announceTo(User::all());

Title and Body Alignment

By default, the alignments will be start and you might want to adjust them:

use App\Models\User;
use Filament\Support\Enums\Alignment;
use Rupadana\FilamentAnnounce\Announce;

Announce::make()
    ->title('Big News!')
    ->icon('heroicon-o-megaphone')
    ->body('Filament can now show very important message to specific users!')
    ->alignment(Align::Center) // this will set both title and body alignments (common alignment)
    ->titleAlignment(Align::Start) // this will set title alignment and take precedence over common alignment methods
    ->bodyAlignment(Align::Start) // this will set body alignment and take precedence over common alignment methods
    ->actions([
        Action::make('view')
            ->button(),
        Action::make('undo')
            ->color('gray'),
    ])
    ->announceTo(User::all());

You can also use alignStart(), alignCenter(), alignEnd(), alignJustify(), alignBetween(), alignLeft() and alignRight() for your convenience.

Add Actions to Announce

Since Announce extends Filament Notification, you can add Filament Notification Actions to your announcements:

use App\Models\User;
use Rupadana\FilamentAnnounce\Announce;

Announce::make()
    ->title('Big News!')
    ->icon('heroicon-o-megaphone')
    ->body('Filament can now show very important message to specific users!')
    ->actions([
        Action::make('view')
            ->button(),
        Action::make('undo')
            ->color('gray'),
    ])
    ->announceTo(User::all());

Read more about Notification Action.

Announcement Resource

Todo

  • Can add actions to every announcement
  • Provide a resource/action to send announcement
  • Add banner-like implementations for global announcement
  • Set end date or time so it will disapear automaticly

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-announce's People

Contributors

rupadana avatar margarizaldi avatar dependabot[bot] avatar github-actions[bot] avatar charlieetienne avatar hussain4real 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.