Skip to content

Commit 46e6f7a

Browse files
authored
fix: styling of chart legend reset every click (#1125)
1 parent 9c12ebb commit 46e6f7a

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

apps/www/src/public/r/styles/default/chart.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
{
2020
"path": "ui/chart/ChartLegend.vue",
21-
"content": "<script setup lang=\"ts\">\nimport type { BulletLegendItemInterface } from '@unovis/ts'\nimport { buttonVariants } from '@/registry/default/ui/button'\nimport { BulletLegend } from '@unovis/ts'\nimport { VisBulletLegend } from '@unovis/vue'\nimport { nextTick, onMounted, ref } from 'vue'\n\nconst props = withDefaults(defineProps<{ items: BulletLegendItemInterface[] }>(), {\n items: () => [],\n})\n\nconst emits = defineEmits<{\n 'legendItemClick': [d: BulletLegendItemInterface, i: number]\n 'update:items': [payload: BulletLegendItemInterface[]]\n}>()\n\nconst elRef = ref<HTMLElement>()\n\nonMounted(() => {\n const selector = `.${BulletLegend.selectors.item}`\n nextTick(() => {\n const elements = elRef.value?.querySelectorAll(selector)\n const classes = buttonVariants({ variant: 'ghost', size: 'sm' }).split(' ')\n elements?.forEach(el => el.classList.add(...classes, '!inline-flex', '!mr-2'))\n })\n})\n\nfunction onLegendItemClick(d: BulletLegendItemInterface, i: number) {\n emits('legendItemClick', d, i)\n const isBulletActive = !props.items[i].inactive\n const isFilterApplied = props.items.some(i => i.inactive)\n if (isFilterApplied && isBulletActive) {\n // reset filter\n emits('update:items', props.items.map(item => ({ ...item, inactive: false })))\n }\n else {\n // apply selection, set other item as inactive\n emits('update:items', props.items.map(item => item.name === d.name ? ({ ...d, inactive: false }) : { ...item, inactive: true }))\n }\n}\n</script>\n\n<template>\n <div ref=\"elRef\" class=\"w-max\">\n <VisBulletLegend\n :items=\"items\"\n :on-legend-item-click=\"onLegendItemClick\"\n />\n </div>\n</template>\n",
21+
"content": "<script setup lang=\"ts\">\nimport type { BulletLegendItemInterface } from '@unovis/ts'\nimport { buttonVariants } from '@/registry/default/ui/button'\nimport { BulletLegend } from '@unovis/ts'\nimport { VisBulletLegend } from '@unovis/vue'\nimport { nextTick, onMounted, ref } from 'vue'\n\nconst props = withDefaults(defineProps<{ items: BulletLegendItemInterface[] }>(), {\n items: () => [],\n})\n\nconst emits = defineEmits<{\n 'legendItemClick': [d: BulletLegendItemInterface, i: number]\n 'update:items': [payload: BulletLegendItemInterface[]]\n}>()\n\nconst elRef = ref<HTMLElement>()\n\nfunction keepStyling() {\n const selector = `.${BulletLegend.selectors.item}`\n nextTick(() => {\n const elements = elRef.value?.querySelectorAll(selector)\n const classes = buttonVariants({ variant: 'ghost', size: 'sm' }).split(' ')\n elements?.forEach(el => el.classList.add(...classes, '!inline-flex', '!mr-2'))\n })\n}\n\nonMounted(() => {\n keepStyling()\n})\n\nfunction onLegendItemClick(d: BulletLegendItemInterface, i: number) {\n emits('legendItemClick', d, i)\n const isBulletActive = !props.items[i].inactive\n const isFilterApplied = props.items.some(i => i.inactive)\n if (isFilterApplied && isBulletActive) {\n // reset filter\n emits('update:items', props.items.map(item => ({ ...item, inactive: false })))\n }\n else {\n // apply selection, set other item as inactive\n emits('update:items', props.items.map(item => item.name === d.name ? ({ ...d, inactive: false }) : { ...item, inactive: true }))\n }\n keepStyling()\n}\n</script>\n\n<template>\n <div\n ref=\"elRef\" class=\"w-max\" :style=\"{\n '--vis-legend-bullet-size': '16px',\n }\"\n >\n <VisBulletLegend\n :items=\"items\"\n :on-legend-item-click=\"onLegendItemClick\"\n />\n </div>\n</template>\n",
2222
"type": "registry:ui",
2323
"target": ""
2424
},

apps/www/src/public/r/styles/new-york/chart.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
{
2020
"path": "ui/chart/ChartLegend.vue",
21-
"content": "<script setup lang=\"ts\">\nimport type { BulletLegendItemInterface } from '@unovis/ts'\nimport { buttonVariants } from '@/registry/new-york/ui/button'\nimport { BulletLegend } from '@unovis/ts'\nimport { VisBulletLegend } from '@unovis/vue'\nimport { nextTick, onMounted, ref } from 'vue'\n\nconst props = withDefaults(defineProps<{ items: BulletLegendItemInterface[] }>(), {\n items: () => [],\n})\n\nconst emits = defineEmits<{\n 'legendItemClick': [d: BulletLegendItemInterface, i: number]\n 'update:items': [payload: BulletLegendItemInterface[]]\n}>()\n\nconst elRef = ref<HTMLElement>()\n\nonMounted(() => {\n const selector = `.${BulletLegend.selectors.item}`\n nextTick(() => {\n const elements = elRef.value?.querySelectorAll(selector)\n const classes = buttonVariants({ variant: 'ghost', size: 'xs' }).split(' ')\n\n elements?.forEach(el => el.classList.add(...classes, '!inline-flex', '!mr-2'))\n })\n})\n\nfunction onLegendItemClick(d: BulletLegendItemInterface, i: number) {\n emits('legendItemClick', d, i)\n const isBulletActive = !props.items[i].inactive\n const isFilterApplied = props.items.some(i => i.inactive)\n if (isFilterApplied && isBulletActive) {\n // reset filter\n emits('update:items', props.items.map(item => ({ ...item, inactive: false })))\n }\n else {\n // apply selection, set other item as inactive\n emits('update:items', props.items.map(item => item.name === d.name ? ({ ...d, inactive: false }) : { ...item, inactive: true }))\n }\n}\n</script>\n\n<template>\n <div ref=\"elRef\" class=\"w-max\">\n <VisBulletLegend\n :items=\"items\"\n :on-legend-item-click=\"onLegendItemClick\"\n />\n </div>\n</template>\n",
21+
"content": "<script setup lang=\"ts\">\nimport type { BulletLegendItemInterface } from '@unovis/ts'\nimport { buttonVariants } from '@/registry/new-york/ui/button'\nimport { BulletLegend } from '@unovis/ts'\nimport { VisBulletLegend } from '@unovis/vue'\nimport { nextTick, onMounted, ref } from 'vue'\n\nconst props = withDefaults(defineProps<{ items: BulletLegendItemInterface[] }>(), {\n items: () => [],\n})\n\nconst emits = defineEmits<{\n 'legendItemClick': [d: BulletLegendItemInterface, i: number]\n 'update:items': [payload: BulletLegendItemInterface[]]\n}>()\n\nconst elRef = ref<HTMLElement>()\n\nfunction keepStyling() {\n const selector = `.${BulletLegend.selectors.item}`\n nextTick(() => {\n const elements = elRef.value?.querySelectorAll(selector)\n const classes = buttonVariants({ variant: 'ghost', size: 'xs' }).split(' ')\n\n elements?.forEach(el => el.classList.add(...classes, '!inline-flex', '!mr-2'))\n })\n}\n\nonMounted(() => {\n keepStyling()\n})\n\nfunction onLegendItemClick(d: BulletLegendItemInterface, i: number) {\n emits('legendItemClick', d, i)\n const isBulletActive = !props.items[i].inactive\n const isFilterApplied = props.items.some(i => i.inactive)\n if (isFilterApplied && isBulletActive) {\n // reset filter\n emits('update:items', props.items.map(item => ({ ...item, inactive: false })))\n }\n else {\n // apply selection, set other item as inactive\n emits('update:items', props.items.map(item => item.name === d.name ? ({ ...d, inactive: false }) : { ...item, inactive: true }))\n }\n keepStyling()\n}\n</script>\n\n<template>\n <div\n ref=\"elRef\" class=\"w-max\" :style=\"{\n '--vis-legend-bullet-size': '16px',\n }\"\n >\n <VisBulletLegend\n :items=\"items\"\n :on-legend-item-click=\"onLegendItemClick\"\n />\n </div>\n</template>\n",
2222
"type": "registry:ui",
2323
"target": ""
2424
},

apps/www/src/registry/default/ui/chart/ChartLegend.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ const emits = defineEmits<{
1616
1717
const elRef = ref<HTMLElement>()
1818
19-
onMounted(() => {
19+
function keepStyling() {
2020
const selector = `.${BulletLegend.selectors.item}`
2121
nextTick(() => {
2222
const elements = elRef.value?.querySelectorAll(selector)
2323
const classes = buttonVariants({ variant: 'ghost', size: 'sm' }).split(' ')
2424
elements?.forEach(el => el.classList.add(...classes, '!inline-flex', '!mr-2'))
2525
})
26+
}
27+
28+
onMounted(() => {
29+
keepStyling()
2630
})
2731
2832
function onLegendItemClick(d: BulletLegendItemInterface, i: number) {
@@ -37,11 +41,16 @@ function onLegendItemClick(d: BulletLegendItemInterface, i: number) {
3741
// apply selection, set other item as inactive
3842
emits('update:items', props.items.map(item => item.name === d.name ? ({ ...d, inactive: false }) : { ...item, inactive: true }))
3943
}
44+
keepStyling()
4045
}
4146
</script>
4247

4348
<template>
44-
<div ref="elRef" class="w-max">
49+
<div
50+
ref="elRef" class="w-max" :style="{
51+
'--vis-legend-bullet-size': '16px',
52+
}"
53+
>
4554
<VisBulletLegend
4655
:items="items"
4756
:on-legend-item-click="onLegendItemClick"

apps/www/src/registry/new-york/ui/chart/ChartLegend.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ const emits = defineEmits<{
1616
1717
const elRef = ref<HTMLElement>()
1818
19-
onMounted(() => {
19+
function keepStyling() {
2020
const selector = `.${BulletLegend.selectors.item}`
2121
nextTick(() => {
2222
const elements = elRef.value?.querySelectorAll(selector)
2323
const classes = buttonVariants({ variant: 'ghost', size: 'xs' }).split(' ')
2424
2525
elements?.forEach(el => el.classList.add(...classes, '!inline-flex', '!mr-2'))
2626
})
27+
}
28+
29+
onMounted(() => {
30+
keepStyling()
2731
})
2832
2933
function onLegendItemClick(d: BulletLegendItemInterface, i: number) {
@@ -38,11 +42,16 @@ function onLegendItemClick(d: BulletLegendItemInterface, i: number) {
3842
// apply selection, set other item as inactive
3943
emits('update:items', props.items.map(item => item.name === d.name ? ({ ...d, inactive: false }) : { ...item, inactive: true }))
4044
}
45+
keepStyling()
4146
}
4247
</script>
4348

4449
<template>
45-
<div ref="elRef" class="w-max">
50+
<div
51+
ref="elRef" class="w-max" :style="{
52+
'--vis-legend-bullet-size': '16px',
53+
}"
54+
>
4655
<VisBulletLegend
4756
:items="items"
4857
:on-legend-item-click="onLegendItemClick"

packages/cli/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits)
866866
<template>
867867
<DialogPortal>
868868
<DialogOverlay
869-
class="fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"
869+
class="fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"
870870
/>
871871
<DialogContent
872872
v-bind="forwarded"
@@ -999,7 +999,7 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits)
999999
<template>
10001000
<DialogPortal>
10011001
<DialogOverlay
1002-
class="fixed inset-0 z-50 grid place-items-center overflow-y-auto bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"
1002+
class="fixed inset-0 z-50 grid place-items-center overflow-y-auto bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"
10031003
>
10041004
<DialogContent
10051005
:class="

0 commit comments

Comments
 (0)