Skip to content

Commit

Permalink
Set max width
Browse files Browse the repository at this point in the history
  • Loading branch information
matbur committed Dec 12, 2024
1 parent 85d3ac6 commit 316b46c
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 54 deletions.
23 changes: 11 additions & 12 deletions templates/templates.templ
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,7 @@ templ OnlinePage(params OnlinePageParams) {
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<div class="mt-3">
if params.Image != "" {
<img src={ params.Image }/>
}
</div>
@img(params.Image)
</div>
</div>
</div>
Expand Down Expand Up @@ -332,7 +328,7 @@ templ OfflinePage(params OfflinePageParams) {
</div>
</div>
<button type="submit" class="btn btn-primary" disabled>Submit</button>
<div id="img-placeholder" class="mt-3"></div>
@img("")
</div>
</div>
</div>
Expand Down Expand Up @@ -381,19 +377,22 @@ templ OfflinePage(params OfflinePageParams) {

function callGoFunction() {
const values = getValues();

console.log('values', values);

const imagePlaceholder = document.getElementById("img-placeholder");
const img = document.getElementById("img");
const { imageBase64, err } = imageText(values);
if (err) {
imagePlaceholder.innerHTML = "err: " + err;
console.error(err)
} else {
const img = document.createElement("img")
img.setAttribute("src", "data:image/png;base64," + imageBase64)
imagePlaceholder.replaceChildren(img)
img.setAttribute("src", "data:image/png;base64," + imageBase64);
}
}
</script>
}
}

templ img(src string) {
<div class="mt-3">
<img id="img" src={ src } style="max-width:100%;"/>
</div>
}
119 changes: 77 additions & 42 deletions templates/templates_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 316b46c

Please sign in to comment.