Debian Codegraph @

resources/src/mediawiki.special.block/components/BlockDetailsOptions.vue

raw
1 <template>
2 <cdx-field :is-fieldset="true">
3 <cdx-checkbox
4 v-for="checkbox in checkboxes"
5 :key="'checkbox-' + checkbox.value"
6 v-model="wrappedModel"
7 :input-value="checkbox.value"
8 :disabled="disabledState( checkbox )"
9 :class="checkbox.class"
10 >
11 {{ checkbox.label }}
12 </cdx-checkbox>
13 <template #label>
14 {{ label }}
15 <span class="cdx-label__label__optional-flag">
16 {{ $i18n( 'htmlform-optional-flag' ).text() }}
17 </span>
18 </template>
19 <template #description>
20 {{ description }}
21 </template>
22 </cdx-field>
23 </template>
24
25 <script>
26 const { defineComponent, toRef } = require( 'vue' );
27 const { storeToRefs } = require( 'pinia' );
28 const { CdxCheckbox, CdxField, useModelWrapper } = require( '@wikimedia/codex' );
29 const useBlockStore = require( '../stores/block.js' );
30
31 // @vue/component
32 module.exports = exports = defineComponent( {
33 name: 'BlockDetailsField',
34 components: { CdxCheckbox, CdxField },
35 props: {
36 /**
37 * The label displaying for the list of checkboxes
38 */
39 label: {
40 type: String,
41 required: true
42 },
43 /**
44 * The description displaying for list of checkboxes
45 */
46 description: {
47 type: String,
48 required: true
49 },
50 /**
51 * The list of checkboxes to display
52 */
53 checkboxes: {
54 type: Array,
55 required: true
56 },
57 /**
58 * The current checkboxes selected
59 */
60 // eslint-disable-next-line vue/no-unused-properties
61 modelValue: {
62 type: Array,
63 required: true
64 }
65 },
66 emits: [
67 'update:modelValue'
68 ],
69 setup( props, { emit } ) {
70 const wrappedModel = useModelWrapper(
71 toRef( props, 'modelValue' ),
72 emit
73 );
74 const { hideNameDisabled } = storeToRefs( useBlockStore() );
75
76 /**
77 * We want the disabled state of the 'Hide username' option to be reactive,
78 * as it should be disabled when the block type is not 'sitewide'.
79 *
80 * @param {Object} checkbox
81 * @return {boolean}
82 */
83 function disabledState( checkbox ) {
84 return checkbox.value === 'wpHideName' ? hideNameDisabled.value : checkbox.disabled;
85 }
86
87 return {
88 wrappedModel,
89 disabledState
90 };
91 }
92 } );
93 </script>