Getting Started
Installation
Install the packages you need from npm:
# Core package (required for all transformations)npm install @reallygoodwork/coral-core
# Transform React to Coral specificationnpm install @reallygoodwork/react-to-coral
# Generate React from Coral specificationnpm install @reallygoodwork/coral-to-react
# Generate HTML from Coral specificationnpm install @reallygoodwork/coral-to-html
# Tailwind CSS utilitiesnpm install @reallygoodwork/coral-tw2cssnpm install @reallygoodwork/style-to-tailwindQuick Example: React → Coral → React
Transform a React component to a Coral specification and back:
import { transformReactComponentToSpec } from '@reallygoodwork/react-to-coral'import { coralToReact } from '@reallygoodwork/coral-to-react'
// Your React component as a stringconst reactCode = `export const Button = ({ label, onClick }) => { return ( <button className="px-4 py-2 bg-blue-500 text-white rounded" onClick={onClick}> {label} </button> )}`
// Transform to Coral specificationconst spec = transformReactComponentToSpec(reactCode)
// Generate React component from specificationconst { reactCode: generatedCode, cssCode } = await coralToReact(spec, { componentFormat: 'arrow', styleFormat: 'inline',})Quick Example: HTML → Coral
Transform HTML into a Coral specification:
import { transformHTMLToSpec } from '@reallygoodwork/coral-core'
const html = `<div class="container mx-auto"> <h1 style="font-size: 24px; color: blue;">Hello World</h1> <p>Welcome to Coral</p></div>`
const spec = transformHTMLToSpec(html)Quick Example: Coral → HTML
Generate HTML from a Coral specification:
import { coralToHTML } from '@reallygoodwork/coral-to-html'
const spec = { elementType: 'div', styles: { padding: '20px', backgroundColor: '#f0f0f0' }, children: [ { elementType: 'h1', textContent: 'Hello World' } ]}
const html = await coralToHTML(spec)Quick Example: Tailwind → CSS
Convert Tailwind classes to CSS style objects:
import { tailwindToCSS } from '@reallygoodwork/coral-tw2css'
const styles = tailwindToCSS('p-4 bg-blue-500 text-white rounded-lg')// {// paddingInlineStart: '1rem',// paddingInlineEnd: '1rem',// paddingBlockStart: '1rem',// paddingBlockEnd: '1rem',// backgroundColor: '#3b82f6',// color: '#ffffff',// borderRadius: '0.5rem'// }Development
To work on the monorepo locally:
-
Clone the repository:
Terminal window git clone https://github.com/reallygoodwork/coral.gitcd coral -
Install dependencies:
Terminal window pnpm install -
Build all packages:
Terminal window pnpm build -
Run tests:
Terminal window pnpm test -
Run in development mode:
Terminal window pnpm dev
Package Links
- @reallygoodwork/coral-core - Core types and utilities
- @reallygoodwork/coral-tw2css - Tailwind to CSS
- @reallygoodwork/style-to-tailwind - CSS to Tailwind
- @reallygoodwork/react-to-coral - React to Coral
- @reallygoodwork/coral-to-react - Coral to React
- @reallygoodwork/coral-to-html - Coral to HTML
Next Steps
- Learn about releasing packages
- Explore available packages