@raystack/apsara 0.19.1 → 0.20.1
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/calendar/date-picker.d.ts +2 -1
- package/dist/calendar/date-picker.d.ts.map +1 -1
- package/dist/index.cjs +97 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +5 -8
- package/dist/index.js +97 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,8 +6,9 @@ interface DatePickerProps {
|
|
|
6
6
|
textFieldProps?: TextfieldProps;
|
|
7
7
|
calendarProps?: PropsSingleRequired & PropsBase;
|
|
8
8
|
onSelect?: (date: Date) => void;
|
|
9
|
+
placeholder?: string;
|
|
9
10
|
value?: Date;
|
|
10
11
|
}
|
|
11
|
-
export declare function DatePicker({ side, dateFormat, textFieldProps, calendarProps, value, onSelect, }: DatePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export declare function DatePicker({ side, dateFormat, placeholder, textFieldProps, calendarProps, value, onSelect, }: DatePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
12
13
|
export {};
|
|
13
14
|
//# sourceMappingURL=date-picker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-picker.d.ts","sourceRoot":"","sources":["../../calendar/date-picker.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"date-picker.d.ts","sourceRoot":"","sources":["../../calendar/date-picker.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAOlE,UAAU,eAAe;IACvB,IAAI,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,aAAa,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,IAAI,CAAC;CACd;AAED,wBAAgB,UAAU,CAAC,EACzB,IAAY,EACZ,UAAyB,EACzB,WAA0B,EAC1B,cAAc,EACd,aAAa,EACb,KAAkB,EAClB,QAAmB,GACpB,EAAE,eAAe,2CAyIjB"}
|
package/dist/index.cjs
CHANGED
|
@@ -10188,7 +10188,7 @@ function Image({ alt, children, className, ...props }) {
|
|
|
10188
10188
|
return jsxRuntimeExports.jsx("img", { alt: alt, className: image({ className }), ...props });
|
|
10189
10189
|
}
|
|
10190
10190
|
|
|
10191
|
-
var styles$k = {"textfield":"inputfield-module_textfield__l6K73","textfield-sm":"inputfield-module_textfield-sm__QTt1x","textfield-md":"inputfield-module_textfield-md__pQWpW","textfield-
|
|
10191
|
+
var styles$k = {"textfield":"inputfield-module_textfield__l6K73","textfield-sm":"inputfield-module_textfield-sm__QTt1x","textfield-md":"inputfield-module_textfield-md__pQWpW","textfield-invalid":"inputfield-module_textfield-invalid__XFKPz","textfield-valid":"inputfield-module_textfield-valid__euwnE","bold":"inputfield-module_bold__MzkDx"};
|
|
10192
10192
|
|
|
10193
10193
|
const InputField = ({ label, children, ...props }) => {
|
|
10194
10194
|
return (jsxRuntimeExports.jsxs(Flex, { direction: "column", gap: "extra-small", ...props, children: [label && jsxRuntimeExports.jsx(Label, { className: styles$k.bold, children: label }), children] }));
|
|
@@ -28045,7 +28045,7 @@ function DayPicker(props) {
|
|
|
28045
28045
|
props.footer && (React.createElement(components.Footer, { className: classNames[UI.Footer], style: styles?.[UI.Footer], role: "status", "aria-live": "polite" }, props.footer)))));
|
|
28046
28046
|
}
|
|
28047
28047
|
|
|
28048
|
-
var styles$6 = {"calendarRoot":"calendar-module_calendarRoot__KnBz-","caption_label":"calendar-module_caption_label__C5Ys7","dropdowns":"calendar-module_dropdowns__Wn53e","dropdown_trigger":"calendar-module_dropdown_trigger__dsyaq","dropdown_item_text":"calendar-module_dropdown_item_text__Tudqv","nav_button":"calendar-module_nav_button__8W5py","nav_button_previous":"calendar-module_nav_button_previous__lWJYm","nav_button_next":"calendar-module_nav_button_next__1MzRT","months":"calendar-module_months__IN75k","nav":"calendar-module_nav__aGeze","month_caption":"calendar-module_month_caption__Ws6Hx","day":"calendar-module_day__rQFGK","disabled":"calendar-module_disabled__jqgRB","outside":"calendar-module_outside__nq5XC","selected":"calendar-module_selected__kiiAZ","range_middle":"calendar-module_range_middle__PmzFi","range_start":"calendar-module_range_start__ZUooG","range_end":"calendar-module_range_end__PKrm7","week":"calendar-module_week__kCvKJ","day_button":"calendar-module_day_button__vCKP1","today":"calendar-module_today__iXQIQ","weekday":"calendar-module_weekday__xzf6F","hidden":"calendar-module_hidden__wqJVo","calendarPopover":"calendar-module_calendarPopover__PY4sa","
|
|
28048
|
+
var styles$6 = {"calendarRoot":"calendar-module_calendarRoot__KnBz-","caption_label":"calendar-module_caption_label__C5Ys7","dropdowns":"calendar-module_dropdowns__Wn53e","dropdown_trigger":"calendar-module_dropdown_trigger__dsyaq","dropdown_item_text":"calendar-module_dropdown_item_text__Tudqv","nav_button":"calendar-module_nav_button__8W5py","nav_button_previous":"calendar-module_nav_button_previous__lWJYm","nav_button_next":"calendar-module_nav_button_next__1MzRT","months":"calendar-module_months__IN75k","nav":"calendar-module_nav__aGeze","month_caption":"calendar-module_month_caption__Ws6Hx","day":"calendar-module_day__rQFGK","disabled":"calendar-module_disabled__jqgRB","outside":"calendar-module_outside__nq5XC","selected":"calendar-module_selected__kiiAZ","range_middle":"calendar-module_range_middle__PmzFi","range_start":"calendar-module_range_start__ZUooG","range_end":"calendar-module_range_end__PKrm7","week":"calendar-module_week__kCvKJ","day_button":"calendar-module_day_button__vCKP1","today":"calendar-module_today__iXQIQ","weekday":"calendar-module_weekday__xzf6F","hidden":"calendar-module_hidden__wqJVo","calendarPopover":"calendar-module_calendarPopover__PY4sa","dropdown_icon":"calendar-module_dropdown_icon__rDTbz","dropdown_content":"calendar-module_dropdown_content__ajJ5V"};
|
|
28049
28049
|
|
|
28050
28050
|
const root$1 = cva(styles$6.calendarRoot);
|
|
28051
28051
|
function DropDown({ options = [], value, onChange, onDropdownOpen, }) {
|
|
@@ -28099,7 +28099,7 @@ const Calendar = function ({ className, classNames, showOutsideDays = true, onDr
|
|
|
28099
28099
|
}, className: root$1({ className }), mode: "single", ...props }));
|
|
28100
28100
|
};
|
|
28101
28101
|
|
|
28102
|
-
var styles$5 = {"textfield":"textfield-module_textfield__u4AGg","textfield-sm":"textfield-module_textfield-sm__OKPic","textfield-md":"textfield-module_textfield-md__e2ayW","textfield-
|
|
28102
|
+
var styles$5 = {"textfield":"textfield-module_textfield__u4AGg","textfield-sm":"textfield-module_textfield-sm__OKPic","textfield-md":"textfield-module_textfield-md__e2ayW","textfield-invalid":"textfield-module_textfield-invalid__RtgIy","textfield-valid":"textfield-module_textfield-valid__6rMM9","textfield-leading":"textfield-module_textfield-leading__AE-ld","textfield-trailing":"textfield-module_textfield-trailing__Hj2jX","leadingIcon":"textfield-module_leadingIcon__u-GJ6","trailingIcon":"textfield-module_trailingIcon__q-49S"};
|
|
28103
28103
|
|
|
28104
28104
|
const textfield = cva(styles$5.textfield, {
|
|
28105
28105
|
variants: {
|
|
@@ -28144,24 +28144,110 @@ var dayjs_min = {exports: {}};
|
|
|
28144
28144
|
var dayjs_minExports = dayjs_min.exports;
|
|
28145
28145
|
var dayjs = /*@__PURE__*/getDefaultExportFromCjs(dayjs_minExports);
|
|
28146
28146
|
|
|
28147
|
-
|
|
28147
|
+
var customParseFormat$1 = {exports: {}};
|
|
28148
|
+
|
|
28149
|
+
(function (module, exports) {
|
|
28150
|
+
!function(e,t){module.exports=t();}(commonjsGlobal,(function(){var e={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},t=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,n=/\d\d/,r=/\d\d?/,i=/\d*[^-_:/,()\s\d]+/,o={},s=function(e){return (e=+e)+(e>68?1900:2e3)};var a=function(e){return function(t){this[e]=+t;}},f=[/[+-]\d\d:?(\d\d)?|Z/,function(e){(this.zone||(this.zone={})).offset=function(e){if(!e)return 0;if("Z"===e)return 0;var t=e.match(/([+-]|\d\d)/g),n=60*t[1]+(+t[2]||0);return 0===n?0:"+"===t[0]?-n:n}(e);}],h=function(e){var t=o[e];return t&&(t.indexOf?t:t.s.concat(t.f))},u=function(e,t){var n,r=o.meridiem;if(r){for(var i=1;i<=24;i+=1)if(e.indexOf(r(i,0,t))>-1){n=i>12;break}}else n=e===(t?"pm":"PM");return n},d={A:[i,function(e){this.afternoon=u(e,!1);}],a:[i,function(e){this.afternoon=u(e,!0);}],S:[/\d/,function(e){this.milliseconds=100*+e;}],SS:[n,function(e){this.milliseconds=10*+e;}],SSS:[/\d{3}/,function(e){this.milliseconds=+e;}],s:[r,a("seconds")],ss:[r,a("seconds")],m:[r,a("minutes")],mm:[r,a("minutes")],H:[r,a("hours")],h:[r,a("hours")],HH:[r,a("hours")],hh:[r,a("hours")],D:[r,a("day")],DD:[n,a("day")],Do:[i,function(e){var t=o.ordinal,n=e.match(/\d+/);if(this.day=n[0],t)for(var r=1;r<=31;r+=1)t(r).replace(/\[|\]/g,"")===e&&(this.day=r);}],M:[r,a("month")],MM:[n,a("month")],MMM:[i,function(e){var t=h("months"),n=(h("monthsShort")||t.map((function(e){return e.slice(0,3)}))).indexOf(e)+1;if(n<1)throw new Error;this.month=n%12||n;}],MMMM:[i,function(e){var t=h("months").indexOf(e)+1;if(t<1)throw new Error;this.month=t%12||t;}],Y:[/[+-]?\d+/,a("year")],YY:[n,function(e){this.year=s(e);}],YYYY:[/\d{4}/,a("year")],Z:f,ZZ:f};function c(n){var r,i;r=n,i=o&&o.formats;for(var s=(n=r.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function(t,n,r){var o=r&&r.toUpperCase();return n||i[r]||e[r]||i[o].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(function(e,t,n){return t||n.slice(1)}))}))).match(t),a=s.length,f=0;f<a;f+=1){var h=s[f],u=d[h],c=u&&u[0],l=u&&u[1];s[f]=l?{regex:c,parser:l}:h.replace(/^\[|\]$/g,"");}return function(e){for(var t={},n=0,r=0;n<a;n+=1){var i=s[n];if("string"==typeof i)r+=i.length;else {var o=i.regex,f=i.parser,h=e.slice(r),u=o.exec(h)[0];f.call(t,u),e=e.replace(u,"");}}return function(e){var t=e.afternoon;if(void 0!==t){var n=e.hours;t?n<12&&(e.hours+=12):12===n&&(e.hours=0),delete e.afternoon;}}(t),t}}return function(e,t,n){n.p.customParseFormat=!0,e&&e.parseTwoDigitYear&&(s=e.parseTwoDigitYear);var r=t.prototype,i=r.parse;r.parse=function(e){var t=e.date,r=e.utc,s=e.args;this.$u=r;var a=s[1];if("string"==typeof a){var f=!0===s[2],h=!0===s[3],u=f||h,d=s[2];h&&(d=s[2]),o=this.$locale(),!f&&d&&(o=n.Ls[d]),this.$d=function(e,t,n){try{if(["x","X"].indexOf(t)>-1)return new Date(("X"===t?1e3:1)*e);var r=c(t)(e),i=r.year,o=r.month,s=r.day,a=r.hours,f=r.minutes,h=r.seconds,u=r.milliseconds,d=r.zone,l=new Date,m=s||(i||o?1:l.getDate()),M=i||l.getFullYear(),Y=0;i&&!o||(Y=o>0?o-1:l.getMonth());var p=a||0,v=f||0,D=h||0,g=u||0;return d?new Date(Date.UTC(M,Y,m,p,v,D,g+60*d.offset*1e3)):n?new Date(Date.UTC(M,Y,m,p,v,D,g)):new Date(M,Y,m,p,v,D,g)}catch(e){return new Date("")}}(t,a,r),this.init(),d&&!0!==d&&(this.$L=this.locale(d).$L),u&&t!=this.format(a)&&(this.$d=new Date("")),o={};}else if(a instanceof Array)for(var l=a.length,m=1;m<=l;m+=1){s[1]=a[m-1];var M=n.apply(this,s);if(M.isValid()){this.$d=M.$d,this.$L=M.$L,this.init();break}m===l&&(this.$d=new Date(""));}else i.call(this,e);};}}));
|
|
28151
|
+
} (customParseFormat$1));
|
|
28152
|
+
|
|
28153
|
+
var customParseFormatExports = customParseFormat$1.exports;
|
|
28154
|
+
var customParseFormat = /*@__PURE__*/getDefaultExportFromCjs(customParseFormatExports);
|
|
28155
|
+
|
|
28156
|
+
dayjs.extend(customParseFormat);
|
|
28157
|
+
function DatePicker({ side = "top", dateFormat = "DD/MM/YYYY", placeholder = "DD/MM/YYYY", textFieldProps, calendarProps, value = new Date(), onSelect = () => { }, }) {
|
|
28158
|
+
const defaultDate = dayjs(value).format(dateFormat);
|
|
28148
28159
|
const [showCalendar, setShowCalendar] = React.useState(false);
|
|
28149
|
-
const
|
|
28150
|
-
const
|
|
28160
|
+
const [calendarVal, setCalendarVal] = React.useState(value);
|
|
28161
|
+
const [inputState, setInputState] = React.useState();
|
|
28162
|
+
const isDropdownOpenRef = React.useRef(false);
|
|
28163
|
+
const textFieldRef = React.useRef(null);
|
|
28164
|
+
const contentRef = React.useRef(null);
|
|
28165
|
+
const isInputFieldFocused = React.useRef(false);
|
|
28166
|
+
const calendarValRef = React.useRef(value);
|
|
28167
|
+
React.useEffect(() => {
|
|
28168
|
+
calendarValRef.current = calendarVal;
|
|
28169
|
+
}, [calendarVal]);
|
|
28170
|
+
function isElementOutside(el) {
|
|
28171
|
+
return !isDropdownOpenRef.current && // Month and Year dropdown from Date picker
|
|
28172
|
+
!textFieldRef.current?.contains(el) && // TextField
|
|
28173
|
+
!contentRef.current?.contains(el);
|
|
28174
|
+
}
|
|
28175
|
+
const handleMouseDown = React.useCallback((event) => {
|
|
28176
|
+
const el = (event.target);
|
|
28177
|
+
if (el && isElementOutside(el))
|
|
28178
|
+
removeEventListeners();
|
|
28179
|
+
}, []);
|
|
28180
|
+
function registerEventListeners() {
|
|
28181
|
+
isInputFieldFocused.current = true;
|
|
28182
|
+
document.addEventListener('mouseup', handleMouseDown);
|
|
28183
|
+
}
|
|
28184
|
+
function removeEventListeners() {
|
|
28185
|
+
isInputFieldFocused.current = false;
|
|
28186
|
+
setShowCalendar(false);
|
|
28187
|
+
const updatedVal = dayjs(calendarValRef.current).format(dateFormat);
|
|
28188
|
+
if (textFieldRef.current)
|
|
28189
|
+
textFieldRef.current.value = updatedVal;
|
|
28190
|
+
if (inputState === undefined)
|
|
28191
|
+
onSelect(dayjs(updatedVal).toDate());
|
|
28192
|
+
document.removeEventListener('mouseup', handleMouseDown);
|
|
28193
|
+
}
|
|
28151
28194
|
const handleSelect = (day) => {
|
|
28152
28195
|
onSelect(day);
|
|
28153
|
-
|
|
28196
|
+
setCalendarVal(day);
|
|
28197
|
+
calendarValRef.current = day;
|
|
28198
|
+
setInputState(undefined);
|
|
28199
|
+
removeEventListeners();
|
|
28154
28200
|
};
|
|
28155
28201
|
function onDropdownOpen() {
|
|
28156
|
-
|
|
28202
|
+
isDropdownOpenRef.current = true;
|
|
28157
28203
|
}
|
|
28158
28204
|
function onOpenChange(open) {
|
|
28159
|
-
if (!
|
|
28205
|
+
if (!isDropdownOpenRef.current && !(isInputFieldFocused.current && showCalendar)) {
|
|
28160
28206
|
setShowCalendar(Boolean(open));
|
|
28161
28207
|
}
|
|
28162
|
-
|
|
28208
|
+
isDropdownOpenRef.current = false;
|
|
28209
|
+
}
|
|
28210
|
+
function handleInputFocus() {
|
|
28211
|
+
if (isInputFieldFocused.current)
|
|
28212
|
+
return;
|
|
28213
|
+
if (!showCalendar)
|
|
28214
|
+
setShowCalendar(true);
|
|
28215
|
+
}
|
|
28216
|
+
function handleInputBlur(event) {
|
|
28217
|
+
if (isInputFieldFocused.current) {
|
|
28218
|
+
const el = event.relatedTarget;
|
|
28219
|
+
if (el && isElementOutside(el))
|
|
28220
|
+
removeEventListeners();
|
|
28221
|
+
}
|
|
28222
|
+
else {
|
|
28223
|
+
registerEventListeners();
|
|
28224
|
+
setTimeout(() => textFieldRef.current?.focus());
|
|
28225
|
+
}
|
|
28226
|
+
}
|
|
28227
|
+
function handleKeyUp(event) {
|
|
28228
|
+
if (event.code === 'Enter' && textFieldRef.current) {
|
|
28229
|
+
textFieldRef.current.blur();
|
|
28230
|
+
removeEventListeners();
|
|
28231
|
+
}
|
|
28232
|
+
}
|
|
28233
|
+
function handleInputChange(event) {
|
|
28234
|
+
const { value } = event.target;
|
|
28235
|
+
const format = value.includes("/") ? "DD/MM/YYYY" : value.includes("-") ? "DD-MM-YYYY" : undefined;
|
|
28236
|
+
const date = dayjs(value, format);
|
|
28237
|
+
const isValidDate = date.isValid();
|
|
28238
|
+
const isAfter = calendarProps?.startMonth !== undefined ? dayjs(date).isSameOrAfter(calendarProps.startMonth) : true;
|
|
28239
|
+
const isBefore = calendarProps?.endMonth !== undefined ? dayjs(date).isSameOrBefore(calendarProps.endMonth) : true;
|
|
28240
|
+
const isValid = isValidDate && isAfter && isBefore && dayjs(date).isSameOrBefore(dayjs());
|
|
28241
|
+
if (isValid) {
|
|
28242
|
+
setCalendarVal(date.toDate());
|
|
28243
|
+
if (inputState === 'invalid')
|
|
28244
|
+
setInputState(undefined);
|
|
28245
|
+
}
|
|
28246
|
+
else {
|
|
28247
|
+
setInputState('invalid');
|
|
28248
|
+
}
|
|
28163
28249
|
}
|
|
28164
|
-
return (jsxRuntimeExports.jsxs(Popover, { open: showCalendar, onOpenChange: onOpenChange, children: [jsxRuntimeExports.jsx(
|
|
28250
|
+
return (jsxRuntimeExports.jsxs(Popover, { open: showCalendar, onOpenChange: onOpenChange, children: [jsxRuntimeExports.jsx(TextField, { ref: textFieldRef, defaultValue: defaultDate, trailing: jsxRuntimeExports.jsx(Popover.Trigger, { asChild: true, children: jsxRuntimeExports.jsx(CalendarIcon, {}) }), onChange: handleInputChange, onFocus: handleInputFocus, onBlur: handleInputBlur, state: inputState, placeholder: placeholder, onKeyUp: handleKeyUp, ...textFieldProps }), jsxRuntimeExports.jsx(Popover.Content, { side: side, className: styles$6.calendarPopover, ref: contentRef, children: jsxRuntimeExports.jsx(Calendar, { required: true, ...calendarProps, onDropdownOpen: onDropdownOpen, mode: "single", selected: calendarVal, month: calendarVal, onSelect: handleSelect, onMonthChange: setCalendarVal }) })] }));
|
|
28165
28251
|
}
|
|
28166
28252
|
|
|
28167
28253
|
function RangePicker({ side = "top", dateFormat = "DD/MM/YYYY", textFieldProps, calendarProps, onSelect = () => { }, value = {
|