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

Is there any way to override the mark style? #14

Open
DevCraftsmanShubham opened this issue Apr 9, 2020 · 2 comments
Open

Is there any way to override the mark style? #14

DevCraftsmanShubham opened this issue Apr 9, 2020 · 2 comments

Comments

@DevCraftsmanShubham
Copy link

I need custom styling for mark which highlights the text, is there anyway i can do that?

@guillaumedsde
Copy link

Hi, if you're using the TokenAnnotator, there are examples of how to do that in the repository, if you use the TextAnnotator, last I checked it did not work.

I filed an issue and a PR is opened

@mattychen
Copy link

@Sk1794 set renderMark as a custom prop to override the default highlight.

<TokenAnnotator
        tokens={["My", "text", "needs", "annotating", "for", "NLP", "training"]}
        value={[{ start: 5, end: 6, tag: "TOPIC", color: "#EEE" }]}
        renderMark={ *YourCustomComponent* }
      />

You will get an error due to the way props is currently passed down in the source code, but you can ignore it.

Warning: React does not recognize the `renderMark` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `rendermark` instead. If you accidentally passed it from a parent component, remove it from the DOM element.

This is found in the current source code:

  const {tokens, value, onChange, getSpan: _, ...divProps} = props
  const splits = splitTokensWithOffsets(tokens, value)
  return (
    <div {...divProps} onMouseUp={handleMouseUp}>
      {splits.map((split, i) =>
        split.mark ? (
          renderMark({
            key: `${split.start}-${split.end}`,
            ...split,
            onClick: handleSplitClick,
          })
        ) : (
          <Token key={split.i} {...split} />
        )
      )}
    </div>
  )
}

where renderMark is thrown in as divProps, but it will work.

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

3 participants