@strapi/design-system 1.8.1 → 1.9.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/BaseCheckbox/BaseCheckbox.cjs +4 -4
- package/dist/BaseCheckbox/BaseCheckbox.js +19 -18
- package/dist/CarouselInput/Carousel.cjs +4 -4
- package/dist/CarouselInput/Carousel.js +13 -13
- package/dist/CarouselInput/CarouselInput.cjs +1 -1
- package/dist/CarouselInput/CarouselInput.js +14 -13
- package/dist/Checkbox/Checkbox.cjs +2 -2
- package/dist/Checkbox/Checkbox.js +22 -21
- package/dist/Combobox/Combobox.cjs +10 -10
- package/dist/Combobox/Combobox.js +57 -56
- package/dist/DatePicker/DatePicker.cjs +9 -9
- package/dist/DatePicker/DatePicker.js +67 -66
- package/dist/DateTimePicker/DateTimePicker.cjs +3 -3
- package/dist/DateTimePicker/DateTimePicker.js +46 -42
- package/dist/JSONInput/JSONInput.cjs +33 -1
- package/dist/JSONInput/JSONInput.js +85 -46
- package/dist/Popover/Popover.cjs +3 -3
- package/dist/Popover/Popover.js +52 -51
- package/dist/Select/MultiSelect.cjs +7 -7
- package/dist/Select/MultiSelect.js +45 -44
- package/dist/Select/SingleSelect.cjs +1 -1
- package/dist/Select/SingleSelect.js +35 -34
- package/dist/TextInput/TextInput.cjs +1 -1
- package/dist/TextInput/TextInput.js +15 -14
- package/dist/TimePicker/TimePicker.cjs +2 -2
- package/dist/TimePicker/TimePicker.js +38 -38
- package/dist/ToggleInput/ToggleInput.cjs +20 -4
- package/dist/ToggleInput/ToggleInput.js +44 -18
- package/dist/Typography/Typography.cjs +1 -1
- package/dist/Typography/Typography.js +6 -6
- package/dist/Typography/utils.cjs +1 -1
- package/dist/Typography/utils.js +4 -5
- package/dist/themes/utils.cjs +9 -9
- package/dist/themes/utils.js +9 -9
- package/package.json +10 -10
- package/dist/JSONInput/JSONInputContainer.cjs +0 -33
- package/dist/JSONInput/JSONInputContainer.js +0 -39
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),ye=require("react"),$=require("@floating-ui/react-dom"),D=require("@internationalized/date"),xe=require("@radix-ui/react-focus-guards"),Ce=require("@radix-ui/react-focus-scope"),oe=require("@strapi/icons"),q=require("@strapi/ui-primitives"),be=require("react-dom"),we=require("react-remove-scroll"),ke=require("styled-components"),Te=require("../DesignSystemProvider.cjs"),Pe=require("../DismissibleLayer/index.cjs"),Se=require("../helpers/context.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),ye=require("react"),$=require("@floating-ui/react-dom"),D=require("@internationalized/date"),xe=require("@radix-ui/react-focus-guards"),Ce=require("@radix-ui/react-focus-scope"),oe=require("@strapi/icons"),q=require("@strapi/ui-primitives"),be=require("react-dom"),we=require("react-remove-scroll"),ke=require("styled-components"),Te=require("../DesignSystemProvider.cjs"),Pe=require("../DismissibleLayer/index.cjs"),Se=require("../helpers/context.cjs"),je=require("../helpers/deprecations.cjs"),J=require("../hooks/useComposeRefs.cjs"),Ee=require("../hooks/useControllableState.cjs"),R=require("../hooks/useDateFormatter.cjs"),se=require("../hooks/useId.cjs"),Y=require("../Select/SingleSelect.cjs"),Ie=require("../Portal/Portal.cjs"),B=require("../Flex/Flex.cjs"),ne=require("../themes/utils.cjs"),U=require("../Box/Box.cjs"),W=require("../Typography/Typography.cjs"),Fe=require("../Field/Field.cjs"),Re=require("../Field/FieldLabel.cjs"),ve=require("../Field/FieldHint.cjs"),Ae=require("../Field/FieldError.cjs"),Me=e=>e&&e.__esModule?e:{default:e};function qe(e){if(e&&e.__esModule)return e;const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,t.get?t:{enumerable:!0,get:()=>e[n]})}}return r.default=e,Object.freeze(r)}const c=qe(ye),E=Me(ke),_e=200,re=15,[Oe,_]=Se.createContext("DatePicker"),le=c.forwardRef(({calendarLabel:e,className:r,initialDate:n,locale:t,maxDate:o,minDate:i,monthSelectLabel:g="Month",onChange:d,selectedDate:l,yearSelectLabel:b="Year",error:k,id:h,disabled:x=!1,placeholder:T,required:w=!1,onClear:S,clearLabel:j="Clear",size:u,ariaLabel:p,selectedDateLabel:s,...f},m)=>{const P=D.getLocalTimeZone(),v=Te.useDesignSystem("DatePicker"),A=t??v.locale,M=R.useDateFormatter(A,{day:"2-digit",month:"2-digit",year:"numeric"}),[O,H]=c.useState(!1),[Z,C]=c.useState(null),[I,G]=c.useState(null),[ce,ue]=c.useState(null),[V,N]=c.useState(),[L,Q]=Ee.useControllableState({defaultProp:n?F(n):void 0,prop:l?F(l):void 0,onChange(y){d&&d(y?.toDate(P))}}),[ee,te]=c.useMemo(()=>{const y=n?F(n):D.today("UTC"),z=i?F(i):y.set({day:1,month:1,year:y.year-_e});let X=o?F(o):y.set({day:31,month:12,year:y.year+re});return X.compare(z)<0&&(X=z.set({day:31,month:12,year:z.year+re})),[z,X]},[i,o,n]),[de,K]=c.useState(Ne({currentValue:L,minDate:ee,maxDate:te})),fe=se.useId(),he=c.useRef(null),me=y=>{S&&!x&&(N(""),Q(void 0),S(y),I?.focus())},pe=c.useCallback(y=>{y&&L&&K(L),H(y)},[L]);c.useLayoutEffect(()=>{if(l){const y=F(l);N(M.format(y.toDate(P))),K(y)}else N("")},[l,M,P]),c.useLayoutEffect(()=>{if(n&&V===void 0){const y=F(n);N(M.format(y.toDate(P)))}},[n,V,M,P]);const ge=`${h}-hint`,De=`${h}-error`;return a.jsxs(Oe,{calendarDate:de,content:ce,contentId:fe,disabled:x,locale:A,minDate:ee,maxDate:te,open:O,onCalendarDateChange:K,onContentChange:ue,onOpenChange:pe,onTextInputChange:G,onTextValueChange:N,onTriggerChange:C,onValueChange:Q,required:w,textInput:I,textValue:V,timeZone:P,trigger:Z,value:L,children:[a.jsxs($e,{className:r,size:u,hasError:!!k,children:[a.jsx(Ye,{"aria-hidden":!0}),a.jsx(Ue,{ref:m,placeholder:T,"aria-describedby":`${ge} ${De}`,id:h,...f}),V&&S?a.jsx(ze,{as:"button",hasRadius:!0,background:"transparent",type:"button",onClick:me,"aria-disabled":x,"aria-label":j,title:j,ref:he,children:a.jsx(oe.Cross,{})}):null]}),a.jsx(Ie.Portal,{children:a.jsx(Ge,{label:e,children:a.jsx(et,{monthSelectLabel:g,yearSelectLabel:b})})})]})}),ae=e=>!!e.match(/^[^a-zA-Z]*$/),Ne=({currentValue:e,minDate:r,maxDate:n})=>{const t=D.today("UTC");return e||(D.minDate(r,t)===r&&D.maxDate(n,t)===n?t:D.minDate(r,t)===t?r:D.maxDate(n,t)===t?n:t)},Le="DatePickerTrigger",$e=c.forwardRef(({hasError:e,size:r="M",...n},t)=>{const o=_(Le),i=J.useComposedRefs(t,d=>o.onTriggerChange(d)),g=()=>{o.disabled||o.onOpenChange(!0)};return a.jsx(Ce.FocusScope,{asChild:!0,trapped:o.open,onMountAutoFocus:d=>{d.preventDefault()},onUnmountAutoFocus:d=>{document.getSelection()?.empty(),d.preventDefault()},children:a.jsx(Ve,{ref:i,$hasError:e,$size:r,...n,paddingLeft:3,paddingRight:3,hasRadius:!0,gap:3,overflow:"hidden",background:o.disabled?"neutral150":"neutral0",onClick:q.composeEventHandlers(n.onClick,()=>{o.textInput?.focus()}),onPointerDown:q.composeEventHandlers(n.onPointerDown,d=>{const l=d.target;l.hasPointerCapture(d.pointerId)&&l.releasePointerCapture(d.pointerId),(l.closest("button")??l.closest("div"))===d.currentTarget&&d.button===0&&d.ctrlKey===!1&&(g(),o.textInput?.focus())})})})}),Ve=E.default(B.Flex)`
|
|
2
2
|
border: 1px solid ${({theme:e,$hasError:r})=>r?e.colors.danger600:e.colors.neutral200};
|
|
3
3
|
min-height: ${({theme:e,$size:r})=>ne.getThemeSize("input")({theme:e,size:r})};
|
|
4
4
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
${({theme:e,$hasError:r})=>ne.inputFocusStyle()({theme:e,hasError:r})};
|
|
17
|
-
`,ze=
|
|
17
|
+
`,ze=E.default(U.Box)`
|
|
18
18
|
border: none;
|
|
19
19
|
|
|
20
20
|
svg {
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
svg path {
|
|
26
26
|
fill: ${({theme:e})=>e.colors.neutral600};
|
|
27
27
|
}
|
|
28
|
-
`,Ye=
|
|
28
|
+
`,Ye=E.default(oe.Calendar)`
|
|
29
29
|
& > path {
|
|
30
30
|
fill: ${({theme:e})=>e.colors.neutral500};
|
|
31
31
|
}
|
|
32
|
-
`,Be="DatePickerTextInput",Ue=c.forwardRef(({placeholder:e,...r},n)=>{const t=_(Be),{onTextValueChange:o,textValue:i,onTextInputChange:g,onOpenChange:d,disabled:l,locale:b}=t,k=J.useComposedRefs(n,u=>g(u)),
|
|
32
|
+
`,Be="DatePickerTextInput",Ue=c.forwardRef(({placeholder:e,...r},n)=>{const t=_(Be),{onTextValueChange:o,textValue:i,onTextInputChange:g,onOpenChange:d,disabled:l,locale:b}=t,k=J.useComposedRefs(n,u=>g(u)),h=()=>{l||d(!0)},x=R.useDateFormatter(b,{year:"numeric",month:"2-digit",day:"2-digit"}),[T,w,S]=c.useMemo(()=>{const u=x.formatToParts(new Date),p=u.filter(m=>m.type==="year"||m.type==="month"||m.type==="day"),s=p.map(m=>{switch(m.type){case"day":return"DD";case"month":return"MM";case"year":return"YYYY";default:return""}}),f=u.find(m=>m.type==="literal")?.value??"";return[s,f,p]},[x]),j=T.map(u=>`\\d{${u.length}}`).join(`\\${w}`);return a.jsx(He,{role:"combobox",type:"text",inputMode:"numeric",ref:k,"aria-autocomplete":"none","aria-controls":t.contentId,"aria-disabled":t.disabled,"aria-expanded":t.open,"aria-required":t.required,"aria-haspopup":"dialog","data-state":t.open?"open":"closed",disabled:l,"data-disabled":l?"":void 0,pattern:j,placeholder:e??T.join(w),...r,value:i??"",onBlur:q.composeEventHandlers(r.onBlur,()=>{if(!t.textValue){t.onValueChange(void 0);return}t.onTextValueChange(x.format(t.calendarDate.toDate(t.timeZone))),t.onValueChange(t.calendarDate)}),onChange:q.composeEventHandlers(r.onChange,u=>{if(ae(u.target.value)){const p=u.target.value.split(w),[s,f,m]=S.map((C,I)=>{const G=p[I];return{...C,value:G}}).sort((C,I)=>C.type==="year"?1:I.type==="year"?-1:C.type==="month"?1:I.type==="month"?-1:0).map(C=>C.value),P=t.calendarDate.year;let v=t.calendarDate.year;if(m){let C=m.length===1?`0${m}`:m;v=m.length<3?Number(`${P}`.slice(0,4-C.length)+C):Number(C)}m&&m.length<3&&v>t.maxDate.year&&(v-=100);const A=t.calendarDate.set({year:v}),M=A.calendar.getMonthsInYear(A),O=A.set({month:f&&Number(f)<=M?Number(f):void 0}),H=O.calendar.getDaysInMonth(O),Z=O.set({day:s&&Number(s)<=H?Number(s):void 0});t.onCalendarDateChange(We(Z,t.minDate,t.maxDate)),t.onTextValueChange(u.target.value)}}),onKeyDown:q.composeEventHandlers(r.onKeyDown,u=>{if(!t.open&&(ae(u.key)||["ArrowDown","Backspace"].includes(u.key)))h();else if(["Tab"].includes(u.key)&&t.open)u.preventDefault();else if(["Escape"].includes(u.key))t.open?t.onOpenChange(!1):(t.onValueChange(void 0),t.onTextValueChange("")),u.preventDefault();else if(t.open&&["ArrowDown","ArrowUp","ArrowLeft","ArrowRight"].includes(u.key))switch(u.preventDefault(),u.key){case"ArrowDown":{const p=t.calendarDate.add({weeks:1});if(t.maxDate&&p.compare(t.maxDate)>0)return;t.onCalendarDateChange(p);return}case"ArrowRight":{const p=t.calendarDate.add({days:1});if(t.maxDate&&p.compare(t.maxDate)>0)return;t.onCalendarDateChange(p);return}case"ArrowUp":{const p=t.calendarDate.subtract({weeks:1});if(t.minDate&&p.compare(t.minDate)<0)return;t.onCalendarDateChange(p);return}case"ArrowLeft":{const p=t.calendarDate.subtract({days:1});if(t.minDate&&p.compare(t.minDate)<0)return;t.onCalendarDateChange(p)}}else t.open&&["Enter"].includes(u.key)&&(u.preventDefault(),o(x.format(t.calendarDate.toDate(t.timeZone))),t.onValueChange(t.calendarDate),t.onOpenChange(!1))})})});function We(e,r,n){return r&&(e=D.maxDate(e,r)),n&&(e=D.minDate(e,n)),e}const He=E.default.input`
|
|
33
33
|
width: 100%;
|
|
34
34
|
font-size: ${14/16}rem;
|
|
35
35
|
color: ${({theme:e})=>e.colors.neutral800};
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
&[aria-disabled='true'] {
|
|
45
45
|
cursor: inherit;
|
|
46
46
|
}
|
|
47
|
-
`,Ze="DatePickerContent",Ge=c.forwardRef((e,r)=>{const[n,t]=c.useState(),o=_(Ze);if(c.useLayoutEffect(()=>{t(new DocumentFragment)},[]),!o.open){const i=n;return i?be.createPortal(a.jsx("div",{children:e.children}),i):null}return a.jsx(Xe,{...e,ref:r})}),Ke="DatePickerContent",Xe=c.forwardRef((e,r)=>{const{label:n="Choose date",...t}=e,{onOpenChange:o,...i}=_(Ke),{x:g,y:d,
|
|
47
|
+
`,Ze="DatePickerContent",Ge=c.forwardRef((e,r)=>{const[n,t]=c.useState(),o=_(Ze);if(c.useLayoutEffect(()=>{t(new DocumentFragment)},[]),!o.open){const i=n;return i?be.createPortal(a.jsx("div",{children:e.children}),i):null}return a.jsx(Xe,{...e,ref:r})}),Ke="DatePickerContent",Xe=c.forwardRef((e,r)=>{const{label:n="Choose date",...t}=e,{onOpenChange:o,...i}=_(Ke),{x:g,y:d,refs:l,strategy:b}=$.useFloating({strategy:"fixed",placement:"bottom-start",middleware:[$.offset({mainAxis:4}),$.shift(),$.flip()],elements:{reference:i.trigger},whileElementsMounted:$.autoUpdate});c.useEffect(()=>{const h=()=>{o(!1)};return window.addEventListener("blur",h),window.addEventListener("resize",h),()=>{window.removeEventListener("blur",h),window.removeEventListener("resize",h)}},[o]);const k=J.useComposedRefs(r,h=>i.onContentChange(h),l.setFloating);return xe.useFocusGuards(),a.jsx(we.RemoveScroll,{allowPinchZoom:!0,children:a.jsx(Pe.DismissibleLayer,{asChild:!0,onFocusOutside:h=>{h.preventDefault()},onDismiss:()=>{o(!1)},children:a.jsx(Je,{ref:k,"data-state":i.open?"open":"closed",onContextMenu:h=>h.preventDefault(),id:i.contentId,role:"dialog","aria-modal":"true","aria-label":n,style:{left:g,top:d,position:b},hasRadius:!0,background:"neutral0",padding:1,...t})})})}),Je=E.default(U.Box)`
|
|
48
48
|
box-shadow: ${({theme:e})=>e.shadows.filterShadow};
|
|
49
49
|
z-index: ${({theme:e})=>e.zIndices[0]};
|
|
50
50
|
border: 1px solid ${({theme:e})=>e.colors.neutral150};
|
|
51
|
-
`,Qe="DatePickerCalendar",et=c.forwardRef(({monthSelectLabel:e,yearSelectLabel:r,...n},t)=>{const{locale:o,timeZone:i,minDate:g,maxDate:d,calendarDate:l,onCalendarDateChange:b}=_(Qe),k=D.startOfMonth(l),
|
|
51
|
+
`,Qe="DatePickerCalendar",et=c.forwardRef(({monthSelectLabel:e,yearSelectLabel:r,...n},t)=>{const{locale:o,timeZone:i,minDate:g,maxDate:d,calendarDate:l,onCalendarDateChange:b}=_(Qe),k=D.startOfMonth(l),h=c.useMemo(()=>{const s=g.year,f=d.year;return[...Array(f-s+1).keys()].map(m=>(s+m).toString())},[g,d]),x=R.useDateFormatter(o,{month:"long"}),T=c.useMemo(()=>[...Array(l.calendar.getMonthsInYear(l)).keys()].map(s=>x.format(l.set({month:s+1}).toDate(i))),[l,x,i]),w=R.useDateFormatter(o,{weekday:"short"}),S=c.useMemo(()=>{let s=D.startOfWeek(D.today(i),o);return[...new Array(7).keys()].map(f=>{let P=s.add({days:f}).toDate(i);return w.format(P)})},[i,o,w]),j=s=>{if(typeof s=="number")return;const f=l.set({month:T.indexOf(s)+1});b(f)},u=s=>{if(typeof s=="number")return;const f=l.set({year:parseInt(s,10)});b(f)},p=tt(k,o);return a.jsxs(B.Flex,{ref:t,direction:"column",alignItems:"stretch",padding:4,...n,children:[a.jsxs(nt,{justifyContent:"flex-start",paddingBottom:4,paddingLeft:2,paddingRight:2,gap:2,children:[a.jsx(Y.SingleSelectInput,{label:e,size:"S",value:T[l.month-1],onChange:j,children:T.map(s=>a.jsx(Y.SingleSelectOption,{value:s,children:s},s))}),a.jsx(Y.SingleSelectInput,{size:"S",value:l.year.toString(),label:r,onChange:u,children:h.map(s=>a.jsx(Y.SingleSelectOption,{value:s,children:s},s))})]}),a.jsxs("table",{role:"grid",children:[a.jsx("thead",{"aria-hidden":!0,children:a.jsx("tr",{"aria-rowindex":0,children:S.map((s,f)=>a.jsx(rt,{"aria-colindex":f,children:s},s))})}),a.jsx("tbody",{children:[...new Array(6).keys()].map(s=>a.jsx("tr",{"aria-rowindex":s+2,children:p(s).map((f,m)=>f?a.jsx(st,{"aria-colindex":m+1,date:f,startDate:k},f.toString()):a.jsx(ie,{"aria-colindex":m+1}))},s))})]})]})}),tt=(e,r)=>n=>{let t=e.add({weeks:n}),o=[];t=D.startOfWeek(t,r);let i=D.getDayOfWeek(t,r);for(let g=0;g<i;g++)o.push(null);for(;o.length<7;){o.push(t);let g=t.add({days:1});if(D.isSameDay(t,g))break;t=g}for(;o.length<7;)o.push(null);return o},nt=E.default(B.Flex)`
|
|
52
52
|
div[role='combobox'] {
|
|
53
53
|
border: 1px solid transparent;
|
|
54
54
|
background: transparent;
|
|
@@ -69,10 +69,10 @@
|
|
|
69
69
|
background-color: ${({theme:e})=>e.colors.neutral100};
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
`,rt=c.forwardRef(({children:e,...r},n)=>a.jsx(at,{as:"th",role:"gridcell",ref:n,...r,height:`${24/16}rem`,width:`${32/16}rem`,children:a.jsx(W.Typography,{variant:"pi",fontWeight:"bold",color:"neutral800",children:e.slice(0,2)})})),at=
|
|
72
|
+
`,rt=c.forwardRef(({children:e,...r},n)=>a.jsx(at,{as:"th",role:"gridcell",ref:n,...r,height:`${24/16}rem`,width:`${32/16}rem`,children:a.jsx(W.Typography,{variant:"pi",fontWeight:"bold",color:"neutral800",children:e.slice(0,2)})})),at=E.default(U.Box)`
|
|
73
73
|
border-radius: ${({theme:e})=>e.borderRadius};
|
|
74
74
|
text-transform: capitalize;
|
|
75
|
-
`,ot="DatePickerCalendarCell",st=c.forwardRef(({date:e,startDate:r,...n},t)=>{const{timeZone:o,locale:i,calendarDate:g,onValueChange:d,onOpenChange:l,onTextValueChange:b,onCalendarDateChange:k}=_(ot),
|
|
75
|
+
`,ot="DatePickerCalendarCell",st=c.forwardRef(({date:e,startDate:r,...n},t)=>{const{timeZone:o,locale:i,calendarDate:g,onValueChange:d,onOpenChange:l,onTextValueChange:b,onCalendarDateChange:k}=_(ot),h=D.isSameDay(g,e),x=R.useDateFormatter(i,{weekday:"long",day:"numeric",month:"long",year:"numeric"}),T=c.useMemo(()=>x.format(e.toDate(o)),[x,e,o]),w=R.useDateFormatter(i,{day:"numeric",calendar:e.calendar.identifier}),S=c.useMemo(()=>w.formatToParts(e.toDate(o)).find(f=>f.type==="day").value,[w,e,o]),j=R.useDateFormatter(i,{day:"2-digit",month:"2-digit",year:"numeric"}),u=D.endOfMonth(r),p=e.compare(r)<0||e.compare(u)>0;let s="neutral900";return h?s="primary600":p&&(s="neutral600"),a.jsx(ie,{as:"td",role:"gridcell",ref:t,"aria-selected":h,...n,hasRadius:!0,"aria-label":T,tabIndex:h?0:-1,background:h?"primary100":"neutral0",cursor:"pointer",onPointerDown:q.composeEventHandlers(n.onPointerDown,f=>{f.preventDefault(),k(e),d(e),b(j.format(e.toDate(o))),l(!1)}),children:a.jsx(W.Typography,{variant:"pi",textColor:s,children:S})})}),ie=E.default(U.Box)`
|
|
76
76
|
text-align: center;
|
|
77
77
|
padding: ${7/16}rem;
|
|
78
78
|
// Trick to prevent the outline from overflowing because of the general outline-offset
|
|
@@ -85,4 +85,4 @@
|
|
|
85
85
|
color: ${({theme:e})=>e.colors.primary600};
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
`,lt=c.forwardRef((e,r)=>{const{error:n,hint:t,id:o,required:i,label:g,...d}=e,l=se.useId(o);return a.jsx(
|
|
88
|
+
`,lt=c.forwardRef((e,r)=>{const{error:n,hint:t,id:o,required:i,label:g,...d}=e,l=se.useId(o);return a.jsx(Fe.Field,{error:n,hint:t,required:i,id:l,children:a.jsxs(B.Flex,{direction:"column",alignItems:"stretch",gap:1,children:[a.jsx(Re.FieldLabel,{children:g}),a.jsx(le,{ref:r,id:l,error:n,required:i,...d}),a.jsx(ve.FieldHint,{}),a.jsx(Ae.FieldError,{})]})})}),it=je.once(console.warn),F=e=>{if(typeof e=="string"){it("It looks like you're passing a string as representation of a Date to the DatePicker. This is deprecated, look to passing a Date instead.");const t=Date.parse(e);Number.isNaN(t)?e=new Date:e=new Date(t)}const r=e.toISOString(),n=D.parseAbsolute(r,"UTC");return D.toCalendarDate(n)},ct=lt;exports.DatePicker=ct;exports.DatePickerInput=le;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsxs as F, jsx as i } from "react/jsx-runtime";
|
|
2
2
|
import * as c from "react";
|
|
3
3
|
import { useFloating as be, offset as we, shift as xe, flip as ke, autoUpdate as Te } from "@floating-ui/react-dom";
|
|
4
|
-
import { getLocalTimeZone as
|
|
4
|
+
import { getLocalTimeZone as Pe, today as J, minDate as H, maxDate as X, startOfMonth as Ee, startOfWeek as le, getDayOfWeek as Ie, isSameDay as se, endOfMonth as Ae, parseAbsolute as Re, toCalendarDate as Se } from "@internationalized/date";
|
|
5
5
|
import { useFocusGuards as Me } from "@radix-ui/react-focus-guards";
|
|
6
6
|
import { FocusScope as ve } from "@radix-ui/react-focus-scope";
|
|
7
7
|
import { Cross as $e, Calendar as Fe } from "@strapi/icons";
|
|
8
|
-
import { composeEventHandlers as
|
|
9
|
-
import { createPortal as
|
|
10
|
-
import { RemoveScroll as
|
|
8
|
+
import { composeEventHandlers as N } from "@strapi/ui-primitives";
|
|
9
|
+
import { createPortal as Ne } from "react-dom";
|
|
10
|
+
import { RemoveScroll as Le } from "react-remove-scroll";
|
|
11
11
|
import I from "styled-components";
|
|
12
12
|
import { useDesignSystem as Oe } from "../DesignSystemProvider.js";
|
|
13
13
|
import { DismissibleLayer as _e } from "../DismissibleLayer/index.js";
|
|
@@ -27,7 +27,7 @@ import { Field as Ze } from "../Field/Field.js";
|
|
|
27
27
|
import { FieldLabel as qe } from "../Field/FieldLabel.js";
|
|
28
28
|
import { FieldHint as Ke } from "../Field/FieldHint.js";
|
|
29
29
|
import { FieldError as Ge } from "../Field/FieldError.js";
|
|
30
|
-
const je = 200, oe = 15, [He,
|
|
30
|
+
const je = 200, oe = 15, [He, L] = Ve("DatePicker"), Xe = c.forwardRef(({
|
|
31
31
|
/**
|
|
32
32
|
* DatePickerCalendar props
|
|
33
33
|
*/
|
|
@@ -45,12 +45,12 @@ const je = 200, oe = 15, [He, N] = Ve("DatePicker"), Xe = c.forwardRef(({
|
|
|
45
45
|
* Combobox props
|
|
46
46
|
*/
|
|
47
47
|
error: x,
|
|
48
|
-
id:
|
|
49
|
-
disabled:
|
|
48
|
+
id: f,
|
|
49
|
+
disabled: y = !1,
|
|
50
50
|
placeholder: k,
|
|
51
51
|
required: w = !1,
|
|
52
|
-
onClear:
|
|
53
|
-
clearLabel:
|
|
52
|
+
onClear: P,
|
|
53
|
+
clearLabel: E = "Clear",
|
|
54
54
|
size: d,
|
|
55
55
|
/**
|
|
56
56
|
* @preserve
|
|
@@ -62,9 +62,9 @@ const je = 200, oe = 15, [He, N] = Ve("DatePicker"), Xe = c.forwardRef(({
|
|
|
62
62
|
* @deprecated This is no longer used.
|
|
63
63
|
*/
|
|
64
64
|
selectedDateLabel: o,
|
|
65
|
-
...
|
|
65
|
+
...m
|
|
66
66
|
}, p) => {
|
|
67
|
-
const T =
|
|
67
|
+
const T = Pe(), M = Oe("DatePicker"), v = t ?? M.locale, $ = S(v, {
|
|
68
68
|
day: "2-digit",
|
|
69
69
|
month: "2-digit",
|
|
70
70
|
year: "numeric"
|
|
@@ -83,7 +83,7 @@ const je = 200, oe = 15, [He, N] = Ve("DatePicker"), Xe = c.forwardRef(({
|
|
|
83
83
|
minDate: te,
|
|
84
84
|
maxDate: re
|
|
85
85
|
})), pe = ce(), he = c.useRef(null), ge = (D) => {
|
|
86
|
-
|
|
86
|
+
P && !y && (_(""), ee(void 0), P(D), A?.focus());
|
|
87
87
|
}, De = c.useCallback((D) => {
|
|
88
88
|
D && V && G(V), Z(D);
|
|
89
89
|
}, [V]);
|
|
@@ -99,13 +99,13 @@ const je = 200, oe = 15, [He, N] = Ve("DatePicker"), Xe = c.forwardRef(({
|
|
|
99
99
|
_($.format(D.toDate(T)));
|
|
100
100
|
}
|
|
101
101
|
}, [n, Y, $, T]);
|
|
102
|
-
const ye = `${
|
|
103
|
-
return F(He, { calendarDate: fe, content: ue, contentId: pe, disabled:
|
|
102
|
+
const ye = `${f}-hint`, Ce = `${f}-error`;
|
|
103
|
+
return F(He, { calendarDate: fe, content: ue, contentId: pe, disabled: y, locale: v, minDate: te, maxDate: re, open: O, onCalendarDateChange: G, onContentChange: me, onOpenChange: De, onTextInputChange: K, onTextValueChange: _, onTriggerChange: C, onValueChange: ee, required: w, textInput: A, textValue: Y, timeZone: T, trigger: q, value: V, children: [F(et, { className: r, size: d, hasError: !!x, children: [i(nt, { "aria-hidden": !0 }), i(ot, { ref: p, placeholder: k, "aria-describedby": `${ye} ${Ce}`, id: f, ...m }), Y && P ? i(rt, { as: "button", hasRadius: !0, background: "transparent", type: "button", onClick: ge, "aria-disabled": y, "aria-label": E, title: E, ref: he, children: i($e, {}) }) : null] }), i(Ue, { children: i(ct, { label: e, children: i(pt, { monthSelectLabel: g, yearSelectLabel: b }) }) })] });
|
|
104
104
|
}), ie = (e) => !!e.match(/^[^a-zA-Z]*$/), Je = ({ currentValue: e, minDate: r, maxDate: n }) => {
|
|
105
105
|
const t = J("UTC");
|
|
106
106
|
return e || (H(r, t) === r && X(n, t) === n ? t : H(r, t) === t ? r : X(n, t) === t ? n : t);
|
|
107
107
|
}, Qe = "DatePickerTrigger", et = c.forwardRef(({ hasError: e, size: r = "M", ...n }, t) => {
|
|
108
|
-
const a =
|
|
108
|
+
const a = L(Qe), s = Q(t, (u) => a.onTriggerChange(u)), g = () => {
|
|
109
109
|
a.disabled || a.onOpenChange(!0);
|
|
110
110
|
};
|
|
111
111
|
return i(ve, {
|
|
@@ -119,9 +119,9 @@ const je = 200, oe = 15, [He, N] = Ve("DatePicker"), Xe = c.forwardRef(({
|
|
|
119
119
|
onUnmountAutoFocus: (u) => {
|
|
120
120
|
document.getSelection()?.empty(), u.preventDefault();
|
|
121
121
|
},
|
|
122
|
-
children: i(tt, { ref: s, $hasError: e, $size: r, ...n, paddingLeft: 3, paddingRight: 3, hasRadius: !0, gap: 3, overflow: "hidden", background: a.disabled ? "neutral150" : "neutral0", onClick:
|
|
122
|
+
children: i(tt, { ref: s, $hasError: e, $size: r, ...n, paddingLeft: 3, paddingRight: 3, hasRadius: !0, gap: 3, overflow: "hidden", background: a.disabled ? "neutral150" : "neutral0", onClick: N(n.onClick, () => {
|
|
123
123
|
a.textInput?.focus();
|
|
124
|
-
}), onPointerDown:
|
|
124
|
+
}), onPointerDown: N(n.onPointerDown, (u) => {
|
|
125
125
|
const l = u.target;
|
|
126
126
|
l.hasPointerCapture(u.pointerId) && l.releasePointerCapture(u.pointerId), (l.closest("button") ?? l.closest("div")) === u.currentTarget && u.button === 0 && u.ctrlKey === !1 && (g(), a.textInput?.focus());
|
|
127
127
|
}) })
|
|
@@ -158,14 +158,14 @@ const je = 200, oe = 15, [He, N] = Ve("DatePicker"), Xe = c.forwardRef(({
|
|
|
158
158
|
fill: ${({ theme: e }) => e.colors.neutral500};
|
|
159
159
|
}
|
|
160
160
|
`, at = "DatePickerTextInput", ot = c.forwardRef(({ placeholder: e, ...r }, n) => {
|
|
161
|
-
const t =
|
|
161
|
+
const t = L(at), { onTextValueChange: a, textValue: s, onTextInputChange: g, onOpenChange: u, disabled: l, locale: b } = t, x = Q(n, (d) => g(d)), f = () => {
|
|
162
162
|
l || u(!0);
|
|
163
|
-
},
|
|
163
|
+
}, y = S(b, {
|
|
164
164
|
year: "numeric",
|
|
165
165
|
month: "2-digit",
|
|
166
166
|
day: "2-digit"
|
|
167
|
-
}), [k, w,
|
|
168
|
-
const d =
|
|
167
|
+
}), [k, w, P] = c.useMemo(() => {
|
|
168
|
+
const d = y.formatToParts(/* @__PURE__ */ new Date()), h = d.filter((p) => p.type === "year" || p.type === "month" || p.type === "day"), o = h.map((p) => {
|
|
169
169
|
switch (p.type) {
|
|
170
170
|
case "day":
|
|
171
171
|
return "DD";
|
|
@@ -176,18 +176,18 @@ const je = 200, oe = 15, [He, N] = Ve("DatePicker"), Xe = c.forwardRef(({
|
|
|
176
176
|
default:
|
|
177
177
|
return "";
|
|
178
178
|
}
|
|
179
|
-
}),
|
|
180
|
-
return [o,
|
|
181
|
-
}, [
|
|
182
|
-
return i(lt, { role: "combobox", type: "text", inputMode: "numeric", ref: x, "aria-autocomplete": "none", "aria-controls": t.contentId, "aria-disabled": t.disabled, "aria-expanded": t.open, "aria-required": t.required, "aria-haspopup": "dialog", "data-state": t.open ? "open" : "closed", disabled: l, "data-disabled": l ? "" : void 0, pattern:
|
|
179
|
+
}), m = d.find((p) => p.type === "literal")?.value ?? "";
|
|
180
|
+
return [o, m, h];
|
|
181
|
+
}, [y]), E = k.map((d) => `\\d{${d.length}}`).join(`\\${w}`);
|
|
182
|
+
return i(lt, { role: "combobox", type: "text", inputMode: "numeric", ref: x, "aria-autocomplete": "none", "aria-controls": t.contentId, "aria-disabled": t.disabled, "aria-expanded": t.open, "aria-required": t.required, "aria-haspopup": "dialog", "data-state": t.open ? "open" : "closed", disabled: l, "data-disabled": l ? "" : void 0, pattern: E, placeholder: e ?? k.join(w), ...r, value: s ?? "", onBlur: N(r.onBlur, () => {
|
|
183
183
|
if (!t.textValue) {
|
|
184
184
|
t.onValueChange(void 0);
|
|
185
185
|
return;
|
|
186
186
|
}
|
|
187
|
-
t.onTextValueChange(
|
|
188
|
-
}), onChange:
|
|
187
|
+
t.onTextValueChange(y.format(t.calendarDate.toDate(t.timeZone))), t.onValueChange(t.calendarDate);
|
|
188
|
+
}), onChange: N(r.onChange, (d) => {
|
|
189
189
|
if (ie(d.target.value)) {
|
|
190
|
-
const h = d.target.value.split(w), [o,
|
|
190
|
+
const h = d.target.value.split(w), [o, m, p] = P.map((C, A) => {
|
|
191
191
|
const K = h[A];
|
|
192
192
|
return {
|
|
193
193
|
...C,
|
|
@@ -201,15 +201,15 @@ const je = 200, oe = 15, [He, N] = Ve("DatePicker"), Xe = c.forwardRef(({
|
|
|
201
201
|
}
|
|
202
202
|
p && p.length < 3 && M > t.maxDate.year && (M -= 100);
|
|
203
203
|
const v = t.calendarDate.set({ year: M }), $ = v.calendar.getMonthsInYear(v), O = v.set({
|
|
204
|
-
month:
|
|
204
|
+
month: m && Number(m) <= $ ? Number(m) : void 0
|
|
205
205
|
}), Z = O.calendar.getDaysInMonth(O), q = O.set({
|
|
206
206
|
day: o && Number(o) <= Z ? Number(o) : void 0
|
|
207
207
|
});
|
|
208
208
|
t.onCalendarDateChange(it(q, t.minDate, t.maxDate)), t.onTextValueChange(d.target.value);
|
|
209
209
|
}
|
|
210
|
-
}), onKeyDown:
|
|
210
|
+
}), onKeyDown: N(r.onKeyDown, (d) => {
|
|
211
211
|
if (!t.open && (ie(d.key) || ["ArrowDown", "Backspace"].includes(d.key)))
|
|
212
|
-
|
|
212
|
+
f();
|
|
213
213
|
else if (["Tab"].includes(d.key) && t.open)
|
|
214
214
|
d.preventDefault();
|
|
215
215
|
else if (["Escape"].includes(d.key))
|
|
@@ -245,7 +245,7 @@ const je = 200, oe = 15, [He, N] = Ve("DatePicker"), Xe = c.forwardRef(({
|
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
else
|
|
248
|
-
t.open && ["Enter"].includes(d.key) && (d.preventDefault(), a(
|
|
248
|
+
t.open && ["Enter"].includes(d.key) && (d.preventDefault(), a(y.format(t.calendarDate.toDate(t.timeZone))), t.onValueChange(t.calendarDate), t.onOpenChange(!1));
|
|
249
249
|
}) });
|
|
250
250
|
});
|
|
251
251
|
function it(e, r, n) {
|
|
@@ -267,16 +267,16 @@ const lt = I.input`
|
|
|
267
267
|
cursor: inherit;
|
|
268
268
|
}
|
|
269
269
|
`, st = "DatePickerContent", ct = c.forwardRef((e, r) => {
|
|
270
|
-
const [n, t] = c.useState(), a =
|
|
270
|
+
const [n, t] = c.useState(), a = L(st);
|
|
271
271
|
if (c.useLayoutEffect(() => {
|
|
272
272
|
t(new DocumentFragment());
|
|
273
273
|
}, []), !a.open) {
|
|
274
274
|
const s = n;
|
|
275
|
-
return s ?
|
|
275
|
+
return s ? Ne(i("div", { children: e.children }), s) : null;
|
|
276
276
|
}
|
|
277
277
|
return i(ut, { ...e, ref: r });
|
|
278
278
|
}), dt = "DatePickerContent", ut = c.forwardRef((e, r) => {
|
|
279
|
-
const { label: n = "Choose date", ...t } = e, { onOpenChange: a, ...s } =
|
|
279
|
+
const { label: n = "Choose date", ...t } = e, { onOpenChange: a, ...s } = L(dt), { x: g, y: u, refs: l, strategy: b } = be({
|
|
280
280
|
strategy: "fixed",
|
|
281
281
|
placement: "bottom-start",
|
|
282
282
|
middleware: [
|
|
@@ -286,33 +286,34 @@ const lt = I.input`
|
|
|
286
286
|
xe(),
|
|
287
287
|
ke()
|
|
288
288
|
],
|
|
289
|
+
elements: {
|
|
290
|
+
reference: s.trigger
|
|
291
|
+
},
|
|
289
292
|
whileElementsMounted: Te
|
|
290
293
|
});
|
|
291
294
|
c.useEffect(() => {
|
|
292
|
-
const
|
|
295
|
+
const f = () => {
|
|
293
296
|
a(!1);
|
|
294
297
|
};
|
|
295
|
-
return window.addEventListener("blur",
|
|
296
|
-
window.removeEventListener("blur",
|
|
298
|
+
return window.addEventListener("blur", f), window.addEventListener("resize", f), () => {
|
|
299
|
+
window.removeEventListener("blur", f), window.removeEventListener("resize", f);
|
|
297
300
|
};
|
|
298
|
-
}, [a])
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const y = Q(r, (m) => s.onContentChange(m), b);
|
|
302
|
-
return Me(), i(Ne, { allowPinchZoom: !0, children: i(_e, {
|
|
301
|
+
}, [a]);
|
|
302
|
+
const x = Q(r, (f) => s.onContentChange(f), l.setFloating);
|
|
303
|
+
return Me(), i(Le, { allowPinchZoom: !0, children: i(_e, {
|
|
303
304
|
asChild: !0,
|
|
304
305
|
// When focus is trapped, a focusout event may still happen.
|
|
305
306
|
// We make sure we don't trigger our `onDismiss` in such case.
|
|
306
|
-
onFocusOutside: (
|
|
307
|
-
|
|
307
|
+
onFocusOutside: (f) => {
|
|
308
|
+
f.preventDefault();
|
|
308
309
|
},
|
|
309
310
|
onDismiss: () => {
|
|
310
311
|
a(!1);
|
|
311
312
|
},
|
|
312
|
-
children: i(mt, { ref:
|
|
313
|
+
children: i(mt, { ref: x, "data-state": s.open ? "open" : "closed", onContextMenu: (f) => f.preventDefault(), id: s.contentId, role: "dialog", "aria-modal": "true", "aria-label": n, style: {
|
|
313
314
|
left: g,
|
|
314
315
|
top: u,
|
|
315
|
-
position:
|
|
316
|
+
position: b
|
|
316
317
|
}, hasRadius: !0, background: "neutral0", padding: 1, ...t })
|
|
317
318
|
}) });
|
|
318
319
|
}), mt = I(W)`
|
|
@@ -320,27 +321,27 @@ const lt = I.input`
|
|
|
320
321
|
z-index: ${({ theme: e }) => e.zIndices[0]};
|
|
321
322
|
border: 1px solid ${({ theme: e }) => e.colors.neutral150};
|
|
322
323
|
`, ft = "DatePickerCalendar", pt = c.forwardRef(({ monthSelectLabel: e, yearSelectLabel: r, ...n }, t) => {
|
|
323
|
-
const { locale: a, timeZone: s, minDate: g, maxDate: u, calendarDate: l, onCalendarDateChange: b } =
|
|
324
|
-
const o = g.year,
|
|
325
|
-
return [...Array(
|
|
326
|
-
}, [g, u]),
|
|
324
|
+
const { locale: a, timeZone: s, minDate: g, maxDate: u, calendarDate: l, onCalendarDateChange: b } = L(ft), x = Ee(l), f = c.useMemo(() => {
|
|
325
|
+
const o = g.year, m = u.year;
|
|
326
|
+
return [...Array(m - o + 1).keys()].map((p) => (o + p).toString());
|
|
327
|
+
}, [g, u]), y = S(a, { month: "long" }), k = c.useMemo(() => [...Array(l.calendar.getMonthsInYear(l)).keys()].map((o) => y.format(l.set({ month: o + 1 }).toDate(s))), [l, y, s]), w = S(a, { weekday: "short" }), P = c.useMemo(() => {
|
|
327
328
|
let o = le(J(s), a);
|
|
328
|
-
return [...new Array(7).keys()].map((
|
|
329
|
-
let T = o.add({ days:
|
|
329
|
+
return [...new Array(7).keys()].map((m) => {
|
|
330
|
+
let T = o.add({ days: m }).toDate(s);
|
|
330
331
|
return w.format(T);
|
|
331
332
|
});
|
|
332
|
-
}, [s, a, w]),
|
|
333
|
+
}, [s, a, w]), E = (o) => {
|
|
333
334
|
if (typeof o == "number")
|
|
334
335
|
return;
|
|
335
|
-
const
|
|
336
|
-
b(
|
|
336
|
+
const m = l.set({ month: k.indexOf(o) + 1 });
|
|
337
|
+
b(m);
|
|
337
338
|
}, d = (o) => {
|
|
338
339
|
if (typeof o == "number")
|
|
339
340
|
return;
|
|
340
|
-
const
|
|
341
|
-
b(
|
|
341
|
+
const m = l.set({ year: parseInt(o, 10) });
|
|
342
|
+
b(m);
|
|
342
343
|
}, h = ht(x, a);
|
|
343
|
-
return F(U, { ref: t, direction: "column", alignItems: "stretch", padding: 4, ...n, children: [F(gt, { justifyContent: "flex-start", paddingBottom: 4, paddingLeft: 2, paddingRight: 2, gap: 2, children: [i(ne, { label: e, size: "S", value: k[l.month - 1], onChange:
|
|
344
|
+
return F(U, { ref: t, direction: "column", alignItems: "stretch", padding: 4, ...n, children: [F(gt, { justifyContent: "flex-start", paddingBottom: 4, paddingLeft: 2, paddingRight: 2, gap: 2, children: [i(ne, { label: e, size: "S", value: k[l.month - 1], onChange: E, children: k.map((o) => i(ae, { value: o, children: o }, o)) }), i(ne, { size: "S", value: l.year.toString(), label: r, onChange: d, children: f.map((o) => i(ae, { value: o, children: o }, o)) })] }), F("table", { role: "grid", children: [i("thead", { "aria-hidden": !0, children: i("tr", { "aria-rowindex": 0, children: P.map((o, m) => i(Dt, { "aria-colindex": m, children: o }, o)) }) }), i("tbody", { children: [...new Array(6).keys()].map((o) => i("tr", { "aria-rowindex": o + 2, children: h(o).map((m, p) => m ? i(bt, { "aria-colindex": p + 1, date: m, startDate: x }, m.toString()) : i(de, { "aria-colindex": p + 1 })) }, o)) })] })] });
|
|
344
345
|
}), ht = (e, r) => (n) => {
|
|
345
346
|
let t = e.add({ weeks: n }), a = [];
|
|
346
347
|
t = le(t, r);
|
|
@@ -382,23 +383,23 @@ const lt = I.input`
|
|
|
382
383
|
border-radius: ${({ theme: e }) => e.borderRadius};
|
|
383
384
|
text-transform: capitalize;
|
|
384
385
|
`, Ct = "DatePickerCalendarCell", bt = c.forwardRef(({ date: e, startDate: r, ...n }, t) => {
|
|
385
|
-
const { timeZone: a, locale: s, calendarDate: g, onValueChange: u, onOpenChange: l, onTextValueChange: b, onCalendarDateChange: x } =
|
|
386
|
+
const { timeZone: a, locale: s, calendarDate: g, onValueChange: u, onOpenChange: l, onTextValueChange: b, onCalendarDateChange: x } = L(Ct), f = se(g, e), y = S(s, {
|
|
386
387
|
weekday: "long",
|
|
387
388
|
day: "numeric",
|
|
388
389
|
month: "long",
|
|
389
390
|
year: "numeric"
|
|
390
|
-
}), k = c.useMemo(() =>
|
|
391
|
+
}), k = c.useMemo(() => y.format(e.toDate(a)), [y, e, a]), w = S(s, {
|
|
391
392
|
day: "numeric",
|
|
392
393
|
calendar: e.calendar.identifier
|
|
393
|
-
}),
|
|
394
|
+
}), P = c.useMemo(() => w.formatToParts(e.toDate(a)).find((m) => m.type === "day").value, [w, e, a]), E = S(s, {
|
|
394
395
|
day: "2-digit",
|
|
395
396
|
month: "2-digit",
|
|
396
397
|
year: "numeric"
|
|
397
398
|
}), d = Ae(r), h = e.compare(r) < 0 || e.compare(d) > 0;
|
|
398
399
|
let o = "neutral900";
|
|
399
|
-
return
|
|
400
|
-
|
|
401
|
-
}), children: i(B, { variant: "pi", textColor: o, children:
|
|
400
|
+
return f ? o = "primary600" : h && (o = "neutral600"), i(de, { as: "td", role: "gridcell", ref: t, "aria-selected": f, ...n, hasRadius: !0, "aria-label": k, tabIndex: f ? 0 : -1, background: f ? "primary100" : "neutral0", cursor: "pointer", onPointerDown: N(n.onPointerDown, (m) => {
|
|
401
|
+
m.preventDefault(), x(e), u(e), b(E.format(e.toDate(a))), l(!1);
|
|
402
|
+
}), children: i(B, { variant: "pi", textColor: o, children: P }) });
|
|
402
403
|
}), de = I(W)`
|
|
403
404
|
text-align: center;
|
|
404
405
|
padding: ${7 / 16}rem;
|
|
@@ -414,7 +415,7 @@ const lt = I.input`
|
|
|
414
415
|
}
|
|
415
416
|
`, wt = c.forwardRef((e, r) => {
|
|
416
417
|
const { error: n, hint: t, id: a, required: s, label: g, ...u } = e, l = ce(a);
|
|
417
|
-
return i(Ze, { error: n, hint: t, required: s,
|
|
418
|
+
return i(Ze, { error: n, hint: t, required: s, id: l, children: F(U, { direction: "column", alignItems: "stretch", gap: 1, children: [i(qe, { children: g }), i(Xe, { ref: r, id: l, error: n, required: s, ...u }), i(Ke, {}), i(Ge, {})] }) });
|
|
418
419
|
}), xt = Ye(console.warn), R = (e) => {
|
|
419
420
|
if (typeof e == "string") {
|
|
420
421
|
xt("It looks like you're passing a string as representation of a Date to the DatePicker. This is deprecated, look to passing a Date instead.");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),w=require("react"),p=require("@internationalized/date"),G=require("styled-components"),J=require("../DatePicker/DatePicker.cjs"),K=require("../DesignSystemProvider.cjs"),Q=require("../helpers/deprecations.cjs"),W=require("../hooks/useComposeRefs.cjs"),X=require("../hooks/useControllableState.cjs"),Y=require("../hooks/useDateFormatter.cjs"),x=require("../hooks/useId.cjs"),ee=require("../TimePicker/TimePicker.cjs"),te=require("../Field/Field.cjs"),P=require("../Flex/Flex.cjs"),ne=require("../Field/FieldLabel.cjs"),j=require("../VisuallyHidden/VisuallyHidden.cjs"),re=require("../Field/FieldHint.cjs"),se=require("../Field/FieldError.cjs"),S=e=>e&&e.__esModule?e:{default:e},ie=S(w),_=S(G),ae=w.forwardRef(({ariaLabel:e,clearLabel:d="clear",dateLabel:h="Choose date",timeLabel:o="Choose time",disabled:l=!1,error:D,hint:L,id:R,label:V,labelAction:H,onChange:q,onClear:u,name:$,required:g=!1,selectButtonTitle:de,size:C="M",step:v,value:T,initialDate:I,...E},M)=>{const y=ie.default.useRef(null),[r,m]=X.useControllableState({defaultProp:I?a(I,!1):void 0,prop:T?a(T,!1):T??void 0,onChange(t){q&&q(t?.toDate(p.getLocalTimeZone()))}}),N=K.useDesignSystem("DateTimePicker"),O=Y.useDateFormatter(N.locale,{hour:"2-digit",minute:"2-digit",hour12:!1}),c=r?O.format(r.toDate(p.getLocalTimeZone())):"",U=t=>{let s=t?a(t):void 0;if(!(s&&r&&s.compare(r)===0)){if(c&&s){const[f,b]=c.split(":");s=s.set({hour:parseInt(f,10),minute:parseInt(b,10)})}m(s)}},z=t=>{if(!t)return;const[s,f]=t.split(":"),b=r?r.set({hour:parseInt(s,10),minute:parseInt(f,10)}):a(new Date).set({hour:parseInt(s,10),minute:parseInt(f,10)});m(b)},B=t=>{m(void 0),u&&u(t)},Z=()=>{const t=r?r.set({hour:0,minute:0}):a(new Date);m(t)},i=x.useId(R),F=x.useId(),k=x.useId(),A=W.useComposedRefs(y,M);return n.jsx(te.Field,{name:$,as:"fieldset",id:i,"aria-labelledby":i,hint:L,error:D,required:g,children:n.jsxs(P.Flex,{as:"span",direction:"column",alignItems:"stretch",gap:1,children:[n.jsx(ne.FieldLabel,{onClick:()=>{y.current.focus()},as:"legend",id:i,action:H,children:V}),n.jsxs(P.Flex,{flex:"1",gap:1,children:[n.jsx(j.VisuallyHidden,{as:"label",htmlFor:k,children:h}),n.jsx(le,{...E,selectedDate:r?.toDate("UTC"),onChange:U,error:typeof D=="string",required:g,size:C,onClear:u?B:void 0,clearLabel:`${d} date`,disabled:l,id:k,ref:A,"aria-describedby":`${i}-hint ${i}-error`}),n.jsx(j.VisuallyHidden,{as:"label",htmlFor:F,children:o}),n.jsx(ce,{size:C,error:typeof D=="string",value:c,onChange:z,onClear:u&&c!==void 0&&c!=="00:00"?Z:void 0,clearLabel:`${d} time`,required:g,disabled:l,step:v,id:F,"aria-describedby":`${i}-hint ${i}-error`})]}),n.jsx(re.FieldHint,{}),n.jsx(se.FieldError,{})]})})}),oe=Q.once(console.warn),a=(e,d=!0)=>{if(typeof e=="string"){oe("It looks like you're passing a string as representation of a Date to the DatePicker. This is deprecated, look to passing a Date instead.");const l=Date.parse(e);Number.isNaN(l)?e=new Date:e=new Date(l)}const h=e.toISOString();let o=p.parseAbsoluteToLocal(h);return d&&(o=o.set({hour:0,minute:0})),p.toCalendarDateTime(o)},le=_.default(J.DatePickerInput)`
|
|
2
2
|
flex: 1 1 70%;
|
|
3
3
|
min-width: 120px;
|
|
4
|
-
`,
|
|
4
|
+
`,ce=_.default(ee.TimePickerInput)`
|
|
5
5
|
flex: 1 1 30%;
|
|
6
6
|
min-width: 120px;
|
|
7
|
-
`;exports.DateTimePicker=
|
|
7
|
+
`;exports.DateTimePicker=ae;exports.convertUTCDateToCalendarDateTime=a;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { jsx as o, jsxs as
|
|
2
|
-
import
|
|
3
|
-
import { getLocalTimeZone as
|
|
1
|
+
import { jsx as o, jsxs as F } from "react/jsx-runtime";
|
|
2
|
+
import v, { forwardRef as G } from "react";
|
|
3
|
+
import { getLocalTimeZone as P, parseAbsoluteToLocal as J, toCalendarDateTime as K } from "@internationalized/date";
|
|
4
4
|
import $ from "styled-components";
|
|
5
|
-
import { DatePickerInput as
|
|
6
|
-
import { useDesignSystem as
|
|
7
|
-
import { once as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
5
|
+
import { DatePickerInput as Q } from "../DatePicker/DatePicker.js";
|
|
6
|
+
import { useDesignSystem as W } from "../DesignSystemProvider.js";
|
|
7
|
+
import { once as X } from "../helpers/deprecations.js";
|
|
8
|
+
import { useComposedRefs as Y } from "../hooks/useComposeRefs.js";
|
|
9
|
+
import { useControllableState as ee } from "../hooks/useControllableState.js";
|
|
10
|
+
import { useDateFormatter as te } from "../hooks/useDateFormatter.js";
|
|
11
|
+
import { useId as b } from "../hooks/useId.js";
|
|
12
|
+
import { TimePickerInput as re } from "../TimePicker/TimePicker.js";
|
|
13
|
+
import { Field as oe } from "../Field/Field.js";
|
|
13
14
|
import { Flex as L } from "../Flex/Flex.js";
|
|
14
|
-
import { FieldLabel as
|
|
15
|
+
import { FieldLabel as ie } from "../Field/FieldLabel.js";
|
|
15
16
|
import { VisuallyHidden as S } from "../VisuallyHidden/VisuallyHidden.js";
|
|
16
|
-
import { FieldHint as
|
|
17
|
-
import { FieldError as
|
|
18
|
-
const
|
|
17
|
+
import { FieldHint as ne } from "../Field/FieldHint.js";
|
|
18
|
+
import { FieldError as ae } from "../Field/FieldError.js";
|
|
19
|
+
const Se = G(({
|
|
19
20
|
/**
|
|
20
21
|
* @preserve
|
|
21
22
|
* @deprecated This is no longer used.
|
|
@@ -26,11 +27,11 @@ const xe = ({
|
|
|
26
27
|
timeLabel: a = "Choose time",
|
|
27
28
|
disabled: s = !1,
|
|
28
29
|
error: h,
|
|
29
|
-
hint:
|
|
30
|
-
id:
|
|
31
|
-
label:
|
|
32
|
-
labelAction:
|
|
33
|
-
onChange:
|
|
30
|
+
hint: R,
|
|
31
|
+
id: V,
|
|
32
|
+
label: _,
|
|
33
|
+
labelAction: N,
|
|
34
|
+
onChange: I,
|
|
34
35
|
onClear: c,
|
|
35
36
|
name: j,
|
|
36
37
|
required: D = !1,
|
|
@@ -38,24 +39,24 @@ const xe = ({
|
|
|
38
39
|
* @preserve
|
|
39
40
|
* @deprecated This is no longer used.
|
|
40
41
|
*/
|
|
41
|
-
selectButtonTitle:
|
|
42
|
+
selectButtonTitle: de,
|
|
42
43
|
size: C = "M",
|
|
43
44
|
step: z,
|
|
44
45
|
value: g,
|
|
45
|
-
initialDate:
|
|
46
|
+
initialDate: k,
|
|
46
47
|
...B
|
|
47
|
-
}) => {
|
|
48
|
-
const
|
|
49
|
-
defaultProp:
|
|
48
|
+
}, E) => {
|
|
49
|
+
const w = v.useRef(null), [t, f] = ee({
|
|
50
|
+
defaultProp: k ? m(k, !1) : void 0,
|
|
50
51
|
prop: g ? m(g, !1) : g ?? void 0,
|
|
51
52
|
onChange(e) {
|
|
52
|
-
|
|
53
|
+
I && I(e?.toDate(P()));
|
|
53
54
|
}
|
|
54
|
-
}), H =
|
|
55
|
+
}), H = W("DateTimePicker"), O = te(H.locale, {
|
|
55
56
|
hour: "2-digit",
|
|
56
57
|
minute: "2-digit",
|
|
57
58
|
hour12: !1
|
|
58
|
-
}), l = t ? O.format(t.toDate(
|
|
59
|
+
}), l = t ? O.format(t.toDate(P())) : "", U = (e) => {
|
|
59
60
|
let r = e ? m(e) : void 0;
|
|
60
61
|
if (!(r && t && r.compare(t) === 0)) {
|
|
61
62
|
if (l && r) {
|
|
@@ -64,37 +65,40 @@ const xe = ({
|
|
|
64
65
|
}
|
|
65
66
|
f(r);
|
|
66
67
|
}
|
|
67
|
-
},
|
|
68
|
+
}, q = (e) => {
|
|
68
69
|
if (!e)
|
|
69
70
|
return;
|
|
70
|
-
const [r, u] = e.split(":"), T = t ? t.set({ hour: parseInt(r, 10), minute: parseInt(u, 10) }) : m(/* @__PURE__ */ new Date()).set({
|
|
71
|
+
const [r, u] = e.split(":"), T = t ? t.set({ hour: parseInt(r, 10), minute: parseInt(u, 10) }) : m(/* @__PURE__ */ new Date()).set({
|
|
72
|
+
hour: parseInt(r, 10),
|
|
73
|
+
minute: parseInt(u, 10)
|
|
74
|
+
});
|
|
71
75
|
f(T);
|
|
72
|
-
},
|
|
76
|
+
}, A = (e) => {
|
|
73
77
|
f(void 0), c && c(e);
|
|
74
78
|
}, M = () => {
|
|
75
79
|
const e = t ? t.set({ hour: 0, minute: 0 }) : m(/* @__PURE__ */ new Date());
|
|
76
80
|
f(e);
|
|
77
|
-
}, i =
|
|
78
|
-
return o(
|
|
79
|
-
|
|
80
|
-
}, as: "legend", id: i, action:
|
|
81
|
-
},
|
|
81
|
+
}, i = b(V), x = b(), y = b(), Z = Y(w, E);
|
|
82
|
+
return o(oe, { name: j, as: "fieldset", id: i, "aria-labelledby": i, hint: R, error: h, required: D, children: F(L, { as: "span", direction: "column", alignItems: "stretch", gap: 1, children: [o(ie, { onClick: () => {
|
|
83
|
+
w.current.focus();
|
|
84
|
+
}, as: "legend", id: i, action: N, children: _ }), F(L, { flex: "1", gap: 1, children: [o(S, { as: "label", htmlFor: y, children: p }), o(le, { ...B, selectedDate: t?.toDate("UTC"), onChange: U, error: typeof h == "string", required: D, size: C, onClear: c ? A : void 0, clearLabel: `${d} date`, disabled: s, id: y, ref: Z, "aria-describedby": `${i}-hint ${i}-error` }), o(S, { as: "label", htmlFor: x, children: a }), o(me, { size: C, error: typeof h == "string", value: l, onChange: q, onClear: c && l !== void 0 && l !== "00:00" ? M : void 0, clearLabel: `${d} time`, required: D, disabled: s, step: z, id: x, "aria-describedby": `${i}-hint ${i}-error` })] }), o(ne, {}), o(ae, {})] }) });
|
|
85
|
+
}), se = X(console.warn), m = (n, d = !0) => {
|
|
82
86
|
if (typeof n == "string") {
|
|
83
|
-
|
|
87
|
+
se("It looks like you're passing a string as representation of a Date to the DatePicker. This is deprecated, look to passing a Date instead.");
|
|
84
88
|
const s = Date.parse(n);
|
|
85
89
|
Number.isNaN(s) ? n = /* @__PURE__ */ new Date() : n = new Date(s);
|
|
86
90
|
}
|
|
87
91
|
const p = n.toISOString();
|
|
88
|
-
let a =
|
|
89
|
-
return d && (a = a.set({ hour: 0, minute: 0 })),
|
|
90
|
-
},
|
|
92
|
+
let a = J(p);
|
|
93
|
+
return d && (a = a.set({ hour: 0, minute: 0 })), K(a);
|
|
94
|
+
}, le = $(Q)`
|
|
91
95
|
flex: 1 1 70%;
|
|
92
96
|
min-width: 120px;
|
|
93
|
-
`,
|
|
97
|
+
`, me = $(re)`
|
|
94
98
|
flex: 1 1 30%;
|
|
95
99
|
min-width: 120px;
|
|
96
100
|
`;
|
|
97
101
|
export {
|
|
98
|
-
|
|
102
|
+
Se as DateTimePicker,
|
|
99
103
|
m as convertUTCDateToCalendarDateTime
|
|
100
104
|
};
|