npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@srsholmes/solid-code-input

v0.0.18

Published

Simple Code Input with syntax highlighting for SolidJS

Downloads

75

Readme

Solid Code Input

Solid Code Input is a small component for SolidJS that allows you to create a lightweight text area component which will automatically syntax highlight the code you type in it. It is designed for basic use cases where you want to display code to the user, and allow them to edit it, without all the overhead of a full blown code editor.

https://user-images.githubusercontent.com/3579905/222016141-0f6e9225-8dda-484e-a712-8af2caf1bf99.mp4

It supports both PrismJS and HighlightJS to do the syntax highlighting, and will use either depending on which library you pass in as a prop.

Features

  • Very Lightweight
  • Easier to use than CodeMirror, Ace, and Monaco
  • Supports both PrismJS and HighlightJS
  • Auto Indentation
  • Tab to indent
  • Auto resize to fit content
  • Resizable
  • Placeholders

Installation

npm install @srsholmes/solid-code-input
# or
yarn add @srsholmes/solid-code-input

Usage

import { CodeInput } from '@srsholmes/solid-code-input';

<CodeInput
  autoHeight={true}
  resize="both"
  placeholder="Input your code here..."
  prismJS={Prism}
  onChange={setInput}
  value={'const hello = "world";'}
  language={'typescript'}
/>;

API

CodeInput takes the following props: | Name | Type | Description | |---------------|-----------------------------------------------------|-----------------------------------------------------------------------------------| | prismJS | typeof Prism | Optional. An instance of the Prism library for syntax highlighting. | | highlightjs | typeof highlightjs | Optional. An instance of the Highlight.js library for syntax highlighting. | | value | string | Required. The value of the code input. | | language | string | Required. The language of the code input. | | onChange | (value: string) => void | Required. A callback function that is called when the value of the input changes. | | placeholder | string | Optional. Placeholder text for the input. | | resize | 'both' | 'horizontal' | 'vertical' | Optional. Specifies whether the input can be resized, and in which direction. | | autoHeight | boolean | Optional. Specifies whether the input height should adjust automatically. |

Types

export type CodeInputProps = {
  prismJS?: typeof Prism;
  highlightjs?: typeof highlightjs;
  value: string;
  language: string;
  onChange: (value: string) => void;
  placeholder?: string;
  resize?: 'both' | 'horizontal' | 'vertical';
  autoHeight?: boolean;
};

Example App

solid-code-input

To run the example app, clone the repo and run the following commands:

git clone https://github.com/srsholmes/solid-code-input
yarn # Install dependencies
yarn build # Build the component from source
cd example
yarn
yarn dev

Shout outs

Shout out to Oliver Geer (WebCoder49) for this awesome article which inspired this component Creating an Editable Textarea That Supports Syntax-Highlighted Code.

The method used was heavily inspired by this repo code-input, and the auto indent was taken directly from his indent plugin.

License

MIT