adata-ui 2.1.18 → 2.1.20
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/-error.vue +170 -170
- package/.editorconfig +12 -12
- package/.gitlab-ci.yml +16 -16
- package/.nuxtrc +1 -1
- package/.nvmrc +1 -1
- package/.playground/app.config.ts +5 -5
- package/.playground/nuxt.config.ts +3 -3
- package/README.md +75 -75
- package/app.config.ts +28 -28
- package/app.vue +8 -8
- package/assets/styles/index.scss +104 -104
- package/assets/styles/modules/_base.scss +5 -5
- package/assets/styles/modules/_typography.scss +152 -152
- package/components/elements/README.md +1 -1
- package/components/elements/a-select-row/index.vue +140 -140
- package/components/elements/accordion/AAccordion.vue +197 -197
- package/components/elements/accordion/AAccordionGroup/AAccordionGroup.vue +145 -145
- package/components/elements/accordion/AAccordionGroup/types.ts +20 -20
- package/components/elements/accordion/AAccordionGroup/ui.config.ts +22 -22
- package/components/elements/accordion/types.ts +14 -14
- package/components/elements/accordion/ui.config.ts +22 -22
- package/components/elements/alert/AAlert.vue +65 -65
- package/components/elements/banner/ABanner.vue +49 -49
- package/components/elements/bg-block/ABgBlock.vue +11 -11
- package/components/elements/button/AButton.vue +188 -188
- package/components/elements/button/types.ts +24 -24
- package/components/elements/button-login/index.vue +21 -21
- package/components/elements/calendar/ACalendar.vue +83 -83
- package/components/elements/carousel/ACarousel.vue +159 -159
- package/components/elements/carousel/config.ui.ts +15 -15
- package/components/elements/carousel/types.ts +18 -18
- package/components/elements/chip-wrapper/AChipWrapper.vue +80 -80
- package/components/elements/chip-wrapper/types.ts +12 -12
- package/components/elements/chips/AChips.vue +32 -32
- package/components/elements/companies/AOurClients.vue +42 -42
- package/components/elements/curve-block/ACurveBlock.vue +291 -291
- package/components/elements/digit-badge/ADigitBadge.vue +83 -83
- package/components/elements/error-template/index.vue +48 -48
- package/components/elements/error-template/types.ts +23 -23
- package/components/elements/feature-description/AFeatureDescription.vue +112 -112
- package/components/elements/illustrations/noAccess.vue +71 -71
- package/components/elements/infinite-carousel/AInfiniteCarousel.vue +57 -57
- package/components/elements/infinite-scroll/AInfiniteScroll.vue +33 -33
- package/components/elements/leave-note/ALeaveNote.vue +78 -78
- package/components/elements/pagination/APagination.vue +110 -110
- package/components/elements/photos-animation/APhotosAnimation.vue +85 -85
- package/components/elements/select/ASelect.vue +445 -445
- package/components/elements/select/ASelectMobile.vue +186 -186
- package/components/elements/select/ui/select-button.vue +112 -112
- package/components/elements/select/ui/select-list.vue +99 -99
- package/components/elements/show-more/AShowMore.vue +35 -35
- package/components/elements/skeleton/ASkeleton.vue +44 -44
- package/components/elements/star-rating/AStarRating.vue +181 -181
- package/components/elements/star-rating/types.ts +7 -7
- package/components/elements/star-rating/ui/Star.vue +74 -74
- package/components/elements/status-badge/AStatusBadge.vue +74 -74
- package/components/elements/table/ATable.vue +93 -93
- package/components/elements/table/table.config.ts +32 -32
- package/components/elements/tree-select/ATreeSelect.vue +169 -169
- package/components/elements/tree-select/TreeService.ts +249 -249
- package/components/elements/tree-select/components/tree-select-nodes.vue +90 -90
- package/components/elements/tree-select/types.ts +34 -34
- package/components/elements/tree-select-mobile/ATreeSelectMobile.vue +79 -79
- package/components/elements/tree-select-mobile/components/ATreeSelectNodesMobile.vue +175 -175
- package/components/features/color-mode/AColorMode.client.vue +53 -53
- package/components/features/dropdown/ADropdown.vue +124 -124
- package/components/features/go-top/GoTop.vue +58 -58
- package/components/features/lang-switcher/lang-switcher.vue +63 -63
- package/components/features/payment/banner/BasicPlusLimitBanner.vue +104 -104
- package/components/features/payment/banner/PaymentBanner.vue +108 -108
- package/components/features/payment/banner/UpSellBanner.vue +125 -125
- package/components/features/payment/process/PaymentKaspiQrSidePanel.vue +158 -158
- package/components/features/payment/process/PaymentKaspiRedirectSidePanel.vue +112 -112
- package/components/features/payment/process/PaymentMethodSidePanel.vue +121 -121
- package/components/features/payment/process/PaymentProcess.vue +138 -138
- package/components/features/payment/process/PaymentTopUpSidePanel.vue +130 -130
- package/components/features/pk-mobile-services/APkMobileServices.vue +149 -149
- package/components/features//321/201hange-version/AChangeVersion.vue +20 -20
- package/components/forms/README.md +1 -1
- package/components/forms/checkbox/ACheckbox.vue +149 -149
- package/components/forms/feedback-form/FeedbackForm.vue +177 -177
- package/components/forms/input/button/AInputButton.vue +53 -53
- package/components/forms/input/date/AInputDate.vue +213 -213
- package/components/forms/input/password/AInputPassword.vue +53 -53
- package/components/forms/input/standard/AInputStandard.vue +412 -412
- package/components/forms/input/textarea/ATextarea.vue +200 -200
- package/components/forms/radio-button/ARadioButton.vue +95 -95
- package/components/forms/request-demo/ARequestDemo.vue +108 -108
- package/components/forms/toggle/AToggle.vue +157 -157
- package/components/forms/toggle/types.ts +16 -16
- package/components/modals/AConfirmationEmail.vue +40 -40
- package/components/modals/AboutTariffModal.vue +114 -114
- package/components/modals/AnotherDeviceModal.vue +60 -60
- package/components/modals/ApplicationAcceptedModal.vue +47 -47
- package/components/modals/ConnectingTariffModal.vue +67 -67
- package/components/modals/ContactsMobileModel.vue +182 -182
- package/components/modals/ContentNavigationModal.vue +355 -355
- package/components/modals/Insufficient-funds-modal.vue +77 -77
- package/components/modals/LimitReachedModal.vue +30 -30
- package/components/modals/NoAccessModal.vue +37 -37
- package/components/modals/PaymentMethodModal.vue +101 -101
- package/components/modals/RedirectsBanksModal.vue +69 -69
- package/components/modals/ReplenishModal.vue +132 -132
- package/components/modals/ReportBugConfirmModal.vue +30 -30
- package/components/modals/ReportBugModal.vue +156 -156
- package/components/modals/Resend.vue +82 -82
- package/components/modals/SubmitApplicationModal.vue +123 -123
- package/components/modals/id/AuthModal.vue +82 -82
- package/components/modals/id/IdAutoLogoutModal.vue +45 -45
- package/components/modals/id/IdBanner.vue +61 -61
- package/components/modals/id/IdConfirmAccountOtpModal.vue +186 -186
- package/components/modals/id/IdConfirmSuccessfulModal.vue +41 -41
- package/components/modals/id/IdLoginModal.vue +330 -326
- package/components/modals/id/IdModals.vue +114 -114
- package/components/modals/id/IdNewPasswordModal.vue +129 -129
- package/components/modals/id/IdOtpInput.vue +155 -155
- package/components/modals/id/IdPasswordSuccessfulModal.vue +25 -25
- package/components/modals/id/IdRecoveryModal.vue +117 -117
- package/components/modals/id/IdRegistrationModal.vue +215 -215
- package/components/modals/id/IdResetPasswordOtpModal.vue +158 -158
- package/components/modals/id/IdTwoFactorModal.vue +130 -130
- package/components/navigation/README.md +1 -1
- package/components/navigation/bottom-navigation/ABottomNavigation.vue +106 -106
- package/components/navigation/breadcrumbs/ABreadcrumbs.vue +66 -66
- package/components/navigation/breadcrumbs/types.ts +4 -4
- package/components/navigation/footer/AFooter.vue +279 -279
- package/components/navigation/footer/ui/a-footer-accordion.vue +118 -118
- package/components/navigation/header/AHeader.vue +217 -217
- package/components/navigation/header/AlmatyContacts.vue +145 -145
- package/components/navigation/header/AstanaContacts.vue +67 -67
- package/components/navigation/header/CardGallery.vue +249 -249
- package/components/navigation/header/ContactMenu.vue +114 -114
- package/components/navigation/header/HeaderLink.vue +267 -267
- package/components/navigation/header/ListItem.vue +31 -31
- package/components/navigation/header/NavCard.vue +41 -41
- package/components/navigation/header/NavList.vue +131 -131
- package/components/navigation/header/NotificationsMenu.vue +51 -51
- package/components/navigation/header/ProductMenu.vue +143 -143
- package/components/navigation/header/ProfileMenu.vue +194 -194
- package/components/navigation/header/TopHeader.vue +194 -194
- package/components/navigation/header/types.ts +28 -28
- package/components/navigation/line-tabs/ALineTabs.vue +111 -111
- package/components/navigation/line-tabs/types.ts +21 -21
- package/components/navigation/mobile-navigation/AMobileNavigation.vue +104 -104
- package/components/navigation/pill-tabs/APillTabs.vue +171 -171
- package/components/navigation/pill-tabs/types.ts +23 -23
- package/components/navigation/side-navigation/ASideNavigation.vue +406 -406
- package/components/overlays/README.md +1 -1
- package/components/overlays/modal/AModal.vue +332 -332
- package/components/overlays/side-panel/ASidePanel.vue +439 -439
- package/components/overlays/sideover/ASlideover.vue +351 -351
- package/components/overlays/tooltip/ATooltip.vue +237 -237
- package/components/transitions/ATransitionHeight.vue +67 -67
- package/components/utils/index.ts +19 -19
- package/components/utils/removeTrailingSlash.ts +7 -7
- package/composables/highlight.ts +18 -18
- package/composables/modalsState.ts +8 -8
- package/composables/projectState.ts +2 -2
- package/composables/useAdaptive.ts +46 -46
- package/composables/useBuyTariffs.ts +91 -91
- package/composables/useCarouselScroll.ts +49 -49
- package/composables/useHeaderNavigationLinks.ts +453 -453
- package/composables/useIdModals.ts +36 -36
- package/composables/usePayment.ts +74 -74
- package/composables/useUIValidation.ts +16 -16
- package/composables/useUrls.ts +21 -21
- package/eslint.config.mjs +45 -45
- package/i18n/i18n.config.ts +21 -21
- package/i18n.config.ts +21 -21
- package/icons/adata-logo.vue +17 -17
- package/icons/ai-assistant.vue +13 -13
- package/icons/akimat.vue +20 -20
- package/icons/arrow/arrow-bottom-left-on-square.vue +5 -5
- package/icons/arrow/arrow-circle-down.vue +16 -16
- package/icons/arrow/arrow-circle-reset.vue +16 -16
- package/icons/arrow/arrow-corner.vue +9 -9
- package/icons/arrow/arrow-graph-down.vue +13 -13
- package/icons/arrow/arrow-graph-up.vue +14 -14
- package/icons/arrow/arrow-square-down.vue +15 -15
- package/icons/arrow/arrow-top-right-on-square.vue +6 -6
- package/icons/arrow-currency-gray.vue +5 -5
- package/icons/arrow-currency-green.vue +5 -5
- package/icons/arrow-currency-red.vue +5 -5
- package/icons/arrow-side-up.vue +6 -6
- package/icons/avatar.vue +12 -12
- package/icons/bank.vue +5 -5
- package/icons/block.vue +16 -16
- package/icons/bookmark/bookmark-filled.vue +18 -18
- package/icons/bookmark/bookmark.vue +5 -5
- package/icons/browsers/browser-duck.vue +65 -65
- package/icons/browsers/browser-google.vue +30 -30
- package/icons/browsers/browser-yandex.vue +13 -13
- package/icons/building-vector.vue +7 -7
- package/icons/calculator.vue +7 -7
- package/icons/calendar.vue +24 -24
- package/icons/car.vue +7 -7
- package/icons/chart-bar.vue +5 -5
- package/icons/chart-pie.vue +16 -16
- package/icons/check/check-circle.vue +6 -6
- package/icons/check/check-shield.vue +14 -14
- package/icons/check/check.vue +17 -17
- package/icons/check/checkmark-circle.vue +6 -6
- package/icons/check-sb.vue +7 -7
- package/icons/checkbox/checkbox-active.vue +17 -17
- package/icons/checkbox/checkbox-empty.vue +10 -10
- package/icons/checkbox/checkbox-intermediate.vue +7 -7
- package/icons/chevron/chevron-down.vue +5 -5
- package/icons/chevron/chevron-left.vue +5 -5
- package/icons/chevron/chevron-right.vue +5 -5
- package/icons/chevron/chevron-up.vue +5 -5
- package/icons/chevron/double-chevron-right.vue +12 -12
- package/icons/clipboard-text.vue +7 -7
- package/icons/clock.vue +25 -25
- package/icons/close.vue +16 -16
- package/icons/company/company-bazis.vue +21 -21
- package/icons/company/company-bereke.vue +25 -25
- package/icons/company/company-bigroup.vue +16 -16
- package/icons/company/company-erg.vue +17 -17
- package/icons/company/company-forte.vue +21 -21
- package/icons/company/company-halyk.vue +15 -15
- package/icons/company/company-jusan.vue +31 -31
- package/icons/company/company-kaspi.vue +14 -14
- package/icons/company/company-mycar.vue +13 -13
- package/icons/company/company-samruk.vue +21 -21
- package/icons/company-egov-small.vue +15 -15
- package/icons/company.vue +8 -8
- package/icons/copy.vue +7 -7
- package/icons/currency/currency-dollar.vue +16 -16
- package/icons/currency/currency-down.vue +22 -22
- package/icons/currency/currency-eur.vue +57 -57
- package/icons/currency/currency-rub.vue +7 -7
- package/icons/currency/currency-tenge.vue +9 -9
- package/icons/currency/currency-usd.vue +221 -221
- package/icons/currency/currency-yuan.vue +25 -25
- package/icons/default-avatar.vue +20 -20
- package/icons/delete.vue +7 -7
- package/icons/document.vue +5 -5
- package/icons/download.vue +11 -11
- package/icons/edit.vue +7 -7
- package/icons/education.vue +16 -16
- package/icons/egov-small.vue +7 -7
- package/icons/excel-icon.vue +14 -14
- package/icons/expand-window.vue +7 -7
- package/icons/eye-closed.vue +26 -26
- package/icons/eye-open.vue +7 -7
- package/icons/eye-opened.vue +23 -23
- package/icons/file/file.vue +16 -16
- package/icons/file/files.vue +16 -16
- package/icons/filter.vue +5 -5
- package/icons/flag.vue +7 -7
- package/icons/gift.vue +8 -8
- package/icons/globe.vue +16 -16
- package/icons/google.vue +41 -41
- package/icons/graph-pie.vue +14 -14
- package/icons/hand/hand-thumb-up-filled.vue +5 -5
- package/icons/hand/hand-thumb-up.vue +5 -5
- package/icons/hand-with-phone/hand-with-phone-dark.vue +52 -52
- package/icons/hand-with-phone/hand-with-phone-light.vue +52 -52
- package/icons/handshake.vue +5 -5
- package/icons/hcheck.vue +14 -14
- package/icons/hdocument.vue +7 -7
- package/icons/history.vue +5 -5
- package/icons/horizontal-more.vue +13 -13
- package/icons/hot-line.vue +6 -6
- package/icons/hummer.vue +16 -16
- package/icons/id.vue +7 -7
- package/icons/info/info-circle.vue +29 -29
- package/icons/invoice.vue +7 -7
- package/icons/judge.vue +14 -14
- package/icons/kaspi-qr.vue +13 -13
- package/icons/link-chain.vue +28 -28
- package/icons/link.vue +7 -7
- package/icons/linkedin.vue +24 -24
- package/icons/loader-circle.vue +27 -27
- package/icons/location.vue +8 -8
- package/icons/lock.vue +5 -5
- package/icons/logo.vue +15 -15
- package/icons/logout.vue +16 -16
- package/icons/magnify/magnifying-glass-minus.vue +8 -8
- package/icons/magnify/magnifying-glass-plus.vue +9 -9
- package/icons/magnify/magnifying-glass.vue +9 -9
- package/icons/mail.vue +7 -7
- package/icons/mailru.vue +34 -34
- package/icons/main-filter.vue +5 -5
- package/icons/map/map-pin-filled.vue +7 -7
- package/icons/map/map-pin-rect.vue +15 -15
- package/icons/map/map-pin.vue +7 -7
- package/icons/map-marker-start.vue +7 -7
- package/icons/map-paper.vue +5 -5
- package/icons/medal.vue +7 -7
- package/icons/menu-filled.vue +20 -20
- package/icons/menu.vue +8 -8
- package/icons/message/message.vue +12 -12
- package/icons/minus/minus-circle.vue +10 -10
- package/icons/money.vue +5 -5
- package/icons/monitoring.vue +10 -10
- package/icons/moon.vue +8 -8
- package/icons/more.vue +29 -29
- package/icons/note-pencil.vue +14 -14
- package/icons/note.vue +14 -14
- package/icons/notification.vue +16 -16
- package/icons/paperclip.vue +7 -7
- package/icons/payment/payment-card.vue +6 -6
- package/icons/payment/payment-kaspi.vue +11 -11
- package/icons/person-vector.vue +7 -7
- package/icons/person-with-briefcase.vue +10 -10
- package/icons/phone-filled.vue +5 -5
- package/icons/phone.vue +7 -7
- package/icons/plus/plus-circle.vue +8 -8
- package/icons/plus/plus.vue +13 -13
- package/icons/profile.vue +5 -5
- package/icons/radio/radio-check.vue +8 -8
- package/icons/radio/radio-empty.vue +10 -10
- package/icons/receipt.vue +8 -8
- package/icons/robot.vue +14 -14
- package/icons/sanctions.vue +8 -8
- package/icons/scales/scale.vue +16 -16
- package/icons/scales/scales.vue +5 -5
- package/icons/scales/standing-scales.vue +15 -15
- package/icons/search.vue +27 -27
- package/icons/share/share-alt.vue +5 -5
- package/icons/share/share.vue +14 -14
- package/icons/ship.vue +8 -8
- package/icons/socials/face-book.vue +15 -15
- package/icons/socials/instagram.vue +19 -19
- package/icons/socials/telegram.vue +15 -15
- package/icons/socials/tik-tok.vue +15 -15
- package/icons/socials/youtube.vue +16 -16
- package/icons/sort/sort-asc.vue +15 -15
- package/icons/sort/sort-desc.vue +15 -15
- package/icons/splitting-arrows.vue +8 -8
- package/icons/star/star-filled.vue +40 -40
- package/icons/star/star-half-filled.vue +20 -20
- package/icons/star/star.vue +25 -25
- package/icons/sun.vue +14 -14
- package/icons/sviazi.vue +5 -5
- package/icons/tag.vue +30 -30
- package/icons/tasks.vue +10 -10
- package/icons/tender-search.vue +11 -11
- package/icons/toasts/check-circle-toast.vue +6 -6
- package/icons/toasts/warning-triangle-toast.vue +7 -7
- package/icons/trash.vue +13 -13
- package/icons/triangle.vue +10 -10
- package/icons/truck.vue +7 -7
- package/icons/user-square.vue +14 -14
- package/icons/user.vue +22 -22
- package/icons/users-focus.vue +8 -8
- package/icons/users-three.vue +7 -7
- package/icons/users.vue +8 -8
- package/icons/warning/warning-circle.vue +29 -29
- package/icons/warning/warning-triangle-filled.vue +12 -12
- package/icons/warning/warning-triangle.vue +28 -28
- package/icons/whatsapp.vue +8 -8
- package/icons/work-bag.vue +11 -11
- package/icons/work-case.vue +9 -9
- package/icons/work-search.vue +10 -10
- package/icons/work.vue +5 -5
- package/icons/x-mark.vue +15 -15
- package/icons/yandex.vue +28 -28
- package/illustrations/address-location.vue +38 -38
- package/illustrations/ball-with-chain.vue +120 -120
- package/illustrations/bill.vue +133 -133
- package/illustrations/buildings.vue +82 -82
- package/illustrations/calendar.vue +156 -156
- package/illustrations/chains.vue +152 -152
- package/illustrations/coin-percent.vue +126 -126
- package/illustrations/coins-stack.vue +202 -202
- package/illustrations/delete-dark.vue +31 -31
- package/illustrations/delete.vue +32 -32
- package/illustrations/doc-with-stamp.vue +126 -126
- package/illustrations/document.vue +64 -64
- package/illustrations/door.vue +74 -74
- package/illustrations/empty-box.vue +77 -77
- package/illustrations/empty-wallet.vue +161 -161
- package/illustrations/graph-in-coin.vue +119 -119
- package/illustrations/hammer.vue +156 -156
- package/illustrations/hand-cash.vue +108 -108
- package/illustrations/info.vue +39 -39
- package/illustrations/mail.vue +68 -68
- package/illustrations/ok.vue +62 -62
- package/illustrations/people-group.vue +237 -237
- package/illustrations/person-with-phone.vue +187 -187
- package/illustrations/person.vue +159 -159
- package/illustrations/phone-check.vue +90 -90
- package/illustrations/phone-payment-method.vue +223 -223
- package/illustrations/stop-hand.vue +77 -77
- package/illustrations/stop-sign.vue +34 -34
- package/illustrations/suit.vue +111 -111
- package/illustrations/suitcase.vue +105 -105
- package/illustrations/terminal-dark.vue +48 -48
- package/illustrations/terminal.vue +234 -234
- package/illustrations/trash-can.vue +108 -108
- package/illustrations/turn-on-tariff.vue +38 -38
- package/illustrations/two-persons.vue +169 -169
- package/lang/en.ts +834 -834
- package/lang/kk.ts +836 -836
- package/lang/ru.ts +837 -837
- package/layouts/default.vue +13 -13
- package/nuxt.config.ts +88 -88
- package/package.json +69 -69
- package/plugins/maska.ts +4 -4
- package/plugins/toast.client.ts +58 -58
- package/public/kaspi/logo.svg +4 -4
- package/shared/constans/pages.ts +89 -89
- package/tailwind.config.ts +163 -163
- package/tests/AButton.test.ts +81 -81
- package/tsconfig.json +6 -6
- package/utils/getMaxZindex.ts +25 -25
- package/utils/localizedNavigation.ts +36 -36
- package/vitest.config.ts +14 -14
|
@@ -1,445 +1,445 @@
|
|
|
1
|
-
<script generic="T" lang="ts" setup>
|
|
2
|
-
import AInput from '~/components/forms/input/standard/AInputStandard.vue'
|
|
3
|
-
import AChips from '~/components/elements/chips/AChips.vue'
|
|
4
|
-
|
|
5
|
-
import { onClickOutside, useToggle } from '@vueuse/core'
|
|
6
|
-
import { isEqual } from 'lodash-es'
|
|
7
|
-
import type { Ref } from 'vue'
|
|
8
|
-
|
|
9
|
-
import { useFloating, offset, flip, shift, size as floatingSize, autoUpdate } from '@floating-ui/vue'
|
|
10
|
-
|
|
11
|
-
type Props = {
|
|
12
|
-
label: string
|
|
13
|
-
required?: boolean
|
|
14
|
-
options: T[]
|
|
15
|
-
hideOverflow?: boolean
|
|
16
|
-
keyToShow?: string
|
|
17
|
-
getOnlyKey?: boolean
|
|
18
|
-
keyToSelect?: string
|
|
19
|
-
clearable?: boolean
|
|
20
|
-
hasButtons?: boolean
|
|
21
|
-
disabled?: boolean
|
|
22
|
-
size?: 'sm' | 'md'
|
|
23
|
-
error?: string | string[]
|
|
24
|
-
startIcon?: object
|
|
25
|
-
searchable?: boolean
|
|
26
|
-
searchLabel?: string
|
|
27
|
-
searchKey?: string
|
|
28
|
-
searchFromOut?: boolean
|
|
29
|
-
multiple?: boolean
|
|
30
|
-
minimalWords?: boolean
|
|
31
|
-
canChipRemove?: boolean
|
|
32
|
-
showFirstItem?: boolean
|
|
33
|
-
buttonBg?: string
|
|
34
|
-
changeableModelValue?: boolean
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type Emits = {
|
|
38
|
-
(e: 'onChange', option?: T | T[]): void
|
|
39
|
-
(e: 'onSubmit', value?: T | T[]): void
|
|
40
|
-
(e: 'onClear'): void
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const props = withDefaults(defineProps<Props>(), {
|
|
44
|
-
required: false,
|
|
45
|
-
hideOverflow: false,
|
|
46
|
-
getOnlyKey: false,
|
|
47
|
-
keyToShow: 'name',
|
|
48
|
-
keyToSelect: 'id',
|
|
49
|
-
clearable: true,
|
|
50
|
-
hasButtons: false,
|
|
51
|
-
disabled: false,
|
|
52
|
-
size: 'sm',
|
|
53
|
-
error: undefined,
|
|
54
|
-
startIcon: undefined,
|
|
55
|
-
searchable: false,
|
|
56
|
-
searchLabel: 'Поиск...',
|
|
57
|
-
searchKey: 'name',
|
|
58
|
-
searchFromOut: false,
|
|
59
|
-
multiple: false,
|
|
60
|
-
minimalWords: false,
|
|
61
|
-
canChipRemove: true,
|
|
62
|
-
showFirstItem: false,
|
|
63
|
-
buttonBg: 'border-deepblue-50 bg-deepblue-50 dark:border-gray-900 dark:bg-gray-200/5',
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
const emits = defineEmits<Emits>()
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const reference = ref<HTMLElement | null>(null)
|
|
71
|
-
const floating = ref<HTMLElement | null>(null)
|
|
72
|
-
const { x, y, strategy, update } = useFloating(reference, floating, {
|
|
73
|
-
placement: 'bottom-start',
|
|
74
|
-
strategy: 'absolute',
|
|
75
|
-
middleware: [
|
|
76
|
-
offset(6),
|
|
77
|
-
flip({ fallbackPlacements: ['top-start'] }),
|
|
78
|
-
shift({ padding: 8 }),
|
|
79
|
-
floatingSize({
|
|
80
|
-
apply({ availableHeight, elements, rects }) {
|
|
81
|
-
const el = elements.floating as HTMLElement
|
|
82
|
-
el.style.width = `${rects.reference.width}px`
|
|
83
|
-
el.style.maxHeight = `${Math.max(140, Math.min(availableHeight, 320))}px`
|
|
84
|
-
el.style.overflowY = props.hideOverflow ? 'hidden' : 'auto'
|
|
85
|
-
},
|
|
86
|
-
}),
|
|
87
|
-
],
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
let cleanup: (() => void) | null = null
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const modelValue = defineModel<T | T[] | null | any>({ required: true })
|
|
95
|
-
const search = defineModel<T | null | any>('search')
|
|
96
|
-
const isOpen = defineModel<T | null | any>('open', {
|
|
97
|
-
default: false
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
const searchValue = ref('')
|
|
101
|
-
const toggleOpen = useToggle(isOpen)
|
|
102
|
-
const wrapper = ref<HTMLDivElement | null>()
|
|
103
|
-
const valueToShow = ref<T | T[] | null>()
|
|
104
|
-
const countedVisibleItems = ref(0)
|
|
105
|
-
|
|
106
|
-
const disabledStyles =
|
|
107
|
-
'disabled:pointer-events-none disabled:opacity-40 disabled:bg-deepblue-50 disabled:text-deepblue-200 disabled:dark:text-gray-500'
|
|
108
|
-
|
|
109
|
-
const componentOptions = computed(() =>
|
|
110
|
-
props.options.filter((item: T) => {
|
|
111
|
-
if (Array.isArray(props.searchKey) && props.searchKey.length === 2) {
|
|
112
|
-
return item[props.searchKey[0] as keyof T].toLowerCase().includes(searchValue.value.toLowerCase()) ||
|
|
113
|
-
item[props.searchKey[1] as keyof T].toLowerCase().includes(searchValue.value.toLowerCase())
|
|
114
|
-
} else {
|
|
115
|
-
return item[props.searchKey as keyof T].toLowerCase().includes(searchValue.value.toLowerCase())
|
|
116
|
-
}
|
|
117
|
-
})
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
onClickOutside(wrapper, () => {
|
|
121
|
-
if (isOpen.value) toggleOpen(false)
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
function onSelect(item: T) {
|
|
125
|
-
if (props.multiple) {
|
|
126
|
-
if (!Array.isArray(valueToShow.value) && !valueToShow.value) {
|
|
127
|
-
valueToShow.value = []
|
|
128
|
-
}
|
|
129
|
-
if (valueToShow.value.some((element: unknown) => isEqual(item, element))) {
|
|
130
|
-
valueToShow.value = (valueToShow as Ref<T[]>).value.filter(
|
|
131
|
-
(element: unknown) => !isEqual(item, element)
|
|
132
|
-
)
|
|
133
|
-
modelValue.value = props.getOnlyKey
|
|
134
|
-
? (modelValue as Ref<T[]>).value.filter(
|
|
135
|
-
(element: unknown) => !isEqual(item[props.keyToSelect as keyof T], element)
|
|
136
|
-
)
|
|
137
|
-
: (modelValue as Ref<T[]>).value.filter((element: unknown) => !isEqual(item, element))
|
|
138
|
-
emits('onChange', modelValue.value)
|
|
139
|
-
return
|
|
140
|
-
}
|
|
141
|
-
valueToShow.value.push(item)
|
|
142
|
-
if (Array.isArray(modelValue.value) && props.getOnlyKey) {
|
|
143
|
-
modelValue.value.push(item[props.keyToSelect as keyof T])
|
|
144
|
-
emits('onChange', modelValue.value)
|
|
145
|
-
} else if (!Array.isArray(modelValue.value)) {
|
|
146
|
-
console.error('model value must be array')
|
|
147
|
-
} else {
|
|
148
|
-
modelValue.value.push(item)
|
|
149
|
-
emits('onChange', modelValue.value)
|
|
150
|
-
}
|
|
151
|
-
} else {
|
|
152
|
-
valueToShow.value = item
|
|
153
|
-
if (props.getOnlyKey) {
|
|
154
|
-
modelValue.value = item[props.keyToSelect as keyof T]
|
|
155
|
-
emits('onChange', item)
|
|
156
|
-
toggleOpen(false)
|
|
157
|
-
} else {
|
|
158
|
-
modelValue.value = item
|
|
159
|
-
emits('onChange', item)
|
|
160
|
-
toggleOpen(false)
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function onClear() {
|
|
166
|
-
if (props.multiple) {
|
|
167
|
-
valueToShow.value = null
|
|
168
|
-
modelValue.value = []
|
|
169
|
-
} else {
|
|
170
|
-
valueToShow.value = null
|
|
171
|
-
modelValue.value = null
|
|
172
|
-
}
|
|
173
|
-
emits('onClear')
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function onClearFromMulti(index: number) {
|
|
177
|
-
valueToShow.value.splice(index, 1)
|
|
178
|
-
modelValue.value.splice(index, 1)
|
|
179
|
-
if (!valueToShow.value.length) {
|
|
180
|
-
valueToShow.value = null
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
watch(
|
|
185
|
-
() => isOpen.value,
|
|
186
|
-
(newValue: boolean) => {
|
|
187
|
-
if (!newValue) searchValue.value = ''
|
|
188
|
-
}
|
|
189
|
-
)
|
|
190
|
-
watch(
|
|
191
|
-
() => modelValue.value,
|
|
192
|
-
() => {
|
|
193
|
-
if (modelValue.value?.length == 0) valueToShow.value = null
|
|
194
|
-
|
|
195
|
-
if (props.changeableModelValue) {
|
|
196
|
-
valueToShow.value = props.options.find(el => el[props.keyToSelect as keyof T] === modelValue.value)
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
watch(
|
|
202
|
-
() => props.options,
|
|
203
|
-
() => {
|
|
204
|
-
if (props.showFirstItem && Array.isArray(props.options)) {
|
|
205
|
-
valueToShow.value = props.options[0]
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
)
|
|
209
|
-
|
|
210
|
-
onBeforeMount(() => {
|
|
211
|
-
if (modelValue.value && !props.getOnlyKey) {
|
|
212
|
-
valueToShow.value = modelValue.value
|
|
213
|
-
} else if (
|
|
214
|
-
(!props.multiple && props.getOnlyKey && modelValue.value) ||
|
|
215
|
-
modelValue.value === null
|
|
216
|
-
) {
|
|
217
|
-
const value = props.options.filter((i: T) => modelValue.value == i[props.keyToSelect])
|
|
218
|
-
valueToShow.value = value.length ? value[0] : null
|
|
219
|
-
} else if (modelValue.value && props.multiple && props.getOnlyKey) {
|
|
220
|
-
const value = props.options.filter((i: T) =>
|
|
221
|
-
modelValue.value.includes(i[props.keyToSelect as keyof T])
|
|
222
|
-
)
|
|
223
|
-
valueToShow.value = value.length ? value : null
|
|
224
|
-
} else if (!props.multiple && !props.label) {
|
|
225
|
-
valueToShow.value = props.options[0]
|
|
226
|
-
}
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
// onBeforeMount(() => {
|
|
230
|
-
// if (props.multiple && !Array.isArray(modelValue)) modelValue.value = []
|
|
231
|
-
// })
|
|
232
|
-
|
|
233
|
-
const buttonWidth = computed(() => wrapper.value?.offsetWidth - 50)
|
|
234
|
-
|
|
235
|
-
const countValueToShow = computed(() => {
|
|
236
|
-
if (props.multiple) {
|
|
237
|
-
return modelValue.value?.length
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
const maxWidthOfChip = computed(() => {
|
|
242
|
-
const minWidthOfChip = 100
|
|
243
|
-
if (countValueToShow.value) {
|
|
244
|
-
const width = (buttonWidth.value - 50) / countValueToShow.value
|
|
245
|
-
if (width < minWidthOfChip) {
|
|
246
|
-
return minWidthOfChip + 'px'
|
|
247
|
-
}
|
|
248
|
-
return width + 'px'
|
|
249
|
-
}
|
|
250
|
-
return props.minimalWords ? minWidthOfChip + 'px' : 'auto'
|
|
251
|
-
})
|
|
252
|
-
const countOfVisibleItems = computed(() => {
|
|
253
|
-
if (!valueToShow.value?.length) return undefined
|
|
254
|
-
const maxCountOfVisibleItems = Math.floor((wrapper.value?.offsetWidth - 50) / 120)
|
|
255
|
-
if (maxCountOfVisibleItems > valueToShow.value.length) return valueToShow.value.length
|
|
256
|
-
else return Math.abs(maxCountOfVisibleItems)
|
|
257
|
-
})
|
|
258
|
-
const countOfInvisibleItems = computed(() => {
|
|
259
|
-
if (!valueToShow.value?.length && !countOfVisibleItems.value) return undefined
|
|
260
|
-
return (valueToShow.value?.length || 0) - countOfVisibleItems.value
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
onMounted(() => (countedVisibleItems.value = countOfVisibleItems.value))
|
|
264
|
-
onUpdated(() => (countedVisibleItems.value = countOfVisibleItems.value))
|
|
265
|
-
defineExpose({
|
|
266
|
-
onClear
|
|
267
|
-
})
|
|
268
|
-
watch(() => isOpen.value, (open) => {
|
|
269
|
-
if (open && reference.value && floating.value) {
|
|
270
|
-
cleanup = autoUpdate(reference.value, floating.value, update)
|
|
271
|
-
} else {
|
|
272
|
-
cleanup?.()
|
|
273
|
-
cleanup = null
|
|
274
|
-
}
|
|
275
|
-
})
|
|
276
|
-
|
|
277
|
-
onUnmounted(() => cleanup?.())
|
|
278
|
-
</script>
|
|
279
|
-
<template>
|
|
280
|
-
<div ref="wrapper" class="relative w-full rounded-md text-sm">
|
|
281
|
-
<button
|
|
282
|
-
ref="reference"
|
|
283
|
-
:class="[
|
|
284
|
-
clearable ? 'pr-16' : 'pr-9',
|
|
285
|
-
{
|
|
286
|
-
'pb-0.5 pt-2.5': valueToShow && !multiple && label,
|
|
287
|
-
'border-red': error,
|
|
288
|
-
'!h-10': size === 'md'
|
|
289
|
-
},
|
|
290
|
-
disabledStyles,
|
|
291
|
-
buttonBg,
|
|
292
|
-
]"
|
|
293
|
-
:disabled="disabled"
|
|
294
|
-
class="hover:border-blue-700 focus-visible:outline-blue relative flex h-8 w-full items-center gap-2 rounded-md border border-solid py-1.5 pl-4 focus-visible:shadow-[0_0_0_4px#1B64B3] dark:hover:border-blue-500"
|
|
295
|
-
@click="toggleOpen()"
|
|
296
|
-
>
|
|
297
|
-
<span
|
|
298
|
-
v-if="valueToShow && !multiple && label"
|
|
299
|
-
class="ease pointer-events-none absolute left-4 top-[6px] text-[10px] leading-none text-gray-500 transition-all duration-300"
|
|
300
|
-
>
|
|
301
|
-
{{ label }}
|
|
302
|
-
<span v-if="required" class="text-red-500 dark:text-red-400">*</span>
|
|
303
|
-
</span>
|
|
304
|
-
<component :is="startIcon" v-if="startIcon" />
|
|
305
|
-
|
|
306
|
-
<span :class="{ 'py-1': size === 'md' }" class=" w-full text-start">
|
|
307
|
-
<span v-if="valueToShow">
|
|
308
|
-
<span v-if="!multiple" class="line-clamp-1 text-deepblue-900 dark:text-gray-200">
|
|
309
|
-
<slot name="single-selected" :value="valueToShow">{{ valueToShow[keyToShow] }}</slot>
|
|
310
|
-
</span>
|
|
311
|
-
<span
|
|
312
|
-
v-else-if="valueToShow"
|
|
313
|
-
:class="{ 'py-0': size === 'md' }"
|
|
314
|
-
class="flex gap-2 py-0.5 text-deepblue-900 dark:text-gray-200"
|
|
315
|
-
>
|
|
316
|
-
<a-chips
|
|
317
|
-
v-for="(item, index) in valueToShow.slice(0, countOfVisibleItems)"
|
|
318
|
-
:key="index"
|
|
319
|
-
:style="{ 'max-width': maxWidthOfChip }"
|
|
320
|
-
class="border-gray-500 text-deepblue-900 dark:text-gray-200"
|
|
321
|
-
view="standard"
|
|
322
|
-
@click.stop="canChipRemove ? onClearFromMulti(index) : (isOpen = true)"
|
|
323
|
-
>
|
|
324
|
-
<span class="truncate">{{ item[keyToShow] }}</span>
|
|
325
|
-
<button v-if="canChipRemove" class="rounded-full bg-deepblue-100 dark:bg-gray-200/10">
|
|
326
|
-
<a-icon-x-mark class="size-3 dark:text-gray-200" />
|
|
327
|
-
</button>
|
|
328
|
-
</a-chips>
|
|
329
|
-
<a-chips
|
|
330
|
-
v-if="(valueToShow?.length || 0) > countOfVisibleItems"
|
|
331
|
-
class="border-blue-700 text-blue-700 dark:border-blue-500 dark:text-blue-500 whitespace-nowrap"
|
|
332
|
-
>
|
|
333
|
-
+ {{ countOfInvisibleItems }}
|
|
334
|
-
</a-chips>
|
|
335
|
-
</span>
|
|
336
|
-
</span>
|
|
337
|
-
<span v-else class="body-400 text-gray-500">{{ label }}</span>
|
|
338
|
-
</span>
|
|
339
|
-
<button
|
|
340
|
-
v-if="((multiple && valueToShow?.length) || (!multiple && valueToShow)) && clearable"
|
|
341
|
-
class="absolute right-10 top-1/2 -translate-y-1/2 rounded-full bg-deepblue-100 dark:bg-gray-200/10"
|
|
342
|
-
@click.stop="onClear"
|
|
343
|
-
>
|
|
344
|
-
<a-icon-x-mark class="!m-0 text-base dark:text-gray-200" />
|
|
345
|
-
</button>
|
|
346
|
-
<span
|
|
347
|
-
:class="{ 'rotate-180': isOpen }"
|
|
348
|
-
class="absolute right-4 top-1/2 -translate-y-1/2 text-base transition-transform"
|
|
349
|
-
>
|
|
350
|
-
<a-icon-chevron-down class="!m-0" style="color: #9da3ac" />
|
|
351
|
-
</span>
|
|
352
|
-
</button>
|
|
353
|
-
<transition>
|
|
354
|
-
<div
|
|
355
|
-
v-if="isOpen"
|
|
356
|
-
ref="floating"
|
|
357
|
-
class="z-[10000] rounded-md bg-white shadow-[0_1px_8px_0_rgba(139,146,156,0.3)] dark:bg-gray-900"
|
|
358
|
-
:style="{
|
|
359
|
-
position: strategy,
|
|
360
|
-
left: x != null ? `${x}px` : '',
|
|
361
|
-
top: y != null ? `${y}px` : '',
|
|
362
|
-
}"
|
|
363
|
-
>
|
|
364
|
-
<slot :options="options" name="options">
|
|
365
|
-
<ul class="select m-2 max-h-[250px] overflow-y-auto overflow-x-hidden">
|
|
366
|
-
<li v-if="searchFromOut" class="p-1">
|
|
367
|
-
<a-input v-model="search" :label="searchLabel" :size="size" clearable color="gray" />
|
|
368
|
-
</li>
|
|
369
|
-
<li v-if="searchable" class="p-1">
|
|
370
|
-
<a-input
|
|
371
|
-
v-model="searchValue"
|
|
372
|
-
:label="searchLabel"
|
|
373
|
-
:size="size"
|
|
374
|
-
clearable
|
|
375
|
-
color="gray"
|
|
376
|
-
/>
|
|
377
|
-
</li>
|
|
378
|
-
<li v-for="(option, index) in componentOptions" :key="index">
|
|
379
|
-
<button
|
|
380
|
-
v-if="!multiple"
|
|
381
|
-
:class="{ 'dark:bg-[#E3E5E80D]': isEqual(valueToShow, option) }"
|
|
382
|
-
:disabled="isEqual(valueToShow, option)"
|
|
383
|
-
class="flex w-full items-center justify-between px-4 py-1.5 text-start hover:bg-deepblue-50 dark:bg-[#E3E5E80D]"
|
|
384
|
-
@click="onSelect(option)"
|
|
385
|
-
>
|
|
386
|
-
<span>
|
|
387
|
-
<slot name="option" :option="option">{{ option[keyToShow] }}</slot>
|
|
388
|
-
</span>
|
|
389
|
-
<span v-if="isEqual(valueToShow, option)">
|
|
390
|
-
<a-icon-check style="color: #0070eb" />
|
|
391
|
-
</span>
|
|
392
|
-
</button>
|
|
393
|
-
<button
|
|
394
|
-
v-else
|
|
395
|
-
:class="{
|
|
396
|
-
'dark:bg-[#E3E5E80D]':
|
|
397
|
-
valueToShow && valueToShow.some((item) => isEqual(option, item))
|
|
398
|
-
}"
|
|
399
|
-
class="flex w-full items-center justify-between px-4 py-1.5 text-start hover:bg-deepblue-50 dark:hover:bg-[#E3E5E80D]"
|
|
400
|
-
@click="onSelect(option)"
|
|
401
|
-
>
|
|
402
|
-
<span>{{ option[keyToShow] }}</span>
|
|
403
|
-
<span v-if="valueToShow && valueToShow.some((item) => isEqual(option, item))">
|
|
404
|
-
<a-icon-check style="color: #0070eb" />
|
|
405
|
-
</span>
|
|
406
|
-
</button>
|
|
407
|
-
</li>
|
|
408
|
-
</ul>
|
|
409
|
-
</slot>
|
|
410
|
-
<div
|
|
411
|
-
v-if="props.hasButtons"
|
|
412
|
-
class="-mb-2 flex w-full flex-col gap-2 rounded-md p-4 shadow-[0_-2px_8px_0#9DA3AC3D] xl:flex-row"
|
|
413
|
-
>
|
|
414
|
-
<slot name="buttons">
|
|
415
|
-
<a-button view="outline" variant="gray" block @click="onClear"> Сбросить </a-button>
|
|
416
|
-
<a-button block @click="emits('onSubmit', modelValue)"> Применить </a-button>
|
|
417
|
-
</slot>
|
|
418
|
-
</div>
|
|
419
|
-
</div>
|
|
420
|
-
</transition>
|
|
421
|
-
</div>
|
|
422
|
-
</template>
|
|
423
|
-
|
|
424
|
-
<style lang="scss" scoped>
|
|
425
|
-
.select {
|
|
426
|
-
&::-webkit-scrollbar {
|
|
427
|
-
border-radius: 2px 0 0 0;
|
|
428
|
-
width: 5px;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
/* Track */
|
|
432
|
-
&::-webkit-scrollbar-track {
|
|
433
|
-
background: #f1f1f1;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/* Handle */
|
|
437
|
-
&::-webkit-scrollbar-thumb {
|
|
438
|
-
background: #888;
|
|
439
|
-
}
|
|
440
|
-
button {
|
|
441
|
-
user-select: text !important;
|
|
442
|
-
cursor: pointer;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
</style>
|
|
1
|
+
<script generic="T" lang="ts" setup>
|
|
2
|
+
import AInput from '~/components/forms/input/standard/AInputStandard.vue'
|
|
3
|
+
import AChips from '~/components/elements/chips/AChips.vue'
|
|
4
|
+
|
|
5
|
+
import { onClickOutside, useToggle } from '@vueuse/core'
|
|
6
|
+
import { isEqual } from 'lodash-es'
|
|
7
|
+
import type { Ref } from 'vue'
|
|
8
|
+
|
|
9
|
+
import { useFloating, offset, flip, shift, size as floatingSize, autoUpdate } from '@floating-ui/vue'
|
|
10
|
+
|
|
11
|
+
type Props = {
|
|
12
|
+
label: string
|
|
13
|
+
required?: boolean
|
|
14
|
+
options: T[]
|
|
15
|
+
hideOverflow?: boolean
|
|
16
|
+
keyToShow?: string
|
|
17
|
+
getOnlyKey?: boolean
|
|
18
|
+
keyToSelect?: string
|
|
19
|
+
clearable?: boolean
|
|
20
|
+
hasButtons?: boolean
|
|
21
|
+
disabled?: boolean
|
|
22
|
+
size?: 'sm' | 'md'
|
|
23
|
+
error?: string | string[]
|
|
24
|
+
startIcon?: object
|
|
25
|
+
searchable?: boolean
|
|
26
|
+
searchLabel?: string
|
|
27
|
+
searchKey?: string
|
|
28
|
+
searchFromOut?: boolean
|
|
29
|
+
multiple?: boolean
|
|
30
|
+
minimalWords?: boolean
|
|
31
|
+
canChipRemove?: boolean
|
|
32
|
+
showFirstItem?: boolean
|
|
33
|
+
buttonBg?: string
|
|
34
|
+
changeableModelValue?: boolean
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type Emits = {
|
|
38
|
+
(e: 'onChange', option?: T | T[]): void
|
|
39
|
+
(e: 'onSubmit', value?: T | T[]): void
|
|
40
|
+
(e: 'onClear'): void
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
44
|
+
required: false,
|
|
45
|
+
hideOverflow: false,
|
|
46
|
+
getOnlyKey: false,
|
|
47
|
+
keyToShow: 'name',
|
|
48
|
+
keyToSelect: 'id',
|
|
49
|
+
clearable: true,
|
|
50
|
+
hasButtons: false,
|
|
51
|
+
disabled: false,
|
|
52
|
+
size: 'sm',
|
|
53
|
+
error: undefined,
|
|
54
|
+
startIcon: undefined,
|
|
55
|
+
searchable: false,
|
|
56
|
+
searchLabel: 'Поиск...',
|
|
57
|
+
searchKey: 'name',
|
|
58
|
+
searchFromOut: false,
|
|
59
|
+
multiple: false,
|
|
60
|
+
minimalWords: false,
|
|
61
|
+
canChipRemove: true,
|
|
62
|
+
showFirstItem: false,
|
|
63
|
+
buttonBg: 'border-deepblue-50 bg-deepblue-50 dark:border-gray-900 dark:bg-gray-200/5',
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const emits = defineEmits<Emits>()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
const reference = ref<HTMLElement | null>(null)
|
|
71
|
+
const floating = ref<HTMLElement | null>(null)
|
|
72
|
+
const { x, y, strategy, update } = useFloating(reference, floating, {
|
|
73
|
+
placement: 'bottom-start',
|
|
74
|
+
strategy: 'absolute',
|
|
75
|
+
middleware: [
|
|
76
|
+
offset(6),
|
|
77
|
+
flip({ fallbackPlacements: ['top-start'] }),
|
|
78
|
+
shift({ padding: 8 }),
|
|
79
|
+
floatingSize({
|
|
80
|
+
apply({ availableHeight, elements, rects }) {
|
|
81
|
+
const el = elements.floating as HTMLElement
|
|
82
|
+
el.style.width = `${rects.reference.width}px`
|
|
83
|
+
el.style.maxHeight = `${Math.max(140, Math.min(availableHeight, 320))}px`
|
|
84
|
+
el.style.overflowY = props.hideOverflow ? 'hidden' : 'auto'
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
],
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
let cleanup: (() => void) | null = null
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
const modelValue = defineModel<T | T[] | null | any>({ required: true })
|
|
95
|
+
const search = defineModel<T | null | any>('search')
|
|
96
|
+
const isOpen = defineModel<T | null | any>('open', {
|
|
97
|
+
default: false
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
const searchValue = ref('')
|
|
101
|
+
const toggleOpen = useToggle(isOpen)
|
|
102
|
+
const wrapper = ref<HTMLDivElement | null>()
|
|
103
|
+
const valueToShow = ref<T | T[] | null>()
|
|
104
|
+
const countedVisibleItems = ref(0)
|
|
105
|
+
|
|
106
|
+
const disabledStyles =
|
|
107
|
+
'disabled:pointer-events-none disabled:opacity-40 disabled:bg-deepblue-50 disabled:text-deepblue-200 disabled:dark:text-gray-500'
|
|
108
|
+
|
|
109
|
+
const componentOptions = computed(() =>
|
|
110
|
+
props.options.filter((item: T) => {
|
|
111
|
+
if (Array.isArray(props.searchKey) && props.searchKey.length === 2) {
|
|
112
|
+
return item[props.searchKey[0] as keyof T].toLowerCase().includes(searchValue.value.toLowerCase()) ||
|
|
113
|
+
item[props.searchKey[1] as keyof T].toLowerCase().includes(searchValue.value.toLowerCase())
|
|
114
|
+
} else {
|
|
115
|
+
return item[props.searchKey as keyof T].toLowerCase().includes(searchValue.value.toLowerCase())
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
onClickOutside(wrapper, () => {
|
|
121
|
+
if (isOpen.value) toggleOpen(false)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
function onSelect(item: T) {
|
|
125
|
+
if (props.multiple) {
|
|
126
|
+
if (!Array.isArray(valueToShow.value) && !valueToShow.value) {
|
|
127
|
+
valueToShow.value = []
|
|
128
|
+
}
|
|
129
|
+
if (valueToShow.value.some((element: unknown) => isEqual(item, element))) {
|
|
130
|
+
valueToShow.value = (valueToShow as Ref<T[]>).value.filter(
|
|
131
|
+
(element: unknown) => !isEqual(item, element)
|
|
132
|
+
)
|
|
133
|
+
modelValue.value = props.getOnlyKey
|
|
134
|
+
? (modelValue as Ref<T[]>).value.filter(
|
|
135
|
+
(element: unknown) => !isEqual(item[props.keyToSelect as keyof T], element)
|
|
136
|
+
)
|
|
137
|
+
: (modelValue as Ref<T[]>).value.filter((element: unknown) => !isEqual(item, element))
|
|
138
|
+
emits('onChange', modelValue.value)
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
valueToShow.value.push(item)
|
|
142
|
+
if (Array.isArray(modelValue.value) && props.getOnlyKey) {
|
|
143
|
+
modelValue.value.push(item[props.keyToSelect as keyof T])
|
|
144
|
+
emits('onChange', modelValue.value)
|
|
145
|
+
} else if (!Array.isArray(modelValue.value)) {
|
|
146
|
+
console.error('model value must be array')
|
|
147
|
+
} else {
|
|
148
|
+
modelValue.value.push(item)
|
|
149
|
+
emits('onChange', modelValue.value)
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
valueToShow.value = item
|
|
153
|
+
if (props.getOnlyKey) {
|
|
154
|
+
modelValue.value = item[props.keyToSelect as keyof T]
|
|
155
|
+
emits('onChange', item)
|
|
156
|
+
toggleOpen(false)
|
|
157
|
+
} else {
|
|
158
|
+
modelValue.value = item
|
|
159
|
+
emits('onChange', item)
|
|
160
|
+
toggleOpen(false)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function onClear() {
|
|
166
|
+
if (props.multiple) {
|
|
167
|
+
valueToShow.value = null
|
|
168
|
+
modelValue.value = []
|
|
169
|
+
} else {
|
|
170
|
+
valueToShow.value = null
|
|
171
|
+
modelValue.value = null
|
|
172
|
+
}
|
|
173
|
+
emits('onClear')
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function onClearFromMulti(index: number) {
|
|
177
|
+
valueToShow.value.splice(index, 1)
|
|
178
|
+
modelValue.value.splice(index, 1)
|
|
179
|
+
if (!valueToShow.value.length) {
|
|
180
|
+
valueToShow.value = null
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
watch(
|
|
185
|
+
() => isOpen.value,
|
|
186
|
+
(newValue: boolean) => {
|
|
187
|
+
if (!newValue) searchValue.value = ''
|
|
188
|
+
}
|
|
189
|
+
)
|
|
190
|
+
watch(
|
|
191
|
+
() => modelValue.value,
|
|
192
|
+
() => {
|
|
193
|
+
if (modelValue.value?.length == 0) valueToShow.value = null
|
|
194
|
+
|
|
195
|
+
if (props.changeableModelValue) {
|
|
196
|
+
valueToShow.value = props.options.find(el => el[props.keyToSelect as keyof T] === modelValue.value)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
watch(
|
|
202
|
+
() => props.options,
|
|
203
|
+
() => {
|
|
204
|
+
if (props.showFirstItem && Array.isArray(props.options)) {
|
|
205
|
+
valueToShow.value = props.options[0]
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
onBeforeMount(() => {
|
|
211
|
+
if (modelValue.value && !props.getOnlyKey) {
|
|
212
|
+
valueToShow.value = modelValue.value
|
|
213
|
+
} else if (
|
|
214
|
+
(!props.multiple && props.getOnlyKey && modelValue.value) ||
|
|
215
|
+
modelValue.value === null
|
|
216
|
+
) {
|
|
217
|
+
const value = props.options.filter((i: T) => modelValue.value == i[props.keyToSelect])
|
|
218
|
+
valueToShow.value = value.length ? value[0] : null
|
|
219
|
+
} else if (modelValue.value && props.multiple && props.getOnlyKey) {
|
|
220
|
+
const value = props.options.filter((i: T) =>
|
|
221
|
+
modelValue.value.includes(i[props.keyToSelect as keyof T])
|
|
222
|
+
)
|
|
223
|
+
valueToShow.value = value.length ? value : null
|
|
224
|
+
} else if (!props.multiple && !props.label) {
|
|
225
|
+
valueToShow.value = props.options[0]
|
|
226
|
+
}
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
// onBeforeMount(() => {
|
|
230
|
+
// if (props.multiple && !Array.isArray(modelValue)) modelValue.value = []
|
|
231
|
+
// })
|
|
232
|
+
|
|
233
|
+
const buttonWidth = computed(() => wrapper.value?.offsetWidth - 50)
|
|
234
|
+
|
|
235
|
+
const countValueToShow = computed(() => {
|
|
236
|
+
if (props.multiple) {
|
|
237
|
+
return modelValue.value?.length
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
const maxWidthOfChip = computed(() => {
|
|
242
|
+
const minWidthOfChip = 100
|
|
243
|
+
if (countValueToShow.value) {
|
|
244
|
+
const width = (buttonWidth.value - 50) / countValueToShow.value
|
|
245
|
+
if (width < minWidthOfChip) {
|
|
246
|
+
return minWidthOfChip + 'px'
|
|
247
|
+
}
|
|
248
|
+
return width + 'px'
|
|
249
|
+
}
|
|
250
|
+
return props.minimalWords ? minWidthOfChip + 'px' : 'auto'
|
|
251
|
+
})
|
|
252
|
+
const countOfVisibleItems = computed(() => {
|
|
253
|
+
if (!valueToShow.value?.length) return undefined
|
|
254
|
+
const maxCountOfVisibleItems = Math.floor((wrapper.value?.offsetWidth - 50) / 120)
|
|
255
|
+
if (maxCountOfVisibleItems > valueToShow.value.length) return valueToShow.value.length
|
|
256
|
+
else return Math.abs(maxCountOfVisibleItems)
|
|
257
|
+
})
|
|
258
|
+
const countOfInvisibleItems = computed(() => {
|
|
259
|
+
if (!valueToShow.value?.length && !countOfVisibleItems.value) return undefined
|
|
260
|
+
return (valueToShow.value?.length || 0) - countOfVisibleItems.value
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
onMounted(() => (countedVisibleItems.value = countOfVisibleItems.value))
|
|
264
|
+
onUpdated(() => (countedVisibleItems.value = countOfVisibleItems.value))
|
|
265
|
+
defineExpose({
|
|
266
|
+
onClear
|
|
267
|
+
})
|
|
268
|
+
watch(() => isOpen.value, (open) => {
|
|
269
|
+
if (open && reference.value && floating.value) {
|
|
270
|
+
cleanup = autoUpdate(reference.value, floating.value, update)
|
|
271
|
+
} else {
|
|
272
|
+
cleanup?.()
|
|
273
|
+
cleanup = null
|
|
274
|
+
}
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
onUnmounted(() => cleanup?.())
|
|
278
|
+
</script>
|
|
279
|
+
<template>
|
|
280
|
+
<div ref="wrapper" class="relative w-full rounded-md text-sm">
|
|
281
|
+
<button
|
|
282
|
+
ref="reference"
|
|
283
|
+
:class="[
|
|
284
|
+
clearable ? 'pr-16' : 'pr-9',
|
|
285
|
+
{
|
|
286
|
+
'pb-0.5 pt-2.5': valueToShow && !multiple && label,
|
|
287
|
+
'border-red': error,
|
|
288
|
+
'!h-10': size === 'md'
|
|
289
|
+
},
|
|
290
|
+
disabledStyles,
|
|
291
|
+
buttonBg,
|
|
292
|
+
]"
|
|
293
|
+
:disabled="disabled"
|
|
294
|
+
class="hover:border-blue-700 focus-visible:outline-blue relative flex h-8 w-full items-center gap-2 rounded-md border border-solid py-1.5 pl-4 focus-visible:shadow-[0_0_0_4px#1B64B3] dark:hover:border-blue-500"
|
|
295
|
+
@click="toggleOpen()"
|
|
296
|
+
>
|
|
297
|
+
<span
|
|
298
|
+
v-if="valueToShow && !multiple && label"
|
|
299
|
+
class="ease pointer-events-none absolute left-4 top-[6px] text-[10px] leading-none text-gray-500 transition-all duration-300"
|
|
300
|
+
>
|
|
301
|
+
{{ label }}
|
|
302
|
+
<span v-if="required" class="text-red-500 dark:text-red-400">*</span>
|
|
303
|
+
</span>
|
|
304
|
+
<component :is="startIcon" v-if="startIcon" />
|
|
305
|
+
|
|
306
|
+
<span :class="{ 'py-1': size === 'md' }" class=" w-full text-start">
|
|
307
|
+
<span v-if="valueToShow">
|
|
308
|
+
<span v-if="!multiple" class="line-clamp-1 text-deepblue-900 dark:text-gray-200">
|
|
309
|
+
<slot name="single-selected" :value="valueToShow">{{ valueToShow[keyToShow] }}</slot>
|
|
310
|
+
</span>
|
|
311
|
+
<span
|
|
312
|
+
v-else-if="valueToShow"
|
|
313
|
+
:class="{ 'py-0': size === 'md' }"
|
|
314
|
+
class="flex gap-2 py-0.5 text-deepblue-900 dark:text-gray-200"
|
|
315
|
+
>
|
|
316
|
+
<a-chips
|
|
317
|
+
v-for="(item, index) in valueToShow.slice(0, countOfVisibleItems)"
|
|
318
|
+
:key="index"
|
|
319
|
+
:style="{ 'max-width': maxWidthOfChip }"
|
|
320
|
+
class="border-gray-500 text-deepblue-900 dark:text-gray-200"
|
|
321
|
+
view="standard"
|
|
322
|
+
@click.stop="canChipRemove ? onClearFromMulti(index) : (isOpen = true)"
|
|
323
|
+
>
|
|
324
|
+
<span class="truncate">{{ item[keyToShow] }}</span>
|
|
325
|
+
<button v-if="canChipRemove" class="rounded-full bg-deepblue-100 dark:bg-gray-200/10">
|
|
326
|
+
<a-icon-x-mark class="size-3 dark:text-gray-200" />
|
|
327
|
+
</button>
|
|
328
|
+
</a-chips>
|
|
329
|
+
<a-chips
|
|
330
|
+
v-if="(valueToShow?.length || 0) > countOfVisibleItems"
|
|
331
|
+
class="border-blue-700 text-blue-700 dark:border-blue-500 dark:text-blue-500 whitespace-nowrap"
|
|
332
|
+
>
|
|
333
|
+
+ {{ countOfInvisibleItems }}
|
|
334
|
+
</a-chips>
|
|
335
|
+
</span>
|
|
336
|
+
</span>
|
|
337
|
+
<span v-else class="body-400 text-gray-500">{{ label }}</span>
|
|
338
|
+
</span>
|
|
339
|
+
<button
|
|
340
|
+
v-if="((multiple && valueToShow?.length) || (!multiple && valueToShow)) && clearable"
|
|
341
|
+
class="absolute right-10 top-1/2 -translate-y-1/2 rounded-full bg-deepblue-100 dark:bg-gray-200/10"
|
|
342
|
+
@click.stop="onClear"
|
|
343
|
+
>
|
|
344
|
+
<a-icon-x-mark class="!m-0 text-base dark:text-gray-200" />
|
|
345
|
+
</button>
|
|
346
|
+
<span
|
|
347
|
+
:class="{ 'rotate-180': isOpen }"
|
|
348
|
+
class="absolute right-4 top-1/2 -translate-y-1/2 text-base transition-transform"
|
|
349
|
+
>
|
|
350
|
+
<a-icon-chevron-down class="!m-0" style="color: #9da3ac" />
|
|
351
|
+
</span>
|
|
352
|
+
</button>
|
|
353
|
+
<transition>
|
|
354
|
+
<div
|
|
355
|
+
v-if="isOpen"
|
|
356
|
+
ref="floating"
|
|
357
|
+
class="z-[10000] rounded-md bg-white shadow-[0_1px_8px_0_rgba(139,146,156,0.3)] dark:bg-gray-900"
|
|
358
|
+
:style="{
|
|
359
|
+
position: strategy,
|
|
360
|
+
left: x != null ? `${x}px` : '',
|
|
361
|
+
top: y != null ? `${y}px` : '',
|
|
362
|
+
}"
|
|
363
|
+
>
|
|
364
|
+
<slot :options="options" name="options">
|
|
365
|
+
<ul class="select m-2 max-h-[250px] overflow-y-auto overflow-x-hidden">
|
|
366
|
+
<li v-if="searchFromOut" class="p-1">
|
|
367
|
+
<a-input v-model="search" :label="searchLabel" :size="size" clearable color="gray" />
|
|
368
|
+
</li>
|
|
369
|
+
<li v-if="searchable" class="p-1">
|
|
370
|
+
<a-input
|
|
371
|
+
v-model="searchValue"
|
|
372
|
+
:label="searchLabel"
|
|
373
|
+
:size="size"
|
|
374
|
+
clearable
|
|
375
|
+
color="gray"
|
|
376
|
+
/>
|
|
377
|
+
</li>
|
|
378
|
+
<li v-for="(option, index) in componentOptions" :key="index">
|
|
379
|
+
<button
|
|
380
|
+
v-if="!multiple"
|
|
381
|
+
:class="{ 'dark:bg-[#E3E5E80D]': isEqual(valueToShow, option) }"
|
|
382
|
+
:disabled="isEqual(valueToShow, option)"
|
|
383
|
+
class="flex w-full items-center justify-between px-4 py-1.5 text-start hover:bg-deepblue-50 dark:bg-[#E3E5E80D]"
|
|
384
|
+
@click="onSelect(option)"
|
|
385
|
+
>
|
|
386
|
+
<span>
|
|
387
|
+
<slot name="option" :option="option">{{ option[keyToShow] }}</slot>
|
|
388
|
+
</span>
|
|
389
|
+
<span v-if="isEqual(valueToShow, option)">
|
|
390
|
+
<a-icon-check style="color: #0070eb" />
|
|
391
|
+
</span>
|
|
392
|
+
</button>
|
|
393
|
+
<button
|
|
394
|
+
v-else
|
|
395
|
+
:class="{
|
|
396
|
+
'dark:bg-[#E3E5E80D]':
|
|
397
|
+
valueToShow && valueToShow.some((item) => isEqual(option, item))
|
|
398
|
+
}"
|
|
399
|
+
class="flex w-full items-center justify-between px-4 py-1.5 text-start hover:bg-deepblue-50 dark:hover:bg-[#E3E5E80D]"
|
|
400
|
+
@click="onSelect(option)"
|
|
401
|
+
>
|
|
402
|
+
<span>{{ option[keyToShow] }}</span>
|
|
403
|
+
<span v-if="valueToShow && valueToShow.some((item) => isEqual(option, item))">
|
|
404
|
+
<a-icon-check style="color: #0070eb" />
|
|
405
|
+
</span>
|
|
406
|
+
</button>
|
|
407
|
+
</li>
|
|
408
|
+
</ul>
|
|
409
|
+
</slot>
|
|
410
|
+
<div
|
|
411
|
+
v-if="props.hasButtons"
|
|
412
|
+
class="-mb-2 flex w-full flex-col gap-2 rounded-md p-4 shadow-[0_-2px_8px_0#9DA3AC3D] xl:flex-row"
|
|
413
|
+
>
|
|
414
|
+
<slot name="buttons">
|
|
415
|
+
<a-button view="outline" variant="gray" block @click="onClear"> Сбросить </a-button>
|
|
416
|
+
<a-button block @click="emits('onSubmit', modelValue)"> Применить </a-button>
|
|
417
|
+
</slot>
|
|
418
|
+
</div>
|
|
419
|
+
</div>
|
|
420
|
+
</transition>
|
|
421
|
+
</div>
|
|
422
|
+
</template>
|
|
423
|
+
|
|
424
|
+
<style lang="scss" scoped>
|
|
425
|
+
.select {
|
|
426
|
+
&::-webkit-scrollbar {
|
|
427
|
+
border-radius: 2px 0 0 0;
|
|
428
|
+
width: 5px;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/* Track */
|
|
432
|
+
&::-webkit-scrollbar-track {
|
|
433
|
+
background: #f1f1f1;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/* Handle */
|
|
437
|
+
&::-webkit-scrollbar-thumb {
|
|
438
|
+
background: #888;
|
|
439
|
+
}
|
|
440
|
+
button {
|
|
441
|
+
user-select: text !important;
|
|
442
|
+
cursor: pointer;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
</style>
|