Skip to content

Instantly share code, notes, and snippets.

@imkost
Created December 5, 2016 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imkost/9e549c7adc48db18e6c79cf92d850735 to your computer and use it in GitHub Desktop.
Save imkost/9e549c7adc48db18e6c79cf92d850735 to your computer and use it in GitHub Desktop.
function NameEditor({ id }) {
// Add color to distinguish name editors
const color = {
0: '#b6e1c1',
1: '#b7c4ed',
}[id];
return `
<div class="nameEditor" style="background: ${color}">
...
Hello, <span class="nameEditor__name-${id}"></span>
...
</div>
`;
}
NameEditor.onKeyUp = (input, id) => {
const elems = document.getElementsByClassName(`nameEditor__name-${id}`);
for (const elem of elems) {
elem.innerText = input.value;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment