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

@handbook/code-block

v1.1.0

Published

[![NPM](https://img.shields.io/npm/v/@handbook/code-block.svg)](https://www.npmjs.com/package/@handbook/code-block) [![TEST](https://github.com/rocket-hangar/handbook/workflows/Test/badge.svg)](https://github.com/rocket-hangar/handbook/actions?query=workf

Downloads

17

Readme

@handbook/code-block

NPM TEST codecov

CodeBlock React components

Use React component.

import { CodeBlock } from '@handbook/code-block';

function Component(sourceCode: string) {
  return <CodeBlock language="js">{sourceCode}</CodeBlock>;
}

Set default code block for mdx documents.

import { MDXCodeBlock } from '@handbook/code-block';

const components = {
  pre: (props) => <div {...props} />,
  code: MDXCodeBlock,
};

API

components/CodeBlock.tsx

export function CodeBlock({ children, language, theme }: CodeBlockProps) {}

export interface CodeBlockProps {
  /**
   * your code block theme
   *
   * you can choose one of dracula, duotoneDark, duotoneLight, github, nightOwl, nightOwlLight, oceanicNext, palenight, shadesOfPurple, synthwave84, ultramin and vsDark
   *
   * @example import github from 'prism-react-renderer/themes/github'
   *
   * @see <rootDir>/node_modules/prism-react-renderer/themes
   */
  theme?: PrismTheme;
  /** source code */
  children: string;
  /** language */
  language: Language;
}

components/MDXCodeBlock.tsx

export function MDXCodeBlock({
  theme = vsDark,
  children,
  className = 'language-javascript',
}: MDXCodeBlockProps) {}

export interface MDXCodeBlockProps {
  /**
   * your code block theme
   *
   * you can choose one of dracula, duotoneDark, duotoneLight, github, nightOwl, nightOwlLight, oceanicNext, palenight, shadesOfPurple, synthwave84, ultramin and vsDark
   *
   * @example import github from 'prism-react-renderer/themes/github'
   *
   * @see <rootDir>/node_modules/prism-react-renderer/themes
   */
  theme?: PrismTheme;
  /** source string */
  children: string;
  /** css className */
  className?: string;
}

How to get source codes

These code block components print source codes only.

If you want to get source codes into your Web App use @handbook/source, @handbook/babel-plugin and @handbook/typescript-source-sampler.

You can print your source code on your Web App easier.

import React from 'react';
import { render } from 'react-dom';
import { source } from '@handbook/source';
import { sampling } from '@handbook/typescript-source-sampler';
import { CodeBlock } from '@handbook/code-block';

const module = source(require('./source/hello'));
const samples = sampling({ source: module.source, samples: ['Class', 'func'] });

function App() {
  return <CodeBlock language="typescript" children={samples.get('Class')} />;
}

render(<App />, document.querySelector('#app'));

See more

  • @handbook/* This package is one of @handbook/* packages. Go to the project home and see more details.