@@ -10,10 +10,12 @@ require('@webcomponents/custom-elements');
10
10
module . exports = {
11
11
/**
12
12
* @param {JSX.Element } app
13
- * @param {string } tagName - The name of the web component. Has to be minus "-" delimited.
14
- * @param {boolean } useShadowDom - If the value is set to "true" the web component will use the `shadowDom`. The default value is true.
13
+ * @param {string } tagName - The name of the web component. Has to be minus '-' delimited.
14
+ * @param {Object } config - The config object used to generate the web component.
15
+ * @param {string } config.useShadowDom - If the value is set to 'true' the web component will use the `shadowDom`. The default value is true.
16
+ * @param {string } config.cssFile - The css file location in the distribution server. Optional.
15
17
*/
16
- create : ( app , tagName , useShadowDom = true ) => {
18
+ create : ( app , tagName , config = { useShadowDom : true } ) => {
17
19
let appInstance ;
18
20
19
21
const lifeCycleHooks = {
@@ -44,7 +46,7 @@ module.exports = {
44
46
const webComponentInstance = this ;
45
47
let mountPoint = webComponentInstance ;
46
48
47
- if ( useShadowDom ) {
49
+ if ( config . useShadowDom ) {
48
50
// Re-assign the webComponentInstance (this) to the newly created shadowRoot
49
51
const shadowRoot = webComponentInstance . attachShadow ( { mode : 'open' } ) ;
50
52
// Re-assign the mountPoint to the newly created "div" element
@@ -63,14 +65,21 @@ module.exports = {
63
65
}
64
66
65
67
ReactDOM . render ( React . cloneElement ( app , extractAttributes ( webComponentInstance ) ) , mountPoint , function ( ) {
66
- appInstance = this ;
68
+ appInstance = this ;
67
69
68
- callConstructorHook ( webComponentInstance ) ;
69
- callLifeCycleHook ( 'connectedCallback' ) ;
70
- } ) ;
70
+ callConstructorHook ( webComponentInstance ) ;
71
+ callLifeCycleHook ( 'connectedCallback' ) ;
72
+ } ) ;
73
+
74
+ if ( config . cssFile ) {
75
+ mountPoint . insertAdjacentHTML (
76
+ 'afterbegin' ,
77
+ `<link rel='stylesheet' type='text/css' href='${ config . cssFile } '/>`
78
+ ) ;
79
+ }
71
80
}
72
81
disconnectedCallback ( ) {
73
- callLifeCycleHook ( 'disconnectedCallback' ) ;
82
+ callLifeCycleHook ( 'disconnectedCallback' ) ;
74
83
}
75
84
attributeChangedCallback ( attributeName , oldValue , newValue , namespace ) {
76
85
callLifeCycleHook ( 'attributeChangedCallback' , [ attributeName , oldValue , newValue , namespace ] ) ;
@@ -81,5 +90,5 @@ module.exports = {
81
90
}
82
91
83
92
customElements . define ( tagName , proto ) ;
84
- } ,
93
+ }
85
94
} ;
0 commit comments