Constructor
new StyletronServer()
Create a new StyletronServer instance
Extends
Methods
getStylesheets() → {Array}
Get an array of stylesheet objects
Example
const styletron = new StyletronServer();
styletron.injectDeclaration({prop: 'color', val: 'red'});
// → 'a'
styletron.getStylesheets();
// → [{css: '.a{color:red}'}]
Returns:
Array of stylesheet objects
- Type
- Array
getStylesheetsOldIE() → {Array}
Get an array of stylesheet objects, with ≤IE9 limit of max 4095 rules per stylesheet
Example
const styletron = new StyletronServer();
styletron.injectDeclaration({prop: 'color', val: 'red'});
// → 'a'
styletron.getStylesheetsOldIE();
// → [{css: '.a{color:red}'}]
Returns:
Array of stylesheet objects
- Type
- Array
getStylesheetsHtml(className) → {String}
Get a string of style elements for server rendering
Example
const styletron = new StyletronServer();
styletron.injectDeclaration({prop: 'color', val: 'red'});
// → 'a'
styletron.getStylesheetsHtml();
// → '<style class="_styletron_hydrate_">.a{color:red}</style>'
styletron.getStylesheetsHtml('custom_class');
// → '<style class="custom_class">.a{color:red}</style>'
Parameters:
Name | Type | Default | Description |
---|---|---|---|
className |
String |
_styletron_hydrate_
|
Class name for style elements |
Returns:
The string of HTML
- Type
- String
getStylesheetsHtmlOldIE(className) → {String}
Get a string of style elements for server rendering, with ≤IE9 limit of max 4095 rules per sheet
Example
const styletron = new StyletronServer();
styletron.injectDeclaration({prop: 'color', val: 'red'});
// → 'a'
styletron.getStylesheetsHtml();
// → '<style class="_styletron_hydrate_">.a{color:red}</style>'
styletron.getStylesheetsHtml('custom_class');
// → '<style class="custom_class">.a{color:red}</style>'
Parameters:
Name | Type | Default | Description |
---|---|---|---|
className |
String |
_styletron_hydrate_
|
Class name for style elements |
Returns:
The string of HTML
- Type
- String
getCss() → {String}
Get the CSS string. For hydrating styles on the client,
getStylesheetsHtml
or getStylesheets
should be used instead.
Example
const styletron = new StyletronServer();
styletron.injectDeclaration({prop: 'color', val: 'red'});
// → 'a'
styletron.getCss();
// → '.a{color:red}'
Returns:
The string of CSS
- Type
- String
injectDeclaration(decl) → {string|undefined}
- Source:
- Overrides:
Injects a declaration (if not already injected) and returns a class name
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
decl |
object | The CSS declaration object Properties
|
Returns:
The class name for the declaration
- Type
- string | undefined