Socket
Socket
Sign inDemoInstall

@amplience/dc-integration-stylitics

Package Overview
Dependencies
0
Maintainers
12
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @amplience/dc-integration-stylitics

Library of utilities to make using Amplience and Stylitics together simpler.


Version published
Weekly downloads
47
decreased by-42.68%
Maintainers
12
Install size
2.93 MB
Created
Weekly downloads
 

Readme

Source

@amplience/dc-integration-stylitics

Stylitics Widgets)

A library for managing Stylitics Widgets within modern web frameworks, configuring them with content items from Amplience, as well as a collection of Content Types and Schemas you can install to make integrating Stylitics with Amplience considerably easier.

⚙️ Features

  • Convert Content Item into Stylitics arguments
  • Automatically create Stylitics Widgets
  • Import Schemas, Content Types, sample Content Items into a Dynamic Content hub
  • Use provided Templates for Content Rendering Service visualisation and cards

🏁 Quickstart

Using the Stylitics integration library requires a simple import from NPM or linking a prebuilt js file.

Once imported, the following two methods can be used:

  • fromContentItem: Convert from a content item containing Stylitics widget configuration into arguments you can provide to create the widget.
  • createWidget: Create a Stylitics widget with a given set of arguments, including view type and account. Automatically loads necessary scripts for the view type asynchronously, and keeps them loaded for future requests.

These can be used regardless of implementation type (NodeJS project, Simple HTML/JS/CSS project or even using the Amplience Content Rendering Service)

The examples below show how you would use in each implementation type. We would recommend using the Amplience DC Delivery SDK to fetch your content

NodeJS Usage Example

Install the package from NPM:

npm i @amplience/dc-integration-stylitics

You can use it in your project as follows:

import { fromContentItem, createWidget } from '@amplience/dc-integration-stylitics';

// Fetch from DC, in the format found in the automation.
const contentItem = {
    ...
}

const element = document.getElementById('widget');

const args = fromContentItem(contentItem);
const widget = await createWidget(element, args);

widget.start();

Similar to using the Stylitics widget manually, you can set overrides before starting the widget, refresh it with new arguments, or destroy() it when finished.

Usage HTML / JavaScript / CSS

For projects that don't use node, you can import a pre-packaged script that places the module in the global scope as ampStylitics:

<script src="https://unpkg.com/@amplience/dc-integration-stylitics/dist/ampStylitics.browser.umd.min.js"></script>

<div id="widget"></div>

<script>
    // Fetch from DC, in the format found in the automation.
    const contentItem = {
        ...
    }

    const element = document.getElementById('widget');

    const args = ampStylitics.fromContentItem(contentItem);
    ampStylitics.createWidget(element, args).then(
        widget => widget.start()
    );
</script>
Example

In the /examples folder you will see an implementation with the following files that includes fetching an item, instantiating the widget and support for real-time visualisation:

HTML Example: examples/stylitics-generic-html.html

JavaScript used to fetch content / visualisation: examples/stylitics-widget.js

FAQs

Last updated on 16 Aug 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc