yapui
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

YAPUI

Yet Another Primitive UI.

Development Requirements

  • node
  • npm | yarn

See package.json for dependencies

Motivation

Can read the full reasoning in the blog post, however the main motivation are:

  • to learn,
  • control the API,
  • opinionated way of styling via objects
  • most important have set of UI components that I have full control over when building my side projects.

Installation

npm install yapui

Setup

Single page application (SPA)

This is how is used in a React SPA

// index.js
import React from 'react';
import { render } from 'react-dom';
import { UiProvider, createStylesRenderer } from 'yapui';
import { App } from './App';

const renderer = createStylesRenderer();
render(
  <UiProvider renderer={renderer}>
    <App />
  </UiProvider>,
  document.getElementById('app')
);

Next.js

Usage in next.js is based on this (now-example)[https://github.com/zeit/next.js/tree/master/examples/with-fela]

// pages/_document.js
import React from 'react';
import Document, { Html, Head, Main, NextScript } from 'next/document';
import { createStylesRenderer, renderToNodeList } from 'yapui';

export default class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const renderer = createStylesRenderer();
    const originalRenderPage = ctx.renderPage;

    ctx.renderPage = () =>
      originalRenderPage({
        enhanceApp: (App) => (props) => <App {...props} renderer={renderer} />,
      });

    const initialProps = await Document.getInitialProps(ctx);
    const styles = renderToNodeList(renderer);
    return {
      ...initialProps,
      // styles prop is then used in the render method automatically
      // by the custom document. No need to add it manually
      styles: [...initialProps.styles, ...styles],
    };
  }

  render() {
    return (
      <Html>
        <Head />
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
}
// pages/_app.js

import React from 'react';
import { UiProvider } from 'yapui';
// before 2.6.1 you need a fallback renderer, now this is included in
// UiProvider
export default function MyApp({ Component, pageProps, renderer }) {
  return (
    <UiProvider renderer={renderer}>
      <Component {...pageProps} />
    </UiProvider>
  );
}

Usage

For the api of each component available See for Storybook and documentation

Scripts

  • install install project dependencies
  • storybook start the storybook dev server
  • build runs build:cjs and build:esm
  • build:storybook builds the storybook site for this project
  • build:cjs builds primitive ui as commonjs compatible module
  • build:esm builds primitive ui as ES modules compatible module
  • clean:dist deletes distribution directory
  • clean:node_modules deletes dependencies directory
  • lint runs eslint script

TODO

  • [ ] document usage
  • [x] finalize api
  • [x] revise components and check if more are needed
  • [x] document api
  • [x] finish typescript declaration files

Readme

Keywords

none

Package Sidebar

Install

npm i yapui

Weekly Downloads

0

Version

3.0.1

License

MIT

Unpacked Size

96.3 kB

Total Files

154

Last publish

Collaborators

  • gtothesquare