Skip to content

Commit

Permalink
Add .text.append and .text.prepend
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiriVulpes committed Dec 28, 2024
1 parent 4423d7c commit 621952a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/ui/utility/TextManipulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@ import type Component from "ui/Component"
import StringApplicator from "ui/utility/StringApplicator"

interface TextManipulator<HOST> extends StringApplicator.Optional<HOST> {
prepend (text: string): HOST
append (text: string): HOST
}

function TextManipulator (component: Component): TextManipulator<Component> {
return StringApplicator(component, value => {
component.element.textContent = value ?? null
return value
})
return Object.assign(
StringApplicator(component, value => {
component.element.textContent = value ?? null
return value
}),
{
prepend (text: string) {
component.element.prepend(document.createTextNode(text))
return component
},
append (text: string) {
component.element.append(document.createTextNode(text))
return component
},
}
)
}

export default TextManipulator

0 comments on commit 621952a

Please sign in to comment.