Skip to content

Commit

Permalink
docs: add props and playgrounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Suevalov committed Apr 24, 2020
1 parent 38356dc commit 4d3773c
Show file tree
Hide file tree
Showing 39 changed files with 316 additions and 76 deletions.
17 changes: 13 additions & 4 deletions packages/boolean/src/BooleanEditor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@ menu: Editors

# Boolean

import { Playground } from 'docz';
import { Playground, Props } from 'docz';
import { BooleanEditor } from './BooleanEditor.tsx';
import { createFakeFieldAPI } from '@contentful/field-editor-test-utils';
import { createFakeFieldAPI, ActionsPlayground } from '@contentful/field-editor-test-utils';

## In Action

<Playground>
{() => {
const [field] = createFakeFieldAPI();
return <BooleanEditor field={field} isInitiallyDisabled={false} />;
const [field, mitt] = createFakeFieldAPI();
return (
<div>
<BooleanEditor field={field} isInitiallyDisabled={false} />
<ActionsPlayground mitt={mitt} />
</div>
);
}}
</Playground>

## Props

<Props of={BooleanEditor} />
6 changes: 6 additions & 0 deletions packages/boolean/src/BooleanEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ export interface BooleanEditorProps {
*/
isInitiallyDisabled: boolean;

/**
* sdk.field
*/
field: FieldAPI;

/**
* sdk.parameters
*/
parameters?: ParametersAPI & {
instance: {
trueLabel?: string;
Expand Down
43 changes: 30 additions & 13 deletions packages/checkbox/src/CheckboxEditor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,21 @@ menu: Editors

# Checkbox

import { Playground } from 'docz';
import { Playground, Props } from 'docz';
import { CheckboxEditor } from './CheckboxEditor.tsx';
import { createFakeFieldAPI, createFakeLocalesAPI } from '@contentful/field-editor-test-utils';
import {
createFakeFieldAPI,
createFakeLocalesAPI,
ActionsPlayground
} from '@contentful/field-editor-test-utils';

## In Action

<Playground>
{() => {
const [field] = createFakeFieldAPI();
return (
<CheckboxEditor field={field} locales={createFakeLocalesAPI()} isInitiallyDisabled={false} />
);
}}
</Playground>

---
### with proper configuration

<Playground>
{() => {
const [field] = createFakeFieldAPI(
const [field, mitt] = createFakeFieldAPI(
mock => ({
...mock,
items: {
Expand All @@ -34,8 +29,30 @@ import { createFakeFieldAPI, createFakeLocalesAPI } from '@contentful/field-edit
}),
['test1', 'test2', 'test3']
);
return (
<div>
<CheckboxEditor
field={field}
locales={createFakeLocalesAPI()}
isInitiallyDisabled={false}
/>
<ActionsPlayground mitt={mitt} />
</div>
);
}}
</Playground>

### no configuration

<Playground>
{() => {
const [field] = createFakeFieldAPI();
return (
<CheckboxEditor field={field} locales={createFakeLocalesAPI()} isInitiallyDisabled={false} />
);
}}
</Playground>

## Props

<Props of={CheckboxEditor} />
8 changes: 6 additions & 2 deletions packages/checkbox/src/CheckboxEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ export interface CheckboxEditorProps {
* is the field disabled initially
*/
isInitiallyDisabled: boolean;

/**
* sdk.field
*/
field: FieldAPI;

/**
* sdk.locales
*/
locales: LocalesAPI;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/date/src/DateEditor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ import { createFakeFieldAPI, ActionsPlayground } from '@contentful/field-editor-
}}

</Playground>

## Props

<Props of={DateEditor} />
6 changes: 6 additions & 0 deletions packages/date/src/DateEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ export interface DateEditorProps {
*/
isInitiallyDisabled: boolean;

/**
* sdk.field
*/
field: FieldAPI;

/**
* sdk.parameters
*/
parameters?: ParametersAPI & {
instance?: {
format?: DateTimeFormat;
Expand Down
17 changes: 14 additions & 3 deletions packages/dropdown/src/DropdownEditor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,33 @@ menu: Editors

import { Playground, Props } from 'docz';
import { DropdownEditor } from './DropdownEditor.tsx';
import { createFakeFieldAPI, createFakeLocalesAPI } from '@contentful/field-editor-test-utils';
import {
createFakeFieldAPI,
createFakeLocalesAPI,
ActionsPlayground
} from '@contentful/field-editor-test-utils';

## In Action

### with proper configuration

<Playground>
{() => {
const [field] = createFakeFieldAPI(mock => {
const [field, mitt] = createFakeFieldAPI(mock => {
return {
...mock,
validations: [{ in: ['banana', 'orange', 'strawberry'] }]
};
});
return (
<DropdownEditor field={field} locales={createFakeLocalesAPI()} isInitiallyDisabled={false} />
<div>
<DropdownEditor
field={field}
locales={createFakeLocalesAPI()}
isInitiallyDisabled={false}
/>
<ActionsPlayground mitt={mitt} />
</div>
);
}}
</Playground>
Expand Down
7 changes: 6 additions & 1 deletion packages/dropdown/src/DropdownEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ export interface DropdownEditorProps {
* is the field disabled initially
*/
isInitiallyDisabled: boolean;

/**
* sdk.field
*/
field: FieldAPI;

/**
* sdk.locales
*/
locales: LocalesAPI;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/json/src/JsonEditor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ import { createFakeFieldAPI, ActionsPlayground } from '@contentful/field-editor-
}}

</Playground>


## Props

<Props of={JsonEditor} />
3 changes: 3 additions & 0 deletions packages/json/src/JsonEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export interface JsonEditorProps {
*/
isInitiallyDisabled: boolean;

/**
* sdk.field
*/
field: FieldAPI;
}

Expand Down
19 changes: 15 additions & 4 deletions packages/list/src/ListEditor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ menu: Editors

# List

import { Playground } from 'docz';
import { Playground, Props } from 'docz';
import { ListEditor } from './ListEditor.tsx';
import { createFakeFieldAPI, createFakeLocalesAPI } from '@contentful/field-editor-test-utils';
import {
createFakeFieldAPI,
createFakeLocalesAPI,
ActionsPlayground
} from '@contentful/field-editor-test-utils';

## In Action

<Playground>
{() => {
const [field] = createFakeFieldAPI();
const [field, mitt] = createFakeFieldAPI();
return (
<ListEditor field={field} locales={createFakeLocalesAPI()} isInitiallyDisabled={false} />
<div>
<ListEditor field={field} locales={createFakeLocalesAPI()} isInitiallyDisabled={false} />
<ActionsPlayground mitt={mitt} />
</div>
);
}}
</Playground>
Expand All @@ -31,3 +38,7 @@ import { createFakeFieldAPI, createFakeLocalesAPI } from '@contentful/field-edit
);
}}
</Playground>

## Props

<Props of={ListEditor} />
6 changes: 6 additions & 0 deletions packages/list/src/ListEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ export interface ListEditorProps {
*/
isInitiallyDisabled: boolean;

/**
* sdk.field
*/
field: FieldAPI;

/**
* sdk.locales
*/
locales: LocalesAPI;
}

Expand Down
6 changes: 5 additions & 1 deletion packages/location/src/LocationEditor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ menu: Editors
# LocationEditor

import { Playground, Props } from 'docz';
import LocationEditor from './LocationEditor.tsx';
import { LocationEditorConnected as LocationEditor } from './LocationEditor.tsx';
import { createFakeFieldAPI, ActionsPlayground } from '@contentful/field-editor-test-utils';

## In Action
Expand Down Expand Up @@ -37,3 +37,7 @@ import { createFakeFieldAPI, ActionsPlayground } from '@contentful/field-editor-
}}

</Playground>

## Props

<Props of={LocationEditor} />
8 changes: 7 additions & 1 deletion packages/location/src/LocationEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ export interface LocationEditorConnectedProps {
*/
isInitiallyDisabled: boolean;

/**
* sdk.field
*/
field: FieldAPI;

/**
* sdk.parameters
*/
parameters?: ParametersAPI & {
instance: {
googleMapsKey?: string;
Expand Down Expand Up @@ -142,7 +148,7 @@ export class LocationEditor extends React.Component<
}
}

export default function LocationEditorConnected(props: LocationEditorConnectedProps) {
export function LocationEditorConnected(props: LocationEditorConnectedProps) {
const { field } = props;
const googleMapsKey = props.parameters ? props.parameters.instance.googleMapsKey : undefined;
const [selectedView, setSelectedView] = React.useState<ViewType>(ViewType.Address);
Expand Down
5 changes: 3 additions & 2 deletions packages/location/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import LocationEditor from './LocationEditor';
export { LocationEditor };
import { LocationEditorConnected } from './LocationEditor';

export const LocationEditor = LocationEditorConnected;
5 changes: 5 additions & 0 deletions packages/markdown/src/MarkdownEditor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ import { createFakeFieldAPI, ActionsPlayground } from '@contentful/field-editor-
);
}}
</Playground>


## Props

<Props of={MarkdownEditor} />
4 changes: 4 additions & 0 deletions packages/markdown/src/MarkdownEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export interface MarkdownEditorProps {
* is the field disabled initially
*/
isInitiallyDisabled: boolean;

sdk: FieldExtensionSDK;
/**
* sdk.parameters
*/
parameters: {
instance: {
canUploadAssets: boolean;
Expand Down
15 changes: 12 additions & 3 deletions packages/multiple-line/src/MultipleLineEditor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ menu: Editors

import { Playground, Props } from 'docz';
import { MultipleLineEditor } from './MultipleLineEditor.tsx';
import { createFakeFieldAPI, createFakeLocalesAPI } from '@contentful/field-editor-test-utils';
import {
createFakeFieldAPI,
createFakeLocalesAPI,
ActionsPlayground
} from '@contentful/field-editor-test-utils';

## In Action

<Playground>
{() => {
const [field] = createFakeFieldAPI();
const [field, mitt] = createFakeFieldAPI();
const locales = createFakeLocalesAPI();
return <MultipleLineEditor field={field} locales={locales} isInitiallyDisabled={false} />;
return (
<div>
<MultipleLineEditor field={field} locales={locales} isInitiallyDisabled={false} />
<ActionsPlayground mitt={mitt} />
</div>
);
}}
</Playground>

Expand Down
6 changes: 6 additions & 0 deletions packages/multiple-line/src/MultipleLineEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ export interface MultipleLineEditorProps {
*/
isInitiallyDisabled: boolean;

/**
* sdk.field
*/
field: FieldAPI;

/**
* sdk.locales
*/
locales: LocalesAPI;
}

Expand Down
Loading

0 comments on commit 4d3773c

Please sign in to comment.