Skip to content

Instantly share code, notes, and snippets.

@Nks
Last active March 15, 2019 17:54
Show Gist options
  • Save Nks/7428218407f9bd15a6b7ca74e63fc7b0 to your computer and use it in GitHub Desktop.
Save Nks/7428218407f9bd15a6b7ca74e63fc7b0 to your computer and use it in GitHub Desktop.
orchid rows button
<?php
declare(strict_types=1);
namespace App\Orchid\Fields;
use Orchid\Screen\Field;
class Button extends Field
{
/**
* @var string
*/
public $view = 'platform::fields.button';
/**
* Override the form view.
*
* @var string
*/
public $typeForm = 'platform::partials.fields.clear';
/**
* Default attributes value.
*
* @var array
*/
public $attributes = [
'type' => 'button',
'class' => 'btn btn-primary',
'modal' => null,
'method' => null,
'icon' => null,
'right' => false,
];
/**
* Attributes available for a particular tag.
*
* @var array
*/
public $inlineAttributes = [
'autofocus',
'disabled',
'tabindex',
'href',
];
/**
* Create instance of the button
*
* @return self
*/
public static function make(): self
{
return (new static())->name('button');
}
/**
* Set the route.
*
* @param string $route
* @return \Orchid\Screen\Field
*/
public function route(string $route)
{
return $this->set('href', $route);
}
/**
* Align button to the right.
*
* @return $this
*/
public function right()
{
$this->attributes['class'] .= ' pull-right';
return $this;
}
/**
* Set the button as block.
*
* @return $this
*/
public function block()
{
$this->attributes['class'] .= ' btn-block';
return $this;
}
}
@component($typeForm,get_defined_vars())
@if(!is_null($modal))
<button type="button"
class="{{ $class }}"
data-action="screen--base#targetModal"
data-modal-title="{{ $title ?? '' }}"
data-modal-key="{{ $modal ?? '' }}"
data-modal-action="{{ url()->current() }}/{{ $method }}"
@include('platform::partials.fields.attributes', ['attributes' => $attributes])
>
<i class="{{ $icon ?? '' }} m-r-xs"></i>{{ $title ?? '' }}
</button>
@else
<a class="{{ $class }}" @include('platform::partials.fields.attributes', ['attributes' => $attributes])>
<i class="{{ $icon ?? '' }} m-r-xs"></i>{{ $title }}
</a>
@endif
@endcomponent
<div class="form-group">
{{$slot}}
@if($errors->has($oldName))
<div class="invalid-feedback d-block">
<small>{{$errors->first($oldName)}}</small>
</div>
@elseif(isset($help))
<small class="form-text text-muted">{{$help}}</small>
@endif
</div>
@isset($hr)
<div class="line line-dashed b-b line-lg"></div>
@endisset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment