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

https://github.com/abians/react-component-screenshot

Effortlessly capture and save high-quality screenshots of your React components with this lightweight tool.
https://github.com/abians/react-component-screenshot

component html2canvas react react-component-screenshot react-screenshot react-screenshot-component screenshot screenshot-react-component

Last synced: 5 months ago
JSON representation

Effortlessly capture and save high-quality screenshots of your React components with this lightweight tool.

Awesome Lists containing this project

README

          


React Component Screenshot
npm travis licenses


React component to take screenshot of the component.

---

## ✨ Features

- 📸 **Take Screenshot**: Take screenshot of the component.
- 📦 **Lightweight**: Only 1KB gzipped.
- 🌐 **Cross Browser**: Works in all modern browsers.
- 🛠 **Easy to Use**: Just wrap your component with `Screenshot` component.
- 📜 **Typescript**: Written in typescript.

## 🔧 Installation

```sh
npm install react-component-screenshot
```

Peer dependencies: `react`, `html2canvas`.

```sh
npm install react html2canvas --save
```

## 🚀 Usage

### 📋 Basic Usage

Wrap your component with `ScreenShot` component and pass the `controller` prop.

```tsx
import { ScreenShotController, ScreenShot } from 'react-component-screenshot';

export function Example() {
// Create a controller
const controller = new ScreenShotController();

const takeCapture = () => {
// Capture and save the screenshot
controller.captureAndSave({
name: 'my-awesome-component',
extension: 'jpg',
type: 'image/jpeg',
quality: 1
});
};

// Wrap your component with ScreenShot component and pass the controller
return (


My awesome Component


Some content


take Capture


);
}
```

### 🔍 Getting the Image as Base64

If you prefer to obtain the image as a base64 string, it's also very easy. 🚀 Just follow this example:

```tsx
import { ScreenShotController, ScreenShot } from 'react-component-screenshot';

export function Example() {
// Create a controller
const controller = new ScreenShotController();

const takeCapture = () => {
// Capture and get the screenshot as base64 string
controller.capture().then((base64) => {
console.log(base64);
});
};

...
}
```

🖼️ Capture Components Not in the DOM

Need to capture a component that's not in the DOM? No problem! 🎉 (Obviusly You don't even need to use the ScreenShot component for this.)

```tsx
import { ScreenShotController, ScreenShot } from 'react-component-screenshot';

export function Example() {
// Create a controller
const controller = new ScreenShotController();

const takeCapture = () => {
// Capture and save the screenshot
controller.captureAndSaveFromComponent({
component: (


My awesome component


Some content



),
name: "my-awesome-component",
extension: "png",
type: "image/png",
quality: 1,
});
};

...
}
```

## 🤝 Contributions

Contributions are welcome. If you find an issue or have an idea to improve react-component-screenshot, feel free to open an issue or submit a pull request. 🚀

## 📜 License

Licensed as MIT open source. 📜