Skip to content

Instantly share code, notes, and snippets.

@BarthesSimpson
Last active June 24, 2019 04:26
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 BarthesSimpson/eff9a299da59900f163b55f8cbb5001c to your computer and use it in GitHub Desktop.
Save BarthesSimpson/eff9a299da59900f163b55f8cbb5001c to your computer and use it in GitHub Desktop.
LetterInput with added characters
function Icon({ i, char, reverse = false }) {
const padding = Array.from({ length: i }, (_, i) => (
<span key={i}>&nbsp;</span>
))
return reverse ? [char, ...padding] : [...padding, char]
}
function Happy({ i }) {
return <Icon i={i} char="ᕕ( ᐛ )ᕗ" />
}
function Neutral({ i }) {
return <Icon i={i} reverse={true} char="¯_(ツ)_/¯" />
}
function Sad({ i }) {
return <Icon i={i} char="¯_(☯෴☯)_/¯" />
}
function Dead({ i }) {
return <Icon i={i} reverse={true} char="(✖╭╮✖)" />
}
//...Inside the render method of <FormInput/>
<span style={{ float: "right", width: "50%" }}>
{len < MAX_LENGTH / 4 ? (
<Happy i={len} />
) : len < MAX_LENGTH / 2 ? (
<Neutral i={len} />
) : len < (3 * MAX_LENGTH) / 4 ? (
<Sad i={len} />
) : (
<Dead i={len} />
)}
</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment