Skip to content

Commit

Permalink
Fix stuff (#4836)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown authored Feb 15, 2021
1 parent 64cbb8d commit 556c1f9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-cows-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields-document': patch
---

Fixed `fields.select` not passing options to the select
5 changes: 5 additions & 0 deletions .changeset/cyan-carrots-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields-document': major
---

Changed `NotEditable` component from rendering a div to a span so it can be used for inline elements
5 changes: 5 additions & 0 deletions .changeset/gorgeous-pugs-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields-document': minor
---

Added `fields.multiselect` prop field
5 changes: 5 additions & 0 deletions .changeset/little-cobras-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields-document': patch
---

Fixed documentation in JSDocs for component blocks API
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/** @jsx jsx */
import { jsx } from '@keystone-ui/core';
import { FieldContainer, FieldLabel, Select, TextInput, Checkbox } from '@keystone-ui/fields';
import {
FieldContainer,
FieldLabel,
Select,
TextInput,
Checkbox,
MultiSelect,
} from '@keystone-ui/fields';
import { HTMLAttributes, ReactElement, ReactNode, useState } from 'react';
import { isValidURL } from '../isValidURL';

Expand All @@ -16,6 +23,10 @@ export type FormField<Value, Options> = {
*/
forceValidation: boolean;
}): ReactElement | null;
/**
* The options are config about the field that are available on the
* preview props when rendering the toolbar and preview component
*/
options: Options;
defaultValue: Value;
/**
Expand Down Expand Up @@ -204,6 +215,7 @@ export const fields = {
onChange(option.value);
}
}}
options={options}
/>
</FieldContainer>
);
Expand All @@ -215,6 +227,43 @@ export const fields = {
},
};
},
multiselect<Option extends { label: string; value: string }>({
label,
options,
defaultValue,
}: {
label: string;
options: readonly Option[];
defaultValue: readonly Option['value'][];
}): FormField<readonly Option['value'][], readonly Option[]> {
const valuesToOption = new Map(options.map(x => [x.value, x]));
return {
kind: 'form',
Input({ value, onChange, autoFocus }) {
return (
<FieldContainer>
<FieldLabel>{label}</FieldLabel>
<MultiSelect
autoFocus={autoFocus}
value={value.map(x => valuesToOption.get(x)!)}
options={options}
onChange={options => {
onChange(options.map(x => x.value));
}}
/>
</FieldContainer>
);
},
options,
defaultValue,
validate(value) {
return (
Array.isArray(value) &&
value.every(value => typeof value === 'string' && valuesToOption.has(value))
);
},
};
},
checkbox({
label,
defaultValue = false,
Expand Down Expand Up @@ -470,14 +519,16 @@ export function component<
}
>(
options: {
/** The preview component shown in the editor */
component: (
props: {
[Key in keyof PropsOption]: ExtractPropFromComponentPropFieldForPreview<PropsOption[Key]>;
}
) => ReactElement | null;
/** The props that the preview component, toolbar and rendered component will receive */
props: PropsOption;
/** The label to show in the insert menu and chrome around the block if chromeless is false */
label: string;
// icon?: ReactElement;
} & (
| {
chromeless: true;
Expand Down Expand Up @@ -508,9 +559,9 @@ export function component<
}

export const NotEditable = ({ children, ...props }: HTMLAttributes<HTMLDivElement>) => (
<div css={{ userSelect: 'none' }} contentEditable={false} {...props}>
<span css={{ userSelect: 'none' }} contentEditable={false} {...props}>
{children}
</div>
</span>
);

type Comp<Props> = (props: Props) => ReactElement | null;
Expand Down

1 comment on commit 556c1f9

@vercel
Copy link

@vercel vercel bot commented on 556c1f9 Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.