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

corner-smoothing

v0.1.5

Published

Squircles for the web.

Downloads

6,540

Readme

Corner smoothing

Squircles for the web.

Supports filled squircles and border quircles. Supports React and vanilla js. Works for all components/HTML elements.

The corner smoothing is the same as the Figma corner smoothing through the use of figma-squircle.

The implementation uses clip-path, so user interactions such as hover follows the smooth corners.

Live demo.

React component

import { Squircle } from 'corner-smoothing'

<Squircle
  cornerRadius={20}
  style={{
    padding: '1rem 1.25rem',
    backgroundColor: '#7c3aed',
    color: '#fff',
    display: 'inline-block',
  }}
>
  Lorem ipsum
</Squircle>

Squircle border

A squircle border is created by rendering two squircles on top of each other. The inner one being smaller and centered in the outer. The border is the region where the outer squircle is not covered by the inner squircle. The inner squircle is rendered with the ::before pseudo-element. The corner radius of the inner squircle is adjusted to follow the radius of the outer squircle to give the correct visuals.

All this happens automatically. You just need to know that the border color is defined by background-color and that actual background color is defined by background-color on the ::before pseudo-element. An added benefit of this is that the border can have a gradient.

import { Squircle } from 'corner-smoothing'
import styled from 'styled-components'

const StyledSquircle = styled.div`
  padding: 1rem 1.25rem;
  display: inline-block;

  /* Border color */
  background: linear-gradient(45deg, #7c3aed, #ff1b6b);

  ::before {
    /* Background color  */
    background: #fff;
  }`

// Create a Squircle with the `Squircle` component:
<Squircle
  cornerRadius={20}
  borderWidth={1}
  as={StyledSquircle}
>
  Lorem ipsum
</Squircle>

React HOC (higher-order component)

import { squircle } from 'corner-smoothing'

// Create a Squircle with the `squircle` HOC:
const MySquircle = squircle(StyledSquircle, {
  cornerRadius: 20,
  borderWidth: 1
})

Vanilla function

Zero dependencies.

import { squircleObserver } from 'auto-text-size'

// squircleObserver runs the returned function directly and
// re-runs it when the element changes size.
const renderSquircle = squircleObserver(element, options)

// There is normally no need to call this manually.
renderSquircle()

// Disconnect the resize observer when done.
renderSquircle.disconnect()

One-off:

import { renderSquircle } from 'corner-smoothing'

renderSquircle(options)

The options are the same as for the React component, excluding the as property.

Options

| Name | Type | Default | Description | | --- | --- | --- | --- | | cornerRadius | number | | Similar to the CSS property border-radius. | | cornerSmoothing | number | 1 | The degree of corner smoothing as a number in the range 0–1. 0 is equivalent to no smoothing and looks like normal border-radius. 1 indicates maximal smoothing. | | preserveSmoothing | boolean | true | Allow corner smoothing to work better on large rounded corners. | | borderWidth | number | undefined | If defined, the border mode is used. | | as | string \| ReactComponent | 'div' | The underlying component that Squircle will use. Only available for the Squircle React component. |

Optional props to override corner radius for individual corners.

| Name | Type | | --- | --- | | topLeftCornerRadius | number | | topRightCornerRadius | number | | bottomRightCornerRadius | number | | bottomLeftCornerRadius | number |

Developing

When developing one typically wants to see the output in the example application without having to publish and reinstall. This is achieved by linking the local package into the example app.

Because of issues with yarn link, Yalc is used instead. A linking approach is preferred over yarn workspaces since we want to use the package as it would appear in the real world.

npm i yalc -g
yarn
yarn watch

# Other terminal
cd example
yarn
yalc link corner-smoothing
yarn dev

Yalc and HMR

Using yalc link (or yalc add--link) makes it so that Next.js HMR detects updates instantly.

Publishing

# Update version number
yarn clean && yarn build
npm publish