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

100% Statements 129/129
100% Branches 9/9
100% Functions 4/4
100% Lines 129/129

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 1301x 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 1x 1x 1x 1x 30x 30x 30x 30x 30x 30x 1x 1x 1x 1x 1x 35x 26x 35x 9x 9x 9x 9x 35x 1x 1x 1x 2x 1x 1x 2x 2x 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 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
<!--
	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-app-expanded-toggle"
		:disabled="!hasExpandedMode"
		data-testid="expanded-toggle"
		@click="waitAndExpand"
	>
		<cdx-icon
			class="ext-wikilambda-app-expanded-toggle__icon"
			:class="iconClass"
			:icon="hasExpandedMode ? icons.cdxIconExpand : iconBullet"
		></cdx-icon>
	</cdx-button>
</template>
 
<script>
const { CdxIcon, CdxButton } = require( '@wikimedia/codex' );
const { defineComponent } = require( 'vue' );
const icons = require( '../../../lib/icons.json' ),
	{ mapGetters } = require( 'vuex' );
 
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-app-expanded-toggle__icon--disabled';
			} else {
				return this.expanded ?
					'ext-wikilambda-app-expanded-toggle__icon--expanded' :
					'ext-wikilambda-app-expanded-toggle__icon--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.app.variables.less';
 
.ext-wikilambda-app-expanded-toggle {
	width: calc( @min-size-icon-small + 2px );
	min-width: calc( @min-size-icon-small + 2px );
	padding: 0;
 
	.ext-wikilambda-app-expanded-toggle__icon {
		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;
			}
		}
 
		// Make the bullet icon a bit bigger
		&--disabled.cdx-icon {
			svg {
				width: @spacing-200;
				height: @spacing-200;
			}
		}
 
		&--collapsed.cdx-icon {
			transform: rotate( -90deg );
		}
	}
}
 
[ dir='rtl' ] {
	.ext-wikilambda-app-expanded-toggle {
		.ext-wikilambda-app-expanded-toggle__icon--collapsed.cdx-icon {
			transform: rotate( 90deg );
		}
	}
}
</style>