@headless-adminapp/fluent 1.1.3 → 1.1.4

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.
@@ -28,6 +28,7 @@ const SwitchControl_1 = require("../form/controls/SwitchControl");
28
28
  const TelephoneControl_1 = require("../form/controls/TelephoneControl");
29
29
  const TextAreaControl_1 = require("../form/controls/TextAreaControl");
30
30
  const TextControl_1 = require("../form/controls/TextControl");
31
+ const TimeControl_1 = require("../form/controls/TimeControl");
31
32
  const UrlControl_1 = require("../form/controls/UrlControl");
32
33
  // Standard Control (Base control)
33
34
  // TextControl
@@ -109,6 +110,10 @@ const StandardControl = (props) => {
109
110
  const Control = componentStore_1.componentStore.getComponent('Form.DurationControl') ?? DurationControl_1.DurationControl;
110
111
  return ((0, jsx_runtime_1.jsx)(Control, { name: name, placeholder: placeholder, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, readOnly: readOnly }));
111
112
  }
113
+ case 'time': {
114
+ const Control = componentStore_1.componentStore.getComponent('Form.TimeControl') ?? TimeControl_1.TimeControl;
115
+ return ((0, jsx_runtime_1.jsx)(Control, { name: name, placeholder: placeholder, value: value, onChange: onChange, onBlur: onBlur, error: isError, disabled: isDisabled, readOnly: readOnly }));
116
+ }
112
117
  default: {
113
118
  return (0, jsx_runtime_1.jsx)(react_1.Fragment, {});
114
119
  }
@@ -0,0 +1,4 @@
1
+ import { ControlProps } from './types';
2
+ export interface TimeControlProps extends ControlProps<number> {
3
+ }
4
+ export declare function TimeControl({ value, onChange, id, name, onBlur, placeholder, disabled, readOnly, }: Readonly<TimeControlProps>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TimeControl = TimeControl;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_components_1 = require("@fluentui/react-components");
9
+ const react_timepicker_compat_1 = require("@fluentui/react-timepicker-compat");
10
+ const locale_1 = require("@headless-adminapp/app/locale");
11
+ const icons_1 = require("@headless-adminapp/icons");
12
+ const dayjs_1 = __importDefault(require("dayjs"));
13
+ const customParseFormat_1 = __importDefault(require("dayjs/plugin/customParseFormat"));
14
+ const react_1 = require("react");
15
+ dayjs_1.default.extend(customParseFormat_1.default);
16
+ function TimeControl({ value, onChange, id, name, onBlur, placeholder, disabled, readOnly, }) {
17
+ const { timeFormats: { short: timeFormat }, timezone, } = (0, locale_1.useLocale)();
18
+ const [internalTimeValue, setInternalTimeValue] = (0, react_1.useState)(value ? (0, dayjs_1.default)().startOf('day').add(value, 'minutes').format(timeFormat) : '');
19
+ const internalTimeValueRef = (0, react_1.useRef)(internalTimeValue);
20
+ internalTimeValueRef.current = internalTimeValue;
21
+ (0, react_1.useEffect)(() => {
22
+ const updatedValue = typeof value === 'number'
23
+ ? (0, dayjs_1.default)().startOf('day').add(value, 'minutes').format(timeFormat)
24
+ : '';
25
+ if (internalTimeValueRef.current !== updatedValue) {
26
+ setInternalTimeValue(updatedValue);
27
+ }
28
+ }, [value, timezone, timeFormat]);
29
+ const isReadonly = readOnly || disabled;
30
+ const selectedTime = (0, react_1.useMemo)(() => {
31
+ if (typeof value !== 'number') {
32
+ return null;
33
+ }
34
+ return (0, dayjs_1.default)().startOf('day').add(value, 'minutes').toDate();
35
+ }, [value]);
36
+ console.log('TimeControl', value, selectedTime);
37
+ return ((0, jsx_runtime_1.jsx)("div", { style: {
38
+ display: 'flex',
39
+ alignItems: 'center',
40
+ gap: react_components_1.tokens.spacingHorizontalS,
41
+ }, children: (0, jsx_runtime_1.jsx)(react_timepicker_compat_1.TimePicker, { appearance: "filled-darker", style: {
42
+ flex: 1,
43
+ minWidth: 0,
44
+ pointerEvents: isReadonly ? 'none' : 'auto',
45
+ }, placeholder: placeholder, id: id, name: name, input: {
46
+ style: { minWidth: 0 },
47
+ }, readOnly: isReadonly, selectedTime: selectedTime, freeform: true, value: internalTimeValue, onTimeChange: (_, data) => {
48
+ console.log('onTimeChange', data);
49
+ if (data.selectedTime) {
50
+ onChange?.((0, dayjs_1.default)(data.selectedTime).diff((0, dayjs_1.default)().startOf('day'), 'minutes'));
51
+ }
52
+ else if (data.selectedTimeText) {
53
+ let resolvedTime = resolveTimeValue(data.selectedTimeText, timeFormat);
54
+ if (!resolvedTime) {
55
+ setInternalTimeValue(value ? (0, dayjs_1.default)(value).format(timeFormat) : '');
56
+ return;
57
+ }
58
+ const newValue = (0, dayjs_1.default)(resolvedTime).diff((0, dayjs_1.default)().startOf('day'), 'minutes');
59
+ if (newValue !== value) {
60
+ onChange?.(newValue);
61
+ }
62
+ setInternalTimeValue((0, dayjs_1.default)(resolvedTime).format(timeFormat));
63
+ }
64
+ else {
65
+ setInternalTimeValue('');
66
+ onChange?.(null);
67
+ }
68
+ }, onInput: (e) => {
69
+ setInternalTimeValue(e.currentTarget.value);
70
+ }, onBlur: () => {
71
+ onBlur?.();
72
+ }, expandIcon: (0, jsx_runtime_1.jsx)("div", { style: {
73
+ display: 'flex',
74
+ alignItems: 'center',
75
+ justifyContent: 'center',
76
+ marginRight: -4,
77
+ color: react_components_1.tokens.colorNeutralForeground2,
78
+ }, children: (0, jsx_runtime_1.jsx)(icons_1.Icons.Clock, { size: 20 }) }) }) }));
79
+ }
80
+ function resolveTimeValue(value, timeFormat) {
81
+ if (!value) {
82
+ return;
83
+ }
84
+ const time = (0, dayjs_1.default)(value, timeFormat);
85
+ if (!time.isValid()) {
86
+ return;
87
+ }
88
+ return time.toDate();
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/fluent",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -50,5 +50,5 @@
50
50
  "uuid": "11.0.3",
51
51
  "yup": "^1.4.0"
52
52
  },
53
- "gitHead": "3a036d597b19d9ef7571b2d206ecb362b74d5228"
53
+ "gitHead": "c672cac064915ef436c61692cc8aa18e3faf82c5"
54
54
  }