Basic Usage

Install:

npm i @star-js/form

Basic Use Case:

Sample form schema:

export const fields = [
{
name: 'breakfast',
label: 'What do you want for breakfast',
required: true,
},
{
name: 'bacon',
type: 'select',
label: 'Do you want bacon with that?',
optionsKey: 'yesNo',
},
{
name: 'eggCount',
label: 'How many eggs?',
validation: 'positive',
},
{
name: 'eggType',
type: 'radioGroup',
label: 'How would you like your eggs?',
optionsKey: 'eggTypes',
},
]
export const options = {
yesNo: [
{ value: true, label: 'Yes' },
{ value: false, label: 'No' },
],
eggTypes: [
{ value: 'SCR', label: 'Scrambled' },
{ value: 'SSU', label: 'Sunny Side Up' },
{ value: 'OE', label: 'Over Easy' },
],
}
export const validation = {
positive: [(val) => !isNaN(val) && Number(val) >= 0, 'A positive number'],
}

imports:

import {
StarForm,
useForm,
FormContext,
AutoForm,
htmlComponentMap,
} from '@star-js/form'
import { fields, options, validation } from './schema'

render form:

<StarForm
isEditing
fields={fields}
validatio={validation}
// values: {},
optionsMap={options}
controlMap={htmlComponentMap}
>
<AutoForm fields={fields} options={options} />
{/*<pre>{JSON.stringify(autoForm.form)}</pre>*/}
</StarForm>
function highlightMe() {
console.log('This line can be highlighted!');
}

Tables

Colons can be used to align columns.

TablesAreCool
col 3 isright-aligned\$1600
col 2 iscentered\$12
zebra stripesare neat\$1

There must be at least 3 dashes separating each header cell. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.

MarkdownLessPretty
Stillrendersnicely
123

Images

Here's our logo (hover to see the title text):

Inline-style: alt text

img



Admonitions

note

This is a note

tip

This is a tip

important

This is important

caution

This is a caution

warning

This is a warning

You can write content using GitHub-flavored Markdown syntax.