https://github.com/georapbox/resize-observer-element
A custom element that offers a declarative interface to the ResizeObserver API.
https://github.com/georapbox/resize-observer-element
custom-elements web-components
Last synced: 8 months ago
JSON representation
A custom element that offers a declarative interface to the ResizeObserver API.
- Host: GitHub
- URL: https://github.com/georapbox/resize-observer-element
- Owner: georapbox
- License: mit
- Created: 2022-04-26T16:01:43.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-25T07:22:31.000Z (over 1 year ago)
- Last Synced: 2025-03-29T00:51:15.119Z (about 1 year ago)
- Topics: custom-elements, web-components
- Language: JavaScript
- Homepage: https://georapbox.github.io/resize-observer-element/
- Size: 358 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/@georapbox/resize-observer-element)
[](https://www.npmjs.com/package/@georapbox/resize-observer-element)
[demo]: https://georapbox.github.io/resize-observer-element/
[license]: https://github.com/georapbox/resize-observer-element/blob/main/LICENSE
[changelog]: https://github.com/georapbox/resize-observer-element/blob/main/CHANGELOG.md
# <resize-observer>
A custom element that offers a declarative interface to the [ResizeObserver API](https://developer.mozilla.org/docs/Web/API/ResizeObserver).
[API documentation](#api) • [Demo][demo]
## Install
```sh
$ npm install --save @georapbox/resize-observer-element
```
## Usage
### Script
```js
import { ResizeObserverElement } from './node_modules/@georapbox/resize-observer-element/dist/resize-observer.js';
// Manually define the element.
ResizeObserverElement.defineCustomElement();
```
Alternatively, you can import the automatically defined custom element.
```js
import './node_modules/@georapbox/resize-observer-element/dist/resize-observer-defined.js';
```
### Markup
```html
Lorem, ipsum dolor sit amet consectetur adipisicing elit.
Quas quo aliquam iure ipsa laborum! Deleniti doloremque quaerat sunt, esse fugit.
Molestias, libero laborum minus facere ullam iusto eius in adipisci quaerat autem placeat quisquam.
```
## API
### Properties
| Name | Reflects | Type | Default | Description |
| ---- | -------- | ---- | ------- | ----------- |
| `disabled` | ✓ | Boolean | `false` | Defines if the resize observer is disabled or not. |
### Slots
| Name | Description |
| ---- | ----------- |
| (default) | The default slot where the elements to observe are placed. |
### Methods
| Name | Type | Description | Arguments |
| ---- | ---- | ----------- | --------- |
| `defineCustomElement` | Static | Defines/registers the custom element with the name provided. If no name is provided, the default name is used. The method checks if the element is already defined, hence will skip trying to redefine it. | `elementName='resize-observer'` |
### Events
| Name | Description | Event Detail |
| ---- | ----------- | ------------ |
| `resize-observer:resize` | Emitted when the element is resized. | `{ entries: ResizeObserverEntry[]` |
## Changelog
For API updates and breaking changes, check the [CHANGELOG][changelog].
## Development setup
### Prerequisites
The project requires `Node.js` and `npm` to be installed on your environment. Preferrably, use [nvm](https://github.com/nvm-sh/nvm) Node Version Manager and use the version of Node.js specified in the `.nvmrc` file by running `nvm use`.
### Install dependencies
Install the project dependencies by running the following command.
```sh
npm install
```
### Build for development
Watch for changes and start a development server by running the following command.
```sh
npm start
```
### Linting
Lint the code by running the following command.
```sh
npm run lint
```
### Testing
Run the tests by running any of the following commands.
```sh
npm test
npm run test:watch # watch mode
```
### Build for production
Create a production build by running the following command.
```sh
npm run build
```
## License
[The MIT License (MIT)][license]