@asdp/ferryui 0.1.4 → 0.1.5

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/index.mjs CHANGED
@@ -1,11 +1,12 @@
1
1
  import { makeStyles, tokens, shorthands, Popover, PopoverTrigger, Input, PopoverSurface, Dialog, DialogSurface, DialogBody, DialogTitle, DialogContent, Body1, Button, Carousel, mergeClasses, CarouselViewport, CarouselSlider, CarouselNav, CarouselNavButton, CarouselCard, Subtitle2, Card, Tooltip, Badge, Caption1, Title2, Caption2, Divider, Title3, Caption1Strong, Field, Label, Text, Body1Strong, typographyStyles, Checkbox, RadioGroup, Radio, Switch, Textarea } from '@fluentui/react-components';
2
2
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
- import React2, { forwardRef, useState, useCallback, useRef, useEffect } from 'react';
3
+ import React2, { forwardRef, useState, useCallback, useRef, useEffect, useMemo } from 'react';
4
4
  import { Icon } from '@iconify/react';
5
5
  import { Controller } from 'react-hook-form';
6
6
  import PhoneInput from 'react-phone-input-2';
7
7
  import Select from 'react-select';
8
8
  import { Calendar } from '@fluentui/react-calendar-compat';
9
+ import moment from 'moment';
9
10
 
