Debian Codegraph @

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

raw
1 <template>
2 <cdx-field :is-fieldset="true">
3 <template #label>
4 {{ $i18n( 'block-reason' ).text() }}
5 </template>
6
7 <cdx-select
8 v-model:selected="wrappedSelected"
9 :menu-items="reasonOptions"
10 name="wpReason"
11 ></cdx-select>
12
13 <cdx-text-input
14 v-model.trim="wrappedOther"
15 :placeholder="$i18n( 'block-reason-other' ).text()"
16 :maxlength="reasonMaxLength"
17 name="wpReason-other"
18 ></cdx-text-input>
19 </cdx-field>
20 </template>
21
22 <script>
23 const { defineComponent, toRef } = require( 'vue' );
24 const { CdxSelect, CdxField, CdxTextInput, useModelWrapper } = require( '@wikimedia/codex' );
25
26 module.exports = exports = defineComponent( {
27 name: 'ReasonField',
28 components: { CdxSelect, CdxField, CdxTextInput },
29 props: {
30 // eslint-disable-next-line vue/no-unused-properties
31 selected: { type: [ String, Number, null ], default: 'other' },
32 // eslint-disable-next-line vue/no-unused-properties
33 other: { type: String, default: '' }
34 },
35 emits: [
36 'update:selected',
37 'update:other'
38 ],
39 setup( props, { emit } ) {
40 const reasonOptions = mw.config.get( 'blockReasonOptions' );
41 const wrappedSelected = useModelWrapper( toRef( props, 'selected' ), emit, 'update:selected' );
42 const wrappedOther = useModelWrapper( toRef( props, 'other' ), emit, 'update:other' );
43 const reasonPreset = mw.config.get( 'blockReasonPreset' );
44
45 if ( reasonPreset !== 'other' && reasonOptions.some( ( option ) => option.value === reasonPreset ) ) {
46 emit( 'update:selected', reasonPreset );
47 }
48
49 return {
50 reasonOptions,
51 reasonMaxLength: mw.config.get( 'blockReasonMaxLength' ),
52 wrappedSelected,
53 wrappedOther
54 };
55 }
56 } );
57 </script>
58
59 <style lang="less">
60 @import 'mediawiki.skin.variables.less';
61
62 .cdx-select-vue {
63 margin-bottom: @spacing-50;
64 width: 100%;
65 }
66 </style>