2021-08-29 04:36:17 -07:00
|
|
|
<template>
|
|
|
|
<table :class="$style.table">
|
|
|
|
<tr>
|
|
|
|
<th :class="$style.row">Name</th>
|
|
|
|
<th :class="$style.row">rem</th>
|
|
|
|
<th :class="$style.row">px</th>
|
|
|
|
</tr>
|
|
|
|
<tr
|
|
|
|
v-for="variable in variables"
|
|
|
|
:key="variable"
|
|
|
|
:style="attr ? { [attr]: `var(${variable})` } : {}"
|
|
|
|
>
|
|
|
|
<td>{{ variable }}</td>
|
|
|
|
<td>{{ sizes[variable].rem }}</td>
|
|
|
|
<td>{{ sizes[variable].px }}</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-04-12 07:39:45 -07:00
|
|
|
import { defineComponent, PropType } from 'vue';
|
2021-08-29 04:36:17 -07:00
|
|
|
|
2023-04-12 07:39:45 -07:00
|
|
|
export default defineComponent({
|
2021-08-29 04:36:17 -07:00
|
|
|
name: 'sizes',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
observer: null as null | MutationObserver,
|
2023-04-12 07:39:45 -07:00
|
|
|
sizes: {} as Record<string, { rem: string; px: number }>,
|
2021-08-29 04:36:17 -07:00
|
|
|
};
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
variables: {
|
2023-04-12 07:39:45 -07:00
|
|
|
type: Array as PropType<string[]>,
|
2021-08-29 04:36:17 -07:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
attr: {
|
|
|
|
type: String,
|
2023-04-12 07:39:45 -07:00
|
|
|
default: '',
|
2021-08-29 04:36:17 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
const setSizes = () => {
|
2023-04-12 07:39:45 -07:00
|
|
|
this.variables.forEach((variable: string) => {
|
2021-08-29 04:36:17 -07:00
|
|
|
const style = getComputedStyle(document.body);
|
|
|
|
const rem = style.getPropertyValue(variable);
|
|
|
|
const px = parseFloat(rem.replace('rem', '')) * 16;
|
|
|
|
|
2023-04-12 07:39:45 -07:00
|
|
|
this.$set(this.sizes, variable, { rem, px });
|
2021-08-29 04:36:17 -07:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
setSizes();
|
|
|
|
|
|
|
|
// when theme class is added or removed, reset color values
|
|
|
|
this.observer = new MutationObserver((mutationsList) => {
|
|
|
|
for (const mutation of mutationsList) {
|
|
|
|
if (mutation.type === 'attributes') {
|
|
|
|
setSizes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const body = document.querySelector('body');
|
|
|
|
if (body) {
|
|
|
|
this.observer.observe(body, { attributes: true });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
destroyed() {
|
|
|
|
if (this.observer) {
|
|
|
|
this.observer.disconnect();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.table {
|
|
|
|
text-align: center;
|
|
|
|
color: var(--color-text-dark);
|
|
|
|
}
|
|
|
|
|
|
|
|
.row {
|
|
|
|
min-width: 150px;
|
|
|
|
}
|
|
|
|
</style>
|