Skip to content

Commit

Permalink
Allow specifying a separate label for Key in keyvaluelist inputs (#43)
Browse files Browse the repository at this point in the history
`label` can now accept either a `string`, as before, or a more complex
object of `{key: string; value: string}` to allow defining labels for
both labels in `keyvaluelist` collection inputs.

`key` is only passed on to the server if `collection` is set to `keyvaluelist`
though it will accept both forms - `key` is dropped at submission-time.
  • Loading branch information
ryanwersal authored Feb 17, 2022
1 parent c6ef876 commit c36a42d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prismatic-io/spectral",
"version": "5.3.0",
"version": "5.3.1",
"description": "Utility library for building Prismatic components",
"keywords": [
"prismatic"
Expand Down
16 changes: 14 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,24 @@ import {

const convertInput = (
key: string,
{ default: defaultValue, type, ...rest }: InputFieldDefinition
{
default: defaultValue,
type,
label,
collection,
...rest
}: InputFieldDefinition
): InputField => ({
...rest,
key,
type,
default: defaultValue ?? InputFieldDefaultMap[type],
key,
collection,
label: typeof label === "string" ? label : label.value,
keyLabel:
collection === "keyvaluelist" && typeof label === "object"
? label.key
: undefined,
});

/**
Expand Down
2 changes: 1 addition & 1 deletion src/types/Inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface BaseInputFieldDefinition {
/** Data type the InputField will collect. */
type: InputFieldType;
/** Interface label of the InputField. */
label: string;
label: { key: string; value: string } | string;
/** Collection type of the InputField */
collection?: InputFieldCollection;
/** Text to show as the InputField placeholder. */
Expand Down
2 changes: 2 additions & 0 deletions src/types/server-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ interface DefaultInputField {
key: string;
/** Interface label of the InputField. */
label: string;
/** Interface label of the Key if the InputField is a 'keyvaluelist'. */
keyLabel?: string;
/** Data type the InputField will collect. */
type: InputFieldType;
/** Collection type of the InputField */
Expand Down

0 comments on commit c36a42d

Please sign in to comment.