Giter Club home page Giter Club logo

svelte-simple-code-editor's Introduction

svelte-simple-code-editor

Simple no-frills code editor with syntax highlighting.

This is the Svelte port of the amazing react-simple-code-editor by @satya164.

Features

  • ๐Ÿค Small - Less than 3KB min+gzip.
  • ๐Ÿ‡ Simple - Quite simple to use, and effectively zero config required!
  • ๐Ÿง™ Elegant - Use a Svelte component rather than setting things up in onMount hook.
  • ๐Ÿ“ค Highly customizable - Offers tons of options that you can modify to get different behaviors.
  • ๐Ÿ’ป SSR friendly - Works seamlessly in Sveltekit and other Server Side Rendering environments!

Installing

# pnpm
pnpm add svelte-simple-code-editor

# npm
npm install svelte-simple-code-editor

# yarn
yarn add svelte-simple-code-editor

Usage

<script>
	import { SimpleCodeEditor } from 'svelte-simple-code-editor';
</script>

<SimpleCodeEditor value="let x = 1;\n console.log(x);" />

Props

There's tons of options available for this package. All of them are already documented within the code itself, so you'll never have to leave the code editor.

value

Code to be shown.

Note: This value is changed from inside of this component. By default, you won't be able to detect changes.

But if you use it as bind:value, all changeswill flow back to the component where yur using SimpleCodeEditor.

Type: string

Default: ""

Example:

<SimpleCodeEditor value="var num = 10;" />

<!-- Update local variable `value` as user types into the editor -->
<SimpleCodeEditor bind:value={value} />

highlight

Highlight function. takes a string and returns a string(the highlighted code).

Type: (value: string) => string

Default: () => ''

Example:

<script>
	import Prism from 'prismjs';
</script>

<SimpleCodeEditor highlight={(code) => Prism.highlight(code, Prism.languages.javascript, 'javascript').value} />

insertSpaces

Insert spaces instead of tabs.

Type: boolean

Default: true

Example:

<SimpleCodeEditor insertSpaces={false} />

tabSize

Tab size. When you hit Tab key, how much indentation should be added.

Type: number

Default: 2

Example:

<SimpleCodeEditor tabSize={4} />

ignoreTabKey

When you hit tab, should it add indentation or focus out of the editor

Type: boolean

Default: false

Example:

<SimpleCodeEditor ignoreTabKey={true} />

preClass

Class to apply to pre tag used internally. This is necessary when using custom themes with PrismJS and you have to give your <pre> tag a class like language-.

Type: string

Default: ""

Example:

<SimpleCodeEditor preClass="language-javascript" />

textAreaProps

Attributes to pass to the internal <textarea> tag.

Type: object

Default: {}

Example:

<SimpleCodeEditor textAreaProps={{ 'aria-label': 'svelte-simple-code-editor-textarea' }} />

Custom style props

You can specify the following style props:

  • --padding: Padding of the editor. Default: 4px

This is it for now. You can recommend more props to be added in the future here: Custom style props to be allowed

License

MIT License ยฉ Puru Vijay

svelte-simple-code-editor's People

Contributors

puruvj avatar

Stargazers

Gijs Burghoorn avatar  avatar Weldhapi avatar  avatar Eyssette avatar Marc Gutenberger avatar Hadi Ahmadi avatar Emmanuel Salomon avatar  avatar

Watchers

 avatar  avatar

Forkers

hirajanwin

svelte-simple-code-editor's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.