Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rg-wood/link-preview

Custom element to hover link previews
https://github.com/rg-wood/link-preview

custom-element link-preview lit web-components webcomponent webcomponents

Last synced: 3 months ago
JSON representation

Custom element to hover link previews

Awesome Lists containing this project

README

        

# `` [![Test](https://github.com/rg-wood/link-preview/actions/workflows/test.yml/badge.svg)](https://github.com/rg-wood/link-preview/actions/workflows/test.yml)

Custom element to hover link previews.

**[Demo](https://rg-wood.github.io/link-preview/)**

## Usage

Include the `` in your markup:

```html
<script
type="module"
src="https://www.unpkg.com/@grislyeye/[email protected]/link-preview.js">
```

Or, if you host the script as part of your project (recommended):

```html

import '@grislyeye/link-preview/link-preview.js'

```

### Examples

To create link previews within the same page:

```html

Link

```

To create link previews within the
[same origin](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy):

```html

Link

```

Previews for external links are limited. You can only do so for pages with suitable
[CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) policies:

```html

Link

```

We do not recommend using `` for external links.

### Styling

`` exposes CSS custom properties and shadow parts that can be used to style the
preview tooltip.

Supports the following
[shadow parts](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_shadow_parts):

| Part | Description |
| --------- | ---------------------------------------------------------------------------------------- |
| `preview` | The preview content container. You can use this to change the preview border style, etc. |

For example:

```css
link-preview::part(preview) {
border: none;
padding-left: 1em;
padding-right: 1em;
}
```