Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

corners

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

corners

  • 0.0.13
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

corners logo

Bundlephobia Types Build status NPM Version MIT License

npm i corners
yarn add corners

Create react components with angled or smooth-rounded corners.

Features

  • premade component factories:
    const MyRoundedButton = rounded.button
    
  • make your own factory:
    const dogEared = corners(chamfer, null, null, null).size(40)
    const MyDogEaredButton = dogEared.button
    
  • CSS clip-path ensures corners are rendered as empty space
  • Components may be dynamically sized: a resize observer is used to detect changes to component size and update the clip-path
  • Specify the corner size when calling a factory (e.g. rounded.size(10).div)
  • Support for drop shadows (e.g. corners(round).options({shadow: {...}}).div)
  • Support for positioning elements outside of the target element
  • Clipping Paths that are inset (or spread ?) from the target element
  • Layers that are inset or spread from the target element
  • Simultaneous use of clipping path and layers

API

corners

corners(...cornerFns).with({ cornerSize, noClipping, above, below }) => ComponentFactory

Creates a new component factory with the given corner functions. The corner functions are applied in the order they are given.

ArgumentTypeRequired?Description
cornerFnsNullable<DrawCorner>[]Yes1, 2, or 4 functions that specify the corners for this factory in clockwise order
cornerSizenumberNoEquivalent to N in css border-radius: Npx
noClippingbooleanNotrue is equivalent to css overflow: visible
abovePartial<Layer>[]NoLayers with the same shape as the component, but rendered above the component
belowPartial<Layer>[]NoLayers with the same shape as the component, but rendered below the component
ReturnsTypeDescription
ComponentFactoryComponentFactoryA new component factory with the given corner functions and options applied.

DrawCorner

(p1, p2, idx) => pathPoints

A function that draws a corner

ArgumentTypeRequired?Description
p1{ x: number; y: number; }YesThe first point of the corner
p2{ x: number; y: number; }YesThe second point of the corner
idxnumberYesThe index of the corner. 0 = top right, 1 = bottom right, 2 = bottom left, 3 = top left.
ReturnsTypeDescription
pathPointsstring[]svg path commands

Layer

A layer takes the same shape as the component it is applied to.

PropertyTypeRequired?Description
colorstringYesThe color of the layer
xnumberYesThe x offset of the layer
ynumberYesThe y offset of the layer
blurnumberYesThe blur radius of the layer
spreadnumberYesThe spread radius of the layer
strokeStrokeNoThe stroke of the layer

Examples

Make a "dog-eared" component

 /¯¯¯¯¯¯¯¯¯|
/          |
|          |
|__________|

(it should look like a dog-eared page)

import type { FC } from "react"
import corners, { chamfer } from "corners"

const upperLeftDogeared = corners(null, null, null, chamfer).with({ cornerSize: 20 })

const DogearedDiv = upperLeftDogeared.div

const MyComponent: FC = () => (
  <DogEaredDiv style={{ background: "black" }}>
    Hello, World!
  </DogEaredDiv>
)

Make a "squircled" component with a drop shadow

import type { FC } from "react"
import { rounded } from "corners"

const LAYER: Record<string, Partial<Layer>> = {
  FAINT_SHADOW: { color: `#0003`, spread: -4, blur: 12, y: -4 },
  LIGHT_FILL: { color: `#f3f3f3` },
}
const RoundedSpanWithShadow = rounded.span.with({
  cornerSize: 15,
  below: [LAYER.LIGHT_FILL, LAYER.FAINT_SHADOW],
  noClipping: true,
})

const MyComponent: FC = () => (
  <RoundedSpanWithShadow>
    Hello, World!
  </RoundedSpanWithShadow>
)

LICENSE

MIT

FAQs

Package last updated on 07 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc