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

Commit a8563c2

Browse files
committed
Do not set CSS variables if they are equal to the default values.
1 parent 0a981bd commit a8563c2

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ What is
250250

251251
## Options
252252

253-
Pass any of the options listed below to `Vue.use(VueCustomTooltip, {...})` to customize the plugin for your project _(not available with [in-component installation](#in-component-install))_.
253+
Pass any of the options listed below to `Vue.use(VueCustomTooltip, {...})` to customize the plugin for your project _(not available with [in-component installation](#in-component-install) - see the [CSS Variables section](#css-variables) below)_.
254254

255255
> **A note on options tied to CSS properties**
256256
>
@@ -339,6 +339,20 @@ Vue.use(VueCustomTooltip, {
339339
})
340340
```
341341

342+
## CSS Variables
343+
344+
In addition to customizing styles via the [Plugin Options](#options), you can alternatively choose to customize styles via CSS variables as shown below:
345+
346+
```css
347+
/* Default values are shown */
348+
:root {
349+
--vue-custom-tooltip-color: #fff;
350+
--vue-custom-tooltip-background: #000;
351+
--vue-custom-tooltip-border-radius: 100px;
352+
--vue-custom-tooltip-font-weight: 400;
353+
}
354+
```
355+
342356
## Props
343357

344358
In addition to the [Plugin Options](#options) above, you may also pass props to the component itself to customize both the look and behavior of the tooltip element.

src/VueCustomTooltip.vue

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,24 @@ export default defineComponent({
3838
const htmlRoot: HTMLElement | null = document && document.documentElement ? document.documentElement : null
3939
if (htmlRoot) {
4040
/* eslint-disable @typescript-eslint/no-non-null-assertion */
41-
htmlRoot.style.setProperty('--vue-custom-tooltip-color', tooltipOptions.color!)
42-
htmlRoot.style.setProperty('--vue-custom-tooltip-background', tooltipOptions.background!)
43-
htmlRoot.style.setProperty('--vue-custom-tooltip-border-radius', `${tooltipOptions.borderRadius!}px`)
44-
htmlRoot.style.setProperty('--vue-custom-tooltip-font-weight', tooltipOptions.fontWeight!.toString())
41+
htmlRoot.style.setProperty(
42+
'--vue-custom-tooltip-color',
43+
tooltipOptions.color !== defaultTooltipOptions.color ? tooltipOptions.color! : null,
44+
)
45+
htmlRoot.style.setProperty(
46+
'--vue-custom-tooltip-background',
47+
tooltipOptions.background !== defaultTooltipOptions.background ? tooltipOptions.background! : null,
48+
)
49+
htmlRoot.style.setProperty(
50+
'--vue-custom-tooltip-border-radius',
51+
tooltipOptions.borderRadius !== defaultTooltipOptions.borderRadius
52+
? `${tooltipOptions.borderRadius!}px`
53+
: null,
54+
)
55+
htmlRoot.style.setProperty(
56+
'--vue-custom-tooltip-font-weight',
57+
tooltipOptions.fontWeight !== defaultTooltipOptions.fontWeight ? tooltipOptions.fontWeight!.toString() : null,
58+
)
4559
/* eslint-enable @typescript-eslint/no-non-null-assertion */
4660
}
4761
}

0 commit comments

Comments
 (0)