-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from lukasoppermann/styled-inputs
Styled inputs
- Loading branch information
Showing
8 changed files
with
262 additions
and
33 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export default (form: HTMLFormElement) => { | ||
const inputs: HTMLInputElement[] = Array.from(form.querySelectorAll('input')) | ||
// repare value for highlighting | ||
const prepareValue = (value: string) => { | ||
// highlight operators | ||
value = value.replaceAll(/[\*\+-]/gi, '<span class="hl_operator">$&</span>') | ||
// slash operator | ||
value = value.replaceAll(/(?<!\<)\//gi, '<span class="hl_operator">$&</span>') | ||
// parenthese | ||
value = value.replaceAll(/[\(\)]/gi, '<span class="hl_parenthese">$&</span>') | ||
// highlight # | ||
value = value.replaceAll('#', '<span class="hl_hash">#</span>') | ||
// return value | ||
return value | ||
} | ||
// leave form field | ||
const onBlur = (event) => { | ||
const input: HTMLInputElement = event.target as HTMLInputElement | ||
const overlay = input.parentNode.querySelector('.input__overlay') | ||
if (overlay !== null) { | ||
overlay.innerHTML = prepareValue(input.value) || '' | ||
overlay.classList.remove('hidden') | ||
} | ||
} | ||
// leave form field | ||
const onFocus = (event: Event) => { | ||
const input: HTMLInputElement = event.target as HTMLInputElement | ||
const overlay = input.parentNode.querySelector('.input__overlay') | ||
if (overlay !== null) { | ||
overlay.classList.add('hidden') | ||
} | ||
} | ||
// bind events | ||
inputs.forEach(input => { | ||
onBlur({ target: input }) | ||
// blur | ||
input.addEventListener('blur', onBlur) | ||
// focus | ||
input.addEventListener('focus', onFocus) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters