All files / ext.wikilambda.edit/components/base ExpandedToggle.vue

100% Statements 22/22
100% Branches 6/6
100% Functions 7/7
100% Lines 21/21

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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133    25x 25x 25x 25x 25x 25x                                 35x                 40x 28x   12x           4x     4x       25x   25x     25x 25x   40x 40x 40x               80x             25x                                                                                                                    
<!--
	WikiLambda Vue component that renders the expanded view toggle icon.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<cdx-button
		weight="quiet"
		:aria-label="$i18n( 'wikilambda-toggle-expanded-view' ).text()"
		class="ext-wikilambda-expand-toggle"
		:disabled="!hasExpandedMode"
		@click="waitAndExpand"
	>
		<cdx-icon
			class="ext-wikilambda-expand-toggle-icon"
			:class="iconClass"
			:icon="hasExpandedMode ? icons.cdxIconExpand : iconBullet"
		></cdx-icon>
	</cdx-button>
</template>
 
<script>
const { defineComponent } = require( 'vue' );
const CdxIcon = require( '@wikimedia/codex' ).CdxIcon,
	CdxButton = require( '@wikimedia/codex' ).CdxButton,
	icons = require( '../../../lib/icons.json' ),
	mapGetters = require( 'vuex' ).mapGetters;
 
module.exports = exports = defineComponent( {
	name: 'wl-expanded-toggle',
	components: {
		'cdx-button': CdxButton,
		'cdx-icon': CdxIcon
	},
	props: {
		expanded: {
			type: Boolean,
			required: true
		},
		hasExpandedMode: {
			type: Boolean,
			required: true
		}
	},
	data: function () {
		return {
			icons: icons,
			iconBullet: {
				path: 'M8 8h4v4H8z'
			}
		};
	},
	computed: Object.assign( mapGetters( [
		'waitForRunningParsers'
	] ), {
		iconClass: function () {
			if ( !this.hasExpandedMode ) {
				return 'ext-wikilambda-expand-toggle-disabled';
			} else {
				return this.expanded ?
					'ext-wikilambda-expand-toggle-expanded' :
					'ext-wikilambda-expand-toggle-collapsed';
			}
		}
	} ),
	methods: {
		waitAndExpand: function ( event ) {
			this.waitForRunningParsers.then( () => this.clickExpandToggle( event ) );
		},
		clickExpandToggle: function ( event ) {
			this.$emit( 'toggle', event );
		}
	}
} );
</script>
 
<style lang="less">
@import '../../ext.wikilambda.edit.variables.less';
 
.ext-wikilambda-expand-toggle {
	width: calc( @min-size-icon-small + 2px );
	min-width: calc( @min-size-icon-small + 2px );
	padding: 0;
 
	.ext-wikilambda-expand-toggle-icon {
		width: @min-size-icon-small;
		height: @min-size-icon-small;
		min-width: @min-size-icon-small;
		min-height: @min-size-icon-small;
		padding: 0;
		color: @color-subtle;
		transition: transform @transition-duration-medium @transition-timing-function-system;
 
		@media ( prefers-reduced-motion ) {
			transition: transform 0ms unset;
		}
 
		&.cdx-icon {
			color: @color-subtle;
			width: @min-size-icon-small;
			height: @min-size-icon-small;
 
			svg {
				width: @size-75;
				height: @size-75;
			}
		}
 
		&.ext-wikilambda-expand-toggle-disabled {
			svg {
				width: @spacing-200;
				height: @spacing-200;
			}
		}
 
		&.ext-wikilambda-expand-toggle-collapsed {
			transform: rotate( -90deg );
		}
	}
}
 
[ dir='rtl' ] {
	.ext-wikilambda-expand-toggle {
		.ext-wikilambda-expand-toggle-icon {
			&.ext-wikilambda-expand-toggle-collapsed {
				transform: rotate( 90deg );
			}
		}
	}
}
</style>