1 | /** @flow */
|
2 | /* eslint-disable block-scoped-const */
|
3 |
|
4 | import type {Config} from '../config';
|
5 |
|
6 | import checkPropsPlugin from './check-props-plugin';
|
7 | import keyframesPlugin from './keyframes-plugin';
|
8 | import mergeStyleArrayPlugin from './merge-style-array-plugin';
|
9 | import prefixPlugin from './prefix-plugin';
|
10 | import removeNestedStylesPlugin from './remove-nested-styles-plugin';
|
11 | import resolveInteractionStylesPlugin
|
12 | from './resolve-interaction-styles-plugin';
|
13 | import resolveMediaQueriesPlugin from './resolve-media-queries-plugin';
|
14 | import visitedPlugin from './visited-plugin';
|
15 |
|
16 | export type PluginConfig = {
|
17 | // Adds a chunk of css to the root style sheet
|
18 | addCSS: (css: string) => {remove: () => void},
|
19 |
|
20 | // Helper function when adding CSS
|
21 | appendImportantToEachValue: (style: Object) => Object,
|
22 |
|
23 | // May not be readable if code has been minified
|
24 | componentName: string,
|
25 |
|
26 | // The Radium configuration
|
27 | config: Config,
|
28 |
|
29 | // Converts an object of CSS rules to a string, for use with addCSS
|
30 | cssRuleSetToString: (
|
31 | selector: string,
|
32 | rules: Object,
|
33 | userAgent: ?string,
|
34 | ) => string,
|
35 |
|
36 | // Retrieve the value of a field on the component
|
37 | getComponentField: (key: string) => any,
|
38 |
|
39 | // Retrieve the value of a field global to the Radium module
|
40 | // Used so that tests can easily clear global state.
|
41 | getGlobalState: (key: string) => any,
|
42 |
|
43 | // Retrieve the value of some state specific to the rendered element.
|
44 | // Requires the element to have a unique key or ref or for an element key
|
45 | // to be passed in.
|
46 | getState: (stateKey: string, elementKey?: string) => any,
|
47 |
|
48 | // Helper function when adding CSS
|
49 | hash: (data: string) => string,
|
50 |
|
51 | // Returns true if the value is a nested style object
|
52 | isNestedStyle: (value: any) => boolean,
|
53 |
|
54 | // Access to the mergeStyles utility
|
55 | mergeStyles: (styles: Array<Object>) => Object,
|
56 |
|
57 | // The props of the rendered element. This can be changed by each plugin,
|
58 | // and successive plugins will see the result of previous plugins.
|
59 | props: Object,
|
60 |
|
61 | // Calls setState on the component with the given key and value.
|
62 | // By default this is specific to the rendered element, but you can override
|
63 | // by passing in the `elementKey` parameter.
|
64 | setState: (stateKey: string, value: any, elementKey?: string) => void,
|
65 |
|
66 | // The style prop of the rendered element. This can be changed by each plugin,
|
67 | // and successive plugins will see the result of previous plugins. Kept
|
68 | // separate from `props` for ease of use.
|
69 | style: Object,
|
70 |
|
71 | // uses the exenv npm module
|
72 | ExecutionEnvironment: {
|
73 | canUseEventListeners: boolean,
|
74 | canUseDOM: boolean,
|
75 | },
|
76 | };
|
77 |
|
78 | export type PluginResult = ?{
|
79 | // Merged into the component directly. Useful for storing things for which you
|
80 | // don't need to re-render, event subscriptions, for instance.
|
81 | componentFields?: ?Object,
|
82 |
|
83 | // Merged into a Radium controlled global state object. Use this instead of
|
84 | // module level state for ease of clearing state between tests.
|
85 | globalState?: ?Object,
|
86 |
|
87 | // Merged into the rendered element's props.
|
88 | props?: ?Object,
|
89 |
|
90 | // Replaces (not merged into) the rendered element's style property.
|
91 | style?: ?Object,
|
92 | };
|
93 |
|
94 | export default {
|
95 | checkProps: checkPropsPlugin,
|
96 | keyframes: keyframesPlugin,
|
97 | mergeStyleArray: mergeStyleArrayPlugin,
|
98 | prefix: prefixPlugin,
|
99 | removeNestedStyles: removeNestedStylesPlugin,
|
100 | resolveInteractionStyles: resolveInteractionStylesPlugin,
|
101 | resolveMediaQueries: resolveMediaQueriesPlugin,
|
102 | visited: visitedPlugin,
|
103 | };
|