Skip to content

Commit

Permalink
fix: Enable lit css importing (#9550)
Browse files Browse the repository at this point in the history
Fixes #9532
  • Loading branch information
caalador authored Dec 2, 2020
1 parent 216dd53 commit ae47abc
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 0 deletions.
6 changes: 6 additions & 0 deletions flow-server/src/main/resources/webpack.generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ module.exports = {
{
test: /\.css$/i,
use: [
{
loader: "lit-css-loader"
},
{
loader: "extract-loader"
},
{
loader: 'css-loader',
options: {
Expand Down
27 changes: 27 additions & 0 deletions flow-tests/test-themes/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>My Project</title>
<style>
body {
margin: 0;
width: 100vw;
height: 100vh;
}

#outlet {
height: 100%;
}
</style>
<custom-style>
<style include="lumo-color lumo-typography"></style>
</custom-style>
<!-- index.ts is included here automatically (either by the dev server or during the build) -->
</head>

<body theme="light">
<div id="outlet"></div>
</body>
</html>
23 changes: 23 additions & 0 deletions flow-tests/test-themes/frontend/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Flow} from '@vaadin/flow-frontend/Flow';
import {Router} from '@vaadin/router';

const {serverSideRoutes} = new Flow({
imports: () => import('../target/frontend/generated-flow-imports'),
});

const routes = [
// for client-side, place routes below (more info https://vaadin.com/docs/v15/flow/typescript/creating-routes.html)
{
path: 'hello',
component: 'hello-world-view',
action: async () => {
await import('./typescript/hello-world-view');
},
},
// for server-side, the next magic line sends all unmatched routes:
...serverSideRoutes, // IMPORTANT: this must be the last entry in the array
]
;

export const router = new Router(document.querySelector('#outlet'));
router.setRoutes(routes);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:host {
display: block;
padding: 1em;
background-color: orange;
}
20 changes: 20 additions & 0 deletions flow-tests/test-themes/frontend/typescript/hello-world-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import '@vaadin/vaadin-text-field';
import { customElement, html, LitElement } from 'lit-element';
import styles from './hello-world-view.css';


@customElement('hello-world-view')
export class HelloWorldView extends LitElement {
name: string = '';

static styles = [styles];

render() {
return html`
<vaadin-text-field label="Your name" @value-changed="${this.nameChanged}"></vaadin-text-field>
`;
}
nameChanged(e: CustomEvent) {
this.name = e.detail.value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@

public class ThemeIT extends ChromeBrowserTest {

@Test
public void typeScriptCssImport_stylesAreApplied() {
getDriver().get(getRootURL() + "/path/hello");

checkLogsForErrors();

final TestBenchElement helloWorld = $(TestBenchElement.class).first()
.findElement(By.tagName("hello-world-view"));

Assert.assertEquals("hello-world-view", helloWorld.getTagName());

Assert.assertEquals(
"CSS was not applied as background color was not as expected.",
"rgba(255, 165, 0, 1)", helloWorld.getCssValue("background-color"));
}

@Test
public void secondTheme_staticFilesNotCopied() {
getDriver().get(getRootURL() + "/path/VAADIN/static/img/bg.jpg");
Expand Down

0 comments on commit ae47abc

Please sign in to comment.