Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I think it would be good to add a react example #45

Open
hmmhmmhm opened this issue May 28, 2021 · 0 comments
Open

I think it would be good to add a react example #45

hmmhmmhm opened this issue May 28, 2021 · 0 comments

Comments

@hmmhmmhm
Copy link

First of all, thank you for developing a good project.
I succeeded in applying joypixels in react, and I want to share components.

EmojiAsset.tsx

import joypixels from 'emoji-toolkit'

const EmojiAsset = (props: { emoji: string }) => {
  const html = () => {
    const styles = [
      `width: 1.2em`,
      `height: 1.2em`,
      'top: -1px',
      'position: relative'
    ]
    const html: string = (joypixels.toImage(props.emoji) as string)
      .split(`<img class="joypixels"`)
      .join(`<img class="joypixels" style="${styles.join(';')}"`)

    return { __html: html }
  }

  return (
    <span
      className="emojiAsset"
      style={{ display: 'inline-block' }}
      dangerouslySetInnerHTML={html()}
    />
  )
}

export default EmojiAsset

index.tsx

const SomePage = () => {
  return (
    <EmojiAsset emoji="📦 Module" />
  )
}

export default SomePage

Example

스크린샷 2021-05-28 오후 7 03 44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant