Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
style.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihe774 committed Dec 1, 2023
1 parent 4bcffd3 commit dc7c709
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
5 changes: 1 addition & 4 deletions src/components/BrightnessPanel.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<script setup lang="ts">
import ColorProvider from "./ColorProvider.vue";
import MonitorList from "./MonitorList.vue";
</script>

<template>
<ColorProvider>
<MonitorList />
</ColorProvider>
<MonitorList />
</template>
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { watchThrottled } from "./watchers";
import monitorManager from "./monitor";
import BrightnessPanel from "./components/BrightnessPanel.vue";
import panelState from "./wm";
import "./style";
import "./style.global.sass";

createApp(BrightnessPanel).mount("#root");
Expand Down
25 changes: 9 additions & 16 deletions src/components/ColorProvider.vue → src/style.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script setup lang="ts">
import { invoke } from "@tauri-apps/api";
import { computed, reactive } from "vue";
import { watchThrottled } from "../watchers";
import panelState from "../wm";
import { watchEffect, reactive } from "vue";
import { watchThrottled } from "./watchers";
import panelState from "./wm";

interface Color {
r: number;
Expand All @@ -21,19 +20,13 @@ watchThrottled(
{ throttle: 1000, immediate: true },
);

const style = computed(() => {
const style: string[] = [];
const html: HTMLHtmlElement = document.querySelector(":root")!;

watchEffect(() => {
for (const [name, { r, g, b }] of Object.entries(colors)) {
style.push(
`--${name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()}:rgb(${r},${g},${b})`,
html.style.setProperty(
`--${name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()}`,
`rgb(${r},${g},${b})`,
);
}
return style.join(";");
});
</script>

<template>
<div :style="style">
<slot />
</div>
</template>

0 comments on commit dc7c709

Please sign in to comment.