Giter Site home page Giter Site logo

jdharrisnz / html-squircle Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 519 KB

Functions for generating superellipse squircles in the form of SVG strings, to be used as clip-path and background inline styles.

License: GNU General Public License v3.0

JavaScript 2.75% TypeScript 97.25%
squircle superellipse smooth-corners

html-squircle's Introduction

html-squircle

Example of the nicely-rounded corners this package can generate.

html-squircle is a lightweight, framework-agnostic JavaScript package designed to create superellipse squircles (smooth, rounded shapes) that can be used as SVG clip paths or backgrounds for web elements. This package is perfect for developers looking to add modern, beautifully-rounded corners to the web with minimal effort.

Features

  • Generate squircles as SVG strings for use in clip-path or background inline styles.
  • Unlike a true superellipse, transitions gracefully into straight edges, making it suitable for UI elements of various sizes.
  • Customizable curve length, curve sharpness, background (solid color or gradient), stroke color, and stroke width.
  • Easy to use with any web framework or vanilla JavaScript.

Installation

You can install html-squircle directly into your project using npm:

npm install html-squircle

Usage

After installing html-squircle, you can import and use it in your project as follows:

import { clipSquircle, bgSquircle } from "html-squircle"

// Example usage for a clip path
const clipPathStyle = clipSquircle({
    bgWidth: 200,
    bgHeight: 200
})

// Example usage for a background with a solid color
const backgroundStyle = bgSquircle({
    bgWidth: 200,
    bgHeight: 200,
    svgBackground: "#ff6347", // Tomato color
    svgStroke: "black",
    svgStrokeWidth: 2
})

// Apply the generated styles to your elements
document.getElementById("yourElementId").style.clipPath = clipPathStyle
document.getElementById("anotherElementId").style.background = backgroundStyle

The clipSquircle and bgSquircle exports provide Apple-like default values to curveLength and curveSharpness, such that square elements will look like app icons. It also makes the default background white, with no stroke, and stroke width 1px.

To create functions with defaults adhering to your own design system, use the newClipSquircler and newBgSquircler exports and supply them with your own preferences.

There is also the getConstantCurveLength export, which you can use as an input to the curveLength parameter to define a curve length in pixels that will not change in response to the size of the element.

html-squircle's People

Contributors

jdharrisnz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.