All files / ext.wikilambda.app/components/visualeditor FunctionInputDefaultValueCheckbox.vue

100% Statements 81/81
100% Branches 8/8
100% Functions 2/2
100% Lines 81/81

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 821x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 3x 7x 7x 2x 7x 1x 7x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 1x 1x 7x 7x 7x 7x 7x 7x 1x 1x  
<!--
	WikiLambda Vue component for default value checkbox in Visual Editor
	Wikifunctions function call input fields.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div v-if="checkboxLabel" class="ext-wikilambda-app-function-input-default-value-checkbox">
		<cdx-checkbox
			:model-value="isChecked"
			@update:model-value="handleCheckboxChange"
		>
			{{ checkboxLabel }}
		</cdx-checkbox>
	</div>
</template>
 
<script>
const { computed, defineComponent, inject } = require( 'vue' );
const Constants = require( '../../Constants.js' );
 
// Codex components
const { CdxCheckbox } = require( '../../../codex.js' );
 
module.exports = exports = defineComponent( {
	name: 'wl-function-input-default-value-checkbox',
	components: {
		'cdx-checkbox': CdxCheckbox
	},
	props: {
		inputType: {
			type: String,
			required: true
		},
		isChecked: {
			type: Boolean,
			required: true
		}
	},
	emits: [ 'update:isChecked' ],
	setup( props, { emit } ) {
		const i18n = inject( 'i18n' );
 
		// Checkbox label
		/**
		 * Returns the appropriate label for the checkbox based on the input type
		 *
		 * @return {string}
		 */
		const checkboxLabel = computed( () => {
			switch ( props.inputType ) {
				case Constants.Z_GREGORIAN_CALENDAR_DATE:
					return i18n( 'wikilambda-visualeditor-wikifunctionscall-default-value-date' ).text();
				case Constants.Z_WIKIDATA_ITEM:
				case Constants.Z_WIKIDATA_REFERENCE_ITEM:
					return i18n( 'wikilambda-visualeditor-wikifunctionscall-default-value-wikidata-item' ).text();
				case Constants.Z_NATURAL_LANGUAGE:
					return i18n( 'wikilambda-visualeditor-wikifunctionscall-default-value-language' ).text();
				default:
					return '';
			}
		} );
 
		// Actions
		/**
		 * Handles checkbox change and emits the new state
		 *
		 * @param {boolean} isChecked
		 */
		function handleCheckboxChange( isChecked ) {
			emit( 'update:isChecked', isChecked );
		}
 
		return {
			checkboxLabel,
			handleCheckboxChange
		};
	}
} );
</script>