@try-at-software/input-elements 1.2.0-beta.1 → 1.2.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,12 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LabelRenderer = void 0;
4
4
  const React = require("react");
5
5
  const react_1 = require("@fluentui/react");
6
+ const FormTextRenderer_1 = require("./FormTextRenderer");
6
7
  const LabelRendererComponent = (props) => {
7
8
  if (!props)
8
9
  return null;
9
10
  const { label, required } = props;
10
11
  if (!label)
11
12
  return null;
12
- return React.createElement(react_1.Label, { required: required }, label);
13
+ return (React.createElement(react_1.Label, { required: required },
14
+ React.createElement(FormTextRenderer_1.FormTextRenderer, { text: label })));
13
15
  };
14
16
  exports.LabelRenderer = React.memo(LabelRendererComponent);
@@ -1,13 +1,12 @@
1
1
  import * as React from 'react';
2
- import { FormText } from '../../Components';
3
2
  import { IBaseInputElementProps } from '../IBaseInputElementProps';
4
3
  import { IDynamicProps } from '../IDynamicProps';
5
4
  import { IOperativeProps } from '../IOperativeProps';
6
5
  import { ISingleValueInputElementProps } from '../ISingleValueInputElementProps';
6
+ import { IDropdownInputConfiguration } from './IDropdownInputConfiguration';
7
7
  import { IDropdownInputProps } from './IDropdownInputProps';
8
8
  import { IFluentUiDropdownInputProps } from './IFluentUiDropdownInputProps';
9
- interface ISingleValueDropdownInputProps extends ISingleValueInputElementProps<string>, IOperativeProps<IBaseInputElementProps>, IDynamicProps<IDropdownInputProps & IFluentUiDropdownInputProps> {
10
- consistencyErrorMessage?: FormText;
9
+ interface ISingleValueDropdownInputProps extends ISingleValueInputElementProps<string>, IDropdownInputConfiguration, IOperativeProps<IBaseInputElementProps>, IDynamicProps<IDropdownInputProps & IFluentUiDropdownInputProps> {
11
10
  }
12
11
  export declare const DropdownInput: React.MemoExoticComponent<(props: ISingleValueDropdownInputProps) => JSX.Element>;
13
12
  export {};
@@ -9,8 +9,13 @@ const Utilities_1 = require("../../Utilities");
9
9
  const ConsistencyErrorMessage = 'The value is not present within the specified options.';
10
10
  const DropdownInputComponent = (props) => {
11
11
  var _a;
12
- const { dynamicProps, operativeProps } = props;
12
+ const { dynamicProps, operativeProps, styles: stylePreferences } = props;
13
13
  const normalizedOptions = react_2.useMemo(() => Utilities_1.DropdownHelper.getNormalizedOptions(dynamicProps.defaultOption, dynamicProps.options), [dynamicProps.defaultOption, dynamicProps.options]);
14
+ const styles = react_2.useMemo(() => {
15
+ if (!(stylePreferences === null || stylePreferences === void 0 ? void 0 : stylePreferences.automaticHeight))
16
+ return undefined;
17
+ return { dropdownItem: { height: 'auto' } };
18
+ }, [stylePreferences]);
14
19
  react_2.useEffect(() => {
15
20
  if (!props.value || normalizedOptions.some((o) => o.key === props.value))
16
21
  return;
@@ -18,11 +23,17 @@ const DropdownInputComponent = (props) => {
18
23
  props.invalidateInput(invalidationOptions);
19
24
  }, [props.value, normalizedOptions, props.consistencyErrorMessage, props.invalidateInput]);
20
25
  const DropdownComponent = react_2.useMemo(() => { var _a; return (_a = dynamicProps.dropdownComponent) !== null && _a !== void 0 ? _a : react_1.Dropdown; }, [dynamicProps.dropdownComponent]);
26
+ const onChange = react_2.useCallback((_event, option) => !!props.onChange && props.onChange(option.id), [props.onChange]);
27
+ const onRenderOption = react_2.useCallback((option, defaultRender) => {
28
+ if (!dynamicProps.renderOption)
29
+ return defaultRender(option);
30
+ return dynamicProps.renderOption(option.id);
31
+ }, []);
21
32
  return (React.createElement(React.Fragment, null,
22
33
  React.createElement(Components_1.LabelRenderer, { label: props.label, required: !!props.renderRequiredIndicator }),
23
- React.createElement(DropdownComponent, { "data-automationid": "dropdown-input", options: normalizedOptions, onChange: (_event, option) => !!props.onChange && props.onChange(option.key), placeholder: operativeProps.placeholder,
34
+ React.createElement(DropdownComponent, { "data-automationid": "dropdown-input", options: normalizedOptions, onChange: onChange, onRenderOption: onRenderOption, placeholder: operativeProps.placeholder,
24
35
  // This value should never be `undefined`.
25
- defaultSelectedKey: props.value || ((_a = dynamicProps.defaultOption) === null || _a === void 0 ? void 0 : _a.key) || null, disabled: dynamicProps.isDisabled }),
36
+ selectedKey: props.value || ((_a = dynamicProps.defaultOption) === null || _a === void 0 ? void 0 : _a.key) || null, disabled: dynamicProps.isDisabled, styles: styles }),
26
37
  React.createElement(Components_1.ErrorRenderer, { error: props.errorMessage, messageBarType: react_1.MessageBarType.error })));
27
38
  };
28
39
  exports.DropdownInput = React.memo(DropdownInputComponent);
@@ -0,0 +1,8 @@
1
+ import { FormText } from '../../Components';
2
+ export interface IDropdownInputStyles {
3
+ automaticHeight?: boolean;
4
+ }
5
+ export interface IDropdownInputConfiguration {
6
+ consistencyErrorMessage?: FormText;
7
+ styles?: IDropdownInputStyles;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { IBaseInputElementDynamicProps } from '../IBaseInputElementDynamicProps';
2
3
  import { IDropdownInputOption } from './IDropdownInputOption';
3
4
  export interface IDropdownInputProps extends IBaseInputElementDynamicProps {
@@ -6,4 +7,5 @@ export interface IDropdownInputProps extends IBaseInputElementDynamicProps {
6
7
  * The default option for the dropdown.
7
8
  */
8
9
  defaultOption: IDropdownInputOption;
10
+ renderOption?: (optionId: string) => JSX.Element;
9
11
  }
@@ -1,4 +1,5 @@
1
1
  export * from './DropdownInput';
2
+ export * from './IDropdownInputConfiguration';
2
3
  export * from './IDropdownInputOption';
3
4
  export * from './IDropdownInputProps';
4
5
  export * from './IFluentUiDropdownInputProps';
@@ -11,6 +11,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./DropdownInput"), exports);
14
+ __exportStar(require("./IDropdownInputConfiguration"), exports);
14
15
  __exportStar(require("./IDropdownInputOption"), exports);
15
16
  __exportStar(require("./IDropdownInputProps"), exports);
16
17
  __exportStar(require("./IFluentUiDropdownInputProps"), exports);
@@ -25,7 +25,7 @@ class SingleValueInputElement extends ExtendedInputElement_1.ExtendedInputElemen
25
25
  };
26
26
  this.invalidateInput = (options) => {
27
27
  this._isInvalidated = true;
28
- if (options.errorMessage)
28
+ if (options === null || options === void 0 ? void 0 : options.errorMessage)
29
29
  this.setError(options.errorMessage);
30
30
  this.updateInternally();
31
31
  this.invalidValueChangeSubscriptions.forEach((x) => x === null || x === void 0 ? void 0 : x());
@@ -63,15 +63,16 @@ class SingleValueInputElement extends ExtendedInputElement_1.ExtendedInputElemen
63
63
  var _a;
64
64
  if (this._isInvalidated)
65
65
  this._isInvalidated = false;
66
+ const previousValue = this.value;
66
67
  this.value = value;
67
68
  if ((_a = this._componentRef) === null || _a === void 0 ? void 0 : _a.current)
68
69
  this._componentRef.current.update(value);
69
70
  this.validate();
70
71
  if (this.isValid) {
71
72
  if (isInitial)
72
- this.initialValueChangeSubscriptions.forEach((x) => x === null || x === void 0 ? void 0 : x(this.value));
73
+ this.initialValueChangeSubscriptions.forEach((x) => x === null || x === void 0 ? void 0 : x(this.value, previousValue));
73
74
  else
74
- this.valueChangeSubscriptions.forEach((x) => x === null || x === void 0 ? void 0 : x(this.value));
75
+ this.valueChangeSubscriptions.forEach((x) => x === null || x === void 0 ? void 0 : x(this.value, previousValue));
75
76
  }
76
77
  else
77
78
  this.invalidValueChangeSubscriptions.forEach((x) => x === null || x === void 0 ? void 0 : x());
@@ -85,11 +86,7 @@ class SingleValueInputElement extends ExtendedInputElement_1.ExtendedInputElemen
85
86
  }
86
87
  /** @inheritdoc */
87
88
  get isValid() {
88
- if (this._isInvalidated)
89
- return false;
90
- if (this.isLoading)
91
- return false;
92
- if (this.errorMessage && this.errorMessage.length > 0)
89
+ if (this._isInvalidated || this.isLoading || this.errorMessage)
93
90
  return false;
94
91
  return (!!this._configuration && !this._configuration.isRequired) || this._valueIsSet || this._initialValueIsSet;
95
92
  }
@@ -126,17 +123,20 @@ class SingleValueInputElement extends ExtendedInputElement_1.ExtendedInputElemen
126
123
  var _a, _b, _c, _d, _e;
127
124
  if (!!((_a = this._configuration) === null || _a === void 0 ? void 0 : _a.shouldExecuteValidation) && this._configuration.shouldExecuteValidation() === false)
128
125
  return;
129
- let errorMessage = null;
126
+ let errorMessage = undefined;
130
127
  if (((_b = this._configuration) === null || _b === void 0 ? void 0 : _b.isRequired) && !this.valueIsValid()) {
131
128
  // If a value is required but the input field is empty.
132
129
  errorMessage = ((_c = this._configuration) === null || _c === void 0 ? void 0 : _c.requiredValidationMessage) || `The field is required`;
133
130
  }
134
131
  else if (((_d = this._configuration) === null || _d === void 0 ? void 0 : _d.isRequired) || this.value || ((_e = this._configuration) === null || _e === void 0 ? void 0 : _e.executeAllValidations)) {
135
132
  // If a value is provided.
136
- this.validationRules.forEach((rule) => {
137
- if (!errorMessage)
138
- errorMessage = rule(this.value);
139
- });
133
+ for (const validationRule of this.validationRules) {
134
+ const currentError = validationRule(this.value);
135
+ if (currentError) {
136
+ errorMessage = currentError;
137
+ break;
138
+ }
139
+ }
140
140
  }
141
141
  this.setError(errorMessage);
142
142
  }
@@ -1,2 +1,2 @@
1
- export declare type ValueChangeSubscription<TValue> = (newValue: TValue) => void;
1
+ export declare type ValueChangeSubscription<TValue> = (newValue: TValue, previousValue: TValue) => void;
2
2
  export declare type InvalidValueChangeSubscription = () => void;
@@ -53,6 +53,7 @@ DropdownHelper.toNormalizedDropdownOption = (inputOption) => {
53
53
  return {
54
54
  text: inputOption.text,
55
55
  key: inputOption.key,
56
+ id: inputOption.key,
56
57
  itemType: itemType,
57
58
  disabled: !!inputOption.disabled
58
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@try-at-software/input-elements",
3
- "version": "1.2.0-beta.1",
3
+ "version": "1.2.0-beta.10",
4
4
  "description": "A package providing different input elements that are extensible and easily configurable for your custom needs.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",