Skip to content

Commit

Permalink
Allow accordion style replicator sets. Rename config to collapse.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Oct 30, 2020
1 parent b2a4250 commit 979daeb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
11 changes: 9 additions & 2 deletions resources/js/components/fieldtypes/replicator/Replicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="replicator-fieldtype-container">

<div class="absolute top-0 right-0 p-3 text-2xs" v-if="values.length > 0">
<div class="absolute top-0 right-0 p-3 text-2xs" v-if="config.collapse !== 'accordion' && values.length > 0">
<button @click="collapseAll" class="text-blue hover:text-black mr-1" v-text="__('Collapse All')" />
<button @click="expandAll" class="text-blue hover:text-black" v-text="__('Expand All')" />
</div>
Expand Down Expand Up @@ -131,6 +131,8 @@ export default {
this.updateSetMeta(set._id, this.meta.new[handle]);
this.values.splice(index, 0, set);
this.expandSet(set._id);
},
collapseSet(id) {
Expand All @@ -140,6 +142,11 @@ export default {
},
expandSet(id) {
if (this.config.collapse === 'accordion') {
this.collapsed = this.value.map(v => v._id).filter(v => v !== id);
return;
}
if (this.collapsed.includes(id)) {
var index = this.collapsed.indexOf(id);
this.collapsed.splice(index, 1);
Expand All @@ -165,7 +172,7 @@ export default {
},
mounted() {
if (this.config.collapsed) this.collapseAll();
if (this.config.collapse) this.collapseAll();
},
watch: {
Expand Down
5 changes: 4 additions & 1 deletion resources/lang/en/fieldtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@
'range.config.prepend' => 'Add text to the beginning (left-side) of the slider.',
'range.config.step' => 'The minimum size between values.',
'relationship.config.mode' => 'Choose your preferred UI style.',
'replicator.config.collapsed' => 'Collapse all sets by default.',
'replicator.config.collapse' => 'The set collapsing behavior.',
'replicator.config.collapse.disabled' => 'All sets expanded by default',
'replicator.config.collapse.enabled' => 'All sets collapsed by default',
'replicator.config.collapse.accordion' => 'Only allow one set to be expanded at a time',
'select.config.clearable' => 'Enable to allow deselecting your option.',
'select.config.multiple' => 'Allow multiple selections.',
'select.config.options' => 'Set the keys and their optional labels.',
Expand Down
15 changes: 11 additions & 4 deletions src/Fieldtypes/Replicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ class Replicator extends Fieldtype
protected function configFieldItems(): array
{
return [
'collapsed' => [
'display' => __('Collapsed'),
'instructions' => __('statamic::fieldtypes.replicator.config.collapsed'),
'type' => 'toggle',
'collapse' => [
'display' => __('Collapse'),
'instructions' => __('statamic::fieldtypes.replicator.config.collapse'),
'type' => 'select',
'cast_booleans' => true,
'width' => 50,
'options' => [
'false' => __('statamic::fieldtypes.replicator.config.collapse.disabled'),
'true' => __('statamic::fieldtypes.replicator.config.collapse.enabled'),
'accordion' => __('statamic::fieldtypes.replicator.config.collapse.accordion'),
],
'default' => false,
],
'sets' => [
'type' => 'sets',
Expand Down

0 comments on commit 979daeb

Please sign in to comment.