|
| 1 | +<script lang="ts"> |
| 2 | +import { defineComponent } from "vue"; |
| 3 | +import XNColorPicker from "xncolorpicker/src/xncolorpicker"; |
| 4 | +
|
| 5 | +export default defineComponent({ |
| 6 | + data: () => ({ |
| 7 | + text: "", |
| 8 | + fontColor: "#563d7c", |
| 9 | + backgroundColor: "mediumturquoise", |
| 10 | + }), |
| 11 | + methods: { |
| 12 | + getColor: (color: XNColorPicker.Color) => |
| 13 | + color.colorType === "single" ? color.color.hex : color.color.str, |
| 14 | + setBackgroundColor(color: XNColorPicker.Color) { |
| 15 | + this.backgroundColor = this.getColor(color); |
| 16 | + }, |
| 17 | + }, |
| 18 | + mounted() { |
| 19 | + new XNColorPicker({ |
| 20 | + color: this.backgroundColor, |
| 21 | + selector: "#colorpicker", |
| 22 | + onCancel: this.setBackgroundColor, |
| 23 | + onChange: this.setBackgroundColor, |
| 24 | + onConfirm: this.setBackgroundColor, |
| 25 | + }); |
| 26 | + }, |
| 27 | +}); |
| 28 | +</script> |
| 29 | + |
| 30 | +<template> |
| 31 | + <form class="mt-3"> |
| 32 | + <div class="mb-3"> |
| 33 | + <label for="badgeText" class="form-label">Text</label> |
| 34 | + <input |
| 35 | + type="text" |
| 36 | + class="form-control w-auto" |
| 37 | + id="badgeText" |
| 38 | + placeholder="badge" |
| 39 | + aria-describedby="badgeTextHelpInline" |
| 40 | + :value="text" |
| 41 | + /> |
| 42 | + <span id="badgeTextHelpInline" class="form-text"> |
| 43 | + Must be 0-16 characters long. |
| 44 | + </span> |
| 45 | + </div> |
| 46 | + <div class="row"> |
| 47 | + <div class="col-6"> |
| 48 | + <label for="badgeFontColor" class="form-label">Font color</label> |
| 49 | + <input |
| 50 | + type="color" |
| 51 | + class="form-control form-control-color" |
| 52 | + id="badgeFontColor" |
| 53 | + title="Choose your color" |
| 54 | + :value="fontColor" |
| 55 | + /> |
| 56 | + </div> |
| 57 | + <div class="col-6"> |
| 58 | + <label class="form-label">Background color</label> |
| 59 | + <div id="colorpicker" class="form-control form-control-color"></div> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + </form> |
| 63 | +</template> |
| 64 | + |
| 65 | +<style lang="scss" scoped> |
| 66 | +@import "bootstrap/scss/functions"; |
| 67 | +
|
| 68 | +@import "bootstrap/scss/variables"; |
| 69 | +
|
| 70 | +@import "bootstrap/scss/maps"; |
| 71 | +@import "bootstrap/scss/mixins"; |
| 72 | +@import "bootstrap/scss/root"; |
| 73 | +
|
| 74 | +@import "bootstrap/scss/utilities"; |
| 75 | +@import "bootstrap/scss/reboot"; |
| 76 | +@import "bootstrap/scss/grid"; |
| 77 | +@import "bootstrap/scss/forms"; |
| 78 | +
|
| 79 | +@import "bootstrap/scss/utilities/api"; |
| 80 | +</style> |
| 81 | + |
| 82 | +<style scoped> |
| 83 | +#colorpicker { |
| 84 | + height: 3rem; |
| 85 | +} |
| 86 | +</style> |
| 87 | + |
| 88 | +<style> |
| 89 | +.fcolorpicker-curbox { |
| 90 | + height: 100%; |
| 91 | + width: 100%; |
| 92 | +} |
| 93 | +</style> |
0 commit comments