Giter Site home page Giter Site logo

hubspot / cms-react Goto Github PK

View Code? Open in Web Editor NEW
19.0 10.0 12.0 3.15 MB

A repo to expose CMS react examples, React defaults modules, and more to CMS devs

Home Page: http://github.hubspot.com/cms-react/

License: Apache License 2.0

JavaScript 34.06% TypeScript 59.76% CSS 4.82% HTML 1.36%

cms-react's Introduction

HubSpot CMS React

Documentation

Check out an expanded documentation page at https://github.hubspot.com/cms-react/

Welcome!

Thank you for taking the time to learn about HubSpot CMS React. As always our goal is to solve for our customers so we welcome any and all feedback. Chat away in #cms-react with other HubSpot developers who are pushing forward with developing with React on the Hubspot CMS. If you do not have access to the developer slack, you can request access here.

How do React modules on the CMS work?

CMS React Modules and Partials are building blocks you can use to write React and JavaScript instead of HubL inside the HubSpot CMS. Note this doesn’t mean you will switch entirely away from HubL, rather we want to provide a pathway to begin writing React to render on both on the server and client. JS modules and partials are built from React components and can directly be referenced via HubL tags in your templates.

Can I use React modules on my CMS account?

Yes! Working with React modules is generally available and can be used with all tiers of the CMS, including free.

This directory contains a copy of all of our internal default React modules. As React modules do not appear in the Design manager, we made them available within this public repository so you can make your own copy and edit as you like. The modules you find in this directory are synced up with our internal code to ensure we keep them up to date.

What if I don't see a default React module in this repo but that is available for use within Hubspot?

Some default React modules contain code that is internal to Hubspot and thus cannot be used in a general way by external developers. If you are are seeking to utilize one of these modules, or otherwise get a better sense of how it works, please reach out to a developer advocate for more information.

If you'd like to get started with your own React module or one of our defaults, we have provided a boilerplate project for you to pick up and get started right away. This boilerplate comes complete with a Sample module so you can test working with this repo with only a few steps on your part. In order to get working with this boilerplate you simply have to:

  • Become familiar with working with our CLI, if you are not already, with our Hubspot CLI documentation
  • Run hs init and select your portal.
  • Within the react-module-boilerplate/src run yarn deploy or npm deploy, which is a helper script we offer which runs the hs project upload react-module-boilerplate CLI command.
  • You will be prompted to create this project in your portal. Confirm and the project will be created.
  • Wait a few moments for the deploy to finish. You can view the projects within your portal at https://app.hubspot.com/developer-projects/{YOUR_PORTAL_ID}

Once the module is uploaded you should be able to see it when you go to edit a page, adding it like any other module.

Examples

In this repository is example usage of some of key features of React modules. These examples are are best understood alongside our official docs. You can quickly try things out without any local setup by opening this repo in Codesandbox.io.

The "Getting Started" example is the most up to date example of CMS React basics. It illustrates the definition and development of Modules with React, uses 3rd party dependencies, islands, and CSS Modules.

NOTE: this is an older example, and Getting Started is a better first example

The "Hello World" example combines partials, modules, islands and CSS modules for styling to show a more cohesive yet straightforward example of how CMS React components and APIs work together.

In this example, we take a look at three different approaches to styling React components. This is not an exhaustive list and there are many ways that styles can be organized and implemented.

Islands are a key concept for React modules in HubSpot. In addition to stitching server-rendered React components into the HTML generated by HubL, JS modules and partials support client-side interactivity with islands. Similar to the islands concept from Astro, Fresh, and others, you can add an <Island /> inside your JS module or partial to automatically code-split and render a component on both the server and client. In addition to allowing you to reuse JavaScript code between the server and browser, islands help you write performant websites by giving you precise control over what JavaScript is shipped to the browser and when it runs.

GraphQL is the future for querying HubSpot data in your CMS pages. As part of JS Modules, a developer can export a GraphQL query string and the Module's root component will then be passed the query result. Additionally we show how a Module that uses GraphQL can be developed using our Storybook integration. This integration will automatically understand the field types of a module and generate controls for a Storybook story.

It seems with every new FE technology on the web comes an implemetation of TodoMVC. We didn't want to be left out and ported a recent version that made use of React and React hooks to work as a JS Module with Islands. Additionally there is an example of our sharedIslandReducer which provides a redux like interface for sharing state across islands.

cms-react's People

Contributors

jontallboy avatar bmatto avatar timmfin avatar mshannon-hs avatar bran-van-d avatar j-malt avatar syncdefaultreactmodules avatar felixmacaspac avatar jazzyclimber avatar joequery avatar ruslanhubspot avatar vashafaris avatar

Stargazers

Arrigo Lupori avatar  avatar Maciej Skurznica avatar Sam avatar smasuda avatar Ahmad Lufi A U avatar Samuel Lembke avatar liz banach avatar Pallob Poddar avatar Oswaldo Acauan avatar Mik avatar Ravi Garg avatar Sean Henri avatar  avatar Brendan Beltz avatar Jennifer Wadella avatar  avatar Harlley Oliveira avatar Mattis Rosenkranz avatar

Watchers

 avatar Ze'ev Klapow avatar Alex Kuhl avatar  avatar  avatar Amy Andrews avatar Jon McLaren avatar Stephen avatar  avatar  avatar

cms-react's Issues

Using RichText Component in React Module causing Content Editor to crash

Hi! Whenever I want to add or edit content inside a module which uses the RichtText component it's causing a crash inside the editor

[ERROR] Couldn't find module in widgetInRichText slice(anonymous) @ app.js:1
[ERROR] Couldn't find module in widgetInRichText slice @project.js:1

Is this a known issue? For now it's not useable and will use dangerouslysetinnerhtml

Failed to get dynamic context within GraphQL query

I cant seem to get this code working when using dynamic context with GraphQL:

export const query =`
# $product_uid: "foo"
query MyQuery($product_uid: String!) {
  HUBDB {
    my_product_collection(limit: 3, filter: {product_uid__contains: $product_uid}) {
      items {
        product_name
      }
    }
  }
}`

I got this error:

Variable 'product_uid' has coerced Null value for NonNull type 'String!

Tested with:

  • @hubspot/cms-components: 0.14.16
  • @hubspot/cms-dev-server: 0.14.13

Hubspot CMS Dev Server doesn't generate types

There's a bug on hubspot-cms-dev server that cause hs-cms-dev-server --generateFieldTypes to not generate field types automatically.
the slashes are different on projectRoot and id in getEntryPathFromId function

image

Currently to (temporarily) fix it I have to change the isInModulesFolder function on

var isInModulesFolder = (filePath, _projectRoot) => {
    const projectRoot = path8.normalize(_projectRoot);
  const getEntryPathFromId = (id) => {
    return id.startsWith(projectRoot) ? id.replace(path8.normalize(`${projectRoot}/`), "") : "";
  };
  const currentModuleId = path8.normalize(filePath);
  const moduleEntryPath = getEntryPathFromId(currentModuleId);
  const subFolderTokens = moduleEntryPath.split(path8.sep);
  return {
    inModuleFolder: subFolderTokens[0] === "components" && subFolderTokens[1] === "modules",
    isRootModuleFile: subFolderTokens.length === 3
  };
};

Input validation on modules

Im currently trying to implement an email input field with validation using react-hook-forms which will eventually trigger a custom API. However, whenever I go to submit the form, I get an error form within cms-dev-server saying "Failed to validate module fields". I've been unable to find anything in particular about inputs in modules. Is there something Im missing when it comes to implementation?

Screenshot 2024-02-27 at 15 36 47

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.