GithubHelp home page GithubHelp logo

episerver / alloyreact Goto Github PK

View Code? Open in Web Editor NEW
21.0 16.0 11.0 35.89 MB

Example of using On-Page Editing with React

License: Apache License 2.0

C# 82.50% JavaScript 9.43% CSS 7.34% ASP 0.51% HTML 0.21%

alloyreact's Introduction

On-Page Edit examples in Alloy using React

Example site for showing how to use On-Page Edit together with React. Please help out by contributing more examples through PR's!

Note: You'll need CMS UI >=11.4.0 and while this is in Beta you need to enable the features.

Site login

User: cmsadmin

Password: sparr0wHawk!

Examples

Overview

  • Webpack is used for transpiling React
  • React components are mounted on-demand, since we don't have a single root component
  • Inside /Static/react/index.js there is code which mounts a React component in any HTML container element with a data-react-component attribute
  • To simplify rendering container elements, there is an HTML helper method called ReactComponentFor in /Helpers/HtmlHelpers.cs
  • The HTML helper makes sure that React scripts are added to the page, whenever at least one React component should be rendered
  • The script resource is defined in module.config

Rendering some number

An int property called SomeNumber has been added to the StandardPage page type. It is decorated with a UI hint called ReactNumber.

Have a look at the display template: /Views/Shared/DisplayTemplates/ReactNumber.cshtml

You'll notice the attributes used to trigger on-page editing features.

You can see it in action by on-page editing this page: http://localhost:27399/en/about-us/news-events/press-releases/

Editing a block-type property

The NewsList property of the NewsPage page type is now rendered by a React component, instead of the Razor view from the default Alloy templates.

Have a look at its display template: /Views/Shared/DisplayTemplates/PageListBlock.cshtml

You can see it in action by on-page editing this page: http://localhost:27399/en/alloy-plan/download-alloy-plan/

Editing a content that has a dynamic DOM

The block type ThreeKeyFactsBlock is rendered as a React component and the user can select what properties to be shown. This requires that the On Page Edit mode (OPE) can update the property overlays so that the editor is editing the correct properties.

Have a look at the component: /Static/react/ThreeKeyFacts.jsx

To see it in action you need to create a block of type ThreeKeyFactsBlock.

Noteworthy files

  • /Static/react/index.js
  • /Static/react/ReactNumber.jsx
  • /Static/react/PageListBlock.jsx
  • /Static/react/ThreeKeyFacts.jsx
  • /Views/Shared/DisplayTemplates/ReactNumber.cshtml
  • /Views/Shared/DisplayTemplates/PageListBlock.cshtml

Tip

The first commit ("Initial checkin") to this repo is a standard Alloy website. If you compare to the first commit, you'll be able to see what was added or changed for these examples.

alloyreact's People

Contributors

seriema avatar tednyberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alloyreact's Issues

Consider using MutationObserver

Reading https://world.episerver.com/blogs/john-philip-johansson/dates/2017/12/taking-more-control-of-client-side-rendering-in-ope-beta2/ i'm wondering if the detection couldn't be solved by using a MutationObserver.

You can use it to keep track of all nodes with data-epi-property-name, even if they are dynamically added. It can also monitor for changes to data (Like if it's changed with content-editable), but i think reading the value when opening the overlay would make sense/reduce the performance overhead.

Very basic example of how MutationObserver could detect changes:

Edit nz7lnp5k0

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.