-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2001] Extract c-file-type-checkboxes from Summary, Authorship and Z…
…oom (#2173) Extract c-file-type-checkboxes from Summary, Authorship and Zoom The checkbox collection is duplicated across many components. Let's abstract them into a separate file.
- Loading branch information
Showing
4 changed files
with
211 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<template lang="pug"> | ||
.checkboxes.mui-form--inline(v-if="fileTypes.length > 0") | ||
label.all-checkbox | ||
input.mui-checkbox--fileType#all(type="checkbox", v-model="isAllChecked", value="all") | ||
span(v-if="allCheckboxLabel", v-bind:title="getTitle(allCheckboxLabel)") | ||
span {{ getLabel(allCheckboxLabel) }} | ||
span(v-else) All | ||
label( | ||
v-for="fileType, index in fileTypes", | ||
v-bind:key="fileType", | ||
v-bind:style="{\ | ||
'background-color': fileTypeColors[fileType],\ | ||
'color': getFontColor(fileTypeColors[fileType])\ | ||
}" | ||
) | ||
input.mui-checkbox--fileType(type="checkbox", v-bind:value="fileType", | ||
v-model="localSelectedFileTypes", v-bind:id="fileType") | ||
span(v-if="fileTypeCheckboxLabels", v-bind:title="getTitle(fileTypeCheckboxLabels[index])") | ||
span {{ getLabel(fileTypeCheckboxLabels[index]) }} | ||
span(v-else) {{ this.fileTypes[index] }} | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, PropType } from 'vue'; | ||
export default defineComponent({ | ||
name: 'c-file-type-checkboxes', | ||
props: { | ||
fileTypes: { | ||
type: Array as PropType<Array<string>>, | ||
required: true, | ||
}, | ||
fileTypeColors: { | ||
type: Object as PropType<Record<string, string>>, | ||
required: true, | ||
}, | ||
selectedFileTypes: { | ||
type: Array as PropType<Array<string>>, | ||
required: true, | ||
}, | ||
allCheckboxLabel: { | ||
type: Object as PropType<{ | ||
fileTitle: string, | ||
fileType: string, | ||
lineCount: number, | ||
blankLineCount: number, | ||
}>, | ||
default: undefined, | ||
}, | ||
fileTypeCheckboxLabels: { | ||
type: Array as PropType<Array<{ | ||
fileTitle: string, | ||
fileType: string, | ||
lineCount: number, | ||
blankLineCount: number, | ||
}>>, | ||
default: undefined, | ||
}, | ||
}, | ||
emits: ['update:selectedFileTypes', 'select-all-checked'], | ||
computed: { | ||
isAllChecked: { | ||
get(): boolean { | ||
return this.selectedFileTypes.length === this.fileTypes.length; | ||
}, | ||
set(value: boolean): void { | ||
if (value) { | ||
this.localSelectedFileTypes = this.fileTypes.slice(); | ||
} else { | ||
this.localSelectedFileTypes = []; | ||
} | ||
this.$emit('select-all-checked', value); | ||
}, | ||
}, | ||
localSelectedFileTypes: { | ||
get(): Array<string> { | ||
return this.selectedFileTypes; | ||
}, | ||
set(value: Array<string>): void { | ||
this.$emit('update:selectedFileTypes', value); | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
getFontColor(color: string): string { | ||
return window.getFontColor(color); | ||
}, | ||
getTitle(label: { | ||
fileTitle: string, | ||
fileType: string, | ||
lineCount: number, | ||
blankLineCount: number, | ||
}): string { | ||
return `${label.fileTitle}: Blank: ${label.blankLineCount}, ` | ||
+ `Non-Blank: ${label.lineCount - label.blankLineCount}`; | ||
}, | ||
getLabel(label: { | ||
fileTitle: string, | ||
fileType: string, | ||
lineCount: number, | ||
blankLineCount: number, | ||
}): string { | ||
return `${label.fileType}\xA0\xA0` | ||
+ `${label.blankLineCount}\xA0\xA0` | ||
+ `(${label.lineCount - label.blankLineCount})\xA0`; | ||
}, | ||
}, | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.all-checkbox { | ||
background-color: #000000; | ||
color: #ffffff; | ||
} | ||
.mui-checkbox--fileType { | ||
vertical-align: middle; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.