@trackunit/react-form-components 0.0.309 → 0.0.311

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.
package/index.cjs.js CHANGED
@@ -15,6 +15,7 @@ var ReactSelect = require('react-select');
15
15
  var ReactAsyncCreatableSelect = require('react-select/async-creatable');
16
16
  var ReactCreatableSelect = require('react-select/creatable');
17
17
  var ReactAsyncSelect = require('react-select/async');
18
+ var sharedUtils = require('@trackunit/shared-utils');
18
19
 
19
20
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
21
 
@@ -1266,7 +1267,7 @@ const useSelect = (_a) => {
1266
1267
  */
1267
1268
  const CreatableSelect = (props) => {
1268
1269
  const { className } = props, propsNoClassName = __rest(props, ["className"]);
1269
- const { id, dataTestId = "creatableSelect", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = dataTestId !== null && dataTestId !== void 0 ? dataTestId : "creatableSelect", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable = false, readOnly, allowCreateWhileLoading, onCreateOption, } = propsNoClassName;
1270
+ const { id, dataTestId = "creatableSelect", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = dataTestId !== null && dataTestId !== void 0 ? dataTestId : "creatableSelect", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable = false, readOnly, openMenuOnClick = !disabled, openMenuOnFocus = !disabled, allowCreateWhileLoading, onCreateOption, } = propsNoClassName;
1270
1271
  const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
1271
1272
  const creatableSelectProps = {
1272
1273
  value,
@@ -1283,9 +1284,9 @@ const CreatableSelect = (props) => {
1283
1284
  isSearchable: disabled || readOnly ? false : isSearchable,
1284
1285
  menuShouldBlockScroll: true,
1285
1286
  menuShouldScrollIntoView: true,
1286
- openMenuOnFocus: true,
1287
+ openMenuOnFocus,
1287
1288
  menuIsOpen: !readOnly ? menuIsOpen : false,
1288
- openMenuOnClick: true,
1289
+ openMenuOnClick,
1289
1290
  closeMenuOnSelect: false,
1290
1291
  isMulti,
1291
1292
  classNamePrefix,
@@ -1982,8 +1983,12 @@ const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
1982
1983
  (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
1983
1984
  onChange === null || onChange === void 0 ? void 0 : onChange(event);
1984
1985
  }, [onChange, innerValue]);
1985
- const selectedOption = options.find(option => { var _a; return option.value === ((_a = innerRef === null || innerRef === void 0 ? void 0 : innerRef.current) === null || _a === void 0 ? void 0 : _a.value); });
1986
- const defaultSelectedOption = options.find(option => option.value === defaultValue);
1986
+ const optionsWithCurrentSelectionToEnsureThatItWorks = [
1987
+ innerValue ? { value: innerValue, label: String(innerValue) } : null,
1988
+ ...options,
1989
+ ].filter(sharedUtils.nonNullable);
1990
+ const selectedOption = optionsWithCurrentSelectionToEnsureThatItWorks.find(option => { var _a; return option.value === ((_a = innerRef === null || innerRef === void 0 ? void 0 : innerRef.current) === null || _a === void 0 ? void 0 : _a.value); });
1991
+ const defaultSelectedOption = optionsWithCurrentSelectionToEnsureThatItWorks.find(option => option.value === innerValue);
1987
1992
  return (jsxRuntime.jsxs(FormGroup, { isInvalid: renderAsInvalid,
1988
1993
  htmlFor,
1989
1994
  className,
@@ -1992,10 +1997,10 @@ const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
1992
1997
  helpAddon,
1993
1998
  tip,
1994
1999
  label,
1995
- disabled, children: [jsxRuntime.jsx("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: options.map(option => {
1996
- return (jsxRuntime.jsx("option", { value: option.value, children: option.label }, option.value));
1997
- }) }), children(Object.assign({ id, isDisabled: disabled, onBlur,
1998
- options, onChange: handleChange, value: selectedOption, defaultValue: defaultSelectedOption }, rest))] }));
2000
+ disabled, children: [jsxRuntime.jsxs("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: [jsxRuntime.jsx("option", { value: innerValue, children: innerValue }), options.map(option => {
2001
+ return (jsxRuntime.jsx("option", { value: option.value, children: option.label }, option.value));
2002
+ })] }), children(Object.assign(Object.assign({}, rest), { id, isDisabled: disabled, onBlur,
2003
+ options, onChange: handleChange, value: selectedOption, defaultValue: defaultSelectedOption }))] }));
1999
2004
  });
2000
2005
 
2001
2006
  /**
@@ -2008,11 +2013,11 @@ const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
2008
2013
  * @param {SelectFieldProps & CreatableSelectProps} props - The props for the CreatableSelectField component
2009
2014
  * @returns {JSX.Element} CreatableSelectField component
2010
2015
  */
2011
- const CreatableSelectField = (_a) => {
2016
+ const CreatableSelectField = React.forwardRef((_a, ref) => {
2012
2017
  var { allowCreateWhileLoading, onCreateOption } = _a, props = __rest(_a, ["allowCreateWhileLoading", "onCreateOption"]);
2013
2018
  const creatableSelectOnlyProps = { allowCreateWhileLoading, onCreateOption };
2014
- return (jsxRuntime.jsx(FormFieldSelectAdapter, Object.assign({}, props, { children: convertedProps => jsxRuntime.jsx(CreatableSelect, Object.assign({}, convertedProps, creatableSelectOnlyProps)) })));
2015
- };
2019
+ return (jsxRuntime.jsx(FormFieldSelectAdapter, Object.assign({}, props, { ref: ref, children: convertedProps => jsxRuntime.jsx(CreatableSelect, Object.assign({}, convertedProps, creatableSelectOnlyProps)) })));
2020
+ });
2016
2021
 
2017
2022
  /**
2018
2023
  * The SelectField component is a Select component wrapped in the FromGroup component.
@@ -2024,9 +2029,10 @@ const CreatableSelectField = (_a) => {
2024
2029
  * @param {SelectFieldProps} props - The props for the SelectField component
2025
2030
  * @returns {JSX.Element} SelectField component
2026
2031
  */
2027
- const SelectField = (props) => {
2028
- return jsxRuntime.jsx(FormFieldSelectAdapter, Object.assign({}, props, { children: convertedProps => jsxRuntime.jsx(Select, Object.assign({}, convertedProps)) }));
2029
- };
2032
+ const SelectField = React.forwardRef((_a, ref) => {
2033
+ var props = __rest(_a, []);
2034
+ return (jsxRuntime.jsx(FormFieldSelectAdapter, Object.assign({}, props, { ref: ref, children: convertedProps => jsxRuntime.jsx(Select, Object.assign({}, convertedProps)) })));
2035
+ });
2030
2036
 
2031
2037
  const cvaTextArea = cssClassVarianceUtilities.cvaMerge([
2032
2038
  cvaInputBase(),
@@ -2314,6 +2320,7 @@ exports.DropZone = DropZone;
2314
2320
  exports.EMAIL_REGEX = EMAIL_REGEX;
2315
2321
  exports.EmailField = EmailField;
2316
2322
  exports.EmailInput = EmailInput;
2323
+ exports.FormFieldSelectAdapter = FormFieldSelectAdapter;
2317
2324
  exports.FormGroup = FormGroup;
2318
2325
  exports.Label = Label;
2319
2326
  exports.MultiSelectMenuItem = MultiSelectMenuItem;
package/index.esm.js CHANGED
@@ -13,6 +13,7 @@ export { default as ValueType } from 'react-select';
13
13
  import ReactAsyncCreatableSelect from 'react-select/async-creatable';
14
14
  import ReactCreatableSelect from 'react-select/creatable';
15
15
  import ReactAsyncSelect from 'react-select/async';
16
+ import { nonNullable } from '@trackunit/shared-utils';
16
17
 
17
18
  var defaultTranslations = {
18
19
  "clearIndicator.icon.tooltip.clearAll": "Clear all",
@@ -1236,7 +1237,7 @@ const useSelect = (_a) => {
1236
1237
  */
1237
1238
  const CreatableSelect = (props) => {
1238
1239
  const { className } = props, propsNoClassName = __rest(props, ["className"]);
1239
- const { id, dataTestId = "creatableSelect", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = dataTestId !== null && dataTestId !== void 0 ? dataTestId : "creatableSelect", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable = false, readOnly, allowCreateWhileLoading, onCreateOption, } = propsNoClassName;
1240
+ const { id, dataTestId = "creatableSelect", prefix, async, maxMenuHeight = 200, label, hasError, disabled, isMulti, value, options, onChange, isLoading, classNamePrefix = dataTestId !== null && dataTestId !== void 0 ? dataTestId : "creatableSelect", onMenuScrollToBottom, filterOption, onInputChange, isSearchable, isClearable = false, readOnly, openMenuOnClick = !disabled, openMenuOnFocus = !disabled, allowCreateWhileLoading, onCreateOption, } = propsNoClassName;
1240
1241
  const { refContainer, refPrefix, customStyles, menuIsOpen, customComponents, menuPlacement, openMenuHandler, closeMenuHandler, orderedOptions, } = useSelect(props);
1241
1242
  const creatableSelectProps = {
1242
1243
  value,
@@ -1253,9 +1254,9 @@ const CreatableSelect = (props) => {
1253
1254
  isSearchable: disabled || readOnly ? false : isSearchable,
1254
1255
  menuShouldBlockScroll: true,
1255
1256
  menuShouldScrollIntoView: true,
1256
- openMenuOnFocus: true,
1257
+ openMenuOnFocus,
1257
1258
  menuIsOpen: !readOnly ? menuIsOpen : false,
1258
- openMenuOnClick: true,
1259
+ openMenuOnClick,
1259
1260
  closeMenuOnSelect: false,
1260
1261
  isMulti,
1261
1262
  classNamePrefix,
@@ -1952,8 +1953,12 @@ const FormFieldSelectAdapter = forwardRef((_a, ref) => {
1952
1953
  (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
1953
1954
  onChange === null || onChange === void 0 ? void 0 : onChange(event);
1954
1955
  }, [onChange, innerValue]);
1955
- const selectedOption = options.find(option => { var _a; return option.value === ((_a = innerRef === null || innerRef === void 0 ? void 0 : innerRef.current) === null || _a === void 0 ? void 0 : _a.value); });
1956
- const defaultSelectedOption = options.find(option => option.value === defaultValue);
1956
+ const optionsWithCurrentSelectionToEnsureThatItWorks = [
1957
+ innerValue ? { value: innerValue, label: String(innerValue) } : null,
1958
+ ...options,
1959
+ ].filter(nonNullable);
1960
+ const selectedOption = optionsWithCurrentSelectionToEnsureThatItWorks.find(option => { var _a; return option.value === ((_a = innerRef === null || innerRef === void 0 ? void 0 : innerRef.current) === null || _a === void 0 ? void 0 : _a.value); });
1961
+ const defaultSelectedOption = optionsWithCurrentSelectionToEnsureThatItWorks.find(option => option.value === innerValue);
1957
1962
  return (jsxs(FormGroup, { isInvalid: renderAsInvalid,
1958
1963
  htmlFor,
1959
1964
  className,
@@ -1962,10 +1967,10 @@ const FormFieldSelectAdapter = forwardRef((_a, ref) => {
1962
1967
  helpAddon,
1963
1968
  tip,
1964
1969
  label,
1965
- disabled, children: [jsx("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: options.map(option => {
1966
- return (jsx("option", { value: option.value, children: option.label }, option.value));
1967
- }) }), children(Object.assign({ id, isDisabled: disabled, onBlur,
1968
- options, onChange: handleChange, value: selectedOption, defaultValue: defaultSelectedOption }, rest))] }));
1970
+ disabled, children: [jsxs("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: [jsx("option", { value: innerValue, children: innerValue }), options.map(option => {
1971
+ return (jsx("option", { value: option.value, children: option.label }, option.value));
1972
+ })] }), children(Object.assign(Object.assign({}, rest), { id, isDisabled: disabled, onBlur,
1973
+ options, onChange: handleChange, value: selectedOption, defaultValue: defaultSelectedOption }))] }));
1969
1974
  });
1970
1975
 
1971
1976
  /**
@@ -1978,11 +1983,11 @@ const FormFieldSelectAdapter = forwardRef((_a, ref) => {
1978
1983
  * @param {SelectFieldProps & CreatableSelectProps} props - The props for the CreatableSelectField component
1979
1984
  * @returns {JSX.Element} CreatableSelectField component
1980
1985
  */
1981
- const CreatableSelectField = (_a) => {
1986
+ const CreatableSelectField = forwardRef((_a, ref) => {
1982
1987
  var { allowCreateWhileLoading, onCreateOption } = _a, props = __rest(_a, ["allowCreateWhileLoading", "onCreateOption"]);
1983
1988
  const creatableSelectOnlyProps = { allowCreateWhileLoading, onCreateOption };
1984
- return (jsx(FormFieldSelectAdapter, Object.assign({}, props, { children: convertedProps => jsx(CreatableSelect, Object.assign({}, convertedProps, creatableSelectOnlyProps)) })));
1985
- };
1989
+ return (jsx(FormFieldSelectAdapter, Object.assign({}, props, { ref: ref, children: convertedProps => jsx(CreatableSelect, Object.assign({}, convertedProps, creatableSelectOnlyProps)) })));
1990
+ });
1986
1991
 
1987
1992
  /**
1988
1993
  * The SelectField component is a Select component wrapped in the FromGroup component.
@@ -1994,9 +1999,10 @@ const CreatableSelectField = (_a) => {
1994
1999
  * @param {SelectFieldProps} props - The props for the SelectField component
1995
2000
  * @returns {JSX.Element} SelectField component
1996
2001
  */
1997
- const SelectField = (props) => {
1998
- return jsx(FormFieldSelectAdapter, Object.assign({}, props, { children: convertedProps => jsx(Select, Object.assign({}, convertedProps)) }));
1999
- };
2002
+ const SelectField = forwardRef((_a, ref) => {
2003
+ var props = __rest(_a, []);
2004
+ return (jsx(FormFieldSelectAdapter, Object.assign({}, props, { ref: ref, children: convertedProps => jsx(Select, Object.assign({}, convertedProps)) })));
2005
+ });
2000
2006
 
2001
2007
  const cvaTextArea = cvaMerge([
2002
2008
  cvaInputBase(),
@@ -2269,4 +2275,4 @@ const UrlField = forwardRef((_a, ref) => {
2269
2275
  */
2270
2276
  setupLibraryTranslations();
2271
2277
 
2272
- export { ActionButton, BaseInput, Checkbox, CreatableSelect, CreatableSelectField, DateField, DateInput, DropZone, EMAIL_REGEX, EmailField, EmailInput, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PasswordField, PasswordInput, PhoneField, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SelectField, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, UrlField, UrlInput, checkIfPhoneNumberHasPlus, countryCodeToFlagEmoji, cvaInput, cvaInputAddon, cvaInputAddonAfter, cvaInputAddonBefore, cvaInputBase, cvaInputBaseDisabled, cvaInputBaseInvalid, cvaInputField, cvaInputPrefix, cvaInputSuffix, cvaSelect, cvaSelectCounter, cvaSelectDynamicTagContainer, cvaSelectIcon, cvaSelectMenu, cvaSelectMenuList, cvaSelectPrefix, cvaSelectXIcon, getCountryAbbreviation, getOrderedOptions, getPhoneNumberWithPlus, isInvalidCountryCode, isInvalidPhoneNumber, isMultiValue, parseSchedule, serializeSchedule, useCustomComponents, usePhoneInput, validateEmailAddress, validatePhoneNumber, weekDay };
2278
+ export { ActionButton, BaseInput, Checkbox, CreatableSelect, CreatableSelectField, DateField, DateInput, DropZone, EMAIL_REGEX, EmailField, EmailInput, FormFieldSelectAdapter, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PasswordField, PasswordInput, PhoneField, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SelectField, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, UrlField, UrlInput, checkIfPhoneNumberHasPlus, countryCodeToFlagEmoji, cvaInput, cvaInputAddon, cvaInputAddonAfter, cvaInputAddonBefore, cvaInputBase, cvaInputBaseDisabled, cvaInputBaseInvalid, cvaInputField, cvaInputPrefix, cvaInputSuffix, cvaSelect, cvaSelectCounter, cvaSelectDynamicTagContainer, cvaSelectIcon, cvaSelectMenu, cvaSelectMenuList, cvaSelectPrefix, cvaSelectXIcon, getCountryAbbreviation, getOrderedOptions, getPhoneNumberWithPlus, isInvalidCountryCode, isInvalidPhoneNumber, isMultiValue, parseSchedule, serializeSchedule, useCustomComponents, usePhoneInput, validateEmailAddress, validatePhoneNumber, weekDay };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "0.0.309",
3
+ "version": "0.0.311",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { GroupBase } from "react-select";
3
3
  import { SelectProps } from "./useSelect";
4
- export interface SelectOption<TValue extends string | number> {
4
+ export interface SelectOption<TValue extends string> {
5
5
  label: string;
6
6
  value: TValue;
7
7
  disabled?: boolean;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CreatableSelectProps } from "../Select/CreatableSelect";
3
- import { BaseOptionType, SelectFieldProps } from "./FormFieldSelectAdapter";
3
+ import { BaseOptionType } from "./FormFieldSelectAdapter";
4
4
  /**
5
5
  * The CreatableSelectField component is a CreatableSelect component wrapped in the FromGroup component.
6
6
  *
@@ -11,4 +11,21 @@ import { BaseOptionType, SelectFieldProps } from "./FormFieldSelectAdapter";
11
11
  * @param {SelectFieldProps & CreatableSelectProps} props - The props for the CreatableSelectField component
12
12
  * @returns {JSX.Element} CreatableSelectField component
13
13
  */
14
- export declare const CreatableSelectField: ({ allowCreateWhileLoading, onCreateOption, ...props }: SelectFieldProps<BaseOptionType> & CreatableSelectProps) => JSX.Element;
14
+ export declare const CreatableSelectField: import("react").ForwardRefExoticComponent<import("dist/libs/react/components/src").CommonProps & {
15
+ label: import("react").ReactNode;
16
+ tip?: import("react").ReactNode;
17
+ helpText?: string | null | undefined;
18
+ helpAddon?: import("react").ReactNode;
19
+ isInvalid?: boolean | undefined;
20
+ } & import("dist/libs/shared/utils/src").MappedOmit<import("../Select/useSelect").SelectProps<BaseOptionType, false, false, import("react-select").GroupBase<BaseOptionType>>, "label" | "onBlur" | "onChange" | "options" | "value" | "defaultValue"> & {
21
+ onBlur?: ((event: import("react").FocusEvent<HTMLInputElement, Element>) => void) | undefined;
22
+ options: BaseOptionType[];
23
+ value?: string | number | undefined;
24
+ defaultValue?: string | number | undefined;
25
+ onChange?: ((event: {
26
+ target: {
27
+ value?: string | number | undefined;
28
+ };
29
+ }) => void) | undefined;
30
+ errorMessage?: string | undefined;
31
+ } & CreatableSelectProps & import("react").RefAttributes<HTMLSelectElement>>;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { BaseOptionType, SelectFieldProps } from "./FormFieldSelectAdapter";
2
+ import { BaseOptionType } from "./FormFieldSelectAdapter";
3
3
  /**
4
4
  * The SelectField component is a Select component wrapped in the FromGroup component.
5
5
  *
@@ -10,4 +10,21 @@ import { BaseOptionType, SelectFieldProps } from "./FormFieldSelectAdapter";
10
10
  * @param {SelectFieldProps} props - The props for the SelectField component
11
11
  * @returns {JSX.Element} SelectField component
12
12
  */
13
- export declare const SelectField: (props: SelectFieldProps<BaseOptionType>) => JSX.Element;
13
+ export declare const SelectField: import("react").ForwardRefExoticComponent<import("dist/libs/react/components/src").CommonProps & {
14
+ label: import("react").ReactNode;
15
+ tip?: import("react").ReactNode;
16
+ helpText?: string | null | undefined;
17
+ helpAddon?: import("react").ReactNode;
18
+ isInvalid?: boolean | undefined;
19
+ } & import("dist/libs/shared/utils/src").MappedOmit<import("../Select/useSelect").SelectProps<BaseOptionType, false, false, import("react-select").GroupBase<BaseOptionType>>, "label" | "onBlur" | "onChange" | "options" | "value" | "defaultValue"> & {
20
+ onBlur?: ((event: import("react").FocusEvent<HTMLInputElement, Element>) => void) | undefined;
21
+ options: BaseOptionType[];
22
+ value?: string | number | undefined;
23
+ defaultValue?: string | number | undefined;
24
+ onChange?: ((event: {
25
+ target: {
26
+ value?: string | number | undefined;
27
+ };
28
+ }) => void) | undefined;
29
+ errorMessage?: string | undefined;
30
+ } & import("react").RefAttributes<HTMLSelectElement>>;
package/src/index.d.ts CHANGED
@@ -23,6 +23,7 @@ export * from "./components/Schedule/ScheduleParser";
23
23
  export * from "./components/Search";
24
24
  export * from "./components/Select";
25
25
  export * from "./components/SelectField/CreatableSelectField";
26
+ export * from "./components/SelectField/FormFieldSelectAdapter";
26
27
  export * from "./components/SelectField/SelectField";
27
28
  export * from "./components/TextArea";
28
29
  export * from "./components/TextAreaField";