|
| 1 | +<template> |
| 2 | + <li class="configuration-category__root"> |
| 3 | + <!-- Header --> |
| 4 | + <label class="configuration-category__header"> |
| 5 | + <input type="checkbox" v-model="opened" style="display:none"> |
| 6 | + <md-icon :kind="opened ? 'expand_more' : 'chevron_right'"/> |
| 7 | + {{ header }} |
| 8 | + <span v-if="headerPeek" class="configuration-category__header-peek"> |
| 9 | + {{ headerPeek }} |
| 10 | + </span> |
| 11 | + </label> |
| 12 | + <!-- Body --> |
| 13 | + <ul v-if="opened" class="configuration-category__body"> |
| 14 | + <li v-if="multi && items.length >= 2"> |
| 15 | + <label class="configuration-category__select-item"> |
| 16 | + <div class="configuration-category__select-item-check"> |
| 17 | + <input |
| 18 | + type="checkbox" |
| 19 | + :checked="allItemsAreChecked" |
| 20 | + @change="$emit('change', null, !allItemsAreChecked)" |
| 21 | + > |
| 22 | + </div> |
| 23 | + <div class="configuration-category__select-item-name"> |
| 24 | + (all rules) |
| 25 | + </div> |
| 26 | + </label> |
| 27 | + </li> |
| 28 | + <li v-for="item of items" :key="item.id" :title="item.description"> |
| 29 | + <label class="configuration-category__select-item"> |
| 30 | + <div class="configuration-category__select-item-check"> |
| 31 | + <input |
| 32 | + :type="selectType" |
| 33 | + :value="item.id" |
| 34 | + :checked="item.checked" |
| 35 | + @change="$emit('change', item.id, $event.target.checked)" |
| 36 | + > |
| 37 | + </div> |
| 38 | + <div class="configuration-category__select-item-name"> |
| 39 | + {{ item.name }} |
| 40 | + </div> |
| 41 | + <a v-if="item.url" class="configuration-category__select-item-link" :href="item.url" target="_blank" rel="noopener"> |
| 42 | + <md-icon kind="launch"/> |
| 43 | + </a> |
| 44 | + </label> |
| 45 | + </li> |
| 46 | + </ul> |
| 47 | + </li> |
| 48 | +</template> |
| 49 | + |
| 50 | +<script> |
| 51 | +import MdIcon from "./md-icon.vue" |
| 52 | +
|
| 53 | +export default { |
| 54 | + name: "ConfigurationCategory", |
| 55 | +
|
| 56 | + components: { MdIcon }, |
| 57 | +
|
| 58 | + props: { |
| 59 | + header: { |
| 60 | + type: String, |
| 61 | + default: "", |
| 62 | + }, |
| 63 | + headerPeek: { |
| 64 | + type: String, |
| 65 | + default: "", |
| 66 | + }, |
| 67 | + items: { |
| 68 | + type: Array, |
| 69 | + default() { |
| 70 | + return [] |
| 71 | + }, |
| 72 | + }, |
| 73 | + multi: { |
| 74 | + type: Boolean, |
| 75 | + default: false, |
| 76 | + }, |
| 77 | + }, |
| 78 | +
|
| 79 | + data() { |
| 80 | + return { opened: false } |
| 81 | + }, |
| 82 | +
|
| 83 | + computed: { |
| 84 | + selectType() { |
| 85 | + return this.multi ? "checkbox" : "radio" |
| 86 | + }, |
| 87 | +
|
| 88 | + allItemsAreChecked() { |
| 89 | + return this.items.every(item => item.checked) |
| 90 | + }, |
| 91 | + }, |
| 92 | +} |
| 93 | +</script> |
| 94 | + |
| 95 | +<style> |
| 96 | +.configuration-category__root { |
| 97 | + list-style: none; |
| 98 | + margin: 0; |
| 99 | + padding: 0; |
| 100 | +} |
| 101 | +
|
| 102 | +.configuration-category__header { |
| 103 | + display: block; |
| 104 | + position: sticky; |
| 105 | + top: 0; |
| 106 | + padding: 8px; |
| 107 | + background-color: #E8F5E9; |
| 108 | + border-bottom: 1px solid #4CAF50; |
| 109 | + font-weight: bold; |
| 110 | + cursor: pointer; |
| 111 | + box-shadow: 0 2px 2px rgba(0,0,0, 0.25); |
| 112 | +} |
| 113 | +.configuration-category__header-peek { |
| 114 | + white-space: nowrap; |
| 115 | + font-weight: normal; |
| 116 | + color: gray; |
| 117 | +} |
| 118 | +
|
| 119 | +.configuration-category__body { |
| 120 | + list-style: none; |
| 121 | + margin: 0; |
| 122 | + padding: 0; |
| 123 | + background-color: white; |
| 124 | +} |
| 125 | +
|
| 126 | +.configuration-category__select-item { |
| 127 | + display: flex; |
| 128 | + align-items: center; |
| 129 | + padding: 4px; |
| 130 | + padding-left: 16px; |
| 131 | + border-bottom: 1px solid #E8F5E9; |
| 132 | +} |
| 133 | +li:last-child > .configuration-category__select-item { |
| 134 | + border-bottom: 1px solid #4CAF50; |
| 135 | +} |
| 136 | +
|
| 137 | +.configuration-category__header:hover, |
| 138 | +.configuration-category__select-item:hover { |
| 139 | + background-image: linear-gradient(to bottom, rgba(0,0,0,0.065), rgba(0,0,0,0.0325) 67%, rgba(0,0,0,0.065)); |
| 140 | +} |
| 141 | +
|
| 142 | +.configuration-category__select-item-check { |
| 143 | + flex-shrink: 0; |
| 144 | + padding-top: 4px; /* align to the rule name */ |
| 145 | + padding-right: 4px; |
| 146 | +} |
| 147 | +.configuration-category__select-item-name { |
| 148 | + flex-grow: 1; |
| 149 | +} |
| 150 | +.configuration-category__select-item-link { |
| 151 | + display: block; |
| 152 | + flex-shrink: 0; |
| 153 | +} |
| 154 | +</style> |
0 commit comments