Skip to content

Commit b2ff68e

Browse files
committed
fix!: reduce specificity of generated stylesheets to 0
By reducing the specificity of selectors in the generated stylesheets to 0, consumers of Plot can much more easily override these styles using their own stylesheets while still enjoying the default styling of Plot.
1 parent a036954 commit b2ff68e

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/legends/ramp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ export function legendRamp(color, options) {
3838
.call((svg) =>
3939
// Warning: if you edit this, change defaultClassName.
4040
svg.append("style").text(
41-
`.${className}-ramp {
41+
`:where(.${className}-ramp) {
4242
display: block;
4343
height: auto;
4444
height: intrinsic;
4545
max-width: 100%;
4646
overflow: visible;
4747
}
48-
.${className}-ramp text {
48+
:where(.${className}-ramp text) {
4949
white-space: pre;
5050
}`
5151
)

src/legends/swatches.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@ function legendItems(scale, options = {}, swatch) {
9696
let extraStyle;
9797

9898
if (columns != null) {
99-
extraStyle = `.${className}-swatches-columns .${className}-swatch {
99+
extraStyle = `:where(.${className}-swatches-columns .${className}-swatch) {
100100
display: flex;
101101
align-items: center;
102102
break-inside: avoid;
103103
padding-bottom: 1px;
104104
}
105-
.${className}-swatches-columns .${className}-swatch::before {
105+
:where(.${className}-swatches-columns .${className}-swatch::before) {
106106
flex-shrink: 0;
107107
}
108-
.${className}-swatches-columns .${className}-swatch-label {
108+
:where(.${className}-swatches-columns .${className}-swatch-label) {
109109
white-space: nowrap;
110110
overflow: hidden;
111111
text-overflow: ellipsis;
@@ -123,13 +123,13 @@ function legendItems(scale, options = {}, swatch) {
123123
item.append("div").attr("class", `${className}-swatch-label`).attr("title", tickFormat).text(tickFormat)
124124
);
125125
} else {
126-
extraStyle = `.${className}-swatches-wrap {
126+
extraStyle = `:where(.${className}-swatches-wrap) {
127127
display: flex;
128128
align-items: center;
129129
min-height: 33px;
130130
flex-wrap: wrap;
131131
}
132-
.${className}-swatches-wrap .${className}-swatch {
132+
:where(.${className}-swatches-wrap .${className}-swatch) {
133133
display: inline-flex;
134134
align-items: center;
135135
margin-right: 1em;
@@ -150,12 +150,12 @@ function legendItems(scale, options = {}, swatch) {
150150
return swatches
151151
.call((div) =>
152152
div.insert("style", "*").text(
153-
`.${className}-swatches {
153+
`:where(.${className}-swatches) {
154154
font-family: system-ui, sans-serif;
155155
font-size: 10px;
156156
margin-bottom: 0.5em;
157157
}
158-
.${className}-swatch > svg {
158+
:where(.${className}-swatch > svg) {
159159
margin-right: 0.5em;
160160
overflow: visible;
161161
}

src/plot.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,15 @@ export function plot(options = {}) {
257257
.call((svg) =>
258258
// Warning: if you edit this, change defaultClassName.
259259
svg.append("style").text(
260-
`.${className} {
260+
`:where(.${className}) {
261261
--plot-background: white;
262262
display: block;
263263
height: auto;
264264
height: intrinsic;
265265
max-width: 100%;
266266
}
267-
.${className} text,
268-
.${className} tspan {
267+
:where(.${className} text),
268+
:where(.${className} tspan) {
269269
white-space: pre;
270270
}`
271271
)

0 commit comments

Comments
 (0)