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

stylable-ui-components

v0.0.8

Published

A CSS-in-JS solution for building stylable components in React

Downloads

348

Readme

Stylable UI Components

build img img img

A CSS-in-JS library for building customizable and responsive UI components in React using props for styling, It allows for the easy creation of styled components with support for shorthand properties, breakpoints, and pseudo-classes.

Features

  • Default Components: Includes a set of common components like Box, Flex, Grid, Text, Button, and more, ready to be used out-of-the-box.
  • Customizable Styles: Supports dynamic styling based on props, including shorthand CSS properties and pseudo-classes.
  • Responsive Design: Built-in support for breakpoints, making it easy to create responsive layouts.
  • Component Factory: Use (createSC) to build new, reusable styled components that fits your UI structure.

Installation

To install the package, run:

npm install stylable-ui-components @emotion/styled

Usage

Start by importing the components and using them in your React app:

import { Box, Flex, Button, Text } from "stylable-ui-components";

const App = () => (
  <Flex justify="center" align="center" p={4}>
    <Box bgColor="lightgray" p={3} borderRadius={8}>
      <Text fontSize={20} mb={2}>
        Hello, world!
      </Text>
      <Button onClick={() => alert("Clicked!")}>Click me</Button>
    </Box>
  </Flex>
);

Available Components:

  • Box, Flex, Grid, Text, Paragraph, Heading
  • Link, Button, Input, Textarea, Image, Card
  • List, ListItem, Container, Badge, Avatar

Using SCFactory (SC)

You can use the SC shorthand to create new styled components dynamically:

import { SC } from "stylable-ui-components";

const App = () => (
  <SC.div backgroundColor="lightblue" padding="16px">
    Custom styled box
  </SC.div>
);

Creating Components with createSC

The createSC function allows you to build custom, reusable styled components. You can pass any HTML tag and default styles to it:

import { createSC } from "stylable-ui-components";

const CustomHeading = createSC("h2", { color: "purple", fontSize: "24px" });

const App = () => (
  <CustomHeading mb={2}>This is a custom heading</CustomHeading>
);

Customizing Styles

Each component accepts CSS props and supports shorthand properties like:

  • p, pt, pr, pb, pl, px, py for padding
  • m, mt, mr, mb, ml, mx, my for margin
  • bg, bgColor, minH, maxW, and more

Pseudo-classes like _hover and _selected can be applied to style components dynamically.

<Button p="1rem" _hover={{ backgroundColor: "darkgray" }}>
  Hover me!
</Button>

Responsive Design

Built-in breakpoints (_xs, _sm, _md, _lg, _xl, _xxl) allow you to create responsive components:

<Box _md={{ backgroundColor: "lightgreen" }}>Responsive box</Box>

You can also inline any pseudo-classes within another:

<Box _hover={{ bgColor: "beige", _md: { backgroundColor: "lightgreen" } }}>
  Hover Responsive box
</Box>

Notes

  • This is still a Work in Progress ⚠️ so some features aren't heavly tested and some syntax changes could occur in newer versions.
  • A run time CSS-in-JS solution could be less performant than other approaches in various cases, thus this is more suitable for small and meduim size projects where this issue is insignifcant.

License

MIT