All Projects → uiwjs → react-code-preview

uiwjs / react-code-preview

Licence: MIT license
Code edit preview for React.

Programming Languages

typescript
32286 projects
Less
1899 projects
HTML
75241 projects
shell
77523 projects

Projects that are alternatives of or similar to react-code-preview

Qlens
QLens is an electron app which dynamically generates GraphQL Schemas and Mongo Schema visualization. QLens significantly cuts development time by automating the formation of their GraphQL schemas based on information fetched from their non-relational database.
Stars: ✭ 110 (+111.54%)
Mutual labels:  codemirror
Markdown Edit
online markdown editor/viewer
Stars: ✭ 188 (+261.54%)
Mutual labels:  codemirror
Bilibili-Column-Helper
bilibili专栏助手,已Archive,后续可能port到vscode插件。
Stars: ✭ 26 (-50%)
Mutual labels:  codemirror
Droppy
**ARCHIVED** Self-hosted file storage
Stars: ✭ 1,564 (+2907.69%)
Mutual labels:  codemirror
Vue Codemirror
⌨️ @codemirror component for @vuejs
Stars: ✭ 2,115 (+3967.31%)
Mutual labels:  codemirror
Vue Codemirror Lite
Lightweight Codemirror Component for Vue.js
Stars: ✭ 244 (+369.23%)
Mutual labels:  codemirror
Code Mirror Themes
📝 A large collection of Code Mirror themes for your coding pleasure
Stars: ✭ 87 (+67.31%)
Mutual labels:  codemirror
dword
Web editor based on CodeMirror
Stars: ✭ 37 (-28.85%)
Mutual labels:  codemirror
Yii2 Podium
Yii 2 forum module project
Stars: ✭ 172 (+230.77%)
Mutual labels:  codemirror
caucus
Realtime Collaborate Editor with Embedded Compiler
Stars: ✭ 278 (+434.62%)
Mutual labels:  codemirror
Editor.md
The open source embeddable online markdown editor (component).
Stars: ✭ 11,741 (+22478.85%)
Mutual labels:  codemirror
Codemirror Graphql
GraphQL mode and helpers for CodeMirror.
Stars: ✭ 147 (+182.69%)
Mutual labels:  codemirror
wc-codemirror
CodeMirror as a vanilla web component
Stars: ✭ 31 (-40.38%)
Mutual labels:  codemirror
Flok
Web-based P2P collaborative editor for live coding sounds and images
Stars: ✭ 119 (+128.85%)
Mutual labels:  codemirror
ClearWriter
A silent notepad.
Stars: ✭ 25 (-51.92%)
Mutual labels:  codemirror
Saite
Interactive document creation for exploratory graphics and visualizations. 咲いて (in bloom). Built on top of hanami vega/vega-lite library with CodeMirror and self hosted ClojureScript
Stars: ✭ 89 (+71.15%)
Mutual labels:  codemirror
Ngx Codemirror
Codemirror Wrapper for Angular
Stars: ✭ 192 (+269.23%)
Mutual labels:  codemirror
fongshen-editor
A highly customizable code-inserting editor for markdown or other languages
Stars: ✭ 35 (-32.69%)
Mutual labels:  codemirror
TW5-codemirror-plus
An attempt to make a better writing experience for TW using codemirror.
Stars: ✭ 26 (-50%)
Mutual labels:  codemirror
kirby-markdown-field
Super-sophisticated markdown editor for Kirby 3, community built.
Stars: ✭ 143 (+175%)
Mutual labels:  codemirror

React Code Preview

Build & Deploy Release npm version Gitee

Code edit preview for React. Preview Demo: https://uiwjs.github.io/react-code-preview

There are often a lot of sample code in the documentation. We hope that you can run the sample code to view the rendering interface as you read the document.

Install

npm install @uiw/react-code-preview --save

Usage

In React 18

Open in CodeSandbox

import Button from '@uiw/react-button';
import CodePreview from '@uiw/react-code-preview';

const code = `import Button from '@uiw/react-button';
import ReactDOM from 'react-dom/client';

ReactDOM.createRoot(_mount_).render(
  <div>
    <Button type="primary">主要按钮</Button>
    <Button type="success">成功按钮</Button>
  </div>,
);`;

export default function App() {
  return <CodePreview code={code} dependencies={{ Button }} />;
}

In React 17

Open in CodeSandbox

import Button from '@uiw/react-button';
import CodePreview from '@uiw/react-code-preview';

const code = `import Button from '@uiw/react-button';
import ReactDOM from 'react-dom';

ReactDOM.render(
  <div>
    <Button type="primary">主要按钮</Button>
    <Button type="success">成功按钮</Button>
  </div>,
  _mount_
);`;

export default function App() {
  return <CodePreview code={code} dependencies={{ Button }} />;
}
  • _mount_ Special strings, the compilation will be replaced.

Props

interface CodePreviewProps extends SplitProps {
  prefixCls?: string;
  style?: React.CSSProperties;
  /**
   * To specify a CSS class, use the className attribute.
   */
  className?: string;
  /**
   * Whether to display the border.
   */
  bordered?: boolean;
  /**
   * `JSX` source code
   */
  code?: string;
  /**
   * Whether to display the code interface.
   */
  noCode?: boolean;
  /**
   * Is the background white or plaid?
   */
  bgWhite?: boolean;
  /**
   * Only show Edit
   */
  onlyEdit?: boolean;
  /**
   * Whether to display the preview interface.
   */
  noPreview?: boolean;
  /**
   * Preview area does not display scroll bars
   */
  noScroll?: boolean;
  /**
   * Modify ReactCodemirror props.
   */
  editProps?: ReactCodeMirrorProps;
  /**
   * Dependent component
   */
  dependencies?: Record<string, any>;
  codePenOption?: CodepenProps & {
    /**
     * Packages that do not require comments.
     * @example ['uiw']
     */
    includeModule?: string[];
  };
  codeSandboxOption?: CodeSandboxProps;
  /** @default 'Code' */
  btnText?: string;
  /** @default 'Hide Editor' */
  btnHideText?: string;
  /**
   * `light` / `dark` / `Extension` Defaults to `light`.
   * @default light
   */
  theme?: ReactCodeMirrorProps['theme'];
}
type CodePenOption = {
  title?: string;
  html?: string;
  js?: string;
  css?: string;
  editors?: string;
  css_external?: string;
  js_external?: string;
  js_pre_processor?: string;
};
type CodepenProps = CodePenOption & React.FormHTMLAttributes<HTMLFormElement>;
type CodeSandboxProps = React.FormHTMLAttributes<HTMLFormElement> & {
  /**
   * Whether we should redirect to the embed instead of the editor.
   */
  embed?: boolean;
  /**
   * The query that will be used in the redirect url. `embed` must be equal to `true`, `embed=true`.
   * [CodeSandbox Embed Options](https://codesandbox.io/docs/embedding#embed-options)
   * @example `view=preview&runonclick=1`
   */
  query?: string;
  /**
   * Instead of redirecting we will send a JSON reponse with `{"sandbox_id": sandboxId}`.
   */
  json?: boolean;
  /**
   * Parameters used to define how the sandbox should be created.
   */
  files?: Record<
    string,
    {
      content?: string | Record<string, any>;
      isBinary?: boolean;
    }
  >;
};

Development

The components are placed in the src directory.

npm run watch # Listen compile .tsx files.
npm run build # compile .tsx files.

npm run doc

Related

Contributors

As always, thanks to our amazing contributors!

Made with github-action-contributors.

License

Licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].