0.32.3 • Published 4 years ago

@mapbox/style-components v0.32.3

Weekly downloads
-
License
Copyright © Mapbo...
Repository
github
Last release
4 years ago

style-components

Maintained by @mapbox/map-design-team.

What are style components?

A style component is an abstraction built on top of the Mapbox GL style spec, designed to make map styles re-usable and composable.

A style component conforms to the style component specification, which is a superset of the Mapbox GL style spec. Style component documents compile to Mapbox GL stylesheets.

A few features of style components:

  • All style components compile to valid Mapbox GL stylesheets.
  • Style components may have other style components nested inside of them.
  • Style components use a design pattern for non-destructive map styling inspired by React whereby a parent component may pass props, which are variable values of a certain type, to a child component.
  • Style components support embeddable vector images, and those vector images can be customized via props just like other values in the stylesheet.
  • The style component compiler outputs stylesheets that can be decompiled into style components by including metadata on the stylesheets about which layers correspond to which components.
  • The style component compiler may be run in the browser, allowing components to be used in user interfaces where the map style changes dynamically based on user input.

Installation and basic usage

npm install @mapbox/style-components
const compiler = require('@mapbox/style-components').compiler;
const style = compiler({
  // value for rootStyleComponent must conform to the style component spec
  rootStyleComponent: {
    id: 'my-config',
    components: {},
    propConfig: {},
    version: 8
  }
});

// Return a Mapbox GL style spec-compliant stylesheet
return style;

Read below for more detailed usage guidelines.

Usage

The style-components library exports two functions for working with stylesheets, two functions for working with svg data, and a validation function:

Output a stylesheet from a component

compiler transforms a style component into a Mapbox GL JS stylesheet. See the compiler documentation for usage guidelines and examples.

compiler uses generateSvgFromIcon to output svgs if svg data is present in the icons property in the style component.

Output a component from a stylesheet

decompiler transforms a Mapbox GL JS stylesheet into a style component. The stylesheet must have metadata associating style layers to components. See the decompiler documentation for usage guidelines and examples.

Output icon JSON from SVG

generateIconFromSvg transforms SVG XML into JSON that conforms to the Icon type in the component spec.

Output SVG from icon JSON

generateSvgFromIcon transforms icon JSON into SVG XML.

Validate component JSON

validate confirms that a provided JSON file satisfies the style component specification. See the validator documentation for more information.

Supported platforms

This library is compiled for use in browsers and Node.js.

Development

Release

First create a CHANGELOG entry for your release by following the instructions here. Commit the entry followed by these commands:

$ npm version {major|minor|patch}
$ git push
$ git push --tags
$ mbx npm publish
0.32.3

4 years ago

0.32.2

4 years ago

0.32.1

4 years ago

0.32.0

4 years ago

0.31.3

4 years ago

0.31.2

5 years ago

0.31.1

5 years ago

0.31.0

5 years ago

0.30.0

5 years ago

0.29.0

5 years ago

0.28.0

5 years ago

0.27.0

5 years ago

0.26.1

5 years ago

0.26.0

5 years ago

0.25.0

5 years ago

0.24.0

5 years ago

0.23.0

5 years ago

0.22.0

5 years ago

0.21.0

5 years ago

0.20.0

5 years ago

0.19.0

5 years ago

0.18.0

5 years ago

0.17.0

5 years ago

0.16.1

5 years ago

0.16.0

5 years ago

0.15.4

5 years ago

0.15.3

5 years ago

0.15.2

5 years ago

0.15.1

5 years ago

0.14.2-dev

5 years ago

0.14.1

5 years ago

0.14.0

5 years ago

0.13.1

5 years ago

0.13.0

5 years ago

0.12.0

5 years ago

0.11.0

5 years ago

0.10.0

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.4

5 years ago

0.8.3

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

6 years ago