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

@quri/squiggle-components

v0.10.0

Published

[![npm version](https://badge.fury.io/js/@quri%2Fsquiggle-components.svg)](https://www.npmjs.com/package/@quri/squiggle-components) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/quantified-uncertainty/squiggle/b

Downloads

788

Readme

npm version License: MIT

Squiggle components

This package contains the React components for Squiggle. These can be used either as a library or hosted as a storybook.

The @quri/squiggle-components package offers several components and utilities for people who want to embed Squiggle components into websites.

This package is pure ESM; if you have trouble with importing it, read this document.

Configuration

First, install this library:

npm add @quri/squiggle-components # or `yarn add`, or `pnpm add`

Styles

Before using this library, you'll have to make a decision on how to use styles.

There are three options:

1. Usage with Tailwind

If you already use Tailwind, you should add ./node_modules/@quri/ui/dist/**/*.js and ./node_modules/@quri/squiggle-components/dist/**/*.js to your tailwind.config.js content configuration:

module.exports = {
  content: [
    ..., // other files for your own project
    './node_modules/@quri/ui/dist/**/*.js',
    './node_modules/@quri/squiggle-components/dist/**/*.js',
  ],
  plugins: [
    require("@tailwindcss/forms")({ strategy: "class" }), // playground settings use tailwind forms
    require("@quri/squiggle-components/tailwind-plugin"), // some squiggle-components styles extend the default Tailwind's theme
  ],
  ..., // other settings
}

It's possible that in the future you might need to change the content or plugins lists. Please check this README and consult with squiggle-components changelog when you update this library to a new version.

In addition, you should import common styles (these include styles from the JS libraries that we use in squiggle-components):

import "@quri/squiggle-components/common.css";

2. Usage without Tailwind

You can import the CSS file that we bundle with this library:

import "@quri/squiggle-components/full.css";

Note that you have to import this CSS file only if you don't use Tailwind.

The downsides of this approach:

  • It will include the Tailwind's global preflight styles, which do some non-trivial CSS resets, e.g. it resets all heading styles.
  • There's a slight risk that your own CSS framework class names will collide with Tailwind class names.

You might want to import squiggle-components CSS before your own CSS resets; in that case, your CSS will get a chance to override the styles that Tailwind's preflight broke for you.

3. Configure Tailwind with scoped styles just for this library

This is the approach that we recommend if the previous one doesn't work for you. It's more complicated, though.

First, install Tailwind in your project.

Then configure Tailwind (in tailwind.config.js) in the similar way as the first approach explained above in the "Usage with Tailwind" section:

// tailwind.config.js
module.exports = {
  content: [
    "./node_modules/@quri/ui/dist/**/*.js",
    "./node_modules/@quri/squiggle-components/dist/**/*.js",
  ],
  plugins: [
    require("@tailwindcss/forms")({ strategy: "class" }),
    require("@quri/squiggle-components/tailwind-plugin"),
  ],
  corePlugins: {
    preflight: false,
  },
  important: ".squiggle",
};

Next, in your CSS file for Tailwind, the one with @tailwind directives, you'll have to insert the full Tailwind's preflight, but wrap it in .squiggle { ... }. This way, Tailwind's preflight will affect only Squiggle components and nothing else.

This will require you to install postcss-nested and add it to your postcss.config.js, like this:

// postcss.config.js
module.exports = {
  plugins: {
    "postcss-nested": {},
    tailwindcss: {},
    autoprefixer: {},
  },
};

You'll also need to include wrapped styles for forms. See scoped-forms.css in packages/website to learn how to do that.

Then, add <TailwindProvider>...</TailwindProvider> on top of your app (it can be imported from @quri/ui package). It will:

  1. Add an additional <div class="squiggle">...</div> for scoped Tailwind styles.
  2. Set up React context that will allow to wrap modals and tooltips with that div too. (This is necessary because our modals and tooltips rely on React portals and jump out of the main DOM tree.)

In addition, you should import common styles (these include styles from the JS libraries that we use in squiggle-components):

import "@quri/squiggle-components/common.css";

Components

Consult with our Storybook to find out which components you can use.

You'll probably need one of <SquiggleChart>, <SquiggleEditor> or <SquigglePlayground>, depending on your goals.

Usage with create-react-app

Create React App seems to be on the way out and might be not compatible with Squiggle. We recommend looking into "production-grade React frameworks" instead.