Skip to content

Commit

Permalink
[1.x] Features: default label, single var autoselect, conditional + b…
Browse files Browse the repository at this point in the history
…utton (#8)

Co-authored-by: Jack Sleight <[email protected]>
  • Loading branch information
caseydwyer and jacksleight authored Nov 1, 2024
1 parent 3d36061 commit 0c1ac94
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 25 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/build/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"css": [
"assets/addon-027ed678.css"
],
"file": "assets/addon-89467a3c.js",
"file": "assets/addon-1bbdcebd.js",
"isEntry": true,
"src": "resources/js/addon.js"
}
Expand Down
26 changes: 21 additions & 5 deletions resources/js/components/fieldtypes/MinisetClassesFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</button>
</div>
<button
v-if="! allVariantsAdded"
class="miniset-add"
@click.prevent="addGroup">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 block opacity-25 hover:opacity-100" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
Expand Down Expand Up @@ -110,16 +111,28 @@ export default {
computed: {
allVariantsAdded() {
return this.variantCount === this.value.length - 1;
},
fields() {
return this.config.fields;
},
showTabs() {
return this.variantCount > 0
},
defaultLabel() {
return this.config.default_label || __('Default');
},
variants() {
return this.config.variants;
},
showTabs() {
return Object.keys(this.variants).length > 0
variantCount() {
return Object.keys(this.variants).length;
},
},
Expand Down Expand Up @@ -147,11 +160,14 @@ export default {
},
addGroup() {
this.addingGroup = true;
if (this.variantCount === 1) {
this.commitGroup(Object.keys(this.variants)[0]);
} else {
this.addingGroup = true;
}
},
commitGroup(variant) {
const existing = this.value.findIndex(group => group.variant === variant);
if (existing !== -1) {
this.addingGroup = false;
Expand Down Expand Up @@ -229,7 +245,7 @@ export default {
groupLabel(group) {
return group.variant
? (this.variants[group.variant] || group.variant)
: __('Default');
: this.defaultLabel;
},
updateGroupMeta(group, value) {
Expand Down
6 changes: 6 additions & 0 deletions src/Fieldtypes/MinisetClassesFieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ protected function configFieldItems(): array
'display' => __('Variants'),
'type' => 'array',
],
'default_label' => [
'display' => __('Default Label'),
'instructions' => __('Custom label for the default tab.'),
'type' => 'text',
'placeholder' => 'Default',
],
];
}

Expand Down

0 comments on commit 0c1ac94

Please sign in to comment.