Skip to content

Commit

Permalink
feat: allow passing class and style attributes (#17)
Browse files Browse the repository at this point in the history
* feat: allow passing "class" and "style" attributes
  • Loading branch information
bill-min committed Apr 28, 2023
1 parent cc259f4 commit 23d051b
Show file tree
Hide file tree
Showing 27 changed files with 124 additions and 17 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,26 @@ It is removed after the request has either errored, or successfully loaded.
</micro-frame>
```

## `class`

Optional `class` attribute which works the same way as [Marko class attribute](https://markojs.com/docs/syntax/#class-attribute).

```marko
<micro-frame src="..." class="a c"/>
<micro-frame src="..." class={ a:true, b:false, c:true }/>
<micro-frame src="..." class=["a", null, { c:true }]/>
```

## `style`

Optional `style` attribute which works the same way as [Marko style attribute](https://markojs.com/docs/syntax/#style-attribute).

```marko
<micro-frame src="..." style="display:block;margin-right:16px"/>
<micro-frame src="..." style={ display: "block", color: false, marginRight: 16 }/>
<micro-frame src="..." style=["display:block", null, { marginRight: 16 }]/>
```

# Communicating between host and child

Communicating with the embedded application happens primarily in one of two ways, either you want to do a full reload of and get new HTML, or you want to orchestrate a client side rendered update.
Expand Down
2 changes: 1 addition & 1 deletion src/components/micro-frame-slot/component/node.marko
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $ {
const loadingPromise =
input.loading && new Promise((res) => (finishLoading = res));
}
<div id=component.id data-slot=input.slot data-from=input.from>
<div id=component.id class=input.class style=input.style data-slot=input.slot data-from=input.from>
<macro name="wait">
<await(stream.next())
client-reorder=input.clientReorder
Expand Down
2 changes: 1 addition & 1 deletion src/components/micro-frame-slot/component/web.marko
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
static function noop() {}

<div>
<div class=input.class style=input.style>
<${
state.err
? input.catch || noop
Expand Down
14 changes: 14 additions & 0 deletions src/components/micro-frame-slot/marko-tag.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,19 @@
"description": "A block rendered while the resource is loading and removed after loading is complete"
}
]
},
"@class": {
"autocomplete": [
{
"description": "Marko class attribute"
}
]
},
"@style": {
"autocomplete": [
{
"description": "Marko style attribute"
}
]
}
}
20 changes: 20 additions & 0 deletions src/components/micro-frame-sse/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,26 @@ It is removed after the request has either errored, or successfully loaded.
</micro-frame-slot>
```

## `class`

Optional `class` attribute which works the same way as [Marko class attribute](https://markojs.com/docs/syntax/#class-attribute).

```marko
<micro-frame-slot from="..." slot="..." class="a c"/>
<micro-frame-slot from="..." slot="..." class={ a:true, b:false, c:true }/>
<micro-frame-slot from="..." slot="..." class=["a", null, { c:true }]/>
```

## `style`

Optional `style` attribute which works the same way as [Marko style attribute](https://markojs.com/docs/syntax/#style-attribute).

```marko
<micro-frame-slot from="..." slot="..." style="display:block;margin-right:16px"/>
<micro-frame-slot from="..." slot="..." style={ display: "block", color: false, marginRight: 16 }/>
<micro-frame-slot from="..." slot="..." style=["display:block", null, { marginRight: 16 }]/>
```

# Communicating between host and child

Communicating between host and child works the same way as [micro-frame](../../../README.md).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
Host app
</div>
<div />
<div />
<div
class="test"
style="display:block;margin-right:16px;"
/>
<div />
<div />
<div />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
Host app
</div>
<div />
<div />
<div
class="test"
style="display:block;margin-right:16px;"
/>
<div />
<div />
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
Host app
</div>
<div />
<div />
<div
class="test"
style="display:block;margin-right:16px;"
/>
<div />
<div />
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
Host app
</div>
<div />
<div />
<div
class="test"
style="display:block;margin-right:16px;"
/>
<div />
<div />
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
Host app
</div>
<div />
<div>
<div
class="test"
style="display:block;margin-right:16px;"
>
<p>
test_html for slot_1
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
Host app
</div>
<div />
<div>
<div
class="test"
style="display:block;margin-right:16px;"
>
<p>
test_html for slot_1
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
Host app
</div>
<div />
<div>
<div
class="test"
style="display:block;margin-right:16px;"
>
<p>
test_html for slot_1
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
/>
</div>
<div
class="test"
data-from="test"
data-slot="slot_1"
id="GENERATED-2"
style="display:block;margin-right:16px;"
/>
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
/>
</div>
<div
class="test"
data-from="test"
data-slot="slot_1"
id="GENERATED-2"
style="display:block;margin-right:16px;"
>
<p>
test_html for slot_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
/>
</div>
<div
class="test"
data-from="test"
data-slot="slot_1"
id="GENERATED-2"
style="display:block;margin-right:16px;"
>
<p>
test_html for slot_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
id="GENERATED-0"
/>
<div
class="test"
data-from="test"
data-slot="slot_1"
id="GENERATED-1"
style="display:block;margin-right:16px;"
>
<p>
test_html for slot_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class {

<if(state.mounted)>
<micro-frame-sse src="embed" name="test" read=(e => [e.lastEventId, e.data]) />
<micro-frame-slot from="test" slot="slot_1" />
<micro-frame-slot from="test" slot="slot_1" class={"test": true} style=["display:block", null, { marginRight: 16 }] />
<micro-frame-slot from="test" slot="slot_2" />
<micro-frame-sse src="embed" name="test2" read=(e => [e.lastEventId, e.data.replace("test", "test_2")]) />
<micro-frame-slot from="test2" slot="slot_1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body>
<div>Host app</div>
<micro-frame-sse src="embed" name="test" read=(e => [e.lastEventId, e.data]) />
<micro-frame-slot from="test" slot="slot_1" />
<micro-frame-slot from="test" slot="slot_1" class={"test": true} style=["display:block", null, { marginRight: 16 }] />
<micro-frame-slot from="test" slot="slot_2" />
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<div>
Host app
</div>
<div />
<div
class="test"
style="display:block;margin-right:16px;"
/>
<script>
$csr_only_index_C=(window.$csr_only_index_C||[]).concat({"l":1,"w":[["s0-8",0,{},{"f":1}]],"t":["XTAXV1jy"]})
</script>
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<div>
Host app
</div>
<div>
<div
class="test"
style="display:block;margin-right:16px;"
>
<div>
Embedded App.
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Host app
</div>
<div
class="test"
data-src="embed"
id="GENERATED-0"
style="display:block;margin-right:16px;"
/>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
Host app
</div>
<div
class="test"
data-src="embed"
id="GENERATED-0"
style="display:block;margin-right:16px;"
>
<div>
Embedded App.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ class {
}

<if(state.mounted)>
<micro-frame src="embed"/>
<micro-frame src="embed" class={"test": true} style=["display:block", null, { marginRight: 16 }] />
</if>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</head>
<body>
<div>Host app</div>
<micro-frame src="embed"/>
<micro-frame src="embed" class={"test": true} style=["display:block", null, { marginRight: 16 }] />
</body>
</html>
2 changes: 1 addition & 1 deletion src/components/micro-frame/component/node.marko
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static async function fetchStream(input, out) {
return res.body[Symbol.asyncIterator]();
}

<div id=component.id data-src=input.src>
<div id=component.id class=input.class style=input.style data-src=input.src>
<if(input.loading)>
<${input.loading}/>
<!-- output a comment used as a marker to detect where the loading content starts so it can be removed -->
Expand Down
2 changes: 1 addition & 1 deletion src/components/micro-frame/component/web.marko
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
static function noop() {}

<div>
<div class=input.class style=input.style>
<${
state.err
? input.catch || noop
Expand Down
14 changes: 14 additions & 0 deletions src/components/micro-frame/marko-tag.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,19 @@
"description": "A block rendered while the resource is loading and removed after loading is complete"
}
]
},
"@class": {
"autocomplete": [
{
"description": "Marko class attribute"
}
]
},
"@style": {
"autocomplete": [
{
"description": "Marko style attribute"
}
]
}
}

0 comments on commit 23d051b

Please sign in to comment.