-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed0b7ae
commit c8f95dd
Showing
4 changed files
with
149 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
Composer/packages/extensions/obiformeditor/src/Form/fields/PromptField/twoSettingFields.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* eslint-disable format-message/literal-pattern */ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** @jsx jsx */ | ||
import { jsx } from '@emotion/core'; | ||
import React, { useState } from 'react'; | ||
import formatMessage from 'format-message'; | ||
import { FieldProps } from '@bfcomposer/react-jsonschema-form'; | ||
import { MicrosoftInputDialog } from '@bfc/shared'; | ||
|
||
import { TextWidget } from '../../widgets'; | ||
|
||
import { field, settingsFieldHalf, settingsFields, settingsFieldFull, settingsFieldValidation } from './styles'; | ||
import { PromptFieldChangeHandler, GetSchema, InputDialogKeys } from './types'; | ||
|
||
interface TwoSettingFieldsProps extends FieldProps<MicrosoftInputDialog> { | ||
onChange: PromptFieldChangeHandler; | ||
getSchema: GetSchema; | ||
fields: { [key: string]: InputDialogKeys | string }[]; | ||
} | ||
export const TwoSettingFields: React.FC<TwoSettingFieldsProps> = props => { | ||
const { fields, formData, idSchema, getSchema, onChange, errorSchema } = props; | ||
const [errorMessage, setErrorMessage] = useState(false); | ||
|
||
const onValidate = errMessage => { | ||
setErrorMessage(errMessage); | ||
}; | ||
return ( | ||
<div css={settingsFields}> | ||
{fields.map((settingField, index) => ( | ||
<div key={index} css={[field, settingsFieldHalf]}> | ||
<TextWidget | ||
onChange={onChange(settingField.name as InputDialogKeys)} | ||
schema={getSchema(settingField.name as InputDialogKeys)} | ||
id={idSchema[settingField.name].__id} | ||
value={formData[settingField.name]} | ||
label={formatMessage(settingField.title as string)} | ||
formContext={props.formContext} | ||
rawErrors={errorSchema[settingField.name] && errorSchema[settingField.name].__errors} | ||
hiddenErrMessage={true} | ||
onValidate={onValidate} | ||
/> | ||
</div> | ||
))} | ||
<div css={[field, settingsFieldFull, settingsFieldValidation]}>{errorMessage}</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters