Skip to content

Repository files navigation

Spider Web Components

By RoleModel Software

Spider is a set of reusable web components built with Lit. It currently provides:

  • rm-pdf-viewer: reskinned PDF viewer built on PDF.js
  • rm-tabs-root, rm-tabs-trigger, rm-tabs-panel: unstyled behavior-first tabs primitives

A customizable PDF viewer web component built on PDF.js. This component provides a reskinned, embeddable PDF viewing experience with text selection, zoom controls, thumbnail navigation, and theme customization.

Installation

yarn add @rolemodel/spider

Usage

Import once to register all components:

import'@rolemodel/spider'

Or import specific component modules from the package distribution output.

Development

yarn dev
yarn test

Components

PDF Viewer rm-pdf-viewer

PDF.js is awesome, but you will notice this paragraph in their setup instructions:

The viewer is built on the display layer and is the UI for PDF viewer in Firefox and the other browser extensions within the project. It can be a good starting point for building your own viewer. However, we do ask if you plan to embed the viewer in your own site, that it not just be an unmodified version. Please re-skin it or build upon it.

This component aims to be that skin layer built upon PDF.js packaged in a lovely drop-in web component.

Basic usage

<!doctype html><html><body><rm-pdf-viewersrc="/path/to/document.pdf"></rm-pdf-viewer></body></html>

With custom close button

<rm-pdf-viewersrc="/document.pdf"><buttonslot="close-button" onclick="window.location.href='/'">
Back to Home
</button></rm-pdf-viewer>

Attributes / properties

NameTypeDefaultDescription
srcstring''PDF URL/path
openbooleanfalseShows the viewer when present/true
initial-pagenumber1Initial page to open
theme-huenumber217Theme hue (0-360)
theme-saturationnumber89Theme saturation (0-100)
escape-closes-viewerbooleanfalseCloses viewer on Escape when search is not open

Slot

SlotDescription
close-buttonCustom close action element rendered in the toolbar

Public methods

MethodDescription
loadPDF()Loads the PDF from src
printPDF()Opens browser print flow for the loaded PDF
downloadPDF()Downloads the current src
fitPDFToScreen()Applies calculated fit-to-screen zoom
performSearch(term)Searches text across pages
goToNextMatch() / goToPreviousMatch()Navigates search matches

Tabs components

Tabs are split into three composable components so behavior is provided without enforcing styling.

rm-tabs-root

Owns the active tab state and coordinates triggers/panels.

NameTypeDescription
activestringCurrent active tab name

rm-tabs-trigger

Declares a selectable tab trigger.

NameTypeDescription
namestringTab name this trigger controls
activeClassstringClass toggled on slotted elements when active
MemberTypeDescription
isActivegettertrue when this trigger is selected
activate()methodDispatches a tab select event for this trigger

rm-tabs-panel

Declares content for a tab.

NameTypeDescription
namestringTab name this panel belongs to
MemberTypeDescription
activegettertrue when this panel is visible
activate()methodDispatches a tab select event for this panel

Tabs event

EventDetailDescription
rm-tab-select{ name: string }Emitted by triggers/panels to request active tab changes

Tabs usage example

<rm-tabs-rootclass="tabs" active="first"><divrole="tablist"><rm-tabs-triggername="first" activeClass="active"><buttontype="button">First</button></rm-tabs-trigger><rm-tabs-triggername="second" activeClass="active"><buttontype="button">Second</button></rm-tabs-trigger></div><rm-tabs-panelname="first"><span>First tab content</span></rm-tabs-panel><rm-tabs-panelname="second"><span>Second tab content</span></rm-tabs-panel></rm-tabs-root>

License

MIT

About

Shared web components library

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages