@atlaskit/editor-plugin-extension
Version:
editor-plugin-extension plugin for @atlaskit/editor-core
62 lines • 2.37 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import React, { Fragment } from 'react';
import { Field } from '@atlaskit/form';
import Select from '@atlaskit/select';
import FieldMessages from '../FieldMessages';
import { getOptionFromValue, validate } from '../utils';
import { formatOptionLabel } from './SelectItem';
export default function SelectField({
name,
field,
onFieldChange,
autoFocus,
placeholder,
fieldDefaultValue
}) {
//ignore arrays as mutli-value select fields are always clearable
const hasValidSingleDefaultValue = !Array.isArray(fieldDefaultValue) && fieldDefaultValue !== undefined;
const isClearable = !hasValidSingleDefaultValue || field.isMultiple;
return /*#__PURE__*/React.createElement(Field, {
name: name,
label: field.label,
defaultValue: getOptionFromValue(field.items, field.defaultValue),
testId: `config-panel-select-${name}`,
isRequired: field.isRequired
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
,
validate: value => {
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return validate(field, value);
},
isDisabled: field.isDisabled
}, ({
fieldProps,
error
}) => /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Select
// Ignored via go/ees005
// eslint-disable-next-line react/jsx-props-no-spreading
, _extends({}, fieldProps, {
// Pass `id` as `inputId` so that the input gets the correct id, and make sure there are no duplicate ids
inputId: fieldProps.id,
id: undefined,
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
onChange: value => {
fieldProps.onChange(value);
onFieldChange(name, true);
}
// add type cast to avoid adding a "IsMulti" generic prop (TODO: ED-12072)
,
isMulti: field.isMultiple || false,
options: field.items || [],
isClearable: isClearable,
validationState: error ? 'error' : 'default',
formatOptionLabel: formatOptionLabel,
autoFocus: autoFocus,
menuPlacement: "auto",
placeholder: placeholder
})), /*#__PURE__*/React.createElement(FieldMessages, {
error: error,
description: field.description
})));
}