@yozora/react-code-live
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.0-alpha.4 • Public • Published

    @yozora/react-code-live


    This component is for rendering the Code data produced by @yozora/tokenizer-indented-code and @yozora/tokenizer-fenced-code.
    This component has been built into @yozora/react-markdown, you can use it directly.

    Install

    • npm

      npm install --save @yozora/react-code-live
    • yarn

      yarn add @yozora/react-code-live

    Usage

    • Basic:

      import React from 'react'
      import CodeLive, { CodeRendererProps } from '@yozora/react-code-live'
      import '@yozora/react-code-live/lib/esm/index.css'
      
      const JsxRenderer = ({ value }: CodeRendererProps): React.ReactElement => {
        // eslint-disable-next-line no-new-func
        const f = new Function(code)
        const v = f()
        return <span data-type="jsx">{ v }</span>
      }
      
      const code = `
        const a = 1 + 2;
        return a * a
      `
      
      const wrapper = (
        <CodeLive
          lang="jsx"
          value={ code }
          CodeRenderer={ JsxRenderer }
        />
      )

    Props

    Name Type Required Default Description
    className string false - Root css class
    collapsed boolean false false Collapse the code block
    darken boolean false - Enable the darken mode
    highlightLinenos number[] false - Line number of Lines that should be highlighted
    lang string false - Language of the source codes
    maxLines number number - Maximum number of rows displayed
    showLinenos boolean false - Whether to display the line numbers
    style React.CSSProperties false - Root css style
    title string false - Code title
    value string true - Literal source codes
    • className: The root element of this component will always bind with the CSS class 'yozora-code-literal'.

    Related

    Install

    npm i @yozora/react-code-live

    DownloadsWeekly Downloads

    175

    Version

    2.0.0-alpha.4

    License

    MIT

    Unpacked Size

    43.9 kB

    Total Files

    11

    Last publish

    Collaborators

    • lemonclown