Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(playground): color picker doesn't work with css variable #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions playground/components.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// generated by unplugin-vue-components
// We suggest you to commit this file into source control
// Read more: https://github.com/vuejs/vue-next/pull/3399
// Read more: https://github.com/vuejs/core/pull/3399
import '@vue/runtime-core'

export {}

declare module '@vue/runtime-core' {
export interface GlobalComponents {
CarbonDocumentDownload: typeof import('~icons/carbon/document-download')['default']
Expand All @@ -13,5 +15,3 @@ declare module '@vue/runtime-core' {
VarItem: typeof import('./src/components/VarItem.vue')['default']
}
}

export {}
14 changes: 13 additions & 1 deletion playground/src/components/VarItem.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import type { Ref } from 'vue'
import { computed } from 'vue'
import { colors } from '../store'

const props = defineProps<{ id: string; value: Ref<string> }>()

Expand All @@ -22,6 +23,17 @@ const style = computed(() =>
),
)

const color = computed({
get() {
const variableRe = /^var\((--prism-.+?)\)$/
const key = value.value.match(variableRe)?.[1]
return key ? colors[key] : value.value
},
set(val: string) {
value.value = val
},
})

const NonStyleAttrs = [
'padding',
'margin',
Expand Down Expand Up @@ -63,7 +75,7 @@ function onclick() {
>
<input
v-if="type === 'color'"
v-model="value"
v-model="color"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we bound v-model with a computed, it will make all color picker readonly

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

type="color"
class="m-auto ml-4 bg-transparent w-8 h-9 border-none outline-none "
>
Expand Down