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

@clds/style-utils

v0.50.0

Published

---

Downloads

2,191

Readme

@clds/style-utils


npm version

This is a utility package that contains helper methods to ease the work with styled-components

media

Available media:

| Breakpoint name | Min width | Max width | | --------------- | --------- | --------- | | phone | 0px | 576px | | tablet | 577px | 768px | | desktop | 769px | 1024px | | wide | 1025px | 1280px |

You should use it when your component should change it's style based on the browser resolution.
This is preffered over using hooks when possible, css is much more performant.
If you use hooks to pass properties to styled components, a new CSS class will be created on each change - this should be avoided.

import { media } from '@clds/style-utils';

const ModalBox = styled.div`
  height: 220px;
  width: 520px;

  @media ${media.tablet()} {
    width: 280px;
  }
`;

By default it will use a range, meaning that if you will use tablet from the example above the media query will be as follows:

(min-width: <MOBILE_RESOLUTION>) and (max-width: <TABLET_RESOLUTION>)

You can use the options in the following way to allow different behaviors:

import { media } from '@clds/style-utils';

const ModalBox = styled.div`
  height: 220px;
  width: 520px;

  @media ${media.tablet({ minOnly: true })} {
    width: 280px;
  }
`;

Because only the query body is generated you will have full intellisense support from IDE in it's content. (hence @media is used, to prevent breaking out from styled component template)
Additional benefit is that you can combine the queries:

import { media } from '@clds/style-utils';

const ModalBox = styled.div`
  height: 220px;
  width: 520px;

  @media ${media.tablet({ minOnly: true })} and ${media.wide({
      maxOnly: true,
    })} {
    width: 280px;
  }
`;

Usage with Hooks

import { useDesktop, usePhone } from '@clds/style-utils';

const View = () => {
  const isPhone = usePhone();
  const isDesktopAndBelow = useDesktop({ maxOnly: true });

  if (isPhone) return <div>This is phone</div>;
  if (isDesktopAndBelow) return <div>This is desktop, tablet or phone</div>;
  return <div>This is above desktop</div>;
};

Available Hooks

  • usePhone
  • useTablet
  • useDesktop
  • useWide

Options

| Name | Type | Description | default | | ------- | ------- | -------------------------------------- | ------- | | maxOnly | boolean | Media query will only have max-width | false | | minOnly | boolean | Media query will only have min-width | false |

checkerboard

A function that returns a checkerboard background style

Options

| Name | Type | Description | default | | ------ | ------ | ----------------------------------- | ----------- | | color1 | string | The first color to use | - | | color2 | string | The second color to use | transparent | | size | number | The size (in pixels) of the squares | 15 |

createStylesheetsFromUrls

A function that creates stylesheet link elements from given urls and appends them to document head.

To identify these link elements, a custom attribute is been added (cld-dynamic-stylesheet). This allows recycling existing link elements by replacing their href when needed, and disposing un-necessary link elements.

For the given input -

import { createStylesheetsFromUrls } from '@clds/style-utils';

const urls = ['https://some-style-sheet.com'];

createStylesheetsFromUrls(urls);

Output will be -

<link
  href="https://some-style-sheet.com"
  rel="stylesheet"
  cld-dynamic-stylesheet="cld"
/>

Versioning

This library follows Semantic Versioning.

License

See LICENSE