0.0.20 • Published 7 months ago

@clearestimates/embed v0.0.20

Weekly downloads
-
License
-
Repository
-
Last release
7 months ago

Clear Estimates Embed Package

This package provides an easy way to embed the Clear Estimates widget into any website using a simple script tag.

Overview

The embed package creates a JavaScript bundle that can be loaded directly in the browser without requiring a build step or React in your host application. It dynamically injects the widget into your page.

Usage

Basic Installation

Add this script to your HTML page:

<script 
  src="https://cdn.clearestimates.com/embed/estimate-builder.js" 
  data-estimate-embed-api-key="your-api-key-here"
  data-estimate-embed-api-url="https://api.clearestimates.com"
  data-estimate-embed-style="inline"
></script>

<!-- Add an element where you want the widget to appear -->
<div id="estimate-builder-container"></div>

Configuration Attributes

All configuration is done through data attributes on the script tag:

AttributeDescriptionRequired
data-estimate-embed-api-keyYour Clear Estimates API keyYes
data-estimate-embed-api-urlAPI endpoint URLYes
data-estimate-embed-styleDisplay mode: "inline" or "popover"No (defaults to "inline")

Display Modes

Inline Mode

The widget will be rendered directly in your page:

<script 
  src="https://cdn.clearestimates.com/embed/estimate-builder.js" 
  data-estimate-embed-api-key="your-api-key"
  data-estimate-embed-api-url="your-api-url"
  data-estimate-embed-style="inline"
></script>

Popover Mode

The widget will appear as a button that opens a popover dialog when clicked:

<script 
  src="https://cdn.clearestimates.com/embed/estimate-builder.js" 
  data-estimate-embed-api-key="your-api-key"
  data-estimate-embed-api-url="your-api-url"
  data-estimate-embed-style="popover"
></script>

Development

Prerequisites

  • Node.js 18+
  • pnpm

Commands

  • pnpm dev: Start development server
  • pnpm build: Build for production
  • pnpm preview: Preview the build locally
  • pnpm clean: Clean build artifacts

Project Structure

src/
├── index.tsx    # Main entry point
└── utils.ts     # Utility functions for configuration

Performance Considerations

The embed script is optimized for performance, but keep these best practices in mind:

  1. Place the script near the end of your <body> tag to avoid blocking page rendering
  2. Consider using the async attribute on the script tag
  3. The "popover" mode has less impact on initial page load time

Troubleshooting

Script Not Loading

  • Check that the URL to the script is correct
  • Ensure there are no network errors in your browser's console

Widget Not Appearing

  • Verify that all required data attributes are set correctly
  • Check for any JavaScript errors in the browser console
  • Ensure you have an element with the ID estimate-builder-container for inline mode
0.0.20

7 months ago

2.0.0

1 year ago

1.1.1

1 year ago