My goal is to create custom form component using custom web elements. I need to add styling for the form component.
So I am using materializecss package. I need to import CSS and JavaScript file. I cannot able to work with the external JS file. I am using WebPack to bundle the files.
In the code i am trying to load Materialize JS file but it's not working. I don't know how to load Js files in custom web elements. Please somebody assist me.
const template = document.createElement('template');
template.innerHTML = `
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<div class="container">
<div class="center-align">
<h3 class="blue-text text-darken-4">Company-Form</h3>
<h5 class="blue-text text-darken-2 title"></h5>
<div class="row">
<div class="col s12">
<div class="card-content">
<div class="row form-content">
</div>
</div>
<div class="card-action btn-action">
</div>
</div>
</div>
</div>
</div>
`;
export default class MyForm extends HTMLElement {
constructor() {
super();
// shadow dom
const shadowDOM = this.attachShadow({ mode: 'open' });
// Render the template
shadowDOM.appendChild(template.content.cloneNode(true));
}
}