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

@shipengine/alchemy

v6.0.16

Published

`shipengine/alchemy` is a toolkit for building re-usable, fully-featured, data-connected and cross-compatible React components (“Elements”)[^1] for use in applications that utilize the [ShipEngine API](https://shipengine.github.io/shipengine-openapi/).

Downloads

425

Readme

Alchemy

shipengine/alchemy is a toolkit for building re-usable, fully-featured, data-connected and cross-compatible React components (“Elements”)[^1] for use in applications that utilize the ShipEngine API.

The library makes opinionated choices about API access, state management, language translations[^2] and UI foundations.

Features:

  • Available to all descendants of the AlchemyProvider:

    • A batteries-included client for accessing ShipeEngine API endpoints with a shared cache and lifecycle management via hooks from @shipengine/react-api.
    • A ShipEngine Giger theme, which can be re-defined at instantiation via the themeConfig prop and accessible on the Emotion css callback prop, and icons via Giger's Icon component.
  • Available to components created via the alchemy.createElement factory:

    • Fully isolated styles. CSS styles are reset at the boundary of each Element, ensuring that they are self-contained and unaffected by the host application’s styles.
    • Fully isolated language translations. A non-global instance of i18next is provided for each Element. Individual translations can be overriden at the Element's point-of-use via the optional resources prop.
    • A configurable ErrorBoundary.

Basic Usage

[!IMPORTANT] In addition to @shipengine/alchemy, you must also add @shipengine/react-api and @shipengine/js-api to your project's dependencies.

  • A single AlchemyProvider should be rendered near the top of the application's component hiearchy
  • The createElement factory is used to create stylistically isolated components that will utilize the AlchemyProvider's API client and theme.
import alchemy, { AlchemyProvider, useListShipments } from "@shipengine/alchemy";
import { themeConfig } from "../themeConfig";

type MyComponentProps = {
  myProp: string;
};

const MyComponent = ({ myProp }: MyComponentProps) => {
  const { data, isLoading, error } = useListShipments();

  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>{error.message}</div>;

  console.log(data);
  // > an object matching the response schema of https://shipengine.github.io/shipengine-openapi/#operation/list_shipments

  return (
    <div
      css={(theme) => ({
        /* ... */
      })}
    >
      Retrieved {data.shipments.length} shipments
    </div>
  );
};

// Your own component that the ErrorBoundary will display when an error occurs
const MyErrorFallback = ({ error }) => <div>Whoops...</div>;

const MyElement = alchemy.createElement(
  MyComponent,
  MyErrorFallback,
  // optional configuration object
  {
    // applied to the container
    css: (theme) => ({
      // ...
    }),

    // i18next translations
    resources: {
      // ...
    },
  }
);

const MyApp = () => {
  return (
    <AlchemyProvider getToken={() => "your-platform-token"} themeConfig={themeConfig}>
      <section>
        Your pre-existing application
        <div>
          Locate the Element wherever you like
          <MyElement
            myProp="just a regular prop"
            // optional translations override prop added by the factory
            resources={{}}
          />
        </div>
      </section>
    </AlchemyProvider>
  );
};