@asdp/ferryui 0.1.5 → 0.1.7

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,4 +1,4 @@
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';
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, Checkbox, MessageBar, MessageBarBody, Accordion, AccordionItem, AccordionHeader, AccordionPanel, typographyStyles, RadioGroup, Radio, Switch, Textarea } from '@fluentui/react-components';
2
2
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
3
  import React2, { forwardRef, useState, useCallback, useRef, useEffect, useMemo } from 'react';
4
4
  import { Icon } from '@iconify/react';
@@ -3361,7 +3361,518 @@ var ModalSelectDate = ({
3361
3361
  }
3362
3362
  );
3363
3363
  };
3364
+ var useStyles10 = makeStyles({
3365
+ dialogSurface: {
3366
+ maxWidth: "600px",
3367
+ width: "100%"
3368
+ },
3369
+ content: {
3370
+ display: "flex",
3371
+ flexDirection: "column",
3372
+ gap: "0px",
3373
+ paddingTop: "10px",
3374
+ paddingLeft: "10px",
3375
+ paddingRight: "10px"
3376
+ },
3377
+ closeButton: {
3378
+ minWidth: "32px",
3379
+ minHeight: "32px"
3380
+ },
3381
+ headerRow: {
3382
+ display: "flex",
3383
+ justifyContent: "end",
3384
+ alignItems: "center",
3385
+ borderBottom: `1px solid ${tokens.colorNeutralStroke2}`
3386
+ },
3387
+ serviceList: {
3388
+ display: "flex",
3389
+ flexDirection: "column",
3390
+ gap: "0px",
3391
+ maxHeight: "400px",
3392
+ overflowY: "auto",
3393
+ paddingLeft: "20px"
3394
+ },
3395
+ serviceItem: {
3396
+ padding: "16px 0px",
3397
+ borderBottom: `1px solid ${tokens.colorNeutralStroke2}`,
3398
+ display: "flex",
3399
+ alignItems: "flex-start",
3400
+ gap: "12px",
3401
+ cursor: "pointer",
3402
+ transition: "background-color 0.2s ease",
3403
+ ":hover": {
3404
+ backgroundColor: tokens.colorNeutralBackground1Hover
3405
+ }
3406
+ },
3407
+ serviceContent: {
3408
+ flex: 1,
3409
+ display: "flex",
3410
+ flexDirection: "column",
3411
+ gap: "4px"
3412
+ },
3413
+ serviceName: {
3414
+ fontSize: tokens.fontSizeBase300,
3415
+ fontWeight: tokens.fontWeightSemibold,
3416
+ color: tokens.colorNeutralForeground1
3417
+ },
3418
+ serviceType: {
3419
+ fontSize: tokens.fontSizeBase200,
3420
+ fontWeight: tokens.fontWeightRegular,
3421
+ color: tokens.colorNeutralForeground2
3422
+ },
3423
+ serviceDescription: {
3424
+ fontSize: tokens.fontSizeBase200,
3425
+ color: tokens.colorNeutralForeground3,
3426
+ lineHeight: "1.4"
3427
+ },
3428
+ footer: {
3429
+ padding: "16px 20px",
3430
+ borderTop: `1px solid ${tokens.colorNeutralStroke2}`
3431
+ },
3432
+ saveButton: {
3433
+ width: "100%",
3434
+ borderRadius: tokens.borderRadiusCircular
3435
+ }
3436
+ });
3437
+ var ModalService = ({
3438
+ open,
3439
+ onClose,
3440
+ title = "Pilih Kelas Layanan",
3441
+ services,
3442
+ selectedServiceIds,
3443
+ onSave,
3444
+ isLoading = false,
3445
+ isError = false
3446
+ }) => {
3447
+ const styles = useStyles10();
3448
+ const [selectedServices, setSelectedServices] = useState(selectedServiceIds);
3449
+ useEffect(() => {
3450
+ if (open) {
3451
+ if (selectedServiceIds && selectedServiceIds.length > 0) {
3452
+ const validIds = services.filter((s) => selectedServiceIds.includes(s.id)).map((s) => s.id);
3453
+ setSelectedServices(validIds);
3454
+ } else {
3455
+ setSelectedServices(services.map((s) => s.id));
3456
+ }
3457
+ }
3458
+ }, [open, services, selectedServiceIds]);
3459
+ const handleClose = () => {
3460
+ onClose();
3461
+ };
3462
+ const handleToggleService = (serviceId) => {
3463
+ setSelectedServices((prev) => {
3464
+ if (prev.includes(serviceId)) {
3465
+ return prev.filter((id) => id !== serviceId);
3466
+ } else {
3467
+ return [...prev, serviceId];
3468
+ }
3469
+ });
3470
+ };
3471
+ const handleToggleAll = () => {
3472
+ if (selectedServices.length === services.length) {
3473
+ setSelectedServices([]);
3474
+ } else {
3475
+ setSelectedServices(services.map((s) => s.id));
3476
+ }
3477
+ };
3478
+ const handleSave = () => {
3479
+ const selectedServiceItems = services.filter((s) => selectedServices.includes(s.id));
3480
+ onSave(selectedServiceItems);
3481
+ };
3482
+ return /* @__PURE__ */ jsx(
3483
+ Dialog,
3484
+ {
3485
+ open,
3486
+ onOpenChange: (_, data) => !data.open && onClose(),
3487
+ children: /* @__PURE__ */ jsx(DialogSurface, { className: styles.dialogSurface, children: /* @__PURE__ */ jsxs(DialogBody, { children: [
3488
+ /* @__PURE__ */ jsx(
3489
+ DialogTitle,
3490
+ {
3491
+ action: /* @__PURE__ */ jsx(
3492
+ Button,
3493
+ {
3494
+ appearance: "subtle",
3495
+ "aria-label": "close",
3496
+ icon: /* @__PURE__ */ jsx(Icon, { icon: "fluent:dismiss-24-regular" }),
3497
+ onClick: handleClose,
3498
+ className: styles.closeButton
3499
+ }
3500
+ ),
3501
+ children: title
3502
+ }
3503
+ ),
3504
+ /* @__PURE__ */ jsx(DialogContent, { className: styles.content, children: isLoading ? /* @__PURE__ */ jsx(Body1, { children: "Loading..." }) : isError ? /* @__PURE__ */ jsx(Body1, { children: "Error loading services" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
3505
+ /* @__PURE__ */ jsxs("div", { className: styles.serviceList, children: [
3506
+ /* @__PURE__ */ jsxs("div", { className: styles.headerRow, children: [
3507
+ /* @__PURE__ */ jsx(Body1, { children: "Pilih Semua" }),
3508
+ /* @__PURE__ */ jsx(
3509
+ Checkbox,
3510
+ {
3511
+ checked: selectedServices.length === services.length,
3512
+ onChange: handleToggleAll
3513
+ }
3514
+ )
3515
+ ] }),
3516
+ services.map((service) => /* @__PURE__ */ jsxs(
3517
+ "div",
3518
+ {
3519
+ className: styles.serviceItem,
3520
+ onClick: () => handleToggleService(service.id),
3521
+ children: [
3522
+ /* @__PURE__ */ jsxs("div", { className: styles.serviceContent, children: [
3523
+ /* @__PURE__ */ jsx(Body1, { className: styles.serviceName, children: service.serviceTypeName }),
3524
+ /* @__PURE__ */ jsx(Caption1, { className: styles.serviceType, children: service.serviceTypeCode }),
3525
+ /* @__PURE__ */ jsx(Caption1, { className: styles.serviceDescription, children: service.serviceDescription })
3526
+ ] }),
3527
+ /* @__PURE__ */ jsx(
3528
+ Checkbox,
3529
+ {
3530
+ checked: selectedServices.includes(service.id),
3531
+ onChange: () => handleToggleService(service.id)
3532
+ }
3533
+ )
3534
+ ]
3535
+ },
3536
+ service.id
3537
+ ))
3538
+ ] }),
3539
+ /* @__PURE__ */ jsx("div", { className: styles.footer, children: /* @__PURE__ */ jsx(
3540
+ Button,
3541
+ {
3542
+ appearance: "primary",
3543
+ size: "medium",
3544
+ className: styles.saveButton,
3545
+ onClick: handleSave,
3546
+ disabled: selectedServices.length === 0,
3547
+ children: "Simpan"
3548
+ }
3549
+ ) })
3550
+ ] }) })
3551
+ ] }) })
3552
+ }
3553
+ );
3554
+ };
3555
+
3556
+ // src/components/ModalTotalPassengers/constants.ts
3557
+ var DEFAULT_SERVICE_CLASSES = [
3558
+ { id: 1, name: "Ekonomi", key: "ekonomi", serviceName: "ECONOMY" },
3559
+ { id: 2, name: "Bisnis", key: "bisnis", serviceName: "BUSINESS" },
3560
+ { id: 3, name: "Eksekutif", key: "eksekutif", serviceName: "EXECUTIVE" }
3561
+ ];
3562
+ var useStyles11 = makeStyles({
3563
+ dialogSurface: {
3564
+ maxWidth: "600px",
3565
+ width: "100%"
3566
+ },
3567
+ passengerSection: {
3568
+ marginTop: tokens.spacingHorizontalM,
3569
+ display: "flex",
3570
+ flexDirection: "column"
3571
+ },
3572
+ accordionHeader: {
3573
+ fontSize: tokens.fontSizeBase300,
3574
+ fontWeight: tokens.fontWeightBold
3575
+ },
3576
+ accordionItem: {
3577
+ borderRadius: tokens.borderRadiusXLarge,
3578
+ marginBottom: "1rem",
3579
+ border: `1px solid ${tokens.colorNeutralStroke2}`
3580
+ },
3581
+ passengerCount: {
3582
+ display: "flex",
3583
+ alignItems: "center",
3584
+ gap: "12px"
3585
+ },
3586
+ counterButton: {
3587
+ minWidth: "24px",
3588
+ height: "24px",
3589
+ padding: "0",
3590
+ borderRadius: tokens.borderRadiusCircular,
3591
+ color: tokens.colorBrandBackground,
3592
+ border: `1px solid ${tokens.colorBrandBackground}`,
3593
+ "&:hover": {
3594
+ border: `1px solid ${tokens.colorBrandBackgroundHover}`,
3595
+ color: tokens.colorBrandBackgroundHover
3596
+ },
3597
+ "&:disabled": {
3598
+ border: `1px solid ${tokens.colorNeutralStrokeDisabled}`,
3599
+ color: tokens.colorNeutralForegroundDisabled
3600
+ }
3601
+ },
3602
+ countText: {
3603
+ minWidth: "24px",
3604
+ textAlign: "center"
3605
+ },
3606
+ nestedSection: {
3607
+ borderTop: `2px solid ${tokens.colorBrandBackground}`,
3608
+ display: "flex",
3609
+ flexDirection: "column",
3610
+ padding: "0.6rem"
3611
+ },
3612
+ nestedRow: {
3613
+ display: "flex",
3614
+ justifyContent: "space-between",
3615
+ alignItems: "center",
3616
+ padding: "4px",
3617
+ borderRadius: tokens.borderRadiusSmall,
3618
+ backgroundColor: tokens.colorNeutralBackground1
3619
+ },
3620
+ submitButton: {
3621
+ marginTop: "16px",
3622
+ width: "100%",
3623
+ borderRadius: tokens.borderRadiusCircular
3624
+ },
3625
+ accordionPanel: {
3626
+ margin: 0
3627
+ }
3628
+ });
3629
+ var ModalTotalPassengers = ({
3630
+ open,
3631
+ onClose,
3632
+ title = "Pilih Jumlah Penumpang",
3633
+ passengerTypes,
3634
+ serviceClasses = DEFAULT_SERVICE_CLASSES,
3635
+ selectedPassengers,
3636
+ onSave,
3637
+ isLoading = false,
3638
+ maxPassengers = 10,
3639
+ infoMessage
3640
+ }) => {
3641
+ const styles = useStyles11();
3642
+ const [passengers, setPassengers] = useState([]);
3643
+ const [openItems, setOpenItems] = useState([]);
3644
+ const defaultInfoMessage = `Anda dapat menambahkan hingga ${maxPassengers} penumpang pada golongan kendaraan ini.`;
3645
+ useEffect(() => {
3646
+ if (passengerTypes.length === 0) return;
3647
+ const defaultPassengers = passengerTypes.map((passengerType) => ({
3648
+ passengerTypeId: passengerType.id,
3649
+ passengerTypeCode: passengerType.passengerTypeCode,
3650
+ passengerTypeName: passengerType.passengerTypeName,
3651
+ services: serviceClasses.map((sc) => ({
3652
+ serviceId: sc.id,
3653
+ serviceName: sc.serviceName,
3654
+ count: 0,
3655
+ passengers: []
3656
+ }))
3657
+ }));
3658
+ if (selectedPassengers && selectedPassengers.length > 0) {
3659
+ const mergedPassengers = defaultPassengers.map((defaultP) => {
3660
+ const selectedP = selectedPassengers.find(
3661
+ (p) => p.passengerTypeCode === defaultP.passengerTypeCode
3662
+ );
3663
+ if (selectedP) {
3664
+ const mergedServices = defaultP.services.map((defaultS) => {
3665
+ const selectedS = selectedP.services.find((s) => s.serviceName === defaultS.serviceName);
3666
+ return selectedS ? { ...defaultS, count: selectedS.count, passengers: selectedS.passengers || [] } : defaultS;
3667
+ });
3668
+ return { ...defaultP, services: mergedServices };
3669
+ }
3670
+ return defaultP;
3671
+ });
3672
+ setPassengers(mergedPassengers);
3673
+ const itemsWithData = selectedPassengers.filter((p) => p.services.some((s) => s.count > 0)).map((p) => {
3674
+ const passengerType = passengerTypes.find(
3675
+ (pt) => pt.passengerTypeCode === p.passengerTypeCode
3676
+ );
3677
+ return passengerType ? String(passengerType.id) : "";
3678
+ }).filter((id) => id !== "");
3679
+ setOpenItems(itemsWithData);
3680
+ } else {
3681
+ setPassengers(defaultPassengers);
3682
+ setOpenItems([]);
3683
+ }
3684
+ }, [open, passengerTypes, serviceClasses, selectedPassengers]);
3685
+ const getServiceCount = (passengerTypeCode, serviceName) => {
3686
+ const passenger = passengers.find((p) => p.passengerTypeCode === passengerTypeCode);
3687
+ if (!passenger) return 0;
3688
+ const service = passenger.services.find((s) => s.serviceName === serviceName);
3689
+ return service?.count || 0;
3690
+ };
3691
+ const getTotalForType = (passengerTypeCode) => {
3692
+ const passenger = passengers.find((p) => p.passengerTypeCode === passengerTypeCode);
3693
+ if (!passenger) return "0";
3694
+ const parts = [];
3695
+ passenger.services.forEach((service) => {
3696
+ if (service.count > 0) {
3697
+ const serviceClass = serviceClasses.find((sc) => sc.serviceName === service.serviceName);
3698
+ const serviceName = serviceClass?.name || service.serviceName;
3699
+ parts.push(`${service.count} ${serviceName}`);
3700
+ }
3701
+ });
3702
+ return parts.length > 0 ? parts.join(", ") : "0";
3703
+ };
3704
+ const handleIncrement = (passengerTypeCode, serviceName) => {
3705
+ setPassengers(
3706
+ (prev) => prev.map((passenger) => {
3707
+ if (passenger.passengerTypeCode === passengerTypeCode) {
3708
+ return {
3709
+ ...passenger,
3710
+ services: passenger.services.map((service) => {
3711
+ if (service.serviceName === serviceName) {
3712
+ const newCount = service.count + 1;
3713
+ const newPassengers = [...service.passengers || []];
3714
+ while (newPassengers.length < newCount) {
3715
+ newPassengers.push({});
3716
+ }
3717
+ return {
3718
+ ...service,
3719
+ count: newCount,
3720
+ passengers: newPassengers
3721
+ };
3722
+ }
3723
+ return service;
3724
+ })
3725
+ };
3726
+ }
3727
+ return passenger;
3728
+ })
3729
+ );
3730
+ };
3731
+ const handleDecrement = (passengerTypeCode, serviceName) => {
3732
+ setPassengers(
3733
+ (prev) => prev.map((passenger) => {
3734
+ if (passenger.passengerTypeCode === passengerTypeCode) {
3735
+ return {
3736
+ ...passenger,
3737
+ services: passenger.services.map((service) => {
3738
+ if (service.serviceName === serviceName && service.count > 0) {
3739
+ const newCount = service.count - 1;
3740
+ const newPassengers = (service.passengers || []).slice(0, newCount);
3741
+ return {
3742
+ ...service,
3743
+ count: newCount,
3744
+ passengers: newPassengers
3745
+ };
3746
+ }
3747
+ return service;
3748
+ })
3749
+ };
3750
+ }
3751
+ return passenger;
3752
+ })
3753
+ );
3754
+ };
3755
+ const handleSave = () => {
3756
+ const filteredPassengers = passengers.map((passenger) => ({
3757
+ ...passenger,
3758
+ services: passenger.services.filter((service) => service.count > 0)
3759
+ })).filter((passenger) => passenger.services.length > 0);
3760
+ onSave(filteredPassengers);
3761
+ };
3762
+ return /* @__PURE__ */ jsx(
3763
+ Dialog,
3764
+ {
3765
+ open,
3766
+ onOpenChange: (_, data) => !data.open && onClose(),
3767
+ children: /* @__PURE__ */ jsx(DialogSurface, { children: /* @__PURE__ */ jsxs(DialogBody, { children: [
3768
+ /* @__PURE__ */ jsx(
3769
+ DialogTitle,
3770
+ {
3771
+ action: /* @__PURE__ */ jsx(
3772
+ Button,
3773
+ {
3774
+ appearance: "subtle",
3775
+ "aria-label": "close",
3776
+ icon: /* @__PURE__ */ jsx(Icon, { icon: "fluent:dismiss-12-regular" }),
3777
+ onClick: onClose
3778
+ }
3779
+ ),
3780
+ children: title
3781
+ }
3782
+ ),
3783
+ /* @__PURE__ */ jsxs(DialogContent, { children: [
3784
+ /* @__PURE__ */ jsx(MessageBar, { shape: "rounded", children: /* @__PURE__ */ jsx(MessageBarBody, { children: infoMessage || defaultInfoMessage }) }),
3785
+ isLoading ? /* @__PURE__ */ jsx(Body1, { children: "Loading..." }) : /* @__PURE__ */ jsxs(Fragment, { children: [
3786
+ /* @__PURE__ */ jsx(
3787
+ Accordion,
3788
+ {
3789
+ collapsible: true,
3790
+ multiple: true,
3791
+ openItems,
3792
+ onToggle: (_, data) => setOpenItems(data.openItems),
3793
+ className: styles.passengerSection,
3794
+ children: passengerTypes.map((passengerType) => {
3795
+ return /* @__PURE__ */ jsxs(
3796
+ AccordionItem,
3797
+ {
3798
+ value: String(passengerType.id),
3799
+ className: styles.accordionItem,
3800
+ children: [
3801
+ /* @__PURE__ */ jsxs(AccordionHeader, { className: styles.accordionHeader, expandIconPosition: "end", children: [
3802
+ passengerType.passengerTypeName,
3803
+ " (",
3804
+ getTotalForType(passengerType.passengerTypeCode),
3805
+ ")"
3806
+ ] }),
3807
+ /* @__PURE__ */ jsx(AccordionPanel, { className: styles.accordionPanel, children: /* @__PURE__ */ jsx("div", { className: styles.nestedSection, children: serviceClasses.map((service) => /* @__PURE__ */ jsxs("div", { className: styles.nestedRow, children: [
3808
+ /* @__PURE__ */ jsx(Body1, { children: service.name }),
3809
+ /* @__PURE__ */ jsxs("div", { className: styles.passengerCount, children: [
3810
+ /* @__PURE__ */ jsx(
3811
+ Button,
3812
+ {
3813
+ appearance: "outline",
3814
+ className: styles.counterButton,
3815
+ size: "small",
3816
+ icon: /* @__PURE__ */ jsx(Icon, { icon: "fluent:subtract-12-regular" }),
3817
+ onClick: (e) => {
3818
+ e.stopPropagation();
3819
+ handleDecrement(
3820
+ passengerType.passengerTypeCode,
3821
+ service.serviceName
3822
+ );
3823
+ },
3824
+ disabled: getServiceCount(
3825
+ passengerType.passengerTypeCode,
3826
+ service.serviceName
3827
+ ) === 0
3828
+ }
3829
+ ),
3830
+ /* @__PURE__ */ jsx(Body1, { className: styles.countText, children: getServiceCount(
3831
+ passengerType.passengerTypeCode,
3832
+ service.serviceName
3833
+ ) }),
3834
+ /* @__PURE__ */ jsx(
3835
+ Button,
3836
+ {
3837
+ appearance: "outline",
3838
+ className: styles.counterButton,
3839
+ size: "small",
3840
+ icon: /* @__PURE__ */ jsx(Icon, { icon: "fluent:add-12-regular" }),
3841
+ onClick: (e) => {
3842
+ e.stopPropagation();
3843
+ handleIncrement(
3844
+ passengerType.passengerTypeCode,
3845
+ service.serviceName
3846
+ );
3847
+ }
3848
+ }
3849
+ )
3850
+ ] })
3851
+ ] }, service.key)) }) })
3852
+ ]
3853
+ },
3854
+ passengerType.id
3855
+ );
3856
+ })
3857
+ }
3858
+ ),
3859
+ /* @__PURE__ */ jsx(
3860
+ Button,
3861
+ {
3862
+ appearance: "primary",
3863
+ size: "medium",
3864
+ className: styles.submitButton,
3865
+ onClick: handleSave,
3866
+ children: "Simpan"
3867
+ }
3868
+ )
3869
+ ] })
3870
+ ] })
3871
+ ] }) })
3872
+ }
3873
+ );
3874
+ };
3364
3875
 
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 };
3876
+ export { BackgroundTicketCard_default as BackgroundTicketCard, BackgroundTicketCardVertical_default as BackgroundTicketCardVertical, CardBanner, CardPromo, CardServiceMenu, CardTicket, CarouselWithCustomNav, DEFAULT_COUNTRY_CODES2 as DEFAULT_COUNTRY_CODES, DEFAULT_SERVICE_CLASSES, InputDynamic_default as InputDynamic, MODAL_PRESETS, ModalIllustration, ModalSearchHarbor, ModalSelectDate, ModalService, ModalTotalPassengers, getModalPreset };
3366
3877
  //# sourceMappingURL=index.mjs.map
3367
3878
  //# sourceMappingURL=index.mjs.map