@asdp/ferryui 0.1.6 → 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, Checkbox, typographyStyles, 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';
@@ -3553,6 +3553,326 @@ var ModalService = ({
3553
3553
  );
3554
3554
  };
3555
3555
 
3556
- 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, ModalService, getModalPreset };
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
+ };
3875
+
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 };
3557
3877
  //# sourceMappingURL=index.mjs.map
3558
3878
  //# sourceMappingURL=index.mjs.map