@headless-adminapp/fluent 0.0.17-alpha.45 → 0.0.17-alpha.46

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.
@@ -15,11 +15,13 @@ const CurrencyControl_1 = require("../form/controls/CurrencyControl");
15
15
  const DateControl_1 = require("../form/controls/DateControl");
16
16
  const DateRangeControl_1 = require("../form/controls/DateRangeControl");
17
17
  const DateTimeControl_1 = require("../form/controls/DateTimeControl");
18
+ const DecimalControl_1 = require("../form/controls/DecimalControl");
19
+ const DurationControl_1 = require("../form/controls/DurationControl");
18
20
  const EmailControl_1 = require("../form/controls/EmailControl");
21
+ const IntegerControl_1 = require("../form/controls/IntegerControl");
19
22
  const LookupControl_1 = require("../form/controls/LookupControl");
20
23
  const MultiSelectControl_1 = __importDefault(require("../form/controls/MultiSelectControl"));
21
24
  const MultiSelectLookupControl_1 = require("../form/controls/MultiSelectLookupControl");
22
- const NumberControl_1 = require("../form/controls/NumberControl");
23
25
  const RichTextControl_1 = require("../form/controls/RichTextControl");
24
26
  const SelectControl_1 = __importDefault(require("../form/controls/SelectControl"));
25
27
  const SwitchControl_1 = require("../form/controls/SwitchControl");
@@ -28,7 +30,7 @@ const TextAreaControl_1 = require("../form/controls/TextAreaControl");
28
30
  const TextControl_1 = require("../form/controls/TextControl");
29
31
  const UrlControl_1 = require("../form/controls/UrlControl");
