Theming
This page includes reference documentation for types relates to the Control Theme API
, used to configure custom styling, icons, and images for Mapbox Search JS Web elements.
Options and Type Definitions
Theme
The Control Theme API is a way to apply your own design system to Mapbox Search JS Web elements.
Control themes use a combination of CSS variables, custom scoped CSS, and SVG icons.
ObjectProperties
(string)
: Optional CSS text to be inserted into Scoped CSS elements. As such, any
CSS will not interact with the rest of the page.
TODO: Class names are element-specific and have yet to be standardized. Breaking changes are likely and will be flagged in CHANGELOG.md.
Example
const theme = {
variables: {
fontFamily: 'Avenir, sans-serif',
unit: '14px',
padding: '0.5em',
borderRadius: '0',
boxShadow: '0 0 0 1px silver',
}
};
autofill({ theme });
ThemeVariables
ThemeVariables
are a collection of CSS variables that style Control Theme API
elements.
Properties
(string)
: Border radius of elements such as modals and listboxes.
Analogous to CSS border-radius
.
(string)
: Box shadow of elements such as modals and listboxes.
Analogous to CSS box-shadow
.
(string)
: Backdrop color of body content behind modals.
Analogous to CSS color
.
Default: black with alpha value
(string)
: Background color for elements such as modals and listboxes.
Analogous to CSS color
.
Default: white
(string)
: Background color for items on press.
Analogous to CSS color
.
Default: dark gray
(string)
: Background color for items on hover.
Analogous to CSS color
.
Default: light gray
(string)
: Color of the primary accent color.
Analogous to CSS color
.
Default: variant of blue
(string)
: Color of the secondary accent color.
Analogous to CSS color
.
Default: blue-gray
(string)
: The timing function to use for listbox animations.
Analogous to CSS <easing-function>
.
Default: ease-out
(string)
: The duration to use for listbox animations.
Analogous to CSS <time>
.
Default: 150ms
(string)
: Font family.
Analogous to CSS font-family
.
Default: Sans-serif system font stack
(string)
: Font weight for headings and item titles.
Analogous to CSS font-weight
.
Default: bold
(string)
: Minimum width of elements such as modals and listboxes.
Analogous to CSS <length>
.
(string)
: Padding of powered by mapbox label in footer of search listbox.
Analogous to CSS <length>
.
((string | Expression))
: Unit is the base font size and can be referenced in other variables as multiples of
1em
.
Analogous to font-size
.
((string | Expression))
: Unit header is a derivative of
unit
and is used for modal headers.
Analogous to font-size
.
ThemeIcons
ThemeIcons
are SVG icons
that are used in Control Theme API elements.
Roughly, icon names and their defaults are the same as Mapbox's Assembly.
Values must be valid SVG plain-text. Unless otherwise noted, icons should be 18px in size and have appropriate dimensions set.
Icons can also be filled with 'currentColor'.
ObjectProperties
Example
const icons = {
close: `
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svg viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.79289 3.79289C4.18342 3.40237 4.81658 3.40237 5.20711 3.79289L9 7.58579L12.7929 3.79289C13.1834 3.40237 13.8166 3.40237 14.2071 3.79289C14.5976 4.18342 14.5976 4.81658 14.2071 5.20711L10.4142 9L14.2071 12.7929C14.5976 13.1834 14.5976 13.8166 14.2071 14.2071C13.8166 14.5976 13.1834 14.5976 12.7929 14.2071L9 10.4142L5.20711 14.2071C4.81658 14.5976 4.18342 14.5976 3.79289 14.2071C3.40237 13.8166 3.40237 13.1834 3.79289 12.7929L7.58579 9L3.79289 5.20711C3.40237 4.81658 3.40237 4.18342 3.79289 3.79289Z" fill="currentColor"/>
</svg>
`
}
ThemeImages
ThemeImages
are raster images that are used in Control Theme API elements.
There are currently only two images, "toggle default" and "toggle satellite," which specify images for a Map/Satellite toggle button.
Values must be valid URLs accessible by the expected browser environment. Data URLs and Blob URLs are also supported.
ObjectProperties
Expression
Currently, the only expression supported is
['mobile', mobile_value, tablet_and_desktop_value]
.
"mobile"
, string, string]