How tangerine-community/tangy-form works
1. What this repository is
This is a UI component library for building multipage forms, centered on a custom element called tangy-form. It is not an application; it is a reusable Web Components package published to npm and consumed from dist/bundle.js or individual module files.
2. Core runtime architecture
The main runtime boundary is the tangy-form container, which coordinates a tree of tangy-form-item children. Each form item wraps one or more input components and represents a page/step or logical unit of the form. The form exposes a submit event and a response model for consumer code.
3. State management
Form state is managed with Redux, which is a key architectural choice in this repo. The central pieces are tangy-form-reducer.js, tangy-form-response-model.js, and tangy-form.js. Inputs report changes into the shared store, and the form reads back values, validity, and item state from that store to drive navigation and response generation.
4. Form-item boundary and conditional logic
tangy-form-item.js is the main orchestration layer between the form container and the inputs. It exposes helper functions used in tangy-if and valid-if expressions, allowing item visibility and validation to depend on other answers. This is the primary place where dynamic form logic is evaluated.
5. Input component subsystem
The input/ directory contains the individual field types: text, checkbox, radio, select, GPS, location, date, timed questions, photo/video/audio capture, signature, QR, consent, gates, and several specialized variants. These are all separate custom elements that plug into the common form state contract rather than being tightly coupled to the form container.
6. Shared input base layers
tangy-input-base.js, tangy-input-lit-base.js, tangy-input-group.js, tangy-input-groups.js, and tangy-list-item.js provide shared behavior and composition patterns for inputs and grouped choices. They reduce duplication across the many field types and define the common lifecycle for registering, reading, validating, and rendering responses.
7. Response and presentation model
The library distinguishes between editable form mode and response-review mode. enableItemReadOnly(), disableItemReadOnly(), hideItemButtons(), and showItemButtons() are part of the presentation boundary that lets the same form render as a user-editable questionnaire or as a read-only response viewer. tangy-complete-button.js and tangy-overlay.js support this UI flow.
8. Utility and integration helpers
The util/ folder holds cross-cutting helpers for location lookup, templating, prompt utilities, DOM property handling, and media conversion (webmToWavConverter.js). These are supporting services rather than primary subsystems, but they matter because several input types depend on them, especially audio and location-based inputs.
9. Styling and design system
Styling is centralized in style/ via shared style modules such as tangy-common-styles.js, tangy-element-styles.js, and mdc-select-style.js. The library is designed around Material Design conventions and exposes theme variables for host applications to override. This means the visual system is intended to be customized at the app boundary, not inside each input.
10. Build, packaging, and distribution
The package is built with webpack (webpack.config.cjs) into dist/bundle.js, which is the main distributable artifact. The repo also contains Polymer configuration (polymer.json), npm packaging metadata, and GitHub Actions/Travis workflows for CI and publishing. index.js and index.html act as top-level entry points for library usage and local demo hosting.
11. Docs, demos, and verification
The demo/ directory is a large set of scenario-specific HTML demos showing different input types, translations, theming, and validation patterns. docs/ contains cookbook and generated reference material. test/ mirrors many of the input types with focused component tests and stubbed fixtures, making it the main place to understand expected component behavior and integration points.
12. External dependencies and runtime assumptions
The repo is built for browser execution using Custom Elements/Polymer, with Redux loaded as a global dependency in some integration modes. Consumers may need webcomponents-loader.js or @webcomponents/webcomponentsjs depending on their app stack. That dependency profile is important architecturally because the library is designed to slot into Angular, React, Vue, or plain HTML, but still expects a Web Components-capable runtime.
Main entry points: tangy-input-base.js Input base · tangy-form.js tangy-form · tangy-form-item.js tangy-form-item · tangy-overlay.js Presenters
Components 22
Core form runtime
Container, item orchestration, state, and response model.
- tangy-form · Top-level form boundary that coordinates item flow, submission, and response generation.
tangy-form.js - tangy-form-item · Wraps logical form steps and mediates between the form container and nested inputs.
tangy-form-item.js - Reducer · Centralized state transitions for values, validity, and item state.
tangy-form-reducer.js - Response model · Builds the readback/submission representation of the form state.
tangy-form-response-model.js - Item helpers · Helper functions exposed to tangy-if and valid-if expressions for dynamic visibility and validation.
tangy-form-item-callback-helpers.js
Input subsystem
Field components and shared input base layers.
- Input base · Common lifecycle and registration behavior for input components.
tangy-input-base.js - Lit base · Lit-based variant of the common input foundation.
tangy-input-lit-base.js - Input groups · Shared grouping and repeated-choice composition primitives.
tangy-input-group.js - Group sets · Higher-level container for grouped input collections.
tangy-input-groups.js - List items · Reusable list-item and choice rendering support.
tangy-list-item.js - Text & choice · Core text, checkbox, radio, select, toggle, and prompt-style inputs.
input/tangy-input.js - Media capture · Audio, video, photo, signature, QR, and related capture components.
input/tangy-photo-capture.js - Location & time · GPS, location, timed, date, partial-date, and related temporal/location components.
input/tangy-gps.js - Specialized inputs · Consent, gates, ACASI, keyboard, grids, and other specialized questionnaire variants.
input/tangy-consent.js
Shared support
Styling, utilities, presentation helpers, and templating.
- Presenters · Complete button, overlay, list, and template helpers for read-only and interactive rendering.
tangy-overlay.js - Style system · Shared styling modules and Material Design theming hooks.
style/tangy-common-styles.js - Utilities · Location, templating, DOM props, prompt, and media conversion helpers.
util/t.js
Build and distribution
Packaging, bundling, demos, docs, and CI.
- Bundle · Primary compiled browser deliverable consumed by host applications.
dist/bundle.js - Entrypoints · Top-level entry files for local hosting and package consumption.
index.js - Demos & docs · Scenario demos, cookbook docs, and reference material for usage and behavior.
demo/index.html - Tests · Component tests and fixture-driven verification for inputs and form behavior.
test/index.html - CI & publish · GitHub Actions, Travis, and package publishing workflows.
.github/workflows/npm-publish.yml
Connections 24
- tangy-form → tangy-form-item: contains · The form coordinates a tree of form items.
- tangy-form → Reducer: uses state · Form actions are reduced into shared Redux state.
- tangy-form → Response model: builds response · Submission and review mode derive from the response model.
- tangy-form-item → Item helpers: evaluates logic · Item visibility and validation depend on helper-evaluated expressions.
- tangy-form-item → Input base: hosts inputs · Items render and register nested inputs through the shared input contract.
- Input base → Reducer: dispatches · Inputs report value and validity changes into the shared store.
- Input base → Response model: reads back · Inputs contribute to response serialization and review mode.
- Lit base → Input base: extends · Lit-based inputs reuse the same core behavior.
- Input groups → List items: composes · Grouped choice widgets reuse list-item rendering.
- Group sets → Input groups: builds on · Higher-level group sets organize repeated grouped inputs.
- Text & choice → Input base: extends · Common text and choice widgets share the base lifecycle.
- Media capture → Input base: extends · Capture components plug into the same form state contract.
- Location & time → Input base: extends · Location and temporal widgets share the base input contract.
- Specialized inputs → Input base: extends · Specialized questionnaire widgets still register through the same base layer.
- Presenters → tangy-form: presentation · Read-only and interactive modes are toggled through form presentation helpers.
- Presenters → tangy-form-item: controls UI · Item-level read-only and button visibility are managed at the item boundary.
- Style system → Presenters: skins · Shared styles and theme variables shape the rendered controls.
- Utilities → Media capture: supports · Media and location inputs depend on cross-cutting utilities.
- Utilities → Location & time: supports · Location lookup, templating, and time helpers are shared across inputs.
- Entrypoints → Bundle: exposes · Package entry points resolve to the built browser artifact.
- Demos & docs → Entrypoints: demonstrates · Demos and docs show how consumers load and use the package.
- Tests → Text & choice: verifies · Focused tests validate field behavior and integration contracts.
- Tests → tangy-form: verifies · Form-level tests cover orchestration and submission behavior.
- CI & publish → Bundle: builds · Automation produces and publishes the distribution artifact.