jss: Add definitions for createGenerateClassName

This commit is contained in:
Sebastian Silbermann
2018-08-21 12:02:55 +02:00
parent b3c691dcd2
commit c334034df9
2 changed files with 10 additions and 1 deletions

View File

@@ -3,6 +3,7 @@
// Definitions by: Brenton Simpson <https://github.com/appsforartists>
// Oleg Slobodskoi <https://github.com/kof>
// Thomas Crockett <https://github.com/pelotom>
// Sebastian Silbermann <https://github.com/eps1lon>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -137,6 +138,10 @@ export declare class JSS {
* Creates a new instance of JSS.
*/
export function create(options?: Partial<JSSOptions>): JSS;
/**
* Creates a GenerateClassName function
*/
export function createGenerateClassName(): GenerateClassName;
declare const sharedInstance: JSS;
/**
* A global JSS instance.

View File

@@ -2,11 +2,12 @@
import {
create as createJSS,
createGenerateClassName,
SheetsRegistry,
default as sharedInstance,
} from 'jss';
const jss = createJSS().setup({});
const jss = createJSS().setup({ createGenerateClassName });
jss.use({}, {}); // $ExpectType JSS
const styleSheet = jss.createStyleSheet<string>(
@@ -46,6 +47,9 @@ const rule = attachedStyleSheet.addRule('dynamicRule', { color: 'indigo' });
rule.prop('border-radius', 5).prop('color'); // $ExpectType string
attachedStyleSheet.classes.dynamicRule; // $ExpectType string
const generateClassName = createGenerateClassName();
const dynamicRuleClassName = generateClassName(rule, attachedStyleSheet);
attachedStyleSheet.deleteRule('dynamicRule');
// test that `addRule` supports the shorthand signature