Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions components/checkbox-field/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.checkbox-field {
position: relative;
display: flex;
align-items: center;
border: none;
cursor: pointer;

& input {
z-index: 2;
width: 20px;
height: 20px;

&:checked {
accent-color: #2c2e30;
}
}
& label {
font-size: rem(14);
font-weight: normal;
width: 100%;
height: 100%;
display: flex;
align-items: center;
cursor: pointer;
gap: rem(16);
}
}
16 changes: 16 additions & 0 deletions components/checkbox-field/view.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="form-field__input checkbox-field">
<label>
<input type="checkbox" name="{{ $name }}" value="{{ $value }}">
{{ $slot }}
</label>
<div class="form-field__footer">
@error($name)
<p class="form-field__error">
{{ $message }}
</p>
@enderror
@isset($helper)
<p class="form-field__helper">{{ $helper }}</p>
@endisset
</div>
</div>
41 changes: 36 additions & 5 deletions components/form-field/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class FormField extends Component
/**
* The for attribute of the label
*/
public string $for;
public ?string $for;

/**
* The label for the input
*/
public string $label;
public ?string $label;

/**
* The text to tell the input is optional
Expand All @@ -36,28 +36,59 @@ class FormField extends Component
*/
public ?string $icon;

/**
* The view used to render the component
*/
public ?string $view;

/**
* The name used in the checkbox
*/
public ?string $name;

/**
* The view used in the checkbox
*/
public ?string $value;

/**
* Create a new component instance.
*/
public function __construct(
string $for,
string $label,
?string $for,
?string $label,
?string $optional = null,
?string $helper = null,
?string $icon = null,
?string $view = 'form-field',
?string $name = null,
?string $value = null,
) {
$this->for = $for;
$this->label = $label;
$this->optional = $optional;
$this->helper = $helper;
$this->icon = $icon;
$this->view = $view;
$this->name = $name;
$this->value = $value;

if ($view !== 'checkbox-field') {
if (! $for) {
throw new \InvalidArgumentException('The "for" attribute is required fields.');
}

if (! $label) {
throw new \InvalidArgumentException('The "label" attribute is required fields.');
}
}
}

/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.form-field');
return view('components.'.$this->view);
}
}
19 changes: 15 additions & 4 deletions src/Components/Publishers/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,35 @@ public function label(): string
*/
public function handle(): FilesCollection
{
$style = File::makeFromStub(
$baseStyle = File::makeFromStub(
stub: 'components/form-field/style.scss',
destination: resource_path('sass/parts/_form-field.scss'),
);

$view = File::makeFromStub(
$baseView = File::makeFromStub(
stub: 'components/form-field/view.blade.php',
destination: resource_path('views/components/form-field.blade.php'),
);
$checkboxStyle = File::makeFromStub(
stub: 'components/checkbox-field/style.scss',
destination: resource_path('sass/parts/_checkbox-field.scss'),
);

$checkboxView = File::makeFromStub(
stub: 'components/checkbox-field/view.blade.php',
destination: resource_path('views/components/checkbox-field.blade.php'),
);

$component = File::makeFromStub(
stub: 'components/form-field/Component.php',
destination: base_path('app/View/Components/FormField.php'),
);

return FilesCollection::make([
$style,
$view,
$baseStyle,
$baseView,
$checkboxStyle,
$checkboxView,
$component,
]);
}
Expand Down