Socket
Book a DemoInstallSign in
Socket

@contentful/experiences-components-react

Package Overview
Dependencies
Maintainers
176
Versions
716
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contentful/experiences-components-react

A basic set of components to use with Studio Experiences

Source
npmnpm
Version
0.0.1-dev-20240320T1226-a6ddb8b.0
Version published
Weekly downloads
6.4K
38.12%
Maintainers
176
Weekly downloads
 
Created
Source

Experience Builder Components

Experience Builder is currently in a private alpha and not available publicly. If you are interested in participating in the alpha, please reach out to your Contentful account team.

This folder contains the source code for the default/example components that can be used with Experience Builder. These components can be used as-is to kick start building your experiences, or used as an example for building your own components.

In this guide

  • Components
  • Getting started
  • Styling
  • withExperienceBuilder util

Components

The following components are available:

Getting started

Installation

npm install @contentful/experiences-components-react

Styling

By default, the components are unstyled. This allows you to style the components to match your brand and design system. If you want a set of default styles to get started, see below.

Including default styles

A set of optional, default styles are included with the components. To include them, import the styles.css file from the @contentful/experiences-components-react package:

import '@contentful/experiences-components-react/styles.css';

Adding custom styles

Each component has a css class that you can use to add your own styles. The classes are named in the style of cf-{component-name} (ie cf-button).

For example, to style the Button component, you can do the following:

.cf-button {
  /* your styles here */
}

All components also support passing in custom class names via the className prop. This allows you to add your own class names to the component, which you can then use to style the component.

withExperienceBuilder util

We provide a helper function (as a higher-order-component) to make it easier to register your own custom components with Experience Builder. This function helps ensure your component has all the required props and is properly registered with Experience Builder.

Usage

import { withExperienceBuilder } from '@/utils/withExperienceBuilder';
import { MyComponent } from './MyComponent';

export const ExperienceBuilderMyComponent = withExperienceBuilder(
  // Your component
  MyComponent,
  // component registration configuration for EB
  {
    id: 'my-component',
    name: 'My Component',
    category: 'Custom',
    variables: {
      label: {
        type: 'Text',
        defaultValue: 'My Component',
      },
    },
  },
);

Container wrapping

By default, the withExperienceBuilder function will not wrap your component in a container. However, it is often useful to have your component wrapped. If the components is wrapped, all the styles generated from Experience Builder will be applied to the wrapping container instead of the component itself. This will make it so the additional styles don't interfere with your component's styles.

To wrap your component, pass in the wrapComponent option:

export const ExperienceBuilderMyComponent = withExperienceBuilder(
  // Your component
  MyComponent,
  // component registration configuration for EB
  { /* EB config */ },
  // wrap the component with a container (defaults to false)
  { wrapComponent: true }
);

You can also provide the tag name the container will use (which defaults to 'div'):

{ wrapComponent: true, wrapContainerTag: 'span' }

FAQs

Package last updated on 20 Mar 2024

Did you know?

Socket

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