-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(color-picker): adds custom color picker (#448)
- Loading branch information
Showing
9 changed files
with
203 additions
and
3 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<template> | ||
<div class="color-well"> | ||
<input @click.prevent="openColorPicker" type="color" v-model="value" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { ipcRenderer } from "electron"; | ||
export default { | ||
props: { | ||
value: { | ||
type: String, | ||
required: true | ||
}, | ||
moduleId: { | ||
type: String, | ||
required: true | ||
}, | ||
prop: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
methods: { | ||
openColorPicker() { | ||
ipcRenderer.send("open-window", "colorPicker"); | ||
ipcRenderer.once("window-ready", (event, { window: windowName, id }) => { | ||
if (windowName !== "colorPicker") { | ||
return; | ||
} | ||
ipcRenderer.sendTo(id, "return-format"); | ||
ipcRenderer.sendTo(id, "module-info", { | ||
moduleId: this.moduleId, | ||
prop: this.prop, | ||
data: this.value | ||
}); | ||
}); | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style></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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<template> | ||
<div> | ||
<Sketch :value="color" @input="updateValue" ref="picker" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { ipcRenderer } from "electron"; | ||
import { Sketch } from "vue-color"; | ||
export default { | ||
components: { | ||
Sketch | ||
}, | ||
data() { | ||
return { | ||
color: "#ff0000ff", | ||
moduleId: null, | ||
prop: null, | ||
// hex, hsl, hsv, rgba | ||
returnFormat: "hex" | ||
}; | ||
}, | ||
created() { | ||
ipcRenderer.on("module-info", (event, { moduleId, prop, data }) => { | ||
this.moduleId = moduleId; | ||
this.prop = prop; | ||
this.color = data; | ||
}); | ||
ipcRenderer.on("value", (event, message) => { | ||
this.color = message; | ||
}); | ||
ipcRenderer.on("return-format", (event, message) => { | ||
this.returnFormat = message; | ||
}); | ||
}, | ||
mounted() { | ||
window.addEventListener("resize", this.resize); | ||
this.resize(); | ||
}, | ||
beforeDestroy() { | ||
window.removeEventListener("resize", this.resize); | ||
}, | ||
methods: { | ||
resize(e) { | ||
const pickerRect = this.$refs.picker.$el.getBoundingClientRect(); | ||
if (e) { | ||
e.preventDefault(); | ||
} | ||
window.resizeTo(pickerRect.width, pickerRect.height); | ||
}, | ||
updateValue(color) { | ||
this.color = color; | ||
ipcRenderer.send("input-update", { | ||
moduleId: this.moduleId, | ||
prop: this.prop, | ||
data: color[this.returnFormat] | ||
}); | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style> | ||
body { | ||
margin: 0; | ||
-webkit-app-region: drag; | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, | ||
"Helvetica Neue", "微軟雅黑", "Microsoft YaHei", "微軟正黑體", | ||
"Microsoft JhengHei", Verdana, Arial, sans-serif !important; | ||
} | ||
.vc-sketch > * { | ||
-webkit-app-region: no-drag; | ||
} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Vue from "vue"; | ||
|
||
import App from "./App.vue"; | ||
|
||
window.Vue = new Vue({ | ||
render: h => h(App) | ||
}).$mount("#app"); |
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