Skip to content

Commit

Permalink
implement variable for bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdankharchenko committed Aug 10, 2019
1 parent 4f25f89 commit 2a3bc33
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 35 deletions.
98 changes: 64 additions & 34 deletions src/AireBootstrapServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function boot()
'group_errors' => 'd-none',
'label' => '',
'input' => 'form-control',

'checkbox' => 'custom-control-input',
'checkbox_label' => 'custom-control-label',
'checkbox_wrapper' => 'custom-control custom-checkbox',
Expand Down Expand Up @@ -66,47 +67,76 @@ public function boot()
'group_help_text' => 'invalid-feedback d-block',
],
],
'variant_classes' => [
'input' => [
'default' => 'form-control',
'sm' => 'form-control-sm',
'lg' => 'form-control-lg',
],
'group_input_group' => [
'default' => 'input-group',
'sm' => 'input-group-sm',
'lg' => 'input-group-lg',
],
'group_input_range' => [
'default' => [
'display' => 'range-default'
]
],
'select' => [
'default' => [
'display' => 'custom-select',
'size' => '',
'color' => '',
],
'sm' => 'custom-select-sm',
'lg' => 'custom-select-lg',
],
'button' => [
'default' => [
'display' => 'btn',
'size' => '',
'color' => 'btn-primary',
],
'sm' => [
'size' => 'btn-sm',
],
'lg' => [
'size' => 'btn-sm',
],
'primary' => [
'color' => 'btn-primary'
],
'secondary' => [
'color' => 'btn-secondary'
],
'success' => [
'color' => 'btn-success'
],
'danger' => [
'color' => 'btn-danger'
],
'warning' => [
'color' => 'btn-warning'
],
'info' => [
'color' => 'btn-info'
],
'light' => [
'color' => 'btn-light'
],
'dark' => [
'color' => 'btn-dark'
],
]
]
]);

Checkbox::registerElementMutator(function (Checkbox $checkbox) {
$checkbox->group->addClass('custom-control custom-checkbox');
});

Input::registerElementMutator(function (Input $input) {
$input->attributes->registerMutator('class', function (ClassNames $classNames) use ($input) {
if (in_array($input->getViewData('variant'), ['sm', 'small'])) {
$classNames->add('form-control-sm');
}

if (in_array($input->getViewData('variant'), ['lg', 'large'])) {
$classNames->add('form-control-lg');
}

return $classNames;
});

$input->group->attributes->input_group->registerMutator('class', function (ClassNames $classNames) use ($input) {

if ($input->attributes->primary()->class->has('form-control-sm')) {
$classNames->add('input-group-sm');
}

if ($input->attributes->primary()->class->has('form-control-lg')) {
$classNames->add('input-group-lg');
}

if (in_array($input->getViewData('variant'), ['sm', 'small'])) {
$classNames->add('input-group-sm');
}

if (in_array($input->getViewData('variant'), ['lg', 'large'])) {
$classNames->add('input-group-lg');
}


return $classNames;
});

$input->attributes->registerMutator('class', function (ClassNames $classNames) use ($input) {

if ('range' === $input->attributes->get('type')) {
Expand Down
2 changes: 1 addition & 1 deletion views/group.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{ $label }}

@if($prepend || $append)
<div class="input-group">
<div {{ $attributes->input_group }}>
@if($prepend)
<div {{ $attributes->prepend }}>
<div class="input-group-text">
Expand Down

0 comments on commit 2a3bc33

Please sign in to comment.