Skip to content

Commit 7a8cc76

Browse files
Lookslike saga components 7 (#79)
* Add build step to dev cmd * Add more components, move app into common-ui - rename common-app common-system-layout - add common-hero-layout - add common-spacer * Add common-todo and reflect value to common-input
1 parent 257e3b5 commit 7a8cc76

File tree

12 files changed

+205
-23
lines changed

12 files changed

+205
-23
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { LitElement, html, css } from "lit";
2+
import { customElement } from "lit/decorators.js";
3+
import {baseStyles} from "./style.js";
4+
5+
@customElement("common-hero-layout")
6+
export class CommonHeroLayoutElement extends LitElement {
7+
static override styles = [
8+
baseStyles,
9+
css`
10+
:host {
11+
display: block;
12+
height: 100%;
13+
}
14+
15+
.layout {
16+
display: grid;
17+
grid-template-columns: 1fr;
18+
grid-template-rows: 3fr 1fr;
19+
grid-template-areas:
20+
"primary"
21+
"secondary"
22+
;
23+
row-gap: var(--gap);
24+
height: 100%;
25+
}
26+
27+
.layout-primary {
28+
grid-area: primary;
29+
overflow-y: auto;
30+
}
31+
32+
.layout-secondary {
33+
grid-area: secondary;
34+
overflow-y: auto;
35+
}
36+
`
37+
];
38+
39+
override render() {
40+
return html`
41+
<div class="layout">
42+
<div class="layout-primary">
43+
<slot></slot>
44+
</div>
45+
<div class="layout-secondary">
46+
<slot name="secondary"></slot>
47+
</div>
48+
</div>
49+
`;
50+
}
51+
}

typescript/packages/common-ui/src/components/common-img.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export class CommonImgElement extends LitElement {
66
static override styles = css`
77
:host {
88
display: block;
9+
width: 100%;
10+
height: 100%;
911
}
1012
1113
.img {

typescript/packages/common-ui/src/components/common-input.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@ export class CommonInputElement extends LitElement {
88
baseStyles,
99
css`
1010
:host {
11-
--height: 40px;
11+
display: block;
12+
--height: 24px;
1213
}
1314
1415
.input {
1516
appearance: none;
16-
background-color: var(--input-background);
1717
border: 0;
18-
border-radius: calc(var(--height) / 2);
18+
outline: 0;
1919
box-sizing: border-box;
2020
font-size: var(--body-size);
2121
width: 100%;
22-
height: 100%;
22+
height: var(--height);
23+
}
24+
25+
:host-context([appearance="rounded"]) .input {
26+
--height: 40px;
27+
background-color: var(--input-background);
28+
border-radius: calc(var(--height) / 2);
2329
padding: 8px 16px;
2430
height: var(--height);
2531
}
@@ -28,11 +34,18 @@ export class CommonInputElement extends LitElement {
2834

2935
@property({ type: String }) value = "";
3036
@property({ type: String }) placeholder = "";
37+
@property({ type: String }) appearance = "default";
3138

3239
override render() {
40+
const oninput = (event: Event) => {
41+
const value = (event.target as HTMLInputElement).value;
42+
this.value = value;
43+
}
44+
3345
return html`
3446
<input
3547
class="input"
48+
@input="${oninput}"
3649
.value="${this.value}"
3750
.placeholder="${this.placeholder}"
3851
type="text" />`;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { LitElement, html, css } from "lit";
2+
import {customElement} from "lit/decorators.js";
3+
4+
@customElement("common-navstack")
5+
export class CommonNavstackElement extends LitElement {
6+
static override styles = css`
7+
:host {
8+
display: block;
9+
width: 100%;
10+
height: 100%;
11+
}
12+
13+
.navstack {
14+
position: relative;
15+
height: 100%;
16+
width: 100%;
17+
}
18+
.navstack ::slotted(*) {
19+
position: absolute;
20+
top: 0;
21+
bottom: 0;
22+
left: 0;
23+
right: 0;
24+
opacity: 0;
25+
}
26+
27+
.navstack ::slotted(*:first-child) {
28+
opacity: 1;
29+
}
30+
`;
31+
32+
override render() {
33+
return html`
34+
<div class="navstack">
35+
<slot></slot>
36+
</div>
37+
`;
38+
}
39+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { LitElement, css } from "lit";
2+
import { customElement } from "lit/decorators.js";
3+
4+
@customElement("common-spacer")
5+
export class CommonSpacerElement extends LitElement {
6+
static override styles = css`
7+
:host {
8+
display: block;
9+
flex-grow: 999;
10+
flex-shrink: 999;
11+
}
12+
`;
13+
}

typescript/packages/lookslike-sagas/src/components/app.ts renamed to typescript/packages/common-ui/src/components/common-system-layout.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { LitElement, html, css } from "lit";
22
import { customElement } from "lit/decorators.js";
3-
import { style } from "@commontools/common-ui/components.js";
3+
import { baseStyles } from "./style.js";
44

5-
const { baseStyles } = style;
6-
7-
@customElement("common-app")
8-
export class CommonAppElement extends LitElement {
5+
@customElement("common-system-layout")
6+
export class CommonSystemLayoutElement extends LitElement {
97
static override styles = [
108
baseStyles,
119
css`
@@ -30,19 +28,15 @@ export class CommonAppElement extends LitElement {
3028
3129
.app-primary {
3230
grid-area: primary;
33-
overflow: auto;
34-
container-type: size;
35-
container-name: app-primary;
31+
overflow: hidden;
3632
}
3733
3834
.app-secondary {
3935
grid-area: secondary;
40-
container-type: inline-size;
4136
}
4237
4338
.app-search {
4439
grid-area: search;
45-
container-type: inline-size;
4640
background-color: var(--secondary-background);
4741
display: block;
4842
padding: var(--gap);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { LitElement, html, css } from "lit";
2+
import { customElement, property } from "lit/decorators.js";
3+
import { baseStyles } from "./style.js";
4+
5+
@customElement("common-todo")
6+
export class CommonTodoElement extends LitElement {
7+
static override styles = [
8+
baseStyles,
9+
css`
10+
:host {
11+
display: block;
12+
}
13+
14+
.todo {
15+
display: grid;
16+
grid-template-columns: min-content 1fr;
17+
align-items: center;
18+
column-gap: var(--pad);
19+
min-height: 40px;
20+
}
21+
22+
.todo-ctl {
23+
display: flex;
24+
gap: var(--gap);
25+
align-items: center;
26+
}
27+
28+
.todo-checkbox {
29+
height: 24px;
30+
width: 24px;
31+
}
32+
`
33+
];
34+
35+
@property({ type: Boolean }) checked = false;
36+
@property({ type: String }) placeholder = "";
37+
@property({ type: String }) value = "";
38+
39+
override render() {
40+
const oncheck = (event: Event) => {
41+
const checked = (event.target as HTMLInputElement).checked;
42+
this.checked = checked;
43+
}
44+
45+
const oninput = (event: Event) => {
46+
const value = (event.target as HTMLInputElement).value;
47+
this.value = value;
48+
}
49+
50+
return html`
51+
<div class="todo">
52+
<div class="todo-ctl">
53+
<input
54+
class="todo-checkbox"
55+
type="checkbox"
56+
@change="${oncheck}"
57+
.checked="${this.checked}" />
58+
</div>
59+
<common-input
60+
class="unibox-input"
61+
@input="${oninput}"
62+
.placeholder="${this.placeholder}"
63+
.value="${this.value}">
64+
</common-input>
65+
</div>
66+
`;
67+
}
68+
}

typescript/packages/common-ui/src/components/common-unibox.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class CommonUniboxElement extends LitElement {
2727
return html`
2828
<div class="unibox">
2929
<common-input
30+
appearance="rounded"
3031
class="unibox-input"
3132
.placeholder="${this.placeholder}"
3233
.value="${this.value}">

typescript/packages/common-ui/src/components/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ export * as CommonVstack from './common-vstack.js';
1414
export * as CommonUnibox from './common-unibox.js';
1515
export * as CommonSuggestion from './common-suggestion.js';
1616
export * as CommonSuggestions from './common-suggestions.js';
17+
export * as CommonSpacer from './common-spacer.js';
18+
export * as CommonHeroLayout from './common-hero-layout.js';
19+
export * as CommonSystemLayout from './common-system-layout.js';
20+
export * as CommonNavstack from './common-navstack.js';
21+
export * as CommonTodo from './common-todo.js';
1722
export * as style from './style.js';

typescript/packages/lookslike-sagas/index.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
</head>
1010
<body class="theme">
1111
<common-screen>
12-
<common-app>
13-
<common-hero>
14-
<common-img src="example/mitchell-orr-jQqR2xGkesc-unsplash.jpg">
15-
</common-img>
16-
</common-hero>
12+
<common-system-layout>
1713
<common-list>
14+
<common-todo value="Buy milk" placeholder="Todo..."></common-todo>
1815
<common-media src="example/mitchell-orr-jQqR2xGkesc-unsplash.jpg">
1916
Hello!
2017
</common-media>
@@ -39,7 +36,7 @@
3936
</common-suggestions>
4037
</div>
4138
<common-unibox slot="search" placeholder="Imagine..."></common-unibox>
42-
</common-app>
39+
</common-system-layout>
4340
</common-screen>
4441
</body>
4542
</html>

0 commit comments

Comments
 (0)