bianic-ui 2.1.0-beta.1 → 2.1.0-beta.2

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/dist/cjs/index.js CHANGED
@@ -267,24 +267,34 @@ var validUnion = function (value, union) {
267
267
  return union.includes(value) ? value : union[0];
268
268
  };
269
269
  var useDetectOutsideClick = function (ref, initialState, ignoreRef, event) {
270
- if (event === void 0) { event = 'click'; }
270
+ if (event === void 0) { event = 'pointerdown'; }
271
271
  var _a = React.useState(initialState), isActive = _a[0], setIsActive = _a[1];
272
272
  React.useEffect(function () {
273
- var pageClickEvent = function (event) {
274
- // If the active element exists and is clicked outside of
275
- if (ignoreRef &&
276
- ignoreRef.current &&
277
- ignoreRef.current.contains(event.target)) ;
278
- else if (ref.current !== null &&
279
- !ref.current.contains(event.target)) {
280
- setIsActive(!isActive);
273
+ var pageClickEvent = function (e) {
274
+ var target = e.target;
275
+ if (!ref || !ref.current)
276
+ return;
277
+ var path = e.composedPath
278
+ ? e.composedPath()
279
+ : null;
280
+ if (ignoreRef && ignoreRef.current) {
281
+ var insideIgnore = Array.isArray(path)
282
+ ? path.includes(ignoreRef.current)
283
+ : target && ignoreRef.current.contains(target);
284
+ if (insideIgnore)
285
+ return;
281
286
  }
287
+ var inside = Array.isArray(path)
288
+ ? path.includes(ref.current)
289
+ : target && ref.current.contains(target);
290
+ if (inside)
291
+ return;
292
+ setIsActive(function (prev) { return !prev; });
282
293
  };
283
- // If the item is active (ie open) then listen for clicks
284
294
  if (isActive)
285
- window.addEventListener(event, pageClickEvent);
286
- return function () { return window.removeEventListener(event, pageClickEvent); };
287
- }, [isActive, ref]);
295
+ window.addEventListener(event, pageClickEvent, true);
296
+ return function () { return window.removeEventListener(event, pageClickEvent, true); };
297
+ }, [isActive, ref, ignoreRef, event]);
288
298
  return [isActive, setIsActive];
289
299
  };
290
300
 
@@ -3167,12 +3177,21 @@ var useCalendarLogic = function (selectedDate, minDate, maxDate) {
3167
3177
  };
3168
3178
 
