Toolwind Corner Shape

repository·main·Indexed 42 days ago

https://github.com/toolwind/corner-shape

A Tailwind CSS plugin for the CSS corner-shape property, providing utilities for advanced corner geometries including squircles, scoops, and notches. Supports static keywords and functional superellipse values across all corners, physical edges, and logical edges. Version 0.0.8-3.

Tokens
1.5K
Snippets
5
Records
8
Agent score
3%

What's inside Toolwind Corner Shape

  1. How corner-shape utilities work

    main

    This plugin provides utilities for the CSS corner-shape property and its per-corner longhands. It allows you to control the shape of element corners using static keywords or the functional superellipse(<value>) value.

    Note: Because corner-shape is a newer CSS property, browser support varies. The utilities degrade gracefully, but you should consider providing design fallbacks (like border-radius) where necessary.

  2. Install @toolwind/corner-shape

    main

    Install the plugin via npm, pnpm, yarn, or bun:

    npm install @toolwind/corner-shape

    Tailwind CSS v4.0.0+

    Import the plugin directly in your CSS file using the @plugin directive:

    @import "tailwindcss";
    @plugin "@toolwind/corner-shape";

    Tailwind CSS < v4.0.0

    Add the plugin to your tailwind.config.js or tailwind.config.cjs file.

    Module JS (ESM):

    import cornerShape from '@toolwind/corner-shape';
    
    export default {
      plugins: [cornerShape]
    }

    Common JS (CJS):

    module.exports = {
      plugins: [
        require('@toolwind/corner-shape'),
      ]
    }
  3. Use corner-shape utilities

    main

    The plugin provides several ways to target corners:

    All corners

    • corner-{shape}
    • corner-superellipse/{value}

    Physical edges (two corners)

    • corner-t-{shape} (top-left and top-right)
    • corner-r-{shape} (top-right and bottom-right)
    • corner-b-{shape} (bottom-right and bottom-left)
    • corner-l-{shape} (top-left and bottom-left)

    Physical single corners

    • corner-tl-{shape}, corner-tr-{shape}, corner-br-{shape}, corner-bl-{shape}

    Logical edges (writing-direction aware)

    • corner-s-{shape} (start-start and end-start)
    • corner-e-{shape} (start-end and end-end)

    Logical single corners

    • corner-ss-{shape}, corner-se-{shape}, corner-ee-{shape}, corner-es-{shape}

    Supported static shapes: round, scoop, bevel, notch, square, squircle.

    All standard Tailwind variants (e.g., hover:, md:, lg:) are supported.

    <div class="
      corner-squircle
      md:corner-t-bevel
      lg:corner-tr-notch
    ">
    </div>
  4. Install and use the corner-shape Tailwind CSS plugin

    main

    The @toolwind/corner-shape plugin provides Tailwind CSS utilities for controlling corner shapes (like round, scoop, bevel, etc.) using both shorthand and longhand syntax. It can be integrated into your Tailwind configuration using the standard plugin API.

    Note: The current implementation provides static keyword utilities for various corners. Functional utilities (like superellipse) are present in the source but currently commented out/in development.

    import plugin from 'tailwindcss/plugin.js';
    import cornerShape from '@toolwind/corner-shape';
    
    export default {
      // ... other config
      plugins: [
        cornerShape,
      ],
    };
  5. Use the superellipse functional value

    main

    You can pass a parameter to the superellipse() function using Tailwind's modifier syntax (/). This is useful for fine-grained control over the curve.

    Syntax: corner-{target}-superellipse/{value}

    Accepted values:

    • A number (e.g., 2, 0.5, -1)
    • Constants: e, pi, infinity (can be negative, e.g., -pi)

    Note: Do not include units in the value.

    <div class="corner-superellipse/1.5"></div>
    <div class="corner-br-superellipse/pi"></div>
    <div class="corner-e-superellipse/-infinity"></div>
  6. Reference: corner-shape keyword equivalents

    main

    The following table maps the static shape keywords to their mathematical superellipse equivalents:

    KeywordDescriptionEquivalent
    bevelStraight, diagonal corner (neither convex nor concave)superellipse(0)
    notch90-degree concave square cornersuperellipse(-infinity)
    roundConvex ordinary ellipse (default/initial value)superellipse(1)
    scoopConcave ordinary ellipsesuperellipse(-1)
    square90-degree convex square cornersuperellipse(infinity)
    squircleConvex curve between round and squaresuperellipse(2)
  7. Use corner-shape static keyword utilities

    main

    The plugin generates utilities for applying specific shapes to different corners. The available shapes (keywords) are:

    • round
    • scoop
    • bevel
    • notch
    • square
    • squircle

    These can be applied to specific corners using shorthand prefixes or to all corners using the default corner-shape-{keyword} syntax.

    <!-- Apply a rounded shape to all corners -->
    <div class="corner-shape-round"></div>
    
    <!-- Apply a scoop shape to the top-left corner -->
    <div class="corner-tl-scoop"></div>
    
    <!-- Apply a bevel shape to the start-start corner -->
    <div class="corner-ss-bevel"></div>
  8. Reference corner-shape shorthand prefixes

    main

    The plugin uses specific shorthand prefixes to target individual corners or groups of corners. Use these prefixes between corner and the shape keyword (e.g., corner-{prefix}-{shape}).

    PrefixTarget Corners
    (none)All corners (e.g., corner-round)
    sstart-start, end-start
    estart-end, end-end
    ttop-left, top-right
    rtop-right, bottom-right
    bbottom-right, bottom-left
    ltop-left, bottom-left
    ssstart-start
    sestart-end
    eeend-end
    esend-start
    tltop-left
    trtop-right
    brbottom-right
    blbottom-left