|
1 |
| -# github-corner |
| 1 | +# github-corner-element |
| 2 | + |
| 3 | +A web component for the corner banner of GitHub, inspired by [Tim Holman](https://github.com/tholman)'s [GitHub Corners](https://github.com/tholman/github-corners). |
| 4 | + |
| 5 | +[Demo](https://yuskawu.github.io/github-corner-element/example) |
| 6 | + |
| 7 | +## Browser Compatibility |
| 8 | + |
| 9 | +It's compatible with browsers which supports [Web Component](https://developer.mozilla.org/en-US/docs/Web/Web_Components)(including `Custom elements`, `Shadow DOM` and `HTML Template`). For modern browsers it should be fine, but old browser may not work. Checkout the compatibility [here](https://caniuse.com/?search=web%20component). |
| 10 | + |
| 11 | +## Installations |
| 12 | + |
| 13 | +Use npm command to install pacakge: |
| 14 | + |
| 15 | +```bash |
| 16 | +npm install github-corner-element |
| 17 | +``` |
| 18 | + |
| 19 | +Then import it directly in your app entry to register `github-corner` element: |
| 20 | + |
| 21 | +```javascript |
| 22 | +// register `github-corner` element in the entry file |
| 23 | +import 'github-corner-element' |
| 24 | +``` |
| 25 | + |
| 26 | +Alternatively, you can load from [UNPKG](https://unpkg.com/) CDN as well: |
| 27 | + |
| 28 | +```html |
| 29 | +<!-- latest version --> |
| 30 | +<script src="https://unpkg.com/github-corner-element"></script> |
| 31 | +<!-- specific version --> |
| 32 | +<script src="https://unpkg.com/github-corner-element@1.0.0"></script> |
| 33 | +<!-- load in ES Module mode --> |
| 34 | +<script type="module" src="https://unpkg.com/github-corner-element/dist/github-corner-element.es.js"></script> |
| 35 | +``` |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +After installation you can use it as well as a normal HTML element: |
| 40 | + |
| 41 | +```html |
| 42 | +<github-corner href="https://github.com/YuskaWu/github-corner-element"></github-corner> |
| 43 | +``` |
| 44 | + |
| 45 | +## Attributes |
| 46 | + |
| 47 | +In addition to the [global attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes), you can also use |
| 48 | +the following additional attributes on `github-corner` element: |
| 49 | + |
| 50 | +| Attribute Name | Type | Default Value | Description | |
| 51 | +|-------------|----|-------------|-------------| |
| 52 | +| href | [href attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-href) of anchor element | none | The URL of github page. | |
| 53 | +| size | value of [width CSS property](https://developer.mozilla.org/en-US/docs/Web/CSS/width) | 5rem | The width and height of github-corner element. | |
| 54 | +| 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. | |
| 55 | +| octocat-color | value of [color CSS property](https://developer.mozilla.org/en-US/docs/Web/CSS/color) | white | The color of the octocat. | |
| 56 | +| banner-color | value of [color CSS property](https://developer.mozilla.org/en-US/docs/Web/CSS/color) | black | The color of the banner. | |
| 57 | +| wave-duration | value of [animation-duration CSS property](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-duration) | 0.5s | The duration to wave octocat's hand. | |
| 58 | + |
| 59 | +Checkout this [page](https://yuskawu.github.io/github-corner-element/example) for more examples. |
| 60 | + |
| 61 | +## Styling |
| 62 | + |
| 63 | +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()](https://developer.mozilla.org/en-US/docs/Web/CSS/::part) CSS pseudo-element. |
| 64 | + |
| 65 | +There are five parts in shadow DOM that can be selected by [::part()](https://developer.mozilla.org/en-US/docs/Web/CSS/::part): |
| 66 | + |
| 67 | +- anchor |
| 68 | +- banner |
| 69 | +- octocat |
| 70 | +- octocat-arm |
| 71 | +- octocat-body |
| 72 | + |
| 73 | +You can use devtool to inspect shadow DOM and checkout the position of these parts. |
| 74 | + |
| 75 | +Here is an example to style the parts inside shadow DOM(see live demo [here](https://yuskawu.github.io/github-corner-element/example#ex-styling)): |
| 76 | + |
| 77 | +```html |
| 78 | +<style> |
| 79 | + .custom-style::part(banner) { |
| 80 | + fill: #cceb34; |
| 81 | + stroke: #d453f5; |
| 82 | + stroke-width: 16; |
| 83 | + transition: fill 0.2s; |
| 84 | + } |
| 85 | +
|
| 86 | + .custom-style:hover::part(banner) { |
| 87 | + fill: white; |
| 88 | + } |
| 89 | +
|
| 90 | + .custom-style::part(octocat) { |
| 91 | + fill: #d453f5; |
| 92 | + stroke: black; |
| 93 | + stroke-width: 3; |
| 94 | + } |
| 95 | +
|
| 96 | + .custom-style::part(octocat-arm) { |
| 97 | + animation-name: wave-hand; |
| 98 | + animation-duration: 0.2s; |
| 99 | + animation-iteration-count: infinite |
| 100 | + } |
| 101 | +</style> |
| 102 | +... |
| 103 | +<github-corner class="custom-style"></github-corner> |
| 104 | +``` |
| 105 | + |
| 106 | +> NOTE: Using this way will have more specificity, styling by the attributes listed above will be overwritten. |
| 107 | +
|
| 108 | +## svg slot |
| 109 | + |
| 110 | +There is a [slot](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/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. |
| 111 | + |
| 112 | +Here is an example to draw eyes on octocat(see live demo [here](https://yuskawu.github.io/github-corner-element/example#ex-slot-eyes)): |
| 113 | + |
| 114 | +```html |
| 115 | +<github-corner> |
| 116 | + <svg slot="svg"> |
| 117 | + <circle cx="160" cy="75" r="4" fill="black" /> |
| 118 | + <circle cx="160" cy="75" r="6" stroke="black" fill="transparent" /> |
| 119 | + <circle cx="180" cy="95" r="4" fill="black" /> |
| 120 | + <circle cx="180" cy="95" r="6" stroke="black" fill="transparent" /> |
| 121 | + </svg> |
| 122 | +</github-corner> |
| 123 | +``` |
| 124 | + |
| 125 | +> NOTE: You can only put an SVG element on the slot, other elements will be ignored. |
| 126 | +
|
| 127 | +## License |
| 128 | + |
| 129 | +MIT |
0 commit comments