@raystack/apsara 0.19.1 → 0.20.0
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 +92 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +5 -8
- package/dist/index.js +92 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.css
CHANGED
|
@@ -1067,10 +1067,10 @@ html[data-theme="dark"] {
|
|
|
1067
1067
|
padding: var(--pd-8);
|
|
1068
1068
|
}
|
|
1069
1069
|
|
|
1070
|
-
.inputfield-module_textfield-
|
|
1070
|
+
.inputfield-module_textfield-invalid__XFKPz {
|
|
1071
1071
|
border: 1px solid var(--border-danger);
|
|
1072
1072
|
}
|
|
1073
|
-
.inputfield-module_textfield-
|
|
1073
|
+
.inputfield-module_textfield-invalid__XFKPz:focus {
|
|
1074
1074
|
border: 1px solid var(--border-danger);
|
|
1075
1075
|
}
|
|
1076
1076
|
|
|
@@ -1086,6 +1086,7 @@ html[data-theme="dark"] {
|
|
|
1086
1086
|
.inputfield-module_bold__MzkDx {
|
|
1087
1087
|
font-weight: 500 !important;
|
|
1088
1088
|
}
|
|
1089
|
+
|
|
1089
1090
|
.link-module_link__3Pld2 {
|
|
1090
1091
|
flex-shrink: 0;
|
|
1091
1092
|
outline: 0;
|
|
@@ -1940,10 +1941,6 @@ html[data-theme="dark"] {
|
|
|
1940
1941
|
min-width: max-content;
|
|
1941
1942
|
}
|
|
1942
1943
|
|
|
1943
|
-
.calendar-module_datePickerInput__aOnRQ {
|
|
1944
|
-
cursor: pointer;
|
|
1945
|
-
}
|
|
1946
|
-
|
|
1947
1944
|
.calendar-module_dropdowns__Wn53e {
|
|
1948
1945
|
display: flex;
|
|
1949
1946
|
align-items: center;
|
|
@@ -2030,10 +2027,10 @@ html[data-theme="dark"] {
|
|
|
2030
2027
|
padding: var(--pd-8);
|
|
2031
2028
|
}
|
|
2032
2029
|
|
|
2033
|
-
.textfield-module_textfield-
|
|
2030
|
+
.textfield-module_textfield-invalid__RtgIy {
|
|
2034
2031
|
outline: 1px solid var(--border-danger);
|
|
2035
2032
|
}
|
|
2036
|
-
.textfield-module_textfield-
|
|
2033
|
+
.textfield-module_textfield-invalid__RtgIy:focus {
|
|
2037
2034
|
outline: 1px solid var(--border-danger);
|
|
2038
2035
|
}
|
|
2039
2036
|
|
package/dist/index.js
CHANGED
|
@@ -10168,7 +10168,7 @@ function Image({ alt, children, className, ...props }) {
|
|
|
10168
10168
|
return jsxRuntimeExports.jsx("img", { alt: alt, className: image({ className }), ...props });
|
|
10169
10169
|
}
|
|
10170
10170
|
|
|
10171
|
-
var styles$k = {"textfield":"inputfield-module_textfield__l6K73","textfield-sm":"inputfield-module_textfield-sm__QTt1x","textfield-md":"inputfield-module_textfield-md__pQWpW","textfield-
|
|
10171
|
+
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"};
|
|
10172
10172
|
|
|
10173
10173
|
const InputField = ({ label, children, ...props }) => {
|
|
10174
10174
|
return (jsxRuntimeExports.jsxs(Flex, { direction: "column", gap: "extra-small", ...props, children: [label && jsxRuntimeExports.jsx(Label, { className: styles$k.bold, children: label }), children] }));
|
|
@@ -28025,7 +28025,7 @@ function DayPicker(props) {
|
|
|
28025
28025
|
props.footer && (React__default.createElement(components.Footer, { className: classNames[UI.Footer], style: styles?.[UI.Footer], role: "status", "aria-live": "polite" }, props.footer)))));
|
|
28026
28026
|
}
|
|
28027
28027
|
|
|
28028
|
-
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","
|
|
28028
|
+
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"};
|
|
28029
28029
|
|
|
28030
28030
|
const root$1 = cva(styles$6.calendarRoot);
|
|
28031
28031
|
function DropDown({ options = [], value, onChange, onDropdownOpen, }) {
|
|
@@ -28079,7 +28079,7 @@ const Calendar = function ({ className, classNames, showOutsideDays = true, onDr
|
|
|
28079
28079
|
}, className: root$1({ className }), mode: "single", ...props }));
|
|
28080
28080
|
};
|
|
28081
28081
|
|
|
28082
|
-
var styles$5 = {"textfield":"textfield-module_textfield__u4AGg","textfield-sm":"textfield-module_textfield-sm__OKPic","textfield-md":"textfield-module_textfield-md__e2ayW","textfield-
|
|
28082
|
+
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"};
|
|
28083
28083
|
|
|
28084
28084
|
const textfield = cva(styles$5.textfield, {
|
|
28085
28085
|
variants: {
|
|
@@ -28124,24 +28124,105 @@ var dayjs_min = {exports: {}};
|
|
|
28124
28124
|
var dayjs_minExports = dayjs_min.exports;
|
|
28125
28125
|
var dayjs = /*@__PURE__*/getDefaultExportFromCjs(dayjs_minExports);
|
|
28126
28126
|
|
|
28127
|
-
|
|
28127
|
+
var customParseFormat$1 = {exports: {}};
|
|
28128
|
+
|
|
28129
|
+
(function (module, exports) {
|
|
28130
|
+
!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);};}}));
|
|
28131
|
+
} (customParseFormat$1));
|
|
28132
|
+
|
|
28133
|
+
var customParseFormatExports = customParseFormat$1.exports;
|
|
28134
|
+
var customParseFormat = /*@__PURE__*/getDefaultExportFromCjs(customParseFormatExports);
|
|
28135
|
+
|
|
28136
|
+
dayjs.extend(customParseFormat);
|
|
28137
|
+
function DatePicker({ side = "top", dateFormat = "DD/MM/YYYY", placeholder = "DD/MM/YYYY", textFieldProps, calendarProps, value = new Date(), onSelect = () => { }, }) {
|
|
28138
|
+
const defaultDate = dayjs(value).format(dateFormat);
|
|
28128
28139
|
const [showCalendar, setShowCalendar] = useState(false);
|
|
28129
|
-
const
|
|
28130
|
-
const
|
|
28140
|
+
const [calendarVal, setCalendarVal] = useState(value);
|
|
28141
|
+
const [inputState, setInputState] = useState();
|
|
28142
|
+
const isDropdownOpenRef = useRef(false);
|
|
28143
|
+
const textFieldRef = useRef(null);
|
|
28144
|
+
const contentRef = useRef(null);
|
|
28145
|
+
const isInputFieldFocused = useRef(false);
|
|
28146
|
+
function isElementOutside(el) {
|
|
28147
|
+
return !isDropdownOpenRef.current && // Month and Year dropdown from Date picker
|
|
28148
|
+
!textFieldRef.current?.contains(el) && // TextField
|
|
28149
|
+
!contentRef.current?.contains(el);
|
|
28150
|
+
}
|
|
28151
|
+
const handleMouseDown = useCallback((event) => {
|
|
28152
|
+
const el = (event.target);
|
|
28153
|
+
if (el && isElementOutside(el))
|
|
28154
|
+
removeEventListeners();
|
|
28155
|
+
}, []);
|
|
28156
|
+
function registerEventListeners() {
|
|
28157
|
+
isInputFieldFocused.current = true;
|
|
28158
|
+
document.addEventListener('mouseup', handleMouseDown, true);
|
|
28159
|
+
}
|
|
28160
|
+
function removeEventListeners() {
|
|
28161
|
+
isInputFieldFocused.current = false;
|
|
28162
|
+
setShowCalendar(false);
|
|
28163
|
+
const updatedVal = dayjs(calendarVal).format(dateFormat);
|
|
28164
|
+
if (textFieldRef.current)
|
|
28165
|
+
textFieldRef.current.value = updatedVal;
|
|
28166
|
+
if (inputState === undefined)
|
|
28167
|
+
onSelect(dayjs(updatedVal).toDate());
|
|
28168
|
+
document.removeEventListener('mouseup', handleMouseDown);
|
|
28169
|
+
}
|
|
28131
28170
|
const handleSelect = (day) => {
|
|
28132
28171
|
onSelect(day);
|
|
28133
|
-
|
|
28172
|
+
setCalendarVal(day);
|
|
28173
|
+
setInputState(undefined);
|
|
28174
|
+
removeEventListeners();
|
|
28134
28175
|
};
|
|
28135
28176
|
function onDropdownOpen() {
|
|
28136
|
-
|
|
28177
|
+
isDropdownOpenRef.current = true;
|
|
28137
28178
|
}
|
|
28138
28179
|
function onOpenChange(open) {
|
|
28139
|
-
if (!
|
|
28180
|
+
if (!isDropdownOpenRef.current && !(isInputFieldFocused.current && showCalendar)) {
|
|
28140
28181
|
setShowCalendar(Boolean(open));
|
|
28141
28182
|
}
|
|
28142
|
-
|
|
28183
|
+
isDropdownOpenRef.current = false;
|
|
28184
|
+
}
|
|
28185
|
+
function handleInputFocus() {
|
|
28186
|
+
if (isInputFieldFocused.current)
|
|
28187
|
+
return;
|
|
28188
|
+
if (!showCalendar)
|
|
28189
|
+
setShowCalendar(true);
|
|
28190
|
+
}
|
|
28191
|
+
function handleInputBlur(event) {
|
|
28192
|
+
if (isInputFieldFocused.current) {
|
|
28193
|
+
const el = event.relatedTarget;
|
|
28194
|
+
if (el && isElementOutside(el))
|
|
28195
|
+
removeEventListeners();
|
|
28196
|
+
}
|
|
28197
|
+
else {
|
|
28198
|
+
registerEventListeners();
|
|
28199
|
+
setTimeout(() => textFieldRef.current?.focus());
|
|
28200
|
+
}
|
|
28201
|
+
}
|
|
28202
|
+
function handleKeyUp(event) {
|
|
28203
|
+
if (event.code === 'Enter' && textFieldRef.current) {
|
|
28204
|
+
textFieldRef.current.blur();
|
|
28205
|
+
removeEventListeners();
|
|
28206
|
+
}
|
|
28207
|
+
}
|
|
28208
|
+
function handleInputChange(event) {
|
|
28209
|
+
const { value } = event.target;
|
|
28210
|
+
const format = value.includes("/") ? "DD/MM/YYYY" : value.includes("-") ? "DD-MM-YYYY" : undefined;
|
|
28211
|
+
const date = dayjs(value, format);
|
|
28212
|
+
const isValidDate = date.isValid();
|
|
28213
|
+
const isAfter = calendarProps?.startMonth !== undefined ? dayjs(date).isSameOrAfter(calendarProps.startMonth) : true;
|
|
28214
|
+
const isBefore = calendarProps?.endMonth !== undefined ? dayjs(date).isSameOrBefore(calendarProps.endMonth) : true;
|
|
28215
|
+
const isValid = isValidDate && isAfter && isBefore && dayjs(date).isSameOrBefore(dayjs());
|
|
28216
|
+
if (isValid) {
|
|
28217
|
+
setCalendarVal(date.toDate());
|
|
28218
|
+
if (inputState === 'invalid')
|
|
28219
|
+
setInputState(undefined);
|
|
28220
|
+
}
|
|
28221
|
+
else {
|
|
28222
|
+
setInputState('invalid');
|
|
28223
|
+
}
|
|
28143
28224
|
}
|
|
28144
|
-
return (jsxRuntimeExports.jsxs(Popover, { open: showCalendar, onOpenChange: onOpenChange, children: [jsxRuntimeExports.jsx(
|
|
28225
|
+
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 }) })] }));
|
|
28145
28226
|
}
|
|
28146
28227
|
|
|
28147
28228
|
function RangePicker({ side = "top", dateFormat = "DD/MM/YYYY", textFieldProps, calendarProps, onSelect = () => { }, value = {
|