You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/themes-store/themes-marketplace-preferences.mdx
+28-29Lines changed: 28 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -209,9 +209,11 @@ In this example:
209
209
210
210
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.
211
211
212
+
To detect preference changes in CSS, we are going to be using a universal `-moz-pref` media query.
213
+
212
214
### Checkbox Preferences
213
215
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.
215
217
216
218
For example, if you have a preference to enable dark mode in your mod:
217
219
@@ -226,7 +228,7 @@ For example, if you have a preference to enable dark mode in your mod:
226
228
You can use the following CSS to change the background color when the dark mode preference is enabled:
`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.
253
248
254
249
For example, if you have a preference to select the background color from a dropdown menu:
255
250
@@ -274,23 +269,25 @@ For example, if you have a preference to select the background color from a drop
274
269
You can use the following CSS to change the background color based on the selected value:
- 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.
294
291
295
292
---
296
293
@@ -327,22 +324,24 @@ You can combine the CSS like this:
0 commit comments