Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

646 B
Raw Blame
import React from "react"
import { markdown, truncate } from "@fider/services"

import "./Markdown.scss"

interface MarkdownProps {
  className?: string
  text?: string
  maxLength?: number
  style: "full" | "plainText"
}

export const Markdown = (props: MarkdownProps) => {
  if (!props.text) {
    return null
  }

  const html = markdown[props.style](props.text)
  const className = `c-markdown ${props.className || ""}`
  const tagName = props.style === "plainText" ? "p" : "div"

  return React.createElement(tagName, {
    className,
    dangerouslySetInnerHTML: { __html: props.maxLength ? truncate(html, props.maxLength) : html },
  })
}