@citizenplane/pimp 8.26.1 → 8.28.1

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.
Files changed (187) hide show
  1. package/dist/{IconAccompaniedMinorEach-CUq3oXbX.js → IconAccompaniedMinorEach-MkIJAypb.js} +1 -1
  2. package/dist/{IconAccompaniedMinorNone-nZ4eSfTj.js → IconAccompaniedMinorNone-DMb-bSCG.js} +1 -1
  3. package/dist/{IconAccompaniedMinorOne-CDMqq14b.js → IconAccompaniedMinorOne-C9ORHm66.js} +1 -1
  4. package/dist/{IconAddReceipt-DRpGiWBU.js → IconAddReceipt-CeJlKuX2.js} +1 -1
  5. package/dist/{IconAirportTerminal-8k-3lKjb.js → IconAirportTerminal-D3p4CRpN.js} +1 -1
  6. package/dist/{IconArrival-m6HnOVje.js → IconArrival-C3oPAqgQ.js} +1 -1
  7. package/dist/IconBaggageCabinNone-valcCKfd.js +22 -0
  8. package/dist/IconBaggageCheckedNone-oq4yx5cO.js +22 -0
  9. package/dist/IconBaggagePersonalNone-BovIoK0M.js +20 -0
  10. package/dist/{IconBroadcast-B13UworG.js → IconBroadcast-CqdgVQaO.js} +1 -1
  11. package/dist/{IconCabinBag-CNnzHz2B.js → IconCabinBag-CMrtn-s6.js} +1 -1
  12. package/dist/IconCalendar-DmUZ-Du1.js +30 -0
  13. package/dist/IconCalendarDelay-DHaiharm.js +22 -0
  14. package/dist/{IconCheckedBaggage-CkxUDHe9.js → IconCheckedBaggage-OeOjHxe7.js} +1 -1
  15. package/dist/{IconCheckedBaggage20-DEtphLSa.js → IconCheckedBaggage20-CXeWuJgc.js} +1 -1
  16. package/dist/{IconCheckedBaggage30-CmAddx5h.js → IconCheckedBaggage30-Cartaaei.js} +1 -1
  17. package/dist/{IconChild-OReHyUco.js → IconChild-ChjkS7Gd.js} +1 -1
  18. package/dist/{IconContact-D2N23RZ5.js → IconContact-CtOxYQIs.js} +1 -1
  19. package/dist/{IconDeparture-D10LaXRX.js → IconDeparture-DJxClL94.js} +1 -1
  20. package/dist/{IconDistribution-SpPiru9I.js → IconDistribution-BmCLzb9p.js} +1 -1
  21. package/dist/{IconDistributionClosed-Bzqe7nju.js → IconDistributionClosed-BMjqoyt9.js} +1 -1
  22. package/dist/{IconDistributionExclusivePair-CjPM-_R1.js → IconDistributionExclusivePair-D71kgwyk.js} +1 -1
  23. package/dist/{IconDistributionSided-DehjCN0D.js → IconDistributionSided-Du56cPXR.js} +1 -1
  24. package/dist/{IconDistributionSupplySided-DWCyXqd1.js → IconDistributionSupplySided-BY9ACIGQ.js} +1 -1
  25. package/dist/{IconDynamicContent-BvzbgXvW.js → IconDynamicContent-DoYbB86x.js} +1 -1
  26. package/dist/IconEndDate-CVABdl-P.js +22 -0
  27. package/dist/{IconFares-zARDpPNl.js → IconFares-BXnx8WJa.js} +1 -1
  28. package/dist/{IconFaresOutlined-DLFV8nwg.js → IconFaresOutlined-CjJhZUKX.js} +1 -1
  29. package/dist/{IconFemale-Ba4uoI-S.js → IconFemale-D4lMoNKt.js} +1 -1
  30. package/dist/{IconFindConversation-d0pP3wG9.js → IconFindConversation-CYdB5hW8.js} +1 -1
  31. package/dist/{IconFire-CXzWKoMB.js → IconFire-Bh3vQ1A3.js} +1 -1
  32. package/dist/{IconFlight-Cof8M5dO.js → IconFlight-RyDIRwoI.js} +1 -1
  33. package/dist/{IconFlightReturn-CA9iGMcW.js → IconFlightReturn-DN7K5zxX.js} +1 -1
  34. package/dist/IconFlightSchedule-DAX_cnvF.js +28 -0
  35. package/dist/{IconHandHeart-CCLKnMOm.js → IconHandHeart-C5jxr29k.js} +1 -1
  36. package/dist/{IconHistory-DI6WD_3J.js → IconHistory-CuJwcjfY.js} +1 -1
  37. package/dist/{IconHourGlass-BorNLEca.js → IconHourGlass-DyrZPbXz.js} +1 -1
  38. package/dist/{IconIdCard-DhbhBkul.js → IconIdCard-lBDLYRPq.js} +1 -1
  39. package/dist/{IconInfant-D4EztT9g.js → IconInfant-E19ozPuk.js} +1 -1
  40. package/dist/{IconItinerary-Bhj_lgG2.js → IconItinerary-5AEG0f9f.js} +1 -1
  41. package/dist/{IconLeave-BvpY7gdD.js → IconLeave-XuFJRd-0.js} +1 -1
  42. package/dist/{IconMale-RMd_9ZSg.js → IconMale-R2ZgQj0s.js} +1 -1
  43. package/dist/{IconMultiSegments-DROUj0t5.js → IconMultiSegments-DfiqdUEm.js} +1 -1
  44. package/dist/IconNoPassport-h-6DjTcc.js +22 -0
  45. package/dist/{IconNoRefund-yNAZr7uX.js → IconNoRefund-C5R_Zxke.js} +1 -1
  46. package/dist/IconNoSeat-C-XnWQk8.js +23 -0
  47. package/dist/{IconNotion-CpZhGILz.js → IconNotion-pdx45QBU.js} +1 -1
  48. package/dist/{IconOffline-Bf1mw_1N.js → IconOffline-EG6mJ-Fs.js} +1 -1
  49. package/dist/{IconOneWay-6oGoLo57.js → IconOneWay-CX6CckSB.js} +2 -2
  50. package/dist/{IconPaid-B3dvioAR.js → IconPaid-BJhBGPy9.js} +1 -1
  51. package/dist/IconPassport-C6THdLYf.js +37 -0
  52. package/dist/{IconPayout-b3TcXwjA.js → IconPayout-MS-qRRR0.js} +1 -1
  53. package/dist/IconPlug-yYpQdJgj.js +22 -0
  54. package/dist/IconPlugOff-DSGcBog-.js +23 -0
  55. package/dist/{IconReceipt-Dh454941.js → IconReceipt-ChU6nBry.js} +1 -1
  56. package/dist/IconRecurrence-DtwCmoXo.js +22 -0
  57. package/dist/{IconRefund-D-FNjukU.js → IconRefund-D1wQXsZj.js} +1 -1
  58. package/dist/{IconRoundTrip-BqVPrNwg.js → IconRoundTrip-DhPU15r6.js} +1 -1
  59. package/dist/{IconRouteNoStop-CZ_QeOIY.js → IconRouteNoStop-C5b0NI9V.js} +1 -1
  60. package/dist/{IconRouteOneStop-DGpLAQmQ.js → IconRouteOneStop-CDL4AJoN.js} +1 -1
  61. package/dist/IconScheduleChange-CasvbB9p.js +22 -0
  62. package/dist/{IconSeatEmpty-BwyVwYQZ.js → IconSeatEmpty-CUDMQzqk.js} +1 -1
  63. package/dist/{IconSeatSold-B_SNoTs-.js → IconSeatSold-mwtkmlhT.js} +1 -1
  64. package/dist/{IconSeatTotal-DUEF7k6I.js → IconSeatTotal-BPegCOjA.js} +1 -1
  65. package/dist/IconStartDate-DoPJpEly.js +22 -0
  66. package/dist/{IconTemplate-D1ACYaHI.js → IconTemplate-CQH8r3U7.js} +1 -1
  67. package/dist/{IconTicket-5Z4b83BP.js → IconTicket-mONYGHBg.js} +1 -1
  68. package/dist/{IconTimer-DbcddAPo.js → IconTimer-BxR1ymxu.js} +1 -1
  69. package/dist/{IconTrafficControl-CEzhRpZt.js → IconTrafficControl-AcQHu-Dm.js} +1 -1
  70. package/dist/{index-DbgX3-2I.js → index-CjeXy6n3.js} +17600 -18506
  71. package/dist/pimp.es.js +1 -1
  72. package/dist/pimp.umd.js +23 -23
  73. package/dist/style.css +1 -1
  74. package/package.json +2 -1
  75. package/src/components/{core/BaseInputLabel.vue → BaseInputLabel.vue} +9 -15
  76. package/src/components/{core/BaseSelectClearButton.vue → BaseSelectClearButton.vue} +2 -2
  77. package/src/components/{atomic-elements/CpAirlineLogo.vue → CpAirlineLogo.vue} +9 -10
  78. package/src/components/{feedback-indicators/CpAlert.vue → CpAlert.vue} +16 -27
  79. package/src/components/{atomic-elements/CpBadge.vue → CpBadge.vue} +27 -44
  80. package/src/components/{buttons/CpButton.vue → CpButton.vue} +63 -104
  81. package/src/components/{date-pickers/CpCalendar.vue → CpCalendar.vue} +157 -156
  82. package/src/components/{toggles/CpCheckbox.vue → CpCheckbox.vue} +45 -54
  83. package/src/components/{date-pickers/CpDate.vue → CpDate.vue} +202 -212
  84. package/src/components/CpDatepicker.vue +203 -0
  85. package/src/components/{atomic-elements/CpDialog.vue → CpDialog.vue} +14 -9
  86. package/src/components/{typography/CpHeading.vue → CpHeading.vue} +11 -31
  87. package/src/components/{visual/CpIcon.vue → CpIcon.vue} +2 -1
  88. package/src/components/{inputs/CpInput.vue → CpInput.vue} +41 -58
  89. package/src/components/{feedback-indicators/CpLoader.vue → CpLoader.vue} +7 -8
  90. package/src/components/{selects/CpMultiselect.vue → CpMultiselect.vue} +60 -91
  91. package/src/components/{atomic-elements/CpPartnerBadge.vue → CpPartnerBadge.vue} +12 -20
  92. package/src/components/{toggles/CpRadio.vue → CpRadio.vue} +47 -58
  93. package/src/components/{selects/CpSelect.vue → CpSelect.vue} +74 -94
  94. package/src/components/{selects/CpSelectMenu.vue → CpSelectMenu.vue} +94 -96
  95. package/src/components/{toggles/CpSwitch.vue → CpSwitch.vue} +51 -67
  96. package/src/components/{lists-and-table/CpTable.vue → CpTable.vue} +159 -113
  97. package/src/components/{lists-and-table/CpTableEmptyState.vue → CpTableEmptyState.vue} +5 -8
  98. package/src/components/{inputs/CpTextarea.vue → CpTextarea.vue} +32 -52
  99. package/src/components/CpToaster.vue +377 -0
  100. package/src/components/{atomic-elements/CpTooltip.vue → CpTooltip.vue} +12 -11
  101. package/src/components/TransitionExpand.vue +70 -0
  102. package/src/components/icons/IconBaggageCabinNone.vue +24 -0
  103. package/src/components/icons/IconBaggageCheckedNone.vue +25 -0
  104. package/src/components/icons/IconBaggagePersonalNone.vue +33 -0
  105. package/src/components/icons/IconCalendar.vue +17 -0
  106. package/src/components/icons/IconCalendarDelay.vue +21 -0
  107. package/src/components/icons/IconEndDate.vue +19 -0
  108. package/src/components/icons/IconFlightSchedule.vue +23 -0
  109. package/src/components/icons/IconNoPassport.vue +23 -24
  110. package/src/components/icons/IconNoSeat.vue +18 -0
  111. package/src/components/icons/IconOneWay.vue +1 -1
  112. package/src/components/icons/IconPassport.vue +15 -22
  113. package/src/components/icons/IconPlug.vue +17 -0
  114. package/src/components/icons/IconPlugOff.vue +18 -0
  115. package/src/components/icons/IconRecurrence.vue +17 -8
  116. package/src/components/icons/IconScheduleChange.vue +17 -26
  117. package/src/components/icons/IconStartDate.vue +19 -0
  118. package/src/components/index.ts +43 -55
  119. package/src/constants/{src/CpCustomIcons.ts → CpCustomIcons.ts} +13 -2
  120. package/src/constants/CpTableConfig.ts +12 -0
  121. package/src/constants/Heading.ts +8 -0
  122. package/src/{utils/constants/src/Intent.js → constants/Intent.ts} +1 -1
  123. package/src/constants/PartnerTypes.ts +6 -0
  124. package/src/constants/Position.ts +10 -0
  125. package/src/constants/Sizes.ts +5 -0
  126. package/src/constants/colors/Colors.ts +10 -0
  127. package/src/constants/colors/ToggleColors.ts +6 -0
  128. package/src/constants/index.ts +10 -5
  129. package/src/directives/ClickOutside.ts +17 -0
  130. package/src/directives/{ResizeSelect.js → ResizeSelect.ts} +3 -3
  131. package/src/helpers/{dom.js → dom.ts} +13 -9
  132. package/src/helpers/{index.js → index.ts} +13 -3
  133. package/src/helpers/object.ts +9 -0
  134. package/src/helpers/string/src/camelize.ts +6 -0
  135. package/src/helpers/string/src/{decamelize.js → decamelize.ts} +1 -1
  136. package/src/libs/CoreDatepicker.vue +4 -4
  137. package/src/plugins/toaster.ts +71 -0
  138. package/src/stories/BaseInputLabel.stories.ts +2 -1
  139. package/src/stories/CpAirlineLogo.stories.ts +1 -1
  140. package/src/stories/CpAlert.stories.ts +2 -1
  141. package/src/stories/CpBadge.stories.ts +1 -1
  142. package/src/stories/CpButton.stories.ts +1 -1
  143. package/src/stories/CpCheckbox.stories.ts +4 -2
  144. package/src/stories/CpDate.stories.ts +4 -2
  145. package/src/stories/CpDatepicker.stories.ts +4 -2
  146. package/src/stories/CpDialog.stories.ts +3 -2
  147. package/src/stories/CpHeading.stories.ts +2 -1
  148. package/src/stories/CpIcon.stories.ts +3 -1
  149. package/src/stories/CpInput.stories.ts +4 -2
  150. package/src/stories/CpLoader.stories.ts +2 -1
  151. package/src/stories/CpMultiselect.stories.ts +3 -2
  152. package/src/stories/CpPartnerBadge.stories.ts +2 -2
  153. package/src/stories/CpRadio.stories.ts +4 -2
  154. package/src/stories/CpSelect.stories.ts +4 -2
  155. package/src/stories/CpSelectMenu.stories.ts +4 -2
  156. package/src/stories/CpSwitch.stories.ts +4 -2
  157. package/src/stories/CpTable.stories.ts +9 -2
  158. package/src/stories/CpTableEmptyState.stories.ts +2 -1
  159. package/src/stories/CpTextarea.stories.ts +4 -2
  160. package/src/stories/CpToaster.stories.ts +2 -1
  161. package/src/stories/CpTooltip.stories.ts +2 -1
  162. package/src/stories/TransitionExpand.stories.ts +4 -2
  163. package/src/types/luxon.d.ts +1 -0
  164. package/src/vendors/ff-polyfill.ts +38 -0
  165. package/vitest.workspace.js +1 -3
  166. package/dist/IconNoPassport-DBmaQH_g.js +0 -18
  167. package/dist/IconPassport-5SwUf6_R.js +0 -20
  168. package/dist/IconRecurrence-CXVkBJ3i.js +0 -24
  169. package/dist/IconScheduleChange-CEIGEhU4.js +0 -19
  170. package/src/components/date-pickers/CpDatepicker.vue +0 -229
  171. package/src/components/feedback-indicators/CpToaster.vue +0 -372
  172. package/src/components/helpers-utilities/TransitionExpand.vue +0 -72
  173. package/src/constants/src/CpTableConfig.ts +0 -14
  174. package/src/constants/src/Position.ts +0 -10
  175. package/src/constants/src/colors/Colors.ts +0 -10
  176. package/src/constants/src/colors/ToggleColors.ts +0 -6
  177. package/src/directives/ClickOutside.js +0 -13
  178. package/src/helpers/object.js +0 -9
  179. package/src/helpers/string/src/camelize.js +0 -6
  180. package/src/plugins/toaster.js +0 -61
  181. package/src/utils/constants/index.js +0 -3
  182. package/src/utils/constants/src/PartnerTypes.js +0 -6
  183. package/src/utils/constants/src/Sizes.js +0 -5
  184. package/src/vendors/ff-polyfill.js +0 -36
  185. /package/src/components/{atomic-elements/CpDialogWrapper.vue → CpDialogWrapper.vue} +0 -0
  186. /package/src/components/{logo/Pimp.vue → Pimp.vue} +0 -0
  187. /package/src/helpers/string/{index.js → index.ts} +0 -0
@@ -15,7 +15,7 @@
15
15
  class="cpSelect__inner"
16
16
  @input="handleChange"
17
17
  >
18
- <option :disabled="hideDefaultValue || null" value="">{{ defaultValue }}</option>
18
+ <option :disabled="hideDefaultValue" value="">{{ defaultValue }}</option>
19
19
  <option v-for="(option, index) in options" :key="index" :value="option.value">{{ option.label }}</option>
20
20
  </select>
21
21
  </div>
@@ -32,100 +32,80 @@
32
32
  </div>
33
33
  </template>
34
34
 
35
- <script>
36
- import { randomString } from '@/helpers'
37
-
38
- import BaseInputLabel from '@/components/core/BaseInputLabel.vue'
39
- import TransitionExpand from '@/components/helpers-utilities/TransitionExpand.vue'
40
-
41
- import { capitalizeFirstLetter } from '@/helpers'
42
-
43
- export default {
44
- name: 'CpSelect',
45
- components: {
46
- BaseInputLabel,
47
- TransitionExpand,
48
- },
49
- props: {
50
- label: {
51
- type: String,
52
- default: '',
53
- },
54
- modelValue: {
55
- type: [String, Number],
56
- default: '',
57
- },
58
- hideDefaultValue: {
59
- type: Boolean,
60
- default: false,
61
- },
62
- defaultValue: {
63
- type: String,
64
- default: 'Select an option',
65
- },
66
- options: {
67
- type: Array,
68
- required: true,
69
- },
70
- name: {
71
- type: String,
72
- default: null,
73
- },
74
- required: {
75
- type: Boolean,
76
- default: null,
77
- },
78
- disabled: {
79
- type: Boolean,
80
- default: null,
81
- },
82
- autocomplete: {
83
- type: String,
84
- default: 'on',
85
- },
86
- isInvalid: {
87
- type: Boolean,
88
- default: false,
89
- },
90
- errorMessage: {
91
- type: String,
92
- default: '',
93
- },
94
- isLarge: {
95
- type: Boolean,
96
- default: false,
97
- },
98
- },
99
- emits: ['update:modelValue'],
100
- data() {
101
- return {
102
- selectReferenceId: '',
103
- }
104
- },
105
- computed: {
106
- capitalizedLabel() {
107
- return capitalizeFirstLetter(this.label)
108
- },
109
- dynamicClasses() {
110
- return {
111
- 'cpSelect--isInvalid': this.isInvalid,
112
- 'cpSelect--isDisabled': this.disabled,
113
- 'cpSelect--isLarge': this.isLarge,
114
- }
115
- },
116
- displayErrorMessage() {
117
- return this.isInvalid && this.errorMessage.length
118
- },
119
- },
120
- mounted() {
121
- this.selectReferenceId = randomString()
122
- },
123
- methods: {
124
- handleChange(e) {
125
- this.$emit('update:modelValue', e.target.value)
126
- },
127
- },
35
+ <script setup lang="ts">
36
+ import { ref, computed, onMounted } from 'vue'
37
+
38
+ import BaseInputLabel from '@/components/BaseInputLabel.vue'
39
+ import TransitionExpand from '@/components/TransitionExpand.vue'
40
+
41
+ import { randomString, capitalizeFirstLetter } from '@/helpers'
42
+
43
+ interface SelectOption {
44
+ label: string
45
+ value: string | number
46
+ }
47
+
48
+ interface Props {
49
+ autocomplete?: string
50
+ defaultValue?: string
51
+ disabled?: boolean
52
+ errorMessage?: string
53
+ hideDefaultValue?: boolean
54
+ isInvalid?: boolean
55
+ isLarge?: boolean
56
+ label?: string
57
+ modelValue?: string | number
58
+ name?: string
59
+ options: SelectOption[]
60
+ required?: boolean
61
+ }
62
+
63
+ interface Emits {
64
+ (e: 'update:modelValue', value: string): void
128
65
  }
66
+
67
+ const props = withDefaults(defineProps<Props>(), {
68
+ label: '',
69
+ modelValue: '',
70
+ hideDefaultValue: false,
71
+ defaultValue: 'Select an option',
72
+ name: undefined,
73
+ required: false,
74
+ disabled: false,
75
+ autocomplete: 'on',
76
+ isInvalid: false,
77
+ errorMessage: '',
78
+ isLarge: false,
79
+ })
80
+
81
+ const emit = defineEmits<Emits>()
82
+
83
+ const selectReferenceId = ref('')
84
+
85
+ const capitalizedLabel = computed(() => {
86
+ return capitalizeFirstLetter(props.label)
87
+ })
88
+
89
+ const dynamicClasses = computed(() => {
90
+ return {
91
+ 'cpSelect--isInvalid': props.isInvalid,
92
+ 'cpSelect--isDisabled': props.disabled,
93
+ 'cpSelect--isLarge': props.isLarge,
94
+ }
95
+ })
96
+
97
+ const displayErrorMessage = computed(() => {
98
+ return props.isInvalid && props.errorMessage.length
99
+ })
100
+
101
+ const handleChange = (e: Event): void => {
102
+ const target = e.target as HTMLSelectElement
103
+ emit('update:modelValue', target.value)
104
+ }
105
+
106
+ onMounted(() => {
107
+ selectReferenceId.value = randomString()
108
+ })
129
109
  </script>
130
110
 
131
111
  <style lang="scss">
@@ -46,106 +46,104 @@
46
46
  </div>
47
47
  </template>
48
48
 
49
- <script>
49
+ <script setup lang="ts">
50
50
  import { animate } from 'animejs'
51
+ import { ref, computed, nextTick } from 'vue'
51
52
 
52
- export default {
53
- props: {
54
- values: {
55
- type: Array,
56
- default: () => [],
57
- required: true,
58
- },
59
- selectedValue: {
60
- type: Object,
61
- default: () => {},
62
- required: true,
63
- },
64
- isMultiSelect: {
65
- type: Boolean,
66
- default: false,
67
- required: false,
68
- },
69
- hasFilter: {
70
- type: Boolean,
71
- default: false,
72
- required: false,
73
- },
74
- dropdownTitle: {
75
- type: String,
76
- default: 'Select value',
77
- required: false,
78
- },
79
- dropdownFilterPlaceholder: {
80
- type: String,
81
- default: 'Filter...',
82
- required: false,
83
- },
84
- dropdownEmptyViewPlaceholder: {
85
- type: String,
86
- default: 'No option found',
87
- required: false,
88
- },
89
- closeOnSelect: {
90
- type: Boolean,
91
- default: true,
92
- required: false,
93
- },
94
- },
95
- emits: ['update:selectedValue', 'on-close', 'on-filter-change'],
96
- data() {
97
- return {
98
- isDropdownOpen: false,
99
- }
100
- },
101
- computed: {
102
- inputType() {
103
- return (this.isMultiSelect && 'checkbox') || 'radio'
104
- },
105
- },
106
- methods: {
107
- enter() {
108
- animate(this.$refs.dropdownRef, {
109
- scale: [0.8, 1],
110
- opacity: [0, 1],
111
- duration: 200,
112
- ease: 'cubicBezier(0.175, 0.885, 0.32, 1.175)',
113
- })
114
- },
115
- toggleDropdown() {
116
- this.isDropdownOpen = !this.isDropdownOpen
117
-
118
- if (this.isDropdownOpen && this.hasFilter) {
119
- this.$nextTick(() => this.$refs.dropdownFilterRef.focus())
120
- }
121
- },
122
- closeDropdown() {
123
- if (!this.isDropdownOpen) {
124
- return
125
- }
53
+ interface SelectValue {
54
+ label: string
55
+ value: string
56
+ }
126
57
 
127
- this.isDropdownOpen = false
128
- this.resetInputValue()
129
- this.$emit('on-close')
130
- },
131
- onChange(value) {
132
- if (value.value !== this.selectedValue.value) {
133
- this.$emit('update:selectedValue', value)
134
- }
135
- if (this.closeOnSelect) {
136
- this.closeDropdown()
58
+ interface Props {
59
+ closeOnSelect?: boolean
60
+ dropdownEmptyViewPlaceholder?: string
61
+ dropdownFilterPlaceholder?: string
62
+ dropdownTitle?: string
63
+ hasFilter?: boolean
64
+ isMultiSelect?: boolean
65
+ selectedValue: SelectValue
66
+ values: SelectValue[]
67
+ }
68
+
69
+ interface Emits {
70
+ (e: 'update:selectedValue', value: SelectValue): void
71
+ (e: 'onClose'): void
72
+ (e: 'onFilterChange', value: string): void
73
+ }
74
+
75
+ const props = withDefaults(defineProps<Props>(), {
76
+ isMultiSelect: false,
77
+ hasFilter: false,
78
+ dropdownTitle: 'Select value',
79
+ dropdownFilterPlaceholder: 'Filter...',
80
+ dropdownEmptyViewPlaceholder: 'No option found',
81
+ closeOnSelect: true,
82
+ })
83
+
84
+ const emit = defineEmits<Emits>()
85
+
86
+ const isDropdownOpen = ref(false)
87
+ const dropdownRef = ref<HTMLElement>()
88
+ const dropdownFilterRef = ref<HTMLInputElement>()
89
+
90
+ const inputType = computed(() => {
91
+ return props.isMultiSelect ? 'checkbox' : 'radio'
92
+ })
93
+
94
+ const enter = (): void => {
95
+ if (dropdownRef.value) {
96
+ animate(dropdownRef.value, {
97
+ scale: [0.8, 1],
98
+ opacity: [0, 1],
99
+ duration: 200,
100
+ ease: 'cubicBezier(0.175, 0.885, 0.32, 1.175)',
101
+ })
102
+ }
103
+ }
104
+
105
+ const toggleDropdown = (): void => {
106
+ isDropdownOpen.value = !isDropdownOpen.value
107
+
108
+ if (isDropdownOpen.value && props.hasFilter) {
109
+ nextTick(() => {
110
+ if (dropdownFilterRef.value) {
111
+ dropdownFilterRef.value.focus()
137
112
  }
138
- },
139
- updateFilterValue(event) {
140
- this.$emit('on-filter-change', event.target.value)
141
- },
142
- resetInputValue() {
143
- this.$emit('on-filter-change', '')
144
- },
145
- isSelectedValue(value) {
146
- return value === this.selectedValue.value
147
- },
148
- },
113
+ })
114
+ }
115
+ }
116
+
117
+ const closeDropdown = (): void => {
118
+ if (!isDropdownOpen.value) {
119
+ return
120
+ }
121
+
122
+ isDropdownOpen.value = false
123
+ resetInputValue()
124
+ emit('onClose')
125
+ }
126
+
127
+ const onChange = (value: SelectValue): void => {
128
+ if (value.value !== props.selectedValue.value) {
129
+ emit('update:selectedValue', value)
130
+ }
131
+ if (props.closeOnSelect) {
132
+ closeDropdown()
133
+ }
134
+ }
135
+
136
+ const updateFilterValue = (event: Event): void => {
137
+ const target = event.target as HTMLInputElement
138
+ emit('onFilterChange', target.value)
139
+ }
140
+
141
+ const resetInputValue = (): void => {
142
+ emit('onFilterChange', '')
143
+ }
144
+
145
+ const isSelectedValue = (value: string): boolean => {
146
+ return value === props.selectedValue.value
149
147
  }
150
148
  </script>
151
149
 
@@ -22,76 +22,60 @@
22
22
  </label>
23
23
  </template>
24
24
 
25
- <script>
26
- import { capitalizeFirstLetter, randomString } from '@/helpers'
25
+ <script setup lang="ts">
26
+ import { ref, computed } from 'vue'
27
+
27
28
  import { ToggleColors } from '@/constants'
29
+ import { capitalizeFirstLetter, randomString } from '@/helpers'
28
30
 
29
- export default {
30
- props: {
31
- modelValue: {
32
- type: Boolean,
33
- default: null,
34
- },
35
- label: {
36
- type: String,
37
- default: '',
38
- },
39
- disabled: {
40
- type: Boolean,
41
- default: false,
42
- },
43
- groupName: {
44
- type: String,
45
- default: '',
46
- required: false,
47
- },
48
- color: {
49
- type: String,
50
- required: false,
51
- default: ToggleColors.BLUE,
52
- validator: (value) => Object.values(ToggleColors).includes(value),
53
- },
54
- reverseLabel: {
55
- type: Boolean,
56
- required: false,
57
- default: false,
58
- },
59
- autofocus: {
60
- type: Boolean,
61
- required: false,
62
- default: false,
63
- },
64
- },
65
- emits: ['update:modelValue'],
66
- data() {
67
- return {
68
- switchUniqueId: '',
69
- }
70
- },
71
- computed: {
72
- capitalizedColor() {
73
- return capitalizeFirstLetter(this.color)
74
- },
75
- computedClasses() {
76
- return [
77
- {
78
- 'cpSwitch--hasLabel': this.label,
79
- 'cpSwitch--isActive': this.modelValue,
80
- 'cpSwitch--isDisabled': this.disabled,
81
- 'cpSwitch--isReversed': this.reverseLabel,
82
- },
83
- `cpSwitch--is${this.capitalizedColor}`,
84
- ]
85
- },
86
- },
87
- mounted() {
88
- this.switchUniqueId = randomString()
89
- },
90
- methods: {
91
- handleClick(value) {
92
- this.$emit('update:modelValue', !value)
31
+ interface Props {
32
+ autofocus?: boolean
33
+ color?: string
34
+ disabled?: boolean
35
+ groupName?: string
36
+ label?: string
37
+ modelValue?: boolean
38
+ reverseLabel?: boolean
39
+ }
40
+
41
+ interface Emits {
42
+ (e: 'update:modelValue', value: boolean): void
43
+ }
44
+
45
+ const props = withDefaults(defineProps<Props>(), {
46
+ modelValue: false,
47
+ label: '',
48
+ disabled: false,
49
+ groupName: '',
50
+ color: ToggleColors.BLUE,
51
+ reverseLabel: false,
52
+ autofocus: false,
53
+ })
54
+
55
+ const emit = defineEmits<Emits>()
56
+
57
+ const switchUniqueId = ref('')
58
+
59
+ switchUniqueId.value = randomString()
60
+
61
+ const capitalizedColor = computed(() => {
62
+ return capitalizeFirstLetter(props.color)
63
+ })
64
+
65
+ const computedClasses = computed(() => {
66
+ return [
67
+ {
68
+ 'cpSwitch--hasLabel': props.label,
69
+ 'cpSwitch--isActive': props.modelValue,
70
+ 'cpSwitch--isDisabled': props.disabled,
71
+ 'cpSwitch--isReversed': props.reverseLabel,
93
72
  },
94
- },
73
+ `cpSwitch--is${capitalizedColor.value}`,
74
+ ]
75
+ })
76
+
77
+ const handleClick = (value: boolean): void => {
78
+ emit('update:modelValue', !value)
95
79
  }
96
80
  </script>
97
81