# ui-genie

> A simple library for data-schema based UI generation

Latest version **0.1.0** (published 2022-02-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install ui-genie
pnpm add ui-genie
yarn add ui-genie
bun add ui-genie
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2022-02-01 |
| First published | 2022-02-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 57 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | vk.stelmakh@gmail.com |
| Maintainers | stelmakh |
| Keywords | React, UI, JSONSchema, generate |

## Links

- npm: https://www.npmjs.com/package/ui-genie
- Repository: https://github.com/stelmakh/ui-genie
- Homepage: https://github.com/stelmakh/ui-genie#readme
- Issues: https://github.com/stelmakh/ui-genie/issues
- npm.io page: https://npm.io/package/ui-genie

## Dependencies (2)

- [ajv](https://npm.io/package/ajv.md) ^8.9.0
- [json-pointer](https://npm.io/package/json-pointer.md) ^0.6.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2022-02-01

## README

# UIGenie

A library for data-schema based UI generation in React applications.

## UIGenieView

`UIGenieView` renders given `data` using `schema` for validation and `componentsMap` to know how to render it

### Installation
```
npm install --save ui-genie
```

### Usage
```tsx
() => (
	<UIGenieView
		schema={schema}
		data={data}
		componentsMap={componentsMap}
	/>
)
```

## UIGenieItems and UIGenieFields

As data is usually presented as either an array or an object, the library exports two additional components: `UIGenieItems` for arrays and `UIGenieFields` for object.


## ComponentsMap

In order to know how to render your `data` elements, the `UIGenieView` components needs to receive a `ComponentsMap` instance. It's basically an array of objects that describe `type` - `component` pairs.

You need to create a new `ComponentsMap` using `name` and then use `addItem` and `removeItem` to add or remove items, respectively.

### Usage
```tsx
const componentsMap = new ComponentsMap('list-view')

componentsMap.addItem({
	name: 'collection',
	type: 'array',
	component: (props: UIGenieProps) => (
		<UIGenieItems {...props}/>
	)
})
componentsMap.addItem({
	name: 'fields',
	type: 'object',
	component: (props: UIGenieProps) => (
		<div className='item'>
			<UIGenieFields {...props}/>
		</div>
	)
})
componentsMap.addItem({
	name: 'stringField',
	type: 'string',
	component: ({data}: UIGenieProps) => (
		<b className='item-name'>{data}</b>
		)
})
componentsMap.addItem({
	name: 'numberField',
	type: 'integer',
	component: ({data}: UIGenieProps) => (
		<div className='item-age'><i>{data} years</i></div>
	)
})
```

## Schema

`UIGenie` supports `JSONSchema` schemas version 6 and above.

## Demo

You can find the demo app [here](https://github.com/stelmakh/ui-genie-demo)

---
_Source: https://npm.io/package/ui-genie · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
