Skip to content

Commit

Permalink
feat(next-tinacms-json): remove deprecated apis
Browse files Browse the repository at this point in the history
- jsonForm hoc
- inlineJsonForm hoc
- InlineJsonForm render-children
- useLocalJsonForm
- useGlobalJsonForm
  • Loading branch information
ncphillips committed Aug 18, 2020
1 parent de834f5 commit 0a03345
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 310 deletions.
110 changes: 31 additions & 79 deletions packages/next-tinacms-json/README.md
Expand Up @@ -8,52 +8,59 @@ The `next-tinacms-json` package provides helpers to make local JSON content edit
yarn add next-tinacms-json
```

## Helpers
## API

| Export | Description|
| --- | --- |
| `JsonFile` | A interface representing a JSON file stored on the local filesystem in Git.|
| `useJsonForm` | [React Hook](https://reactjs.org/docs/hooks-intro.html) that creates a [TinaCMS Form Plugin](https://tinacms.org/docs/plugins/forms) for editing a `JsonFile`.|

```ts
useJsonForm( jsonFile, options? ):[values, form]
```
`useJsonForm` is a [React Hook](https://reactjs.org/docs/hooks-intro.html) that creates a Git form

### _JsonFile_
The `JsonFile` interface represents a JSON file stored on the local filesystem in Git.

```ts
jsonForm( Component, options? ): Component
export interface JsonFile {
fileRelativePath: string
data: any
}
```
`jsonForm` is a [React Higher-Order Component](https://reactjs.org/docs/higher-order-components.html) that creates and registers a Git form

| Name | Description |
| --- | --- |
| `fileRelativePath` | The path to the file relative to the root of the Git repository. |
| `data`| The parsed data from the JSON file.|

### _useJsonForm_ hook
### _useJsonForm_

```js
const [data, form] = useJsonForm(jsonFile, formOptions)
```
The `useJsonForm` function is a [React Hook](https://reactjs.org/docs/hooks-intro.html) creates a [TinaCMS Form Plugin](https://tinacms.org/docs/plugins/forms) for editing a `JsonFile`.

As the first argument, this hook expects an object matching the following interface:
```ts
import { Form, FormOptions } from "tinacms"

```typescript
// A datastructure representing a JSON file stored in Git
interface JsonFile<T = any> {
fileRelativePath: string
data: T
}
export function useJsonForm(
jsonFile: JsonFile,
options?: FormOptions
):[any, Form]
```

As with other Tina form helpers, this hook also accepts a second, optional argument — a [form configuration](/docs/plugins/forms#form-configuration) object.
The `useJsonForm` hook accepts a [JsonFile](#jsonfile) and an optional [FormOptions](/docs/plugins/forms#form-configuration) object. It returns an array with containing the current values aand the Form.


**/pages/index.js**
**Example: pages/index.js**

```js
import * as React from 'react'
import { usePlugin } from 'tinacms'
import { useJsonForm } from 'next-tinacms-json'
export default function Index({ jsonFile }) {
// Create the Form
const [post, form] = useJsonForm(jsonFile)
const [homePage, homePageForm] = useJsonForm(jsonFile)
// Register it with the CMS
usePlugin(form)
usePlugin(homePageForm)
return <h1>{post.title}</h1>
return <h1>{homePage.title}</h1>
}
export async function getStaticProps() {
Expand All @@ -69,58 +76,3 @@ export async function getStaticProps() {
}
}
```
### _jsonForm_ HOC
`jsonForm` accepts two arguments: _a component and an optional [form configuration object](/docs/plugins/forms#form-configuration)_. The component being passed is expected to receive data as props that matches the `jsonFile` interface outlined below.
```typescript
// A datastructure representing a JSON file stored in Git
interface JsonFile<T = any> {
fileRelativePath: string
data: T
}
```
`jsonForm` returns the original component connected with a new JSON form registered with Tina. Below is the same example from `useJsonForm`, but refactored to use the `jsonForm` HOC.
**/pages/index.js**
```js
/**
* 1. import jsonForm
*/
import { jsonForm } from 'next-tinacms-json'
import * as React from 'react'

function Index(props) {
const post = props.jsonFile

return (
<>
<h1>{post.title}</h1>
</>
)
}

/**
* 2. Wrap and export the Page component with jsonForm
*/
export default jsonForm(Page)

export async function getStaticProps() {
const content = await import(`../../posts/index.json`)

return {
props: {
/**
* 3. Make sure your return object matches this shape
*/
jsonFile: {
fileRelativePath: `/posts/index.json`,
data: content.default,
},
},
}
}
```
5 changes: 0 additions & 5 deletions packages/next-tinacms-json/src/index.tsx
Expand Up @@ -16,9 +16,4 @@ limitations under the License.
*/

export * from './json-form.hoc'
export * from './inline-json-form.hoc'
export * from './inline-json-form.rc'
export * from './use-global-json-form'
export * from './use-local-json-form'
export * from './use-json-form'
45 changes: 0 additions & 45 deletions packages/next-tinacms-json/src/inline-json-form.hoc.tsx

This file was deleted.

55 changes: 0 additions & 55 deletions packages/next-tinacms-json/src/inline-json-form.rc.tsx

This file was deleted.

48 changes: 0 additions & 48 deletions packages/next-tinacms-json/src/json-form.hoc.tsx

This file was deleted.

42 changes: 0 additions & 42 deletions packages/next-tinacms-json/src/use-global-json-form.ts

This file was deleted.

36 changes: 0 additions & 36 deletions packages/next-tinacms-json/src/use-local-json-form.ts

This file was deleted.

0 comments on commit 0a03345

Please sign in to comment.