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

RFC: Add bindings to use YFM into ReactJs #42

Open
d3m1d0v opened this issue Dec 18, 2024 · 0 comments
Open

RFC: Add bindings to use YFM into ReactJs #42

d3m1d0v opened this issue Dec 18, 2024 · 0 comments
Labels
RFC Request for Comments

Comments

@d3m1d0v
Copy link
Member

d3m1d0v commented Dec 18, 2024

Description

Many of our services use transformer together with ReactJS and display HTML obtained from transformer inside React-app (usually using dangerouslySetInnerHTML). And each service has its own implementation of this rendering.

Proposal

Create a separate package which contain renderer (bindings) for YFM-HTML inside React-app. This renderer should know about base class name (.yfm) for container, about known modifiers (links-visited and no-list-reset), set default role- and aria- attributes, and so on. It will also may contain any common helpers/utilities/bindings for interacting with content inside React-app (for example, using meta or any other data from transformer).

Package name example: @diplodoc/react

Example of current utils/helpers that should be in this package: first second

Renderer implementation example
type YfmHtmlProps = {
  qa?: string;
  className?: string;
  html?: string;
  role?: string;
  mods?: {
    'links-visited'?: boolean;
    'no-list-reset'?: boolean;
    [key: string]: boolean;
  };
};

const YfmHtmlRenderer = React.forwardRef<HTMLDivElement, YfmStaticViewProps>(props, ref) => {
  return (
    <div
        ref={ref}
        role={props.role ?? 'presentation'}
        dangerouslySetInnerHTML={{__html: props.html}}
        className={cn('yfm', props.mods, props.className)}
        data-qa={props.qa}
    /> 
  );
}
@d3m1d0v d3m1d0v added the RFC Request for Comments label Dec 18, 2024
@d3m1d0v d3m1d0v changed the title RFC: Add utils (or bindings) for render YFM into ReactJs RFC: Add bindings to use YFM into ReactJs Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request for Comments
Projects
None yet
Development

No branches or pull requests

1 participant