UNPKG

@atlaskit/editor-plugin-extension

Version:

editor-plugin-extension plugin for @atlaskit/editor-core

66 lines 3.47 kB
import _extends from "@babel/runtime/helpers/extends"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import React, { Fragment } from 'react'; import { Field } from '@atlaskit/form'; import Select from '@atlaskit/select'; import FieldMessages from '../FieldMessages'; import { getOptionFromValue, validate as _validate } from '../utils'; import { formatOptionLabel } from './SelectItem'; export default function SelectField(_ref) { var name = _ref.name, field = _ref.field, onFieldChange = _ref.onFieldChange, autoFocus = _ref.autoFocus, placeholder = _ref.placeholder, fieldDefaultValue = _ref.fieldDefaultValue; //ignore arrays as mutli-value select fields are always clearable var hasValidSingleDefaultValue = !Array.isArray(fieldDefaultValue) && fieldDefaultValue !== undefined; var isClearable = !hasValidSingleDefaultValue || field.isMultiple; return /*#__PURE__*/React.createElement(Field, { name: name, label: field.label, defaultValue: getOptionFromValue(field.items, field.defaultValue), testId: "config-panel-select-".concat(name), isRequired: field.isRequired // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed) , validate: function validate(value) { // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return _validate(field, value); }, isDisabled: field.isDisabled }, function (_ref2) { var fieldProps = _ref2.fieldProps, error = _ref2.error; return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Select // Ignored via go/ees005 // eslint-disable-next-line react/jsx-props-no-spreading , _extends({}, _objectSpread(_objectSpread({}, 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: function 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 })); }); }