3169
3179
  var PickerCalendar = function (_a) {
3170
- var _b = _a.zIndex, zIndex = _b === void 0 ? 100 : _b, anchorRef = _a.anchorRef, maxDate = _a.maxDate, minDate = _a.minDate, onDateChange = _a.onDateChange; _a.ref; var _c = _a.selectedDate, selectedDate = _c === void 0 ? null : _c, props = __rest(_a, ["zIndex", "anchorRef", "maxDate", "minDate", "onDateChange", "ref", "selectedDate"]);
3180
+ var _b = _a.zIndex, zIndex = _b === void 0 ? 100 : _b, anchorRef = _a.anchorRef, maxDate = _a.maxDate, minDate = _a.minDate, onDateChange = _a.onDateChange; _a.ref; var _c = _a.selectedDate, selectedDate = _c === void 0 ? null : _c, _d = _a.isOpen, isOpen = _d === void 0 ? false : _d, _e = _a.onClose, onClose = _e === void 0 ? function () { } : _e, props = __rest(_a, ["zIndex", "anchorRef", "maxDate", "minDate", "onDateChange", "ref", "selectedDate", "isOpen", "onClose"]);
3171
3181
  // Hooks & States
3172
- var _d = useCalendarLogic(selectedDate, minDate, maxDate), displayDays = _d.displayDays, handleNextDecade = _d.handleNextDecade, handleNextMonth = _d.handleNextMonth, handleNextYear = _d.handleNextYear, handlePickerMode = _d.handlePickerMode, handlePrevDecade = _d.handlePrevDecade, handlePrevMonth = _d.handlePrevMonth, handlePrevYear = _d.handlePrevYear, handleSetSelectedDate = _d.handleSetSelectedDate, isNextDisabled = _d.isNextDisabled, isPrevDisabled = _d.isPrevDisabled, maxDateValue = _d.maxDateValue, minDateValue = _d.minDateValue, pickerMode = _d.pickerMode, setViewMonthValue = _d.setViewMonthValue, setViewYearValue = _d.setViewYearValue, viewMonthValue = _d.viewMonthValue, viewYearValue = _d.viewYearValue, yearDisplayRange = _d.yearDisplayRange;
3182
+ var _f = useCalendarLogic(selectedDate, minDate, maxDate), displayDays = _f.displayDays, handleNextDecade = _f.handleNextDecade, handleNextMonth = _f.handleNextMonth, handleNextYear = _f.handleNextYear, handlePickerMode = _f.handlePickerMode, handlePrevDecade = _f.handlePrevDecade, handlePrevMonth = _f.handlePrevMonth, handlePrevYear = _f.handlePrevYear, handleSetSelectedDate = _f.handleSetSelectedDate, isNextDisabled = _f.isNextDisabled, isPrevDisabled = _f.isPrevDisabled, maxDateValue = _f.maxDateValue, minDateValue = _f.minDateValue, pickerMode = _f.pickerMode, setViewMonthValue = _f.setViewMonthValue, setViewYearValue = _f.setViewYearValue, viewMonthValue = _f.viewMonthValue, viewYearValue = _f.viewYearValue, yearDisplayRange = _f.yearDisplayRange;
3173
3183
  var pickerCalendarRef = React.useRef(null);
3184
+ var _g = useDetectOutsideClick(anchorRef, false, pickerCalendarRef), isPickerOpen = _g[0], setIsPickerOpen = _g[1];
3174
3185
  var style = props.style, className = props.className, restProps = __rest(props, ["style", "className"]);
3175
3186
  var positionStyle = usePopupPosition(anchorRef, pickerCalendarRef)[0];
3187
+ React.useEffect(function () {
3188
+ setIsPickerOpen(isOpen);
3189
+ }, [isOpen]);
3190
+ React.useEffect(function () {
3191
+ if (!isPickerOpen) {
3192
+ onClose();
3193
+ }
3194
+ }, [isPickerOpen]);
3176
3195
  // Event Handlers
3177
3196
  var handleDateSelect = function (date) {
3178
3197
  handleSetSelectedDate(date, onDateChange);
@@ -3185,7 +3204,7 @@ var PickerCalendar = function (_a) {
3185
3204
  setViewYearValue(year);
3186
3205
  handlePickerMode('month');
3187
3206
  };
3188
- return reactDom.createPortal(React.createElement("div", __assign({ className: "bianic-datepicker-calendar absolute flex w-[250px] flex-col gap-[15px] rounded-b-radius-sm bg-bia-white px-1.5 pb-[17px] pt-[15px] text-bia-black shadow-md ".concat(className), ref: pickerCalendarRef, style: __assign(__assign({ zIndex: zIndex }, positionStyle), style) }, restProps),
3207
+ return reactDom.createPortal(React.createElement("div", __assign({ className: "bianic-datepicker-calendar absolute flex w-[250px] flex-col gap-[15px] rounded-b-radius-sm bg-bia-white px-1.5 pb-[17px] pt-[15px] text-bia-black shadow-md ".concat(className), ref: pickerCalendarRef, style: __assign(__assign({ zIndex: zIndex, display: isPickerOpen ? 'block' : 'none' }, positionStyle), style) }, restProps),
3189
3208
  React.createElement("div", { className: "bianic-datepicker-calendar-controller flex w-full items-center justify-between" },
3190
3209
  React.createElement("button", { className: "bianic-datepicker-calendar-prev-button text-bia-coolgrey disabled:text-bia-coolgrey-light-50", disabled: isPrevDisabled(), onClick: pickerMode === 'date'
3191
3210
  ? handlePrevMonth
@@ -3301,12 +3320,11 @@ function DatePicker(_a) {
3301
3320
  var _b = _a.zIndexCalendar, zIndexCalendar = _b === void 0 ? 100 : _b, value = _a.value, onChange = _a.onChange, size = _a.size, disabled = _a.disabled; _a.placeholder; var label = _a.label, minDate = _a.minDate, maxDate = _a.maxDate, required = _a.required, nullDisplay = _a.nullDisplay, inputclassName = _a.inputclassName, containerClassName = _a.containerClassName;
3302
3321
  // State and Ref
3303
3322
  var inputRef = React.useRef(null);
3304
- var wrapperRef = React.useRef(null);
3305
- var _d = useDetectOutsideClick(wrapperRef, false), isPickerOpen = _d[0], setIsPickerOpen = _d[1];
3306
- return (React.createElement("div", { className: "bianic-datepicker-container relative ".concat(containerClassName), ref: wrapperRef },
3323
+ var _d = React.useState(false), isPickerOpen = _d[0], setIsPickerOpen = _d[1];
3324
+ return (React.createElement("div", { className: "bianic-datepicker-container relative ".concat(containerClassName) },
3307
3325
  React.createElement("div", { className: "bianic-datepicker-field-container" },
3308
3326
  React.createElement(DateInputDisplay, { inputClassName: inputclassName, value: value, setValue: onChange, placeholder: "YYYY-MM-DD", nullDisplay: nullDisplay, size: size, label: label, required: required, buttonAction: function () { return setIsPickerOpen(!isPickerOpen); }, ref: inputRef, disabled: disabled })),
3309
- isPickerOpen && (React.createElement(PickerCalendar, { zIndex: zIndexCalendar, anchorRef: inputRef, selectedDate: value, onDateChange: onChange, minDate: minDate, maxDate: maxDate }))));
3327
+ React.createElement(PickerCalendar, { zIndex: zIndexCalendar, anchorRef: inputRef, selectedDate: value, onDateChange: onChange, minDate: minDate, maxDate: maxDate, isOpen: isPickerOpen, onClose: function () { return setIsPickerOpen(false); } })));
3310
3328
  }
3311
3329
 
3312
3330
  var Node = function (_a) {
@@ -2,6 +2,8 @@ import { ComponentPropsWithRef } from 'react';
2
2
  export interface PickerCalendarProps extends ComponentPropsWithRef<'div'> {
3
3
  zIndex?: number | 'auto' | 'inherit';
4
4
  anchorRef: React.RefObject<HTMLDivElement>;
5
+ isOpen?: boolean;
6
+ onClose?: () => void;
5
7
  minDate?: string;
6
8
  maxDate?: string;
7
9
  selectedDate?: string | null;
package/dist/esm/index.js CHANGED
@@ -265,24 +265,34 @@ var validUnion = function (value, union) {
265
265
  return union.includes(value) ? value : union[0];
266
266
  };
267
267
  var useDetectOutsideClick = function (ref, initialState, ignoreRef, event) {
268
- if (event === void 0) { event = 'click'; }
268
+ if (event === void 0) { event = 'pointerdown'; }
269
269
  var _a = useState(initialState), isActive = _a[0], setIsActive = _a[1];
270
270
  useEffect(function () {
271
- var pageClickEvent = function (event) {
272
- // If the active element exists and is clicked outside of
273
- if (ignoreRef &&
274
- ignoreRef.current &&
275
- ignoreRef.current.contains(event.target)) ;
276
- else if (ref.current !== null &&
277
- !ref.current.contains(event.target)) {
278
- setIsActive(!isActive);
271
+ var pageClickEvent = function (e) {
272
+ var target = e.target;
273
+ if (!ref || !ref.current)
274
+ return;
275
+ var path = e.composedPath
276
+ ? e.composedPath()
277
+ : null;
278
+ if (ignoreRef && ignoreRef.current) {
279
+ var insideIgnore = Array.isArray(path)
280
+ ? path.includes(ignoreRef.current)
281
+ : target && ignoreRef.current.contains(target);
282
+ if (insideIgnore)
283
+ return;
279
284
  }
285
+ var inside = Array.isArray(path)
286
+ ? path.includes(ref.current)
287
+ : target && ref.current.contains(target);
288
+ if (inside)
289
+ return;
290
+ setIsActive(function (prev) { return !prev; });
280
291
  };
281
- // If the item is active (ie open) then listen for clicks
282
292
  if (isActive)
283
- window.addEventListener(event, pageClickEvent);
284
- return function () { return window.removeEventListener(event, pageClickEvent); };
285
- }, [isActive, ref]);
293
+ window.addEventListener(event, pageClickEvent, true);
294
+ return function () { return window.removeEventListener(event, pageClickEvent, true); };
295
+ }, [isActive, ref, ignoreRef, event]);
286
296
  return [isActive, setIsActive];
287
297
  };
288
298
 
@@ -3165,12 +3175,21 @@ var useCalendarLogic = function (selectedDate, minDate, maxDate) {
3165
3175
  };
3166
3176
 
3167
3177
  var PickerCalendar = function (_a) {
3168
- var _b = _a.zIndex, zIndex = _b === void 0 ? 100 : _b, anchorRef = _a.anchorRef, maxDate = _a.maxDate, minDate = _a.minDate, onDateChange = _a.onDateChange; _a.ref; var _c = _a.selectedDate, selectedDate = _c === void 0 ? null : _c, props = __rest(_a, ["zIndex", "anchorRef", "maxDate", "minDate", "onDateChange", "ref", "selectedDate"]);
3178
+ var _b = _a.zIndex, zIndex = _b === void 0 ? 100 : _b, anchorRef = _a.anchorRef, maxDate = _a.maxDate, minDate = _a.minDate, onDateChange = _a.onDateChange; _a.ref; var _c = _a.selectedDate, selectedDate = _c === void 0 ? null : _c, _d = _a.isOpen, isOpen = _d === void 0 ? false : _d, _e = _a.onClose, onClose = _e === void 0 ? function () { } : _e, props = __rest(_a, ["zIndex", "anchorRef", "maxDate", "minDate", "onDateChange", "ref", "selectedDate", "isOpen", "onClose"]);
3169
3179
  // Hooks & States
3170
- var _d = useCalendarLogic(selectedDate, minDate, maxDate), displayDays = _d.displayDays, handleNextDecade = _d.handleNextDecade, handleNextMonth = _d.handleNextMonth, handleNextYear = _d.handleNextYear, handlePickerMode = _d.handlePickerMode, handlePrevDecade = _d.handlePrevDecade, handlePrevMonth = _d.handlePrevMonth, handlePrevYear = _d.handlePrevYear, handleSetSelectedDate = _d.handleSetSelectedDate, isNextDisabled = _d.isNextDisabled, isPrevDisabled = _d.isPrevDisabled, maxDateValue = _d.maxDateValue, minDateValue = _d.minDateValue, pickerMode = _d.pickerMode, setViewMonthValue = _d.setViewMonthValue, setViewYearValue = _d.setViewYearValue, viewMonthValue = _d.viewMonthValue, viewYearValue = _d.viewYearValue, yearDisplayRange = _d.yearDisplayRange;
3180
+ var _f = useCalendarLogic(selectedDate, minDate, maxDate), displayDays = _f.displayDays, handleNextDecade = _f.handleNextDecade, handleNextMonth = _f.handleNextMonth, handleNextYear = _f.handleNextYear, handlePickerMode = _f.handlePickerMode, handlePrevDecade = _f.handlePrevDecade, handlePrevMonth = _f.handlePrevMonth, handlePrevYear = _f.handlePrevYear, handleSetSelectedDate = _f.handleSetSelectedDate, isNextDisabled = _f.isNextDisabled, isPrevDisabled = _f.isPrevDisabled, maxDateValue = _f.maxDateValue, minDateValue = _f.minDateValue, pickerMode = _f.pickerMode, setViewMonthValue = _f.setViewMonthValue, setViewYearValue = _f.setViewYearValue, viewMonthValue = _f.viewMonthValue, viewYearValue = _f.viewYearValue, yearDisplayRange = _f.yearDisplayRange;
3171
3181
  var pickerCalendarRef = useRef(null);
3182
+ var _g = useDetectOutsideClick(anchorRef, false, pickerCalendarRef), isPickerOpen = _g[0], setIsPickerOpen = _g[1];
3172
3183
  var style = props.style, className = props.className, restProps = __rest(props, ["style", "className"]);
3173
3184
  var positionStyle = usePopupPosition(anchorRef, pickerCalendarRef)[0];
3185
+ useEffect(function () {
3186
+ setIsPickerOpen(isOpen);
3187
+ }, [isOpen]);
3188
+ useEffect(function () {
3189
+ if (!isPickerOpen) {
3190
+ onClose();
3191
+ }
3192
+ }, [isPickerOpen]);
3174
3193
  // Event Handlers
3175
3194
  var handleDateSelect = function (date) {
3176
3195
  handleSetSelectedDate(date, onDateChange);
@@ -3183,7 +3202,7 @@ var PickerCalendar = function (_a) {
3183
3202
  setViewYearValue(year);
3184
3203
  handlePickerMode('month');
3185
3204
  };
3186
- return createPortal(React.createElement("div", __assign({ className: "bianic-datepicker-calendar absolute flex w-[250px] flex-col gap-[15px] rounded-b-radius-sm bg-bia-white px-1.5 pb-[17px] pt-[15px] text-bia-black shadow-md ".concat(className), ref: pickerCalendarRef, style: __assign(__assign({ zIndex: zIndex }, positionStyle), style) }, restProps),
3205
+ return createPortal(React.createElement("div", __assign({ className: "bianic-datepicker-calendar absolute flex w-[250px] flex-col gap-[15px] rounded-b-radius-sm bg-bia-white px-1.5 pb-[17px] pt-[15px] text-bia-black shadow-md ".concat(className), ref: pickerCalendarRef, style: __assign(__assign({ zIndex: zIndex, display: isPickerOpen ? 'block' : 'none' }, positionStyle), style) }, restProps),
3187
3206
  React.createElement("div", { className: "bianic-datepicker-calendar-controller flex w-full items-center justify-between" },
3188
3207
  React.createElement("button", { className: "bianic-datepicker-calendar-prev-button text-bia-coolgrey disabled:text-bia-coolgrey-light-50", disabled: isPrevDisabled(), onClick: pickerMode === 'date'
3189
3208
  ? handlePrevMonth
@@ -3299,12 +3318,11 @@ function DatePicker(_a) {
3299
3318
  var _b = _a.zIndexCalendar, zIndexCalendar = _b === void 0 ? 100 : _b, value = _a.value, onChange = _a.onChange, size = _a.size, disabled = _a.disabled; _a.placeholder; var label = _a.label, minDate = _a.minDate, maxDate = _a.maxDate, required = _a.required, nullDisplay = _a.nullDisplay, inputclassName = _a.inputclassName, containerClassName = _a.containerClassName;
3300
3319
  // State and Ref
3301
3320
  var inputRef = useRef(null);
3302
- var wrapperRef = useRef(null);
3303
- var _d = useDetectOutsideClick(wrapperRef, false), isPickerOpen = _d[0], setIsPickerOpen = _d[1];
3304
- return (React.createElement("div", { className: "bianic-datepicker-container relative ".concat(containerClassName), ref: wrapperRef },
3321
+ var _d = useState(false), isPickerOpen = _d[0], setIsPickerOpen = _d[1];
3322
+ return (React.createElement("div", { className: "bianic-datepicker-container relative ".concat(containerClassName) },
3305
3323
  React.createElement("div", { className: "bianic-datepicker-field-container" },
3306
3324
  React.createElement(DateInputDisplay, { inputClassName: inputclassName, value: value, setValue: onChange, placeholder: "YYYY-MM-DD", nullDisplay: nullDisplay, size: size, label: label, required: required, buttonAction: function () { return setIsPickerOpen(!isPickerOpen); }, ref: inputRef, disabled: disabled })),
3307
- isPickerOpen && (React.createElement(PickerCalendar, { zIndex: zIndexCalendar, anchorRef: inputRef, selectedDate: value, onDateChange: onChange, minDate: minDate, maxDate: maxDate }))));
3325
+ React.createElement(PickerCalendar, { zIndex: zIndexCalendar, anchorRef: inputRef, selectedDate: value, onDateChange: onChange, minDate: minDate, maxDate: maxDate, isOpen: isPickerOpen, onClose: function () { return setIsPickerOpen(false); } })));
3308
3326
  }
3309
3327
 
3310
3328
  var Node = function (_a) {
@@ -2,6 +2,8 @@ import { ComponentPropsWithRef } from 'react';
2
2
  export interface PickerCalendarProps extends ComponentPropsWithRef<'div'> {
3
3
  zIndex?: number | 'auto' | 'inherit';
4
4
  anchorRef: React.RefObject<HTMLDivElement>;
5
+ isOpen?: boolean;
6
+ onClose?: () => void;
5
7
  minDate?: string;
6
8
  maxDate?: string;
7
9
  selectedDate?: string | null;
package/dist/index.d.ts CHANGED
@@ -465,6 +465,8 @@ declare function DatePicker({ zIndexCalendar, value, onChange, size, disabled, p
465
465
  interface PickerCalendarProps extends ComponentPropsWithRef<'div'> {
466
466
  zIndex?: number | 'auto' | 'inherit';
467
467
  anchorRef: React.RefObject<HTMLDivElement>;
468
+ isOpen?: boolean;
469
+ onClose?: () => void;
468
470
  minDate?: string;
469
471
  maxDate?: string;
470
472
  selectedDate?: string | null;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "@biaenergi:registry": "https://gitlab.com/api/v4/projects/50905269/packages/npm/"
5
5
  },
6
- "version": "2.1.0-beta.1",
6
+ "version": "2.1.0-beta.2",
7
7
  "description": "Design Language System develop by BIAENERGI",
8
8
  "scripts": {
9
9
  "rollup": "rollup -c",