Skip to content

Commit

Permalink
Agregando (context) de estilos
Browse files Browse the repository at this point in the history
  • Loading branch information
JooseNavarro committed Mar 4, 2020
1 parent 058d2ef commit d9255cf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/adapters/component/create-script.ts
Expand Up @@ -4,7 +4,7 @@ import { CreateElement } from "../../interfaces";
export class CreateScript implements CreateElement {

public build( name: string, src: string, options?: HTMLScriptElement): Promise<StatusElement> {
const element = document.createElement('script');
const element = document.createElement(SCRIPT_ELEMENT);
element.type = 'text/javascript';
element.src = src;
element.async = true;
Expand Down
14 changes: 7 additions & 7 deletions lib/adapters/styles/create-style.ts
@@ -1,25 +1,25 @@
import { AdapterServices } from "../../services/adapter.services";
import { StatusElement } from "../../index";
import {AxiosResponse} from "axios";
import { StatusElement } from "../../";
import { AxiosResponse } from "axios";

export class CreateStyle {

public build(name: string, code: string): Promise<StatusElement> {
const element = document.createElement('style');
element.textContent = ` :host { ${ code } }`;
const element = document.createElement(STYLE_ELEMENT);
element.textContent = code;
this.appendChild(element);

return new Promise<StatusElement>((resolve, reject) => {
element.onload = ((e) => resolve({ name, status: true, element: element } ));
element.onerror = ((e) => {
element.onload = (() => resolve({ name, status: true, element: element } ));
element.onerror = (() => {
reject({ name, status: false, element: element } );
element.remove();
} );
});
}

public appendChild(style: HTMLStyleElement): void {
const documentHead = document.body;
const documentHead = document.head;
documentHead.appendChild(style);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/constants/index.ts
@@ -0,0 +1,2 @@
const STYLE_ELEMENT = 'style';
const SCRIPT_ELEMENT = 'script';
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "web-adapter-js",
"version": "0.1.2",
"version": "0.1.3",
"description": "Web Adapter es un paquete que te permite tener una comunicación dinámica con tus Web Componets externos, además podrás cargar tus estilos de forma dinámica.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit d9255cf

Please sign in to comment.