monaye/simple-link-button

Laravel Nova 字段。

1.0.3 2020-09-25 18:37 UTC

This package is auto-updated.

Last update: 2024-09-26 03:42:09 UTC


README

灵感来自 Nova Button (https://github.com/dillingham/nova-button),但仅关注显示 HTML 链接并允许传递所有属性。

screenshot of nova simple link button

安装

composer require monaye/simple-link-button

用法

use Monaye\SimpleLinkButton\SimpleLinkButton;
public function fields(Request $request)
{
    return [
        SimpleLinkButton::make('Google', 'https://google.com'),
    ];
}

类型 & 样式

按钮的默认类型是 fill & 默认样式是 primary。类型和样式可能不匹配。

SimpleLinkButton::make('Google', 'https://google.com')->type('fill'),
SimpleLinkButton::make('Google', 'https://google.com')->type('outline'),
SimpleLinkButton::make('Google', 'https://google.com')->type('link'),
SimpleLinkButton::make('Google', 'https://google.com')->style('primary'),
SimpleLinkButton::make('Google', 'https://google.com')->style('success'),
SimpleLinkButton::make('Google', 'https://google.com')->style('warning'),
SimpleLinkButton::make('Google', 'https://google.com')->style('danger'),
SimpleLinkButton::make('Google', 'https://google.com')->style('info'),
SimpleLinkButton::make('Google', 'https://google.com')->style('grey'),

不匹配的类型和样式。

SimpleLinkButton::make('Google', 'https://google.com')
  ->type('outline')  // fill, outline, link
  ->style('danger'),  // primary, success, warning, danger, info, grey

自定义类型 & 样式

所有样式类都在配置文件中定义。

php artisan vendor:publish --tag=simple-link-button
// config/simple-link-button.php
'buttons' => [

    'fill' => [
        // Fill
        'primary' => 'dim btn btn-default btn-primary',
        'success' => 'dim btn btn-default bg-success text-white',
        'warning' => 'dim btn btn-default bg-warning text-white',
        'danger'  => 'dim btn btn-default bg-danger text-white',
        'info'    => 'dim btn btn-default bg-info text-white',
        'grey'    => 'dim btn btn-default bg-60 text-white',
    ],

    'outline' => [
        // Outline
        'primary' => 'dim btn btn-default border border-primary text-primary',
        'success' => 'dim btn btn-default border border-success text-success',
        'warning' => 'dim btn btn-default border border-warning text-warning ',
        'danger'  => 'dim btn btn-default border border-danger text-danger ',
        'info'    => 'dim btn btn-default border border-info text-info ',
        'grey'    => 'dim btn btn-default border border-60 text-80 ',
    ],

    'link' => [
        // Link
        'primary' => 'dim btn btn-link text-primary',
        'success' => 'dim btn btn-link text-success',
        'warning' => 'dim btn btn-link text-warning',
        'danger'  => 'dim btn btn-link text-danger',
        'info'    => 'dim btn btn-link text-info',
        'grey'    => 'dim btn btn-link text-80',
    ],
]

只需添加额外的配置来定义您自己的 typestyle

// config/simple-link-button.php
'buttons' => [

  ...

  'myown' => [
      'primary' => 'dim btn btn-default bg-90 text-white',
      'neutral' => 'dim btn btn-default bg-30 text-70',
  ]
  SimpleLinkButton::make('Google', 'https://google.com')
    ->type('myown'), // default to primary style

  SimpleLinkButton::make('Google', 'https://google.com')
    ->type('myown')
    ->style('neutral'),

可见性

您可以通过传递布尔值到 visible 方法来显示或隐藏按钮。

SimpleLinkButton::make('Google', 'https://google.com')->visible($this->is_active == false),
SimpleLinkButton::make('Google', 'https://google.com')->visible($this->is_active == true),

如果您需要动态传递类,请将类名传递到 classes 方法。 注意:classes 方法将覆盖 typestyle 类。

SimpleLinkButton::make('Google', 'https://google.com')->classes('my-own-class second-class'),

// to add additional class you will need to combine with pre config classes
// get classes from config file out slide of
$defaultClasses = Arr::get(config('simple-link-button'), "buttons.fill.primary")

// add additional class
SimpleLinkButton::make('Google', 'https://google.com')->classes("myClass ${defaultClass}"),

属性

您可以通过将 key => value 数组传递到 attributes 方法来传递任何属性到 HTML 链接。

SimpleLinkButton::make('Google', 'https://google.com')->attributes(['target' => '_blank']),
SimpleLinkButton::make('Download Pic', '/my-image.png')->attributes(['download'=>'download-image.png', 'title' => 'Download Image']),

作者

希望您觉得它有用。欢迎提出反馈。

在推特上关注我: @winmonaye

特别感谢

此包在很大程度上受到 https://github.com/dillingham/nova-button 的影响。如果您需要更强大的功能,请查看原始包。