diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/html.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/util/html.js b/src/util/html.js index 63d7c1cf..e808eefa 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -411,8 +411,9 @@ export class Template { export class Slot { #defaultTag = new Tag(); + #handleContent = null; - constructor(template, slotName, defaultContent) { + constructor(template, slotName, defaultContentOrHandleContent) { if (!template) { throw new Error(`Expected template`); } @@ -423,7 +424,12 @@ export class Slot { this.template = template; this.slotName = slotName; - this.defaultContent = defaultContent; + + if (typeof defaultContentOrHandleContent === 'function') { + this.#handleContent = defaultContentOrHandleContent; + } else { + this.defaultContent = defaultContentOrHandleContent; + } } set defaultContent(value) { @@ -447,6 +453,14 @@ export class Slot { } toString() { - return this.content.toString(); + return this.valueOf().toString(); + } + + valueOf() { + if (this.#handleContent) { + return this.#handleContent(this.content); + } else { + return this.content; + } } } |