Skip to content

Commit 6c4de96

Browse files
authored
Merge pull request #227 from CosmoCreeper/main
2 parents 5f7ba34 + 51e357b commit 6c4de96

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

content/docs/themes-store/themes-marketplace-preferences.mdx

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,11 @@ In this example:
209209

210210
Once you have defined your preferences in the `preferences.json` file, you can use them in your mod’s CSS to modify the appearance or behavior based on the user’s selections.
211211

212+
To detect preference changes in CSS, we are going to be using a universal `-moz-pref` media query.
213+
212214
### Checkbox Preferences
213215

214-
Checkbox preferences can be detected in your CSS using the `-moz-bool-pref` media query, which evaluates the boolean value (`true` or `false`) of a checkbox preference.
216+
Checkbox preferences can be detected in your CSS using the `-moz-pref` media query, which evaluates the boolean value (`true` or `false`, amongst other things) of a checkbox preference.
215217

216218
For example, if you have a preference to enable dark mode in your mod:
217219

@@ -226,7 +228,7 @@ For example, if you have a preference to enable dark mode in your mod:
226228
You can use the following CSS to change the background color when the dark mode preference is enabled:
227229

228230
```css {1}
229-
@media (-moz-bool-pref: "mod.mymod.enable_dark_mode") {
231+
@media (-moz-pref("mod.mymod.enable_dark_mode")) {
230232
body {
231233
background-color: #000;
232234
color: #fff;
@@ -237,19 +239,12 @@ You can use the following CSS to change the background color when the dark mode
237239
You can also have negative conditions
238240

239241
```css {1}
240-
@media not (-moz-bool-pref: "mod.mymod.enable_dark_mode");
242+
@media not (-moz-pref("mod.mymod.enable_dark_mode"));
241243
```
242244

243245
### Dropdown Preferences
244246

245-
<Callout type="warn" title="Attention">
246-
`property` fields defined in `preferences.json` using the `"dropdown"` type will have one key difference when used in your mod's CSS: <strong>dots (`.`) in the `property` name are replaced with hyphens (`-`)</strong>.
247-
248-
E.g. `mod.mymod.background_color` becomes `mod-mymod-background_color` in the CSS file.
249-
This transformation ensures that the property can be used as an attribute selector or inside a media query.
250-
</Callout>
251-
252-
For dropdown preferences, you can detect the selected value using the `:has(){:css}` CSS pseudo-class, which applies styles based on the selected attribute and value in the DOM.
247+
For dropdown preferences, you can detect the selected value using the `-moz-pref` media query, which compares the value of a preference and a certain value you provide it.
253248

254249
For example, if you have a preference to select the background color from a dropdown menu:
255250

@@ -274,23 +269,25 @@ For example, if you have a preference to select the background color from a drop
274269
You can use the following CSS to change the background color based on the selected value:
275270

276271
```css {2,8,14}
277-
/* Green background */
278-
body:has(#mod-mymod[mod-mymod-background_color="green"]) {
279-
background-color: #008000;
280-
color: #000;
281-
}
272+
body {
273+
/* Green background */
274+
@media (-moz-pref("mod.mymod.background_color", "green")) {
275+
background-color: #008000;
276+
color: #000;
277+
}
282278

283-
/* Blue background */
284-
body:has(#mod-mymod[mod-mymod-background_color="blue"]) {
285-
background-color: #0000ff;
286-
color: #fff;
279+
/* Blue background */
280+
@media (-moz-pref("mod.mymod.background_color", "blue")) {
281+
background-color: #0000ff;
282+
color: #fff;
283+
}
287284
}
288285
```
289286

290287
In this example:
291288

292289
- The background color and text color change based on the value selected in the `background_color` dropdown.
293-
- The selector `body:has(#mod-mymod[background_color="value"]){:css}` checks the `background_color` attribute and applies the relevant styles based on the selected option.
290+
- The selector `@media (-moz-pref("mod.mymod.background_color", "value")){:css}` checks the `background_color` attribute and applies the relevant styles based on the selected option.
294291

295292
---
296293

@@ -327,22 +324,24 @@ You can combine the CSS like this:
327324

328325
```css
329326
/* Checkbox for dark mode */
330-
@media (-moz-bool-pref: "mod.mymod.enable_dark_mode") {
327+
@media (-moz-pref("mod.mymod.enable_dark_mode")) {
331328
body {
332329
background-color: #000;
333330
color: #fff;
334331
}
335332
}
336333

337334
/* Dropdown for background color selection */
338-
body:has(#mod-mymod[mod-mymod-background_color="green"]) {
339-
background-color: #008000;
340-
color: #000;
341-
}
335+
body {
336+
@media (-moz-pref("mod.mymod.background_color", "green")) {
337+
background-color: #008000;
338+
color: #000;
339+
}
342340

343-
body:has(#mod-mymod[mod-mymod-background_color="blue"]) {
344-
background-color: #0000ff;
345-
color: #fff;
341+
@media (-moz-pref("mod.mymod.background_color", "blue")) {
342+
background-color: #0000ff;
343+
color: #fff;
344+
}
346345
}
347346
```
348347

0 commit comments

Comments
 (0)