10
11
  var useStyles = makeStyles({
11
12
  dialogSurface: {
@@ -3035,7 +3036,332 @@ var ModalSearchHarbor = ({
3035
3036
  }
3036
3037
  );
3037
3038
  };
3039
+ var useStyles9 = makeStyles({
3040
+ dialogSurface: {
3041
+ maxWidth: "600px",
3042
+ width: "100%"
3043
+ },
3044
+ content: {
3045
+ display: "flex",
3046
+ flexDirection: "column",
3047
+ gap: "0px",
3048
+ paddingTop: "10px",
3049
+ paddingLeft: "10px",
3050
+ paddingRight: "10px",
3051
+ paddingBottom: "20px",
3052
+ width: "100%",
3053
+ overflow: "hidden"
3054
+ },
3055
+ closeButton: {
3056
+ minWidth: "32px",
3057
+ minHeight: "32px"
3058
+ },
3059
+ tabContainer: {
3060
+ display: "flex",
3061
+ gap: "0px",
3062
+ marginBottom: "16px",
3063
+ borderBottom: `2px solid ${tokens.colorNeutralStroke2}`
3064
+ },
3065
+ tab: {
3066
+ flex: 1,
3067
+ padding: "12px 16px",
3068
+ cursor: "pointer",
3069
+ textAlign: "center",
3070
+ fontSize: tokens.fontSizeBase300,
3071
+ fontWeight: tokens.fontWeightRegular,
3072
+ color: tokens.colorNeutralForeground3,
3073
+ borderBottom: "2px solid transparent",
3074
+ marginBottom: "-2px",
3075
+ transition: "all 0.2s ease",
3076
+ backgroundColor: "transparent",
3077
+ border: "none",
3078
+ ":hover": {
3079
+ color: tokens.colorNeutralForeground1,
3080
+ backgroundColor: tokens.colorNeutralBackground1Hover
3081
+ }
3082
+ },
3083
+ tabActive: {
3084
+ color: tokens.colorBrandForeground1,
3085
+ fontWeight: tokens.fontWeightSemibold,
3086
+ borderBottom: `2px solid ${tokens.colorBrandBackground}`
3087
+ },
3088
+ calendarContainer: {
3089
+ display: "flex",
3090
+ gap: "20px",
3091
+ justifyContent: "center",
3092
+ alignItems: "flex-start",
3093
+ width: "100%"
3094
+ },
3095
+ rangeCalendar: {
3096
+ "& .ms-CalendarDay": {
3097
+ position: "relative"
3098
+ },
3099
+ '& button[class*="ms-CalendarDay"]': {
3100
+ borderRadius: "999px",
3101
+ transition: "all 0.15s ease",
3102
+ border: "none",
3103
+ "&:hover": {
3104
+ backgroundColor: `${tokens.colorBrandBackground} !important`,
3105
+ color: tokens.colorNeutralForegroundStaticInverted
3106
+ }
3107
+ }
3108
+ },
3109
+ rangeStart: {
3110
+ backgroundColor: `${tokens.colorBrandBackground} !important`,
3111
+ color: `${tokens.colorNeutralForegroundStaticInverted} !important`,
3112
+ borderTopLeftRadius: "999px !important",
3113
+ borderBottomLeftRadius: "999px !important",
3114
+ fontWeight: tokens.fontWeightSemibold
3115
+ },
3116
+ rangeEnd: {
3117
+ backgroundColor: `${tokens.colorBrandBackground} !important`,
3118
+ color: `${tokens.colorNeutralForegroundOnBrand} !important`,
3119
+ borderTopRightRadius: "999px !important",
3120
+ borderBottomRightRadius: "999px !important",
3121
+ fontWeight: tokens.fontWeightSemibold
3122
+ },
3123
+ rangeMiddle: {
3124
+ backgroundColor: `${tokens.colorBrandBackground} !important`,
3125
+ color: `${tokens.colorNeutralForegroundStaticInverted} !important`,
3126
+ borderRadius: "0px !important"
3127
+ },
3128
+ rangePreview: {
3129
+ backgroundColor: `${tokens.colorBrandBackground} !important`,
3130
+ color: tokens.colorNeutralForegroundStaticInverted,
3131
+ borderRadius: "0px !important",
3132
+ boxShadow: `inset 0 0 0 1px ${tokens.colorBrandStroke1}`
3133
+ },
3134
+ rangeSingle: {
3135
+ backgroundColor: `${tokens.colorBrandBackground} !important`,
3136
+ color: `${tokens.colorNeutralForegroundOnBrand} !important`,
3137
+ borderRadius: "999px !important",
3138
+ fontWeight: tokens.fontWeightSemibold
3139
+ }
3140
+ });
3141
+ var ModalSelectDate = ({
3142
+ open,
3143
+ onClose,
3144
+ title = "Pilih Tanggal",
3145
+ selectedDepartureDate,
3146
+ selectedReturnDate,
3147
+ initialTab = "one-way",
3148
+ showTabs = true,
3149
+ onSelectDepartureDate,
3150
+ onSelectReturnDate,
3151
+ onTabChange,
3152
+ minDate = /* @__PURE__ */ new Date(),
3153
+ maxDate,
3154
+ dateFormat = "DD MMMM YYYY"
3155
+ }) => {
3156
+ const styles = useStyles9();
3157
+ const [selectedDate, setSelectedDate] = useState(selectedDepartureDate);
3158
+ const [selectedEndDate, setSelectedEndDate] = useState(selectedReturnDate);
3159
+ const [hoveredDate, setHoveredDate] = useState();
3160
+ const [activeTab, setActiveTab] = useState(initialTab);
3161
+ const previewEndDate = useMemo(() => {
3162
+ if (selectedEndDate) return selectedEndDate;
3163
+ if (selectedDate && hoveredDate && hoveredDate > selectedDate) {
3164
+ return hoveredDate;
3165
+ }
3166
+ return void 0;
3167
+ }, [hoveredDate, selectedDate, selectedEndDate]);
3168
+ const isSameCalendarDay = (first, second) => {
3169
+ if (!first || !second) return false;
3170
+ return moment(first).isSame(second, "day");
3171
+ };
3172
+ useEffect(() => {
3173
+ if (open) {
3174
+ setSelectedDate(selectedDepartureDate);
3175
+ setSelectedEndDate(selectedReturnDate);
3176
+ setActiveTab(initialTab);
3177
+ setHoveredDate(void 0);
3178
+ }
3179
+ }, [open, selectedDepartureDate, selectedReturnDate, initialTab]);
3180
+ const handleTabChange = (tab) => {
3181
+ setActiveTab(tab);
3182
+ setSelectedEndDate(void 0);
3183
+ setHoveredDate(void 0);
3184
+ if (onTabChange) {
3185
+ onTabChange(tab);
3186
+ }
3187
+ };
3188
+ const handleClose = () => {
3189
+ setHoveredDate(void 0);
3190
+ onClose();
3191
+ };
3192
+ const handleDateSelect = (date) => {
3193
+ if (!date) return;
3194
+ const currentStart = selectedDate;
3195
+ if (activeTab === "round-trip") {
3196
+ if (!currentStart || selectedEndDate) {
3197
+ setSelectedDate(date);
3198
+ setSelectedEndDate(void 0);
3199
+ setHoveredDate(void 0);
3200
+ onSelectDepartureDate(date);
3201
+ } else {
3202
+ if (date < currentStart) {
3203
+ setSelectedEndDate(currentStart);
3204
+ setSelectedDate(date);
3205
+ onSelectDepartureDate(date);
3206
+ if (onSelectReturnDate) {
3207
+ onSelectReturnDate(currentStart);
3208
+ }
3209
+ } else {
3210
+ setSelectedEndDate(date);
3211
+ if (onSelectReturnDate) {
3212
+ onSelectReturnDate(date);
3213
+ }
3214
+ }
3215
+ setHoveredDate(void 0);
3216
+ handleClose();
3217
+ }
3218
+ } else {
3219
+ setSelectedDate(date);
3220
+ onSelectDepartureDate(date);
3221
+ handleClose();
3222
+ }
3223
+ };
3224
+ const handleCustomDayCellRef = useCallback(
3225
+ (element, date, _classNames) => {
3226
+ if (!element) return;
3227
+ const removeTokens = (className) => {
3228
+ className?.split(/\s+/).filter(Boolean).forEach((token) => element.classList.remove(token));
3229
+ };
3230
+ const addTokens = (className) => {
3231
+ className?.split(/\s+/).filter(Boolean).forEach((token) => element.classList.add(token));
3232
+ };
3233
+ const removableClasses = [
3234
+ styles.rangeStart,
3235
+ styles.rangeEnd,
3236
+ styles.rangeMiddle,
3237
+ styles.rangePreview,
3238
+ styles.rangeSingle
3239
+ ];
3240
+ removableClasses.forEach(removeTokens);
3241
+ if (activeTab !== "round-trip" || !selectedDate) {
3242
+ element.onmouseenter = null;
3243
+ element.onmouseleave = null;
3244
+ return;
3245
+ }
3246
+ const endDateForVisual = previewEndDate;
3247
+ const startTime = selectedDate.getTime();
3248
+ const endTime = endDateForVisual?.getTime();
3249
+ const currentTime = date.getTime();
3250
+ const isSameStartEnd = isSameCalendarDay(endDateForVisual, selectedDate);
3251
+ const isStartDay = isSameCalendarDay(date, selectedDate);
3252
+ const isEndDay = isSameCalendarDay(date, endDateForVisual);
3253
+ if (isStartDay && (!endDateForVisual || isSameStartEnd)) {
3254
+ addTokens(styles.rangeSingle);
3255
+ } else {
3256
+ if (isStartDay) {
3257
+ addTokens(styles.rangeStart);
3258
+ }
3259
+ if (isEndDay && !isSameStartEnd) {
3260
+ addTokens(styles.rangeEnd);
3261
+ }
3262
+ }
3263
+ if (endTime && currentTime > startTime && currentTime < endTime) {
3264
+ addTokens(selectedEndDate ? styles.rangeMiddle : styles.rangePreview);
3265
+ }
3266
+ if (!selectedEndDate) {
3267
+ element.onmouseenter = () => {
3268
+ if (date < selectedDate) return;
3269
+ setHoveredDate((prev) => {
3270
+ if (isSameCalendarDay(prev, date)) {
3271
+ return prev;
3272
+ }
3273
+ return date;
3274
+ });
3275
+ };
3276
+ element.onmouseleave = () => {
3277
+ setHoveredDate(void 0);
3278
+ };
3279
+ } else {
3280
+ element.onmouseenter = null;
3281
+ element.onmouseleave = null;
3282
+ }
3283
+ },
3284
+ [
3285
+ activeTab,
3286
+ previewEndDate,
3287
+ selectedDate,
3288
+ selectedEndDate,
3289
+ styles.rangeEnd,
3290
+ styles.rangeMiddle,
3291
+ styles.rangePreview,
3292
+ styles.rangeSingle,
3293
+ styles.rangeStart
3294
+ ]
3295
+ );
3296
+ return /* @__PURE__ */ jsx(
3297
+ Dialog,
3298
+ {
3299
+ open,
3300
+ onOpenChange: (_, data) => {
3301
+ if (!data.open) {
3302
+ onClose();
3303
+ }
3304
+ },
3305
+ children: /* @__PURE__ */ jsx(DialogSurface, { className: styles.dialogSurface, children: /* @__PURE__ */ jsxs(DialogBody, { children: [
3306
+ /* @__PURE__ */ jsx(
3307
+ DialogTitle,
3308
+ {
3309
+ action: /* @__PURE__ */ jsx(
3310
+ Button,
3311
+ {
3312
+ appearance: "subtle",
3313
+ "aria-label": "close",
3314
+ icon: /* @__PURE__ */ jsx(Icon, { icon: "fluent:dismiss-24-regular" }),
3315
+ onClick: handleClose,
3316
+ className: styles.closeButton
3317
+ }
3318
+ ),
3319
+ children: title
3320
+ }
3321
+ ),
3322
+ /* @__PURE__ */ jsxs(DialogContent, { className: styles.content, children: [
3323
+ showTabs && /* @__PURE__ */ jsxs("div", { className: styles.tabContainer, children: [
3324
+ /* @__PURE__ */ jsx(
3325
+ "button",
3326
+ {
3327
+ disabled: activeTab === "round-trip",
3328
+ className: `${styles.tab} ${activeTab === "one-way" ? styles.tabActive : ""}`,
3329
+ onClick: () => handleTabChange("one-way"),
3330
+ children: "Sekali Jalan"
3331
+ }
3332
+ ),
3333
+ /* @__PURE__ */ jsx(
3334
+ "button",
3335
+ {
3336
+ className: `${styles.tab} ${activeTab === "round-trip" ? styles.tabActive : ""}`,
3337
+ onClick: () => handleTabChange("round-trip"),
3338
+ disabled: activeTab === "one-way",
3339
+ children: "Pulang Pergi"
3340
+ }
3341
+ )
3342
+ ] }),
3343
+ /* @__PURE__ */ jsx("div", { className: styles.calendarContainer, children: /* @__PURE__ */ jsx("div", { style: { width: "100%" }, children: /* @__PURE__ */ jsx("div", { className: activeTab === "round-trip" ? styles.rangeCalendar : "", children: /* @__PURE__ */ jsx(
3344
+ Calendar,
3345
+ {
3346
+ minDate,
3347
+ maxDate,
3348
+ value: selectedDate,
3349
+ onSelectDate: handleDateSelect,
3350
+ showGoToToday: true,
3351
+ highlightSelectedMonth: true,
3352
+ showMonthPickerAsOverlay: false,
3353
+ allFocusable: true,
3354
+ calendarDayProps: {
3355
+ customDayCellRef: handleCustomDayCellRef
3356
+ }
3357
+ }
3358
+ ) }) }) })
3359
+ ] })
3360
+ ] }) })
3361
+ }
3362
+ );
3363
+ };
3038
3364
 
3039
- export { BackgroundTicketCard_default as BackgroundTicketCard, BackgroundTicketCardVertical_default as BackgroundTicketCardVertical, CardBanner, CardPromo, CardServiceMenu, CardTicket, CarouselWithCustomNav, DEFAULT_COUNTRY_CODES2 as DEFAULT_COUNTRY_CODES, InputDynamic_default as InputDynamic, MODAL_PRESETS, ModalIllustration, ModalSearchHarbor, getModalPreset };
3365
+ export { BackgroundTicketCard_default as BackgroundTicketCard, BackgroundTicketCardVertical_default as BackgroundTicketCardVertical, CardBanner, CardPromo, CardServiceMenu, CardTicket, CarouselWithCustomNav, DEFAULT_COUNTRY_CODES2 as DEFAULT_COUNTRY_CODES, InputDynamic_default as InputDynamic, MODAL_PRESETS, ModalIllustration, ModalSearchHarbor, ModalSelectDate, getModalPreset };
3040
3366
  //# sourceMappingURL=index.mjs.map
3041
3367
  //# sourceMappingURL=index.mjs.map