Skip to content

Commit

Permalink
fix(jwc-core): inject styles into host
Browse files Browse the repository at this point in the history
  • Loading branch information
wibus-wee committed Dec 17, 2022
1 parent 0e88121 commit f198477
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 91 deletions.
7 changes: 2 additions & 5 deletions packages/jwc-core/src/wc-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class JwcComponent extends HTMLElement implements JwcElement {
public previousVNode = null;

public host: HTMLElement;
public css: any;

public override shadowRoot: ShadowRoot;

Expand Down Expand Up @@ -95,10 +94,8 @@ export class JwcComponent extends HTMLElement implements JwcElement {
private initShadowRoot() {
let shadowRoot: ShadowRoot = this.shadowRoot || this.attachShadow({ mode: 'open' });
shadowRoot = this.initCSS(this.shadowRoot);
if(this.css) {
shadowRoot.appendChild(createCSSElement(
typeof this.css === 'function' ? this.css() : this.css
))
if(this.$options.css) {
shadowRoot.appendChild(createCSSElement(this.$options.css))
}
if (this.inlineStyles) {
this.customStyles = createCSSElement(this.inlineStyles);
Expand Down
114 changes: 30 additions & 84 deletions packages/jwc-starter-vite-ts/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,6 @@
text-align: center;
}

:root {
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 24px;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}


h1 {
font-size: 3.2em;
line-height: 1.1;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
Expand All @@ -84,21 +18,21 @@ button:focus-visible {
.logo.jwc:hover {
filter: drop-shadow(0 0 2em rgb(0, 0, 0));
}
/*

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
} */
/*
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
} */
}

.card {
padding: 2em;
Expand All @@ -108,23 +42,35 @@ button:focus-visible {
color: #888;
}

@media (prefers-color-scheme: dark) {
.logo.jwc:hover {
filter: drop-shadow(0 0 2em rgb(255, 255, 255));
}
}


button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}


@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}


@media (prefers-color-scheme: dark) {
.logo.jwc:hover {
filter: drop-shadow(0 0 2em rgb(255, 255, 255));
}
}
4 changes: 2 additions & 2 deletions packages/jwc-starter-vite-ts/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { JwcComponent, Component, Prop, Event } from "@jwcjs/core";
import { h } from "@jwcjs/runtime";
import style from './App.css'
import styles from './App.css?inline'

@Component({
name: "app-element",
css: style
css: styles
})
export class App extends JwcComponent {
constructor() {
Expand Down
62 changes: 62 additions & 0 deletions packages/jwc-starter-vite-ts/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

:root {
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 24px;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}


h1 {
font-size: 3.2em;
line-height: 1.1;
}


@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}


#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

0 comments on commit f198477

Please sign in to comment.