Home

Awesome

<div align="center"> <a href="https://github.com/YuskaWu/github-corner-element"> <img src="https://yuskawu.github.io/github-corner-element/github-corner.png" width="150" height="150" alt="github-corner"> </a> </div> <br /> <div align="center"> <a href="https://www.webcomponents.org/element/github-corner-element"> <img src="https://img.shields.io/badge/webcomponents.org-published-blue.svg" alt="webcomponents.org"> </a> <a href="https://www.npmjs.com/package/github-corner-element"> <img src="https://img.shields.io/npm/v/github-corner-element" alt="npm"> </a> <a> <img src="https://img.shields.io/bundlephobia/minzip/github-corner-element" alt="npm bundle size"> </a> </div>

github-corner-element

A web component for the corner banner of GitHub, inspired by Tim Holman's GitHub Corners.

Demo

Browser Compatibility

It's compatible with browsers which supports Web Component(including Custom elements, Shadow DOM and HTML Template). For modern browsers it should be fine, but old browser may not work. Check out the compatibility on Can I use website.

Installations

Use npm command to install pacakge:

npm install github-corner-element

Then import it directly in your app entry to register github-corner element:

// register `github-corner` element in the entry file
import 'github-corner-element'

Alternatively, you can load from UNPKG CDN as well:

<!-- latest version -->
<script src="https://unpkg.com/github-corner-element"></script>
<!-- specific version -->
<script src="https://unpkg.com/github-corner-element@1.0.0"></script>
<!-- load in ES Module mode -->
<script type="module" src="https://unpkg.com/github-corner-element/dist/github-corner-element.es.js"></script>

Usage

After installation you can use it as well as a normal HTML element:

<github-corner href="https://github.com/YuskaWu/github-corner-element"></github-corner>

Attributes

In addition to the global attributes, you can also use the following additional attributes on github-corner element:

Attribute NameTypeDefault ValueDescription
hrefhref attribute of anchor elementnoneThe URL of github page.
sizevalue of width CSS property5remThe width and height of github-corner element.
placement'top-left' | 'top-right' | 'bottom-left' | 'bottom-right''top-right'The placement of github-corner element, it can be one of the four corners.
octocat-colorvalue of color CSS propertywhiteThe color of the octocat.
banner-colorvalue of color CSS propertyblackThe color of the banner.
wave-durationvalue of animation-duration CSS property0.5sThe duration to wave octocat's hand.

Checkout this page for more examples.

Styling

As normal HTML element, you can style it with class and style attribute. But if you want to style elements which is inside the shadow DOM, then you have to use ::part() CSS pseudo-element.

There are five parts in shadow DOM that can be selected by ::part():

You can use devtool to inspect shadow DOM and checkout the position of these parts.

Here is an example to style the parts inside shadow DOM(see live demo):

<style>
  .custom-style::part(banner) {
    fill: #cceb34;
    stroke: #d453f5;
    stroke-width: 16;
    transition: fill 0.2s;
  }

  .custom-style:hover::part(banner) {
    fill: white;
  }

  .custom-style::part(octocat) {
    fill: #d453f5;
    stroke: black;
    stroke-width: 3;
  }

  .custom-style::part(octocat-arm) {
    animation-name: wave-hand;
    animation-duration: 0.2s;
    animation-iteration-count: infinite
  }
</style>
...
<github-corner class="custom-style"></github-corner>

NOTE: Using this way will have more specificity, styling by the attributes listed above will be overwritten.

svg slot

There is a slot named "svg", SVG element on the slot will be cloned and append into the SVG container inside shadow DOM. If you want to add additional SVG to draw something special, or you want to define SVG gradients, you can use the slot to do so.

Here is an example to draw eyes on octocat(see live demo):

<github-corner>
  <svg slot="svg">
    <circle cx="160" cy="75" r="4" fill="black" />
    <circle cx="160" cy="75" r="6" stroke="black" fill="transparent" />
    <circle cx="180" cy="95" r="4" fill="black" />
    <circle cx="180" cy="95" r="6" stroke="black" fill="transparent" />
  </svg>
</github-corner>

NOTE: You can only put an SVG element on the slot, other elements will be ignored.

License

MIT