From b946e398cd54fc24ba758becdeb4b5c3b2b7fa18 Mon Sep 17 00:00:00 2001 From: David VanScott Date: Mon, 28 Feb 2022 14:37:09 -0500 Subject: [PATCH 1/2] Add meta field --- CHANGELOG.md | 8 ++++++-- README.md | 4 ++++ src/Filter.php | 3 ++- src/FilterComponent.php | 3 +++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 425d7ec..5605c9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `livewire-filters` will be documented in this file. -## 0.1 - 202X-XX-XX +## 0.2 - 2022-xx-xx -- initial release +- Added the `meta` field to `Filter` class + +## 0.1 - 2022-02-28 + +- Initial release diff --git a/README.md b/README.md index f21fc61..8c3fe77 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,10 @@ If you would like to set the value of a filter, you can pass the value or an arr When defining a filter, you should use the `default` method to set the initial value of the filter. This will store the initial value on the object as well to help with determining the status of active filters as well as resetting the filter to its original state. Calling the `default` method without any arguments will return the initial value that you specified when you defined the filter. +### `meta(array $values)` + +If you would like to set additional information on the filter to be used in the view file, you can pass an array of values into the `meta` method. Calling the `meta` method without any arguments will return the current array of meta information. + ## Events ### `livewire-filters-reset` diff --git a/src/Filter.php b/src/Filter.php index b4d0ff5..f56c351 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -8,7 +8,8 @@ public function __construct( public string $key, public ?array $options = [], public mixed $value = '', - public mixed $initialValue = '' + public mixed $initialValue = '', + public array $meta = [] ) { } diff --git a/src/FilterComponent.php b/src/FilterComponent.php index 6b505f3..322b6ef 100644 --- a/src/FilterComponent.php +++ b/src/FilterComponent.php @@ -10,6 +10,8 @@ abstract class FilterComponent extends Component public string $key = ''; + public array $meta = []; + public array $options = []; public mixed $value; @@ -17,6 +19,7 @@ abstract class FilterComponent extends Component public function mount(Filter $filter): void { $this->key = $filter->key(); + $this->meta = $filter->meta(); $this->options = $filter->options(); $this->value = $filter->value(); From 77eee7f9fd668f425e3df556265905ffe6e5d2f0 Mon Sep 17 00:00:00 2001 From: David VanScott Date: Mon, 28 Feb 2022 14:43:52 -0500 Subject: [PATCH 2/2] Update the changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5605c9b..5a14035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to `livewire-filters` will be documented in this file. -## 0.2 - 2022-xx-xx +## 0.2 - 2022-02-28 - Added the `meta` field to `Filter` class