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

juhuui

v0.0.9

Published

Fun tool for design systems

Downloads

17

Readme

npm version github actions status npm downloads gzip size brotli size

UI tool intended for design systems

I made this tool wanting the best (very objective) of Styled-Components, Chakra-UI but with atomic CSS (single purpose classes). You can merge, nest and create variants. All this sweetness is packed into good performance.

Hopefully you will have the same joy using juhuUi as me.


Features

  • Nesting components
  • Theme (default/customizable)
  • Descriptive class names in developer mode 🍭"color-orange sm:color-blue md:color-green" 🍭
  • @media queries are written as arrays 🎨['green', 'orange', 'pink'] 🎨
  • Same shortcuts as Styled-System ⚡️'p' for padding, 'my' for [margin-top, margin-bottom], 'c' for color, 'bg' backgroundColor, etc. ⚡️
  • Extract "critical CSS" for server side rendering
  • Implement darkmode using CSS variables

Installation

yarn add juhuui

or

npm install juhuui

Usage

It needs a createElement function so it knows how build components. Add this somewhere only once in your javascript tree. This is the solution for now.

import { setup } from 'juhuui';
import { createElement } from 'react';

setup(createElement);

Inline and overwriting styled components

Juhu you can start building components.

import {
  AspectRatioBox,
  Button,
  Box,
  CircularProgress,
  Divider,
  Flex,
  Fun,
  Grid,
  Heading,
  Icon,
  IconButton,
  Input,
  Link,
  List,
  ListItem,
  Progress,
  Stack,
  Tag,
  Text,
  Textarea
} from 'juhuui';

const SayWhat = () => (
  <Flex css={{ direction: 'column' }}>
    <Box css={{ color: 'green' }}>RAINBOW</Box>
    <Fun
      css={{
        '&:hover *': {
          fill: ['red', 'yellow', 'blue']
        }
      }}
    >
      <Text>ZAUBERMOON</Text>
      <Icon name="moon" color="green" />
    </Fun>
  </Flex>
);

Styled component

All components can be created externally. This is useful for separating styles and components. Styles can be overwritten by writing them inline. Please use the 'fw' prop to forward arguments because 'fw' will be removed from the DOM. The with function takes a second argument, an array of strings to be removed from the DOM, as an alternative to 'fw'.

import { Text, Box } from 'juhuui';

const UpperCase = Text.with({
  textTransform: 'uppercase',
  c: 'orange.600'
})

<UpperCase>Hello there!</UpperCase>;

// or

const Colorful = Text.with(({fw}) => ({
  bg: fw.background,
  color: 'orange.600'
}))

<Colorful fw={{ background: 'yellow.200' }}>Orange</Colorful>;
// or overwrite styles by adding a css property inline
<Colorful css={{ backgroundColor  "red.300" }} fw={{ backgroundColor: 'yellow.200' }}>Red</Colorful>;

// or merge

const GreenBox = Box.with({ bg: 'green' })
const Red = Text.with({ color: 'red' })
const SpaceCase = Colorful.merge([GreenBox, Red]).with({ textTransform: 'uppercase' })

<SpaceCase>Invisible green</SpaceCase>
// or inline merge
<Box merge={[GreenBox, Red]}>

Create variants

Variants are a probably a necessity for a good design system.

import { Button } from 'juhuui'

const B = Button.variants({ variant: {
  green: {
    bg: 'green'
  },
  blue: {
    bg: 'blue'
  }
} }).with()

<B variant="green">GREENIE</B>

Create class names

Function for creating class names. Just for the power of freedom. Performance is better than the above. If you are looking for a tool that only creates class names we recommend a smaller tool called otion.

import { css } from 'juhuui';

const classNames = css({
  color: 'green',
  bg: ['blue.300', 'green400', 'brown.500']
});

<div classNames={classNames}></div>;

Media queries

Media queries can be written as an array of values (associated with the theme object) or by using the media key.

import { Box } from 'juhuui';

const Mercy = Box.with({
  media: {
    '(min-width: 90em)': {
      color: 'green.400',
    }
  }
  color: ['blue.300', 'green200', 'brown.500']
});

<Mercy>Merci</Mercy>;

Server side rendering

For extracting critical CSS please use the extractCss function.

Here is a short example how you would do this in Next.js. The data attributes needs to be called "data-process".

import Document, { Head, Html, Main, NextScript } from 'next/document';
import { extractCss } from 'juhuui';

export default class MyDocument extends Document {
  static async getInitialProps({ renderPage }) {
    const page = renderPage();

    const { css, data } = extractCss();
    return { ...page, css, data };
  }

  render() {
    return (
      <Html>
        <Head>
          <style
            id={'_juhuui'}
            dangerouslySetInnerHTML={{ __html: this.props.css }}
            data-process={this.props.data}
          />
        </Head>
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
}

Options

The setup function takes a second object with options.

import { setup, theme } from 'juhuui';
import { h, forwardRef } from 'preact';

const newTheme = {
  ...theme,
  colors: {
    ...theme.colors,
    juhuui: {
      50: 'white',
      100: '#fff7eb',
      200: '#e9f8e8',
      300: '#37b311',
      800: '#07130f',
      900: '#07130f'
    }
  }
};

setup(h, {
  theme: newTheme,
  defaultFun: true, // defaults to true
  forwardRef
});

Future stuff

  • [x] ForwardRef works for styled components not inline
  • [ ] Move theme to a different package
  • [ ] Default React/Preact versions without a need for calling setup
  • [ ] Improve type safety (! high priority. Help highly appreciated)

Benchmarks

You can test and compare it live or download the repository. All credits go to Styled-Components and Necolas for creating this.

Thanks

Thanks to all for being here and beforehand for anybody who wants to contribute either by reporting a bug or by a PR.

Any feedback is met with love and curiosity. Have fun! 💚

Inspiration