Finsweet Attributes is designed to be extensible. You can create your own custom Attribute solutions that integrate seamlessly with the core library.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/finsweet/attributes/llms.txt
Use this file to discover all available pages before exploring further.
Understanding the Package Structure
The Attributes project uses a monorepo structure with pnpm Workspaces. Each package is located in thepackages directory:
attributes- The core library that dynamically imports other packages at runtimeutils- Shared utility functions and types used across all Attributestemplate- A starter template for creating new Attributes- Individual Attribute packages (e.g.,
scrolldisable,list, etc.)
Getting Started with the Template
The easiest way to create a new Attribute is to use the provided template package.Clone the repository
First, fork and clone the Attributes repository:
Install dependencies
Ensure you have pnpm installed, then run:
Package Structure
Every Attribute package follows this structure:Core Files Explained
index.ts
The entry point exports the version and init function:init.ts
The initialization function must implement theFinsweetAttributeInit type:
The
init function is called automatically when your Attribute is loaded. It should return an object with an optional result value and destroy function for cleanup.utils/constants.ts
Define your Attribute’s elements and settings:fs-yourattr-element="trigger").
Setting definitions specify configurable options:
key- The attribute name suffix (e.g.,fs-yourattr-duration)values- Optional array of allowed valuesdefaultValue- Optional default if not specifiedisNumeric- Set totruefor numeric values
Using Attribute Utils
The@finsweet/attributes-utils package provides helpful utilities:
Common Utilities
Waits for Webflow’s initialization to complete. Use this before manipulating Webflow-specific features.
Waits for the DOM to be fully loaded.
Fetches and parses an HTML page. Useful for loading additional content.
Attaches external stylesheets from a document to the current page.
Development Workflow
Best Practices
Use TypeScript for type safety
Use TypeScript for type safety
Define proper types for your functions and data structures. The utils package provides many helpful types like
FinsweetAttributeInit, AttributeElements, and AttributeSettings.Implement cleanup with destroy()
Implement cleanup with destroy()
Always return a
destroy function from your init that removes event listeners, mutation observers, and other side effects. This allows users to properly clean up your Attribute.Wait for Webflow to be ready
Wait for Webflow to be ready
Use
await waitWebflowReady() at the start of your init function if your Attribute interacts with Webflow-specific features like IX2 animations or CMS content.Keep actions reusable
Keep actions reusable
Break your logic into small, reusable functions in the
actions/ directory. This makes your code easier to test and maintain.Document your attributes
Document your attributes
Update the README.md with clear examples of how to use your Attribute, including all available element types and settings.
Proposing New Attributes
Before creating a new Attribute for the official repository, please create an RFC with:- Clear description of the Attribute solution and its purpose
- Breakdown of all HTML attributes that will be used
- Use case examples
- Any potential breaking changes or considerations
Next Steps
API Reference
Explore the complete window.FinsweetAttributes API
Contributing Guide
Learn how to contribute to the project