30
32
  const StandardControl = (props) => {
31
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
33
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
32
34
  const { attribute, label: _label, isError,
33
35
  // errorMessage,
34
36
  name, value, onBlur, onChange,
@@ -90,8 +92,23 @@ const StandardControl = (props) => {
90
92
  return (0, jsx_runtime_1.jsx)(react_1.Fragment, {});
91
93
  }
92
94
  case 'number': {
93
- const Control = (_h = componentStore_1.componentStore.getComponent('Form.NumberControl')) !== null && _h !== void 0 ? _h : NumberControl_1.NumberControl;
94
- return ((0, jsx_runtime_1.jsx)(Control, { name: name, placeholder: placeholder, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, readOnly: readOnly }));
95
+ switch (attribute.format) {
96
+ case 'decimal': {
97
+ const Control = (_h = componentStore_1.componentStore.getComponent('Form.DecimalControl')) !== null && _h !== void 0 ? _h : DecimalControl_1.DecimalControl;
98
+ return ((0, jsx_runtime_1.jsx)(Control, { name: name, placeholder: placeholder, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, readOnly: readOnly, decimalPlaces: attribute.decimalPlaces }));
99
+ }
100
+ case 'integer': {
101
+ const Control = (_j = componentStore_1.componentStore.getComponent('Form.IntegerControl')) !== null && _j !== void 0 ? _j : IntegerControl_1.IntegerControl;
102
+ return ((0, jsx_runtime_1.jsx)(Control, { name: name, placeholder: placeholder, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, readOnly: readOnly }));
103
+ }
104
+ case 'duration': {
105
+ const Control = (_k = componentStore_1.componentStore.getComponent('Form.DurationControl')) !== null && _k !== void 0 ? _k : DurationControl_1.DurationControl;
106
+ return ((0, jsx_runtime_1.jsx)(Control, { name: name, placeholder: placeholder, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, readOnly: readOnly }));
107
+ }
108
+ default: {
109
+ return (0, jsx_runtime_1.jsx)(react_1.Fragment, {});
110
+ }
111
+ }
95
112
  }
96
113
  case 'date': {
97
114
  const controlProps = {
@@ -105,11 +122,11 @@ const StandardControl = (props) => {
105
122
  readOnly,
106
123
  };
107
124
  if (attribute.format === 'datetime') {
108
- const Control = (_j = componentStore_1.componentStore.getComponent('Form.DateTimeControl')) !== null && _j !== void 0 ? _j : DateTimeControl_1.DateTimeControl;
125
+ const Control = (_l = componentStore_1.componentStore.getComponent('Form.DateTimeControl')) !== null && _l !== void 0 ? _l : DateTimeControl_1.DateTimeControl;
109
126
  return (0, jsx_runtime_1.jsx)(Control, Object.assign({}, controlProps));
110
127
  }
111
128
  else {
112
- const Control = (_k = componentStore_1.componentStore.getComponent('Form.DateControl')) !== null && _k !== void 0 ? _k : DateControl_1.DateControl;
129
+ const Control = (_m = componentStore_1.componentStore.getComponent('Form.DateControl')) !== null && _m !== void 0 ? _m : DateControl_1.DateControl;
113
130
  return (0, jsx_runtime_1.jsx)(Control, Object.assign({}, controlProps));
114
131
  }
115
132
  }
@@ -124,39 +141,39 @@ const StandardControl = (props) => {
124
141
  disabled: isDisabled,
125
142
  readOnly,
126
143
  };
127
- const Control = (_l = componentStore_1.componentStore.getComponent('Form.DateRangeControl')) !== null && _l !== void 0 ? _l : DateRangeControl_1.DateRangeControl;
144
+ const Control = (_o = componentStore_1.componentStore.getComponent('Form.DateRangeControl')) !== null && _o !== void 0 ? _o : DateRangeControl_1.DateRangeControl;
128
145
  return (0, jsx_runtime_1.jsx)(Control, Object.assign({}, controlProps));
129
146
  }
130
147
  case 'money': {
131
- const Control = (_m = componentStore_1.componentStore.getComponent('Form.CurrencyControl')) !== null && _m !== void 0 ? _m : CurrencyControl_1.CurrencyControl;
148
+ const Control = (_p = componentStore_1.componentStore.getComponent('Form.CurrencyControl')) !== null && _p !== void 0 ? _p : CurrencyControl_1.CurrencyControl;
132
149
  return ((0, jsx_runtime_1.jsx)(Control, { name: name, placeholder: placeholder, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, borderOnFocusOnly: borderOnFocusOnly, readOnly: readOnly }));
133
150
  }
134
151
  case 'lookup': {
135
- const Control = (_o = componentStore_1.componentStore.getComponent('Form.LookupControl')) !== null && _o !== void 0 ? _o : LookupControl_1.LookupControl;
152
+ const Control = (_q = componentStore_1.componentStore.getComponent('Form.LookupControl')) !== null && _q !== void 0 ? _q : LookupControl_1.LookupControl;
136
153
  return ((0, jsx_runtime_1.jsx)(Control, { name: name, value: value, onChange: onChange, onBlur: onBlur, placeholder: placeholder, disabled: isDisabled, dataService: dataService, schema: schemaStore.getSchema(attribute.entity), experienceStore: experienceStore, allowNavigation: allowNavigation, allowNewRecord: allowNewRecord }));
137
154
  }
138
155
  case 'lookups': {
139
- const Control = (_p = componentStore_1.componentStore.getComponent('Form.MultiSelectLookupControl')) !== null && _p !== void 0 ? _p : MultiSelectLookupControl_1.MultiSelectLookupControl;
156
+ const Control = (_r = componentStore_1.componentStore.getComponent('Form.MultiSelectLookupControl')) !== null && _r !== void 0 ? _r : MultiSelectLookupControl_1.MultiSelectLookupControl;
140
157
  return ((0, jsx_runtime_1.jsx)(Control, { name: name, value: value, onChange: onChange, onBlur: onBlur, placeholder: placeholder, disabled: isDisabled, dataService: dataService, schema: schemaStore.getSchema(attribute.entity), experienceStore: experienceStore, allowNavigation: allowNavigation, allowNewRecord: allowNewRecord }));
141
158
  }
142
159
  case 'boolean': {
143
- const Control = (_q = componentStore_1.componentStore.getComponent('Form.SwitchControl')) !== null && _q !== void 0 ? _q : SwitchControl_1.SwitchControl;
160
+ const Control = (_s = componentStore_1.componentStore.getComponent('Form.SwitchControl')) !== null && _s !== void 0 ? _s : SwitchControl_1.SwitchControl;
144
161
  return ((0, jsx_runtime_1.jsx)(Control, { name: name, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, readOnly: readOnly }));
145
162
  }
146
163
  case 'choice': {
147
- const Control = (_r = componentStore_1.componentStore.getComponent('Form.SelectControl')) !== null && _r !== void 0 ? _r : SelectControl_1.default;
164
+ const Control = (_t = componentStore_1.componentStore.getComponent('Form.SelectControl')) !== null && _t !== void 0 ? _t : SelectControl_1.default;
148
165
  return ((0, jsx_runtime_1.jsx)(Control, { name: name, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, options: attribute.options, placeholder: placeholder, borderOnFocusOnly: borderOnFocusOnly, readOnly: readOnly }));
149
166
  }
150
167
  case 'choices': {
151
- const Control = (_s = componentStore_1.componentStore.getComponent('Form.MultiSelectControl')) !== null && _s !== void 0 ? _s : MultiSelectControl_1.default;
168
+ const Control = (_u = componentStore_1.componentStore.getComponent('Form.MultiSelectControl')) !== null && _u !== void 0 ? _u : MultiSelectControl_1.default;
152
169
  return ((0, jsx_runtime_1.jsx)(Control, { name: name, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, options: attribute.options, placeholder: placeholder, borderOnFocusOnly: borderOnFocusOnly, readOnly: readOnly }));
153
170
  }
154
171
  case 'attachment': {
155
- const Control = (_t = componentStore_1.componentStore.getComponent('Form.AttachmentControl')) !== null && _t !== void 0 ? _t : AttachmentControl_1.AttachmentControl;
172
+ const Control = (_v = componentStore_1.componentStore.getComponent('Form.AttachmentControl')) !== null && _v !== void 0 ? _v : AttachmentControl_1.AttachmentControl;
156
173
  return ((0, jsx_runtime_1.jsx)(Control, { fileService: fileService, format: attribute.format, location: attribute.location, name: name, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, placeholder: placeholder, borderOnFocusOnly: borderOnFocusOnly, readOnly: readOnly, fileServiceContext: props.fileServiceContext }));
157
174
  }
158
175
  case 'attachments': {
159
- const Control = (_u = componentStore_1.componentStore.getComponent('Form.AttachmentsControl')) !== null && _u !== void 0 ? _u : AttachmentsControl_1.AttachmentsControl;
176
+ const Control = (_w = componentStore_1.componentStore.getComponent('Form.AttachmentsControl')) !== null && _w !== void 0 ? _w : AttachmentsControl_1.AttachmentsControl;
160
177
  return ((0, jsx_runtime_1.jsx)(Control, { name: name, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, placeholder: placeholder, borderOnFocusOnly: borderOnFocusOnly, readOnly: readOnly }));
161
178
  }
162
179
  // case 'attachment': {
@@ -21,11 +21,11 @@ const react_1 = require("react");
21
21
  const CurrencyControl_1 = require("./controls/CurrencyControl");
22
22
  const DateControl_1 = require("./controls/DateControl");
23
23
  const DateTimeControl_1 = require("./controls/DateTimeControl");
24
+ const DecimalControl_1 = require("./controls/DecimalControl");
24
25
  const EmailControl_1 = require("./controls/EmailControl");
25
26
  const LookupControl_1 = require("./controls/LookupControl");
26
27
  const MultiSelectControl_1 = __importDefault(require("./controls/MultiSelectControl"));
27
28
  const MultiSelectLookupControl_1 = require("./controls/MultiSelectLookupControl");
28
- const NumberControl_1 = require("./controls/NumberControl");
29
29
  const PasswordControl_1 = require("./controls/PasswordControl");
30
30
  const SelectControl_1 = __importDefault(require("./controls/SelectControl"));
31
31
  const SwitchControl_1 = require("./controls/SwitchControl");
@@ -53,7 +53,7 @@ function Control(props) {
53
53
  case 'password':
54
54
  return ((0, jsx_runtime_1.jsx)(PasswordControl_1.PasswordControl, Object.assign({ value: value, onChange: onChange }, rest)));
55
55
  case 'number':
56
- return ((0, jsx_runtime_1.jsx)(NumberControl_1.NumberControl, Object.assign({ value: value, onChange: onChange }, rest)));
56
+ return ((0, jsx_runtime_1.jsx)(DecimalControl_1.DecimalControl, Object.assign({ value: value, onChange: onChange }, rest)));
57
57
  case 'currency':
58
58
  return ((0, jsx_runtime_1.jsx)(CurrencyControl_1.CurrencyControl, Object.assign({ value: value, onChange: onChange }, rest)));
59
59
  case 'date':
@@ -5,8 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DateControl = DateControl;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_components_1 = require("@fluentui/react-components");
8
9
  const react_datepicker_compat_1 = require("@fluentui/react-datepicker-compat");
9
10
  const locale_1 = require("@headless-adminapp/app/locale");
11
+ const icons_1 = require("@headless-adminapp/icons");
10
12
  const dayjs_1 = __importDefault(require("dayjs"));
11
13
  const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
12
14
  const utc_1 = __importDefault(require("dayjs/plugin/utc"));
@@ -21,5 +23,11 @@ function DateControl({ value, onChange, id, name, onBlur, onFocus, placeholder,
21
23
  // error={error}
22
24
  // maxDate={maxDate}
23
25
  // minDate={minDate}
24
- disabled: disabled, readOnly: readOnly, formatDate: (date) => date ? (0, dayjs_1.default)(date).tz(timezone).format(dateFormats.short) : '', value: value ? new Date(value) : null, onSelectDate: (date) => onChange === null || onChange === void 0 ? void 0 : onChange(date ? (0, dayjs_1.default)(date).tz(timezone).startOf('day').toISOString() : null), strings: datePickerStrings }));
26
+ disabled: disabled, readOnly: readOnly, formatDate: (date) => date ? (0, dayjs_1.default)(date).tz(timezone).format(dateFormats.short) : '', value: value ? new Date(value) : null, onSelectDate: (date) => onChange === null || onChange === void 0 ? void 0 : onChange(date ? (0, dayjs_1.default)(date).tz(timezone).startOf('day').toISOString() : null), strings: datePickerStrings, contentAfter: (0, jsx_runtime_1.jsx)("div", { style: {
27
+ display: 'flex',
28
+ alignItems: 'center',
29
+ justifyContent: 'center',
30
+ marginRight: -4,
31
+ color: react_components_1.tokens.colorNeutralForeground2,
32
+ }, children: (0, jsx_runtime_1.jsx)(icons_1.Icons.Calendar, { size: 20 }) }) }));
25
33
  }
