1.1.0 • Published 5 months ago

react-autopg v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

React AUTOPG — Auto Page Generator

A small library for generating page content in a React project from JSON format.

Installation

Install react-autopg with npm or yarn:

Yarn

  yarn add react-autopg

NPM

  npm i react-autopg

Basic usage

yourProject/app/sample-page.js:

import { Page } from 'react-autopg';
import content from './content.json';

function getClassNames(tag) {
  switch (tag) {
    case 'h1':
      return 'text-lg';
    default:
      return 'text-black';
  }
}

export function SamplePage() {
  return <Page content={content} getClassNames={getClassNames} />;
}

Example content.json

{
  "content": {
    "tag": "main",
    "children": [
      {
        "tag": "h1",
        "children": "Heading 1"
      },
      {
        "tag": "section",
        "children": [
          {
            "tag": "h2",
            "children": "Heading 2"
          },
          {
            "tag": "p",
            "children": "Paragraph"
          }
        ]
      }
    ]
  }
}

Authors

1.1.0

5 months ago

1.0.0

6 months ago