8000 Added ability to use filter cards as "select field" by xUJYx · Pull Request #11 · awesome-nova/filter-card · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added ability to use filter cards as "select field" #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions dist/css/card.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.card-panel{height:auto}
2 changes: 1 addition & 1 deletion dist/js/card.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"/js/card.js": "/js/card.js"
"/js/card.js": "/js/card.js",
"/css/card.css": "/css/card.css"
}
3 changes: 3 additions & 0 deletions resources/css/card.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.card-panel {
height: auto;
}
58 changes: 46 additions & 12 deletions resources/js/components/Card.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
<template>
<card class="overflow-hidden flex flex-row">
<button
v-for="option in filter.options"
:key="option.value"
class="py-4 px-8 border-b-2 focus:outline-none flex-1"
:class="[isActive(option) ? 'text-grey-black font-bold border-primary': 'text-grey font-semibold border-40']"
@click="handleChange(option)"
>{{ option.name }}
</button>
<div>
<div v-if="showAsSelect" class="text-center">
<h3
v-if="! hideSelectHeading"
class="text-sm uppercase tracking-wide p-3 text-grey"
>
{{ filter.name }}
</h3>

<div class="p-2 pt-0">
<select-control
class="block w-full form-control-sm form-select"
:value="value"
@change="handleChange"
:options="filter.options"
label="name"
>
<option value="" selected>-- ALL --</option>
</select-control>
</div>
</div>

<card v-else class="overflow-hidden flex flex-row">
<button
v-for="option in filter.options"
:key="option.value"
class="py-4 px-8 border-b-2 focus:outline-none flex-1"
:class="[isActive(option) ? 'text-grey-black font-bold border-primary': 'text-grey font-semibold border-40']"
@click="handleChange(option)"
>
{{ option.name }}
</button>
</card>
</div>
</template>

<script>
Expand All @@ -28,7 +52,7 @@ export default {
},

data: () => ({
filterKey: null,
filterKey: null
}),

created() {
Expand All @@ -37,17 +61,19 @@ export default {

methods: {
handleChange(option) {
const option_value = this.showAsSelect ? option.target.value : option.value;

this.$store.commit(`${this.resourceName}/updateFilterState`, {
filterClass: this.filterKey,
value: option.value,
value: option_value,
})

this.filterChanged()
},

isActive(option) {
return String(this.value) == String(option.value)
},
}
},

computed: {
Expand All @@ -65,6 +91,14 @@ export default {
pageParameter() {
return this.resourceName + '_page'
},

showAsSelect() {
return this.card.show_as_select || false
},

hideSelectHeading() {
return this.card.hide_select_heading || false
},
},
}
</script>
14 changes: 14 additions & 0 deletions src/Cards/FilterCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,18 @@ public function __construct($filter)

$this->withMeta(['filter' => $filter]);
}

public function showAsSelect($show_as_select = true)
{
$this->withMeta(['show_as_select' => $show_as_select]);

return $this;
}

public function hideSelectHeading($hide_select_heading = true)
{
$this->withMeta(['hide_select_heading' => $hide_select_heading]);

return $this;
}
}
1 change: 1 addition & 0 deletions src/FilterCardServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function boot()
{
Event::listen(ServingNova::class, function () {
Nova::script('awesome-nova-filter-card', dirname(__DIR__) . '/dist/js/card.js');
Nova::style('awesome-nova-filter-card', dirname(__DIR__) . '/dist/css/card.css');
});
}
}
1 change: 1 addition & 0 deletions webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ let mix = require('laravel-mix')

mix.setPublicPath('dist')
.js('resources/js/card.js', 'js')
.postCss('resources/css/card.css', 'css')
0