@@ -5,7 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DateTimeControl = DateTimeControl;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_components_1 = require("@fluentui/react-components");
8
9
  const react_datepicker_compat_1 = require("@fluentui/react-datepicker-compat");
10
+ const icons_1 = require("@headless-adminapp/icons");
9
11
  const dayjs_1 = __importDefault(require("dayjs"));
10
12
  function DateTimeControl({ value, onChange, id, name, onBlur, onFocus, placeholder, disabled, readOnly, }) {
11
13
  // const { shortDate: dateFormat } = useLocale();
@@ -17,7 +19,11 @@ function DateTimeControl({ value, onChange, id, name, onBlur, onFocus, placehold
17
19
  // error={error}
18
20
  // maxDate={maxDate}
19
21
  // minDate={minDate}
20
- disabled: disabled, readOnly: readOnly,
21
- // inputFormat={inputFormat}
22
- value: value ? new Date(value) : null, onSelectDate: (date) => onChange === null || onChange === void 0 ? void 0 : onChange(date ? date.toISOString() : null) }));
22
+ disabled: disabled, readOnly: readOnly, value: value ? new Date(value) : null, onSelectDate: (date) => onChange === null || onChange === void 0 ? void 0 : onChange(date ? date.toISOString() : null), allowTextInput: true, contentAfter: (0, jsx_runtime_1.jsx)("div", { style: {
23
+ display: 'flex',
24
+ alignItems: 'center',
25
+ justifyContent: 'center',
26
+ marginRight: -4,
27
+ color: react_components_1.tokens.colorNeutralForeground2,
28
+ }, children: (0, jsx_runtime_1.jsx)(icons_1.Icons.Calendar, { size: 20 }) }) }));
23
29
  }
@@ -0,0 +1,5 @@
1
+ import { ControlProps } from './types';
2
+ export interface DecimalControlProps extends ControlProps<number> {
3
+ decimalPlaces?: number;
4
+ }
5
+ export declare function DecimalControl({ value, onChange, id, name, onBlur, onFocus, error, disabled, placeholder, borderOnFocusOnly, readOnly, decimalPlaces, }: DecimalControlProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DecimalControl = DecimalControl;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ /* eslint-disable unused-imports/no-unused-vars */
6
+ const react_components_1 = require("@fluentui/react-components");
7
+ const react_1 = require("react");
8
+ function DecimalControl({ value, onChange, id, name, onBlur, onFocus, error, disabled, placeholder, borderOnFocusOnly, readOnly, decimalPlaces, }) {
9
+ const [internalValue, setInternalValue] = (0, react_1.useState)(value ? value.toString() : '');
10
+ const internalValueRef = (0, react_1.useRef)(internalValue);
11
+ internalValueRef.current = internalValue;
12
+ (0, react_1.useEffect)(() => {
13
+ let _value = '';
14
+ if (typeof value === 'number') {
15
+ _value = value.toString();
16
+ }
17
+ if (!_value && internalValueRef.current === '-') {
18
+ return;
19
+ }
20
+ if (internalValueRef.current !== _value) {
21
+ setInternalValue(_value);
22
+ }
23
+ }, [value]);
24
+ const handleChange = (e) => {
25
+ let value = e.target.value;
26
+ if (!value) {
27
+ setInternalValue('');
28
+ onChange === null || onChange === void 0 ? void 0 : onChange(null);
29
+ return;
30
+ }
31
+ value = value.replace(',', '');
32
+ if (value === '-') {
33
+ setInternalValue('-');
34
+ onChange === null || onChange === void 0 ? void 0 : onChange(null);
35
+ return;
36
+ }
37
+ if (isNaN(Number(value))) {
38
+ return;
39
+ }
40
+ if (decimalPlaces) {
41
+ const parts = value.split('.');
42
+ if (parts.length > 1) {
43
+ value = `${parts[0]}.${parts[1].slice(0, decimalPlaces)}`;
44
+ }
45
+ }
46
+ setInternalValue(value);
47
+ onChange === null || onChange === void 0 ? void 0 : onChange(Number(value));
48
+ };
49
+ return ((0, jsx_runtime_1.jsx)(react_components_1.Input, { placeholder: placeholder, id: id, appearance: "filled-darker", name: name, value: internalValue, onChange: handleChange, onBlur: () => onBlur === null || onBlur === void 0 ? void 0 : onBlur(), onFocus: () => onFocus === null || onFocus === void 0 ? void 0 : onFocus(), disabled: disabled, readOnly: readOnly, style: {
50
+ width: '100%',
51
+ } }));
52
+ }
@@ -0,0 +1,4 @@
1
+ import { FC } from 'react';
2
+ import { ControlProps } from './types';
3
+ export type DurationControlProps = ControlProps<number> & {};
4
+ export declare const DurationControl: FC<DurationControlProps>;
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DurationControl = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_components_1 = require("@fluentui/react-components");
6
+ const react_1 = require("react");
7
+ const useStyles = (0, react_components_1.makeStyles)({
8
+ listbox: {
9
+ maxHeight: '300px !important',
10
+ },
11
+ });
12
+ const options = [
13
+ { text: '1 minute', value: '1' },
14
+ {
15
+ text: '5 minutes',
16
+ value: '5',
17
+ },
18
+ {
19
+ text: '15 minutes',
20
+ value: '15',
21
+ },
22
+ {
23
+ text: '30 minutes',
24
+ value: '30',
25
+ },
26
+ {
27
+ text: '45 minutes',
28
+ value: '45',
29
+ },
30
+ {
31
+ text: '1 hour',
32
+ value: '60',
33
+ },
34
+ {
35
+ text: '1.5 hours',
36
+ value: '90',
37
+ },
38
+ {
39
+ text: '2 hours',
40
+ value: '120',
41
+ },
42
+ {
43
+ text: '2.5 hours',
44
+ value: '150',
45
+ },
46
+ {
47
+ text: '3 hours',
48
+ value: '180',
49
+ },
50
+ {
51
+ text: '3.5 hours',
52
+ value: '210',
53
+ },
54
+ {
55
+ text: '4 hours',
56
+ value: '240',
57
+ },
58
+ {
59
+ text: '4.5 hours',
60
+ value: '270',
61
+ },
62
+ {
63
+ text: '5 hours',
64
+ value: '300',
65
+ },
66
+ {
67
+ text: '5.5 hours',
68
+ value: '330',
69
+ },
70
+ {
71
+ text: '6 hours',
72
+ value: '360',
73
+ },
74
+ {
75
+ text: '6.5 hours',
76
+ value: '390',
77
+ },
78
+ {
79
+ text: '7 hours',
80
+ value: '420',
81
+ },
82
+ {
83
+ text: '7.5 hours',
84
+ value: '450',
85
+ },
86
+ {
87
+ text: '8 hours',
88
+ value: '480',
89
+ },
90
+ {
91
+ text: '1 day',
92
+ value: '1440',
93
+ },
94
+ {
95
+ text: '2 days',
96
+ value: '2880',
97
+ },
98
+ {
99
+ text: '3 days',
100
+ value: '4320',
101
+ },
102
+ ];
103
+ const DurationControl = ({ value, onChange, id, name, onBlur, onFocus, placeholder, disabled, autoFocus, readOnly, }) => {
104
+ const [searchText, setSearchText] = (0, react_1.useState)('');
105
+ const [filterEnabled, setFilterEnabled] = (0, react_1.useState)(false);
106
+ const styles = useStyles();
107
+ (0, react_1.useEffect)(() => {
108
+ setSearchText(getDisplayValue(value));
109
+ }, [value]);
110
+ const filteredItems = (0, react_1.useMemo)(() => {
111
+ if (!filterEnabled) {
112
+ return options;
113
+ }
114
+ return options.filter((item) => item.text.toLowerCase().includes(searchText.toLowerCase()));
115
+ }, [searchText, filterEnabled]);
116
+ return ((0, jsx_runtime_1.jsx)("div", { style: { position: 'relative', width: '100%' }, children: (0, jsx_runtime_1.jsx)(react_components_1.Combobox, { name: name, appearance: "filled-darker", placeholder: placeholder, inputMode: "search", style: { width: '100%', minWidth: 'unset' }, listbox: { className: styles.listbox }, autoComplete: "off", readOnly: readOnly || disabled, value: searchText, disableAutoFocus: true, selectedOptions: value ? [value.toString()] : [], onBlur: () => {
117
+ let newValue = null;
118
+ if (searchText) {
119
+ newValue = resolveValue(searchText);
120
+ if (newValue === undefined) {
121
+ newValue = value;
122
+ }
123
+ }
124
+ if (newValue !== null) {
125
+ console.log('onBlur', newValue);
126
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
127
+ }
128
+ setSearchText(getDisplayValue(newValue));
129
+ setFilterEnabled(false);
130
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur();
131
+ }, onFocus: onFocus, id: id, autoFocus: autoFocus, onChange: (e) => {
132
+ setFilterEnabled(true);
133
+ setSearchText(e.target.value);
134
+ }, onOptionSelect: (e, item) => {
135
+ console.log('onOptionSelect', e, item);
136
+ if (!item.optionValue) {
137
+ return;
138
+ }
139
+ else {
140
+ onChange === null || onChange === void 0 ? void 0 : onChange(Number(item.optionValue));
141
+ }
142
+ setSearchText('');
143
+ }, children: filteredItems.map((item) => ((0, jsx_runtime_1.jsx)(react_components_1.Option, { value: item.value, children: item.text }, item.value))) }) }));
144
+ };
145
+ exports.DurationControl = DurationControl;
146
+ function getDisplayValue(value) {
147
+ if (!value) {
148
+ return '';
149
+ }
150
+ // No decimal, if value is decimal, round to nearest whole number
151
+ // 1 - 1 minute
152
+ // 2-59 minutes -> 2-59 minutes
153
+ // 90 minutes -> 1.5 hours
154
+ // more than a day -> 1 day, 1.5 days, 2 days, etc.
155
+ // check if value has decimal
156
+ if (value % 1 !== 0) {
157
+ // round to nearest whole number
158
+ value = Math.round(value);
159
+ }
160
+ if (!value) {
161
+ return '';
162
+ }
163
+ if (value === 1) {
164
+ return '1 minute';
165
+ }
166
+ if (value < 60) {
167
+ return `${value} minutes`;
168
+ }
169
+ if (value === 60) {
170
+ return '1 hour';
171
+ }
172
+ if (value < 1440) {
173
+ return `${Number((value / 60).toFixed(2))} hours`;
174
+ }
175
+ if (value === 1440) {
176
+ return '1 day';
177
+ }
178
+ return `${Number((value / 1440).toFixed(2))} days`;
179
+ }
180
+ function resolveValue(value) {
181
+ if (!value) {
182
+ return null;
183
+ }
184
+ const numberValue = Number(value);
185
+ if (!isNaN(numberValue)) {
186
+ return numberValue;
187
+ }
188
+ const timeFormat = /^(\d+):[0-5][0-9]$/;
189
+ if (timeFormat.test(value)) {
190
+ const [hours, minutes] = value.split(':').map(Number);
191
+ return hours * 60 + minutes;
192
+ }
193
+ const minutesFormat = /^(\d+(\.\d+)?) m/;
194
+ if (minutesFormat.test(value)) {
195
+ const [, minutes] = value.match(minutesFormat);
196
+ return Math.floor(Number(minutes));
197
+ }
198
+ const hoursFormat = /^(\d+(\.\d+)?) h/;
199
+ if (hoursFormat.test(value)) {
200
+ const [, hours] = value.match(hoursFormat);
201
+ return Math.floor(Number(hours) * 60);
202
+ }
203
+ const daysFormat = /^(\d+(\.\d+)?) d/;
204
+ if (daysFormat.test(value)) {
205
+ const [, days] = value.match(daysFormat);
206
+ return Math.floor(Number(days) * 1440);
207
+ }
208
+ return undefined;
209
+ }
@@ -0,0 +1,4 @@
1
+ import { ControlProps } from './types';
2
+ export interface IntegerControlProps extends ControlProps<number> {
3
+ }
4
+ export declare function IntegerControl({ value, onChange, id, name, onBlur, onFocus, error, disabled, placeholder, borderOnFocusOnly, readOnly, }: IntegerControlProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntegerControl = IntegerControl;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ /* eslint-disable unused-imports/no-unused-vars */
6
+ const react_components_1 = require("@fluentui/react-components");
7
+ function IntegerControl({ value, onChange, id, name, onBlur, onFocus, error, disabled, placeholder, borderOnFocusOnly, readOnly, }) {
8
+ console.log('IntegerControl', value);
9
+ return ((0, jsx_runtime_1.jsx)(react_components_1.SpinButton, { appearance: "filled-darker", placeholder: placeholder, id: id, name: name, value: value, onChange: (e, data) => {
10
+ if (data.value !== undefined) {
11
+ onChange === null || onChange === void 0 ? void 0 : onChange(data.value);
12
+ }
13
+ else if (!data.displayValue) {
14
+ onChange === null || onChange === void 0 ? void 0 : onChange(null);
15
+ }
16
+ else if (data.displayValue !== undefined) {
17
+ const newValue = parseFloat(data.displayValue);
18
+ if (!Number.isNaN(newValue)) {
19
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
20
+ }
21
+ }
22
+ else {
23
+ onChange === null || onChange === void 0 ? void 0 : onChange(null);
24
+ }
25
+ } }));
26
+ }
package/form/types.d.ts CHANGED
@@ -2,11 +2,11 @@ import { JSX } from 'react';
2
2
  import { CurrencyControlProps } from './controls/CurrencyControl';
3
3
  import { DateControlProps } from './controls/DateControl';
4
4
  import { DateTimeControlProps } from './controls/DateTimeControl';
5
+ import { DecimalControlProps } from './controls/DecimalControl';
5
6
  import { EmailControlProps } from './controls/EmailControl';
6
7
  import { LookupControlProps } from './controls/LookupControl';
7
8
  import { MultiSelectControlProps } from './controls/MultiSelectControl';
8
9
  import { MultiSelectLookupControlProps } from './controls/MultiSelectLookupControl';
9
- import { NumberControlProps } from './controls/NumberControl';
10
10
  import { PasswordControlProps } from './controls/PasswordControl';
11
11
  import { SelectControlProps } from './controls/SelectControl';
12
12
  import { SwitchControlProps } from './controls/SwitchControl';
@@ -32,7 +32,7 @@ export type EmailFormControlProps = BaseFormControlProps & EmailControlProps & {
32
32
  export type PasswordFormControlProps = BaseFormControlProps & PasswordControlProps & {
33
33
  type: 'password';
34
34
  };
35
- export type NumberFormControlProps = BaseFormControlProps & NumberControlProps & {
35
+ export type NumberFormControlProps = BaseFormControlProps & DecimalControlProps & {
36
36
  type: 'number';
37
37
  };
38
38
  export type CurrencyFormControlProps = BaseFormControlProps & CurrencyControlProps & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/fluent",
3
- "version": "0.0.17-alpha.45",
3
+ "version": "0.0.17-alpha.46",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -48,5 +48,5 @@
48
48
  "uuid": "11.0.3",
49
49
  "yup": "^1.4.0"
50
50
  },
51
- "gitHead": "7538074665d8fa6f67ca2a91e62ea32d09570a31"
51
+ "gitHead": "965e72659b066c00c257b06e04368cd7004a9a71"
52
52
  }