@citizenplane/pimp 8.26.0 → 8.27.0

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 (150) hide show
  1. package/dist/{IconAccompaniedMinorEach-DDeSlaA_.js → IconAccompaniedMinorEach-BJYaPpW3.js} +1 -1
  2. package/dist/{IconAccompaniedMinorNone-BKs1gk1K.js → IconAccompaniedMinorNone-D1JR2Qpd.js} +1 -1
  3. package/dist/{IconAccompaniedMinorOne-CpL8FNve.js → IconAccompaniedMinorOne-BJ3jzEDZ.js} +1 -1
  4. package/dist/{IconAddReceipt-DLH3pqjA.js → IconAddReceipt-BX_va94f.js} +1 -1
  5. package/dist/{IconAirportTerminal-Cc4CU6MC.js → IconAirportTerminal-Dzr98nfc.js} +1 -1
  6. package/dist/{IconArrival-CdtUsRVo.js → IconArrival-Ced9HrJH.js} +1 -1
  7. package/dist/{IconBroadcast-QjMZtFA9.js → IconBroadcast-BYX44Wak.js} +1 -1
  8. package/dist/{IconCabinBag-xVC6mOQF.js → IconCabinBag-D1Qs952U.js} +1 -1
  9. package/dist/{IconCheckedBaggage-I_1h49TJ.js → IconCheckedBaggage-Q4_SQL9l.js} +1 -1
  10. package/dist/{IconCheckedBaggage20-CyPcsqrn.js → IconCheckedBaggage20-DVH1-A0V.js} +1 -1
  11. package/dist/{IconCheckedBaggage30-s5htbUIA.js → IconCheckedBaggage30-DYOAf-7Z.js} +1 -1
  12. package/dist/{IconChild-DL43kbm1.js → IconChild-BeCLAr8Y.js} +1 -1
  13. package/dist/{IconContact-FdhTr03q.js → IconContact-B3r39fyI.js} +1 -1
  14. package/dist/{IconDeparture-DNR3OGPD.js → IconDeparture-BflKZUiE.js} +1 -1
  15. package/dist/{IconDistribution-Cl8L6177.js → IconDistribution-CBxQ7UWb.js} +1 -1
  16. package/dist/{IconDistributionClosed-DBT6wR78.js → IconDistributionClosed-BWp_k24K.js} +1 -1
  17. package/dist/{IconDistributionExclusivePair-CkRG6yNV.js → IconDistributionExclusivePair-erLbcLps.js} +1 -1
  18. package/dist/{IconDistributionSided-D_wdvDNf.js → IconDistributionSided-y000n4qB.js} +1 -1
  19. package/dist/{IconDistributionSupplySided-C3VcE8Dw.js → IconDistributionSupplySided-7kCvGwnz.js} +1 -1
  20. package/dist/{IconDynamicContent-Ct1HRd3s.js → IconDynamicContent-SwBxkPMB.js} +1 -1
  21. package/dist/{IconFares-dIGVrtE4.js → IconFares-DTm0Q_RI.js} +1 -1
  22. package/dist/{IconFaresOutlined-bd8kT44f.js → IconFaresOutlined-BFMo_x9Q.js} +1 -1
  23. package/dist/{IconFemale-CMeYHrDy.js → IconFemale-Ma0KeaEM.js} +1 -1
  24. package/dist/{IconFindConversation-BdN2Yd3R.js → IconFindConversation-CpsDYPgD.js} +1 -1
  25. package/dist/{IconFire-obwuluyJ.js → IconFire-DECrDnLM.js} +1 -1
  26. package/dist/{IconFlight-B_6tJxB3.js → IconFlight-D5M0A0CM.js} +1 -1
  27. package/dist/{IconFlightReturn-BEO97PwR.js → IconFlightReturn-CTvqEFME.js} +1 -1
  28. package/dist/{IconHandHeart-hs0yFSEL.js → IconHandHeart-ChgdfXQa.js} +1 -1
  29. package/dist/{IconHistory-CT-jOMRt.js → IconHistory-DpIXDYI5.js} +1 -1
  30. package/dist/{IconHourGlass-CF940vmy.js → IconHourGlass-CIRkFUSM.js} +1 -1
  31. package/dist/{IconIdCard-DKkU58Ix.js → IconIdCard-UD5VZsUi.js} +1 -1
  32. package/dist/{IconInfant-DIUT-6_4.js → IconInfant-CmLUvWpO.js} +1 -1
  33. package/dist/{IconItinerary-D7mOGUmj.js → IconItinerary-CY8irele.js} +1 -1
  34. package/dist/{IconLeave-BExl4uyV.js → IconLeave-C3bpPz6L.js} +1 -1
  35. package/dist/{IconMale-eHGH5XBz.js → IconMale-x4xdulWB.js} +1 -1
  36. package/dist/{IconMultiSegments-KkrKiZrK.js → IconMultiSegments-BhTMfvhQ.js} +1 -1
  37. package/dist/{IconNoPassport-PJ2QqqoI.js → IconNoPassport-_Xm76k6b.js} +1 -1
  38. package/dist/{IconNoRefund-W47AQisu.js → IconNoRefund-B78s0oyF.js} +1 -1
  39. package/dist/{IconNotion-CCnhatKK.js → IconNotion-C22PTLTU.js} +1 -1
  40. package/dist/{IconOffline-3wunTEJG.js → IconOffline-BDzikWE9.js} +1 -1
  41. package/dist/{IconOneWay-BQ5K41Bu.js → IconOneWay-DlTVxokv.js} +2 -2
  42. package/dist/{IconPaid-zwDwWzF8.js → IconPaid-DmGERe85.js} +1 -1
  43. package/dist/{IconPassport-IxhNLS8P.js → IconPassport-6VOlXjxJ.js} +1 -1
  44. package/dist/{IconPayout-BNSON3dj.js → IconPayout-abr6BXCd.js} +1 -1
  45. package/dist/{IconReceipt-DOosYtgi.js → IconReceipt-BnTaihcq.js} +1 -1
  46. package/dist/{IconRecurrence-B8i5kO2Q.js → IconRecurrence-C5TPG2ht.js} +1 -1
  47. package/dist/{IconRefund-DkjF9lEI.js → IconRefund-Ysv8pyMJ.js} +1 -1
  48. package/dist/{IconRoundTrip-BZvhS65z.js → IconRoundTrip-CIVDw8LK.js} +1 -1
  49. package/dist/{IconRouteNoStop-CeSlfnpx.js → IconRouteNoStop-DQrq4gW5.js} +1 -1
  50. package/dist/{IconRouteOneStop-aP1Mj-Bv.js → IconRouteOneStop-pzisj4i4.js} +1 -1
  51. package/dist/{IconScheduleChange-QQ4AMAMI.js → IconScheduleChange-BONs1AAT.js} +1 -1
  52. package/dist/{IconSeatEmpty-DgVBD165.js → IconSeatEmpty-CHij3aGA.js} +1 -1
  53. package/dist/{IconSeatSold-BGBwNZUa.js → IconSeatSold-QspS_zCh.js} +1 -1
  54. package/dist/{IconSeatTotal-Dq9uXccZ.js → IconSeatTotal-DTZ1TcAX.js} +1 -1
  55. package/dist/{IconTemplate-BgruEhjI.js → IconTemplate-BDmmr-9L.js} +1 -1
  56. package/dist/{IconTicket-BTaYnuPt.js → IconTicket--vVn61Ey.js} +1 -1
  57. package/dist/{IconTimer-CyJzne5T.js → IconTimer-CspKpwqZ.js} +1 -1
  58. package/dist/{IconTrafficControl-BeQtpwhK.js → IconTrafficControl-DBamcJNe.js} +1 -1
  59. package/dist/{index-B8RNa4cx.js → index-C3oHnZQk.js} +9152 -10064
  60. package/dist/pimp.es.js +1 -1
  61. package/dist/pimp.umd.js +17 -17
  62. package/dist/style.css +1 -1
  63. package/package.json +2 -1
  64. package/src/components/atomic-elements/CpAirlineLogo.vue +9 -10
  65. package/src/components/atomic-elements/CpBadge.vue +33 -41
  66. package/src/components/atomic-elements/CpDialog.vue +14 -9
  67. package/src/components/atomic-elements/CpPartnerBadge.vue +12 -20
  68. package/src/components/atomic-elements/CpTooltip.vue +12 -11
  69. package/src/components/buttons/CpButton.vue +63 -104
  70. package/src/components/core/BaseInputLabel.vue +9 -15
  71. package/src/components/core/BaseSelectClearButton.vue +1 -1
  72. package/src/components/date-pickers/CpCalendar.vue +154 -153
  73. package/src/components/date-pickers/CpDate.vue +202 -212
  74. package/src/components/date-pickers/CpDatepicker.vue +112 -138
  75. package/src/components/feedback-indicators/CpAlert.vue +16 -27
  76. package/src/components/feedback-indicators/CpLoader.vue +7 -8
  77. package/src/components/feedback-indicators/CpToaster.vue +197 -192
  78. package/src/components/helpers-utilities/TransitionExpand.vue +31 -33
  79. package/src/components/icons/IconOneWay.vue +1 -1
  80. package/src/components/index.ts +28 -40
  81. package/src/components/inputs/CpInput.vue +40 -57
  82. package/src/components/inputs/CpTextarea.vue +30 -50
  83. package/src/components/lists-and-table/CpTable.vue +165 -114
  84. package/src/components/lists-and-table/CpTableEmptyState.vue +5 -8
  85. package/src/components/selects/CpMultiselect.vue +58 -89
  86. package/src/components/selects/CpSelect.vue +70 -90
  87. package/src/components/selects/CpSelectMenu.vue +94 -96
  88. package/src/components/toggles/CpCheckbox.vue +45 -54
  89. package/src/components/toggles/CpRadio.vue +47 -58
  90. package/src/components/toggles/CpSwitch.vue +51 -67
  91. package/src/components/typography/CpHeading.vue +11 -31
  92. package/src/components/visual/CpIcon.vue +2 -1
  93. package/src/constants/{src/CpCustomIcons.ts → CpCustomIcons.ts} +1 -1
  94. package/src/constants/CpTableConfig.ts +12 -0
  95. package/src/constants/Heading.ts +8 -0
  96. package/src/{utils/constants/src/Intent.js → constants/Intent.ts} +1 -1
  97. package/src/constants/PartnerTypes.ts +6 -0
  98. package/src/constants/Position.ts +10 -0
  99. package/src/constants/Sizes.ts +5 -0
  100. package/src/constants/colors/Colors.ts +10 -0
  101. package/src/constants/colors/ToggleColors.ts +6 -0
  102. package/src/constants/index.ts +10 -5
  103. package/src/directives/ClickOutside.ts +17 -0
  104. package/src/directives/{ResizeSelect.js → ResizeSelect.ts} +3 -3
  105. package/src/helpers/{dom.js → dom.ts} +13 -9
  106. package/src/helpers/{index.js → index.ts} +13 -3
  107. package/src/helpers/object.ts +9 -0
  108. package/src/helpers/string/src/camelize.ts +6 -0
  109. package/src/helpers/string/src/{decamelize.js → decamelize.ts} +1 -1
  110. package/src/libs/CoreDatepicker.vue +4 -4
  111. package/src/plugins/toaster.ts +71 -0
  112. package/src/stories/BaseInputLabel.stories.ts +1 -0
  113. package/src/stories/CpAlert.stories.ts +1 -0
  114. package/src/stories/CpBadge.stories.ts +18 -0
  115. package/src/stories/CpCheckbox.stories.ts +3 -1
  116. package/src/stories/CpDate.stories.ts +3 -1
  117. package/src/stories/CpDatepicker.stories.ts +3 -1
  118. package/src/stories/CpDialog.stories.ts +2 -1
  119. package/src/stories/CpHeading.stories.ts +1 -0
  120. package/src/stories/CpIcon.stories.ts +2 -0
  121. package/src/stories/CpInput.stories.ts +3 -1
  122. package/src/stories/CpLoader.stories.ts +1 -0
  123. package/src/stories/CpMultiselect.stories.ts +2 -1
  124. package/src/stories/CpPartnerBadge.stories.ts +1 -1
  125. package/src/stories/CpRadio.stories.ts +3 -1
  126. package/src/stories/CpSelect.stories.ts +3 -1
  127. package/src/stories/CpSelectMenu.stories.ts +3 -1
  128. package/src/stories/CpSwitch.stories.ts +3 -1
  129. package/src/stories/CpTable.stories.ts +8 -1
  130. package/src/stories/CpTableEmptyState.stories.ts +1 -0
  131. package/src/stories/CpTextarea.stories.ts +3 -1
  132. package/src/stories/CpToaster.stories.ts +1 -0
  133. package/src/stories/CpTooltip.stories.ts +1 -0
  134. package/src/stories/TransitionExpand.stories.ts +3 -1
  135. package/src/types/luxon.d.ts +1 -0
  136. package/src/vendors/ff-polyfill.ts +38 -0
  137. package/vitest.workspace.js +1 -3
  138. package/src/constants/src/CpTableConfig.ts +0 -14
  139. package/src/constants/src/Position.ts +0 -10
  140. package/src/constants/src/colors/Colors.ts +0 -10
  141. package/src/constants/src/colors/ToggleColors.ts +0 -6
  142. package/src/directives/ClickOutside.js +0 -13
  143. package/src/helpers/object.js +0 -9
  144. package/src/helpers/string/src/camelize.js +0 -6
  145. package/src/plugins/toaster.js +0 -61
  146. package/src/utils/constants/index.js +0 -3
  147. package/src/utils/constants/src/PartnerTypes.js +0 -6
  148. package/src/utils/constants/src/Sizes.js +0 -5
  149. package/src/vendors/ff-polyfill.js +0 -36
  150. /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'
35
+ <script setup lang="ts">
36
+ import { ref, computed, onMounted } from 'vue'
37
37
 
38
38
  import BaseInputLabel from '@/components/core/BaseInputLabel.vue'
39
39
  import TransitionExpand from '@/components/helpers-utilities/TransitionExpand.vue'
40
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
- },
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
 
@@ -26,63 +26,36 @@
26
26
  </label>
27
27
  </template>
28
28
 
29
- <script setup>
29
+ <script setup lang="ts">
30
30
  import { computed, ref, onMounted, useSlots } from 'vue'
31
31
 
32
- import { capitalizeFirstLetter, randomString } from '@/helpers'
33
32
  import { ToggleColors } from '@/constants'
33
+ import { capitalizeFirstLetter, randomString } from '@/helpers'
34
34
 
35
- const props = defineProps({
36
- modelValue: {
37
- type: [Array, Boolean],
38
- default: () => [],
39
- required: false,
40
- },
41
- checkboxValue: {
42
- type: [String, Number],
43
- default: '',
44
- required: false,
45
- },
46
- checkboxLabel: {
47
- type: String,
48
- required: false,
49
- default: '',
50
- },
51
- isDisabled: {
52
- type: Boolean,
53
- default: false,
54
- required: false,
55
- },
56
- groupName: {
57
- type: String,
58
- default: '',
59
- required: false,
60
- },
61
- capitalizeLabel: {
62
- type: Boolean,
63
- default: true,
64
- },
65
- color: {
66
- type: String,
67
- required: false,
68
- default: ToggleColors.BLUE,
69
- validator: (value) => Object.values(ToggleColors).includes(value),
70
- },
71
- reverseLabel: {
72
- type: Boolean,
73
- required: false,
74
- default: false,
75
- },
76
- autofocus: {
77
- type: Boolean,
78
- required: false,
79
- default: false,
80
- },
81
- helper: {
82
- type: String,
83
- required: false,
84
- default: '',
85
- },
35
+ interface Props {
36
+ autofocus?: boolean
37
+ capitalizeLabel?: boolean
38
+ checkboxLabel?: string
39
+ checkboxValue?: string | number
40
+ color?: string
41
+ groupName?: string
42
+ helper?: string
43
+ isDisabled?: boolean
44
+ modelValue?: boolean | unknown[]
45
+ reverseLabel?: boolean
46
+ }
47
+
48
+ const props = withDefaults(defineProps<Props>(), {
49
+ modelValue: false,
50
+ checkboxValue: '',
51
+ checkboxLabel: '',
52
+ isDisabled: false,
53
+ groupName: '',
54
+ capitalizeLabel: true,
55
+ color: ToggleColors.BLUE,
56
+ reverseLabel: false,
57
+ autofocus: false,
58
+ helper: '',
86
59
  })
87
60
 
88
61
  const emit = defineEmits(['update:modelValue'])
@@ -92,6 +65,9 @@ const checkboxUniqueId = ref('')
92
65
 
93
66
  const isChecked = computed({
94
67
  get() {
68
+ if (Array.isArray(props.modelValue)) {
69
+ return props.modelValue.includes(props.checkboxValue)
70
+ }
95
71
  return props.modelValue
96
72
  },
97
73
  set(newValue) {
@@ -123,7 +99,22 @@ const labelComputedClasses = computed(() => {
123
99
 
124
100
  onMounted(() => (checkboxUniqueId.value = randomString()))
125
101
 
126
- const onChange = () => emit('update:modelValue', checkedProxy.value)
102
+ const onChange = (value: string | number) => {
103
+ if (Array.isArray(props.modelValue)) {
104
+ const currentValues = [...props.modelValue]
105
+ const valueIndex = currentValues.indexOf(value)
106
+
107
+ if (valueIndex > -1) {
108
+ currentValues.splice(valueIndex, 1)
109
+ } else {
110
+ currentValues.push(value)
111
+ }
112
+
113
+ emit('update:modelValue', currentValues)
114
+ } else {
115
+ emit('update:modelValue', !props.modelValue)
116
+ }
117
+ }
127
118
  </script>
128
119
 
129
120
  <style lang="scss">
@@ -28,67 +28,56 @@
28
28
  </div>
29
29
  </template>
30
30
 
31
- <script>
32
- import { capitalizeFirstLetter, randomString } from '@/helpers'
31
+ <script setup lang="ts">
32
+ import { ref } from 'vue'
33
+
33
34
  import { ToggleColors } from '@/constants'
35
+ import { capitalizeFirstLetter, randomString } from '@/helpers'
34
36
 
35
- export default {
36
- props: {
37
- modelValue: {
38
- type: String,
39
- default: '',
40
- required: true,
41
- },
42
- options: {
43
- type: Array,
44
- required: true,
45
- },
46
- groupName: {
47
- type: String,
48
- default: '',
49
- required: false,
50
- },
51
- color: {
52
- type: String,
53
- required: false,
54
- default: ToggleColors.BLUE,
55
- validator: (value) => Object.values(ToggleColors).includes(value),
56
- },
57
- autofocus: {
58
- type: Boolean,
59
- required: false,
60
- default: false,
61
- },
62
- },
63
- emits: ['update:modelValue'],
64
- data() {
65
- return {
66
- radioUniqueId: '',
67
- }
68
- },
69
- mounted() {
70
- this.radioUniqueId = randomString()
71
- },
72
- methods: {
73
- onChange(value) {
74
- this.$emit('update:modelValue', value)
75
- },
76
- getRadioId(index) {
77
- return `${this.radioUniqueId}${index}`
78
- },
79
- isActive(value) {
80
- return value === this.modelValue
81
- },
82
- computedClasses({ value, disabled }) {
83
- return [
84
- {
85
- 'cpRadio--isActive': this.isActive(value),
86
- 'cpRadio--isDisabled': disabled,
87
- },
88
- `cpRadio--is${capitalizeFirstLetter(this.color)}`,
89
- ]
37
+ interface RadioOption {
38
+ additionalData?: string
39
+ description?: string
40
+ disabled?: boolean
41
+ label: string
42
+ value: string
43
+ }
44
+
45
+ interface Props {
46
+ autofocus?: boolean
47
+ color?: string
48
+ groupName?: string
49
+ modelValue: string
50
+ options: RadioOption[]
51
+ }
52
+
53
+ interface Emits {
54
+ (e: 'update:modelValue', value: string): void
55
+ }
56
+
57
+ const props = withDefaults(defineProps<Props>(), {
58
+ groupName: '',
59
+ color: ToggleColors.BLUE,
60
+ autofocus: false,
61
+ })
62
+
63
+ const emit = defineEmits<Emits>()
64
+
65
+ const radioUniqueId = ref(randomString())
66
+
67
+ const onChange = (value: string): void => emit('update:modelValue', value)
68
+
69
+ const getRadioId = (index: number): string => `${radioUniqueId.value}${index}`
70
+
71
+ const isActive = (value: string): boolean => value === props.modelValue
72
+
73
+ const computedClasses = ({ value, disabled }: { disabled?: boolean; value: string }) => {
74
+ return [
75
+ {
76
+ 'cpRadio--isActive': isActive(value),
77
+ 'cpRadio--isDisabled': disabled,
90
78
  },
91
- },
79
+ `cpRadio--is${capitalizeFirstLetter(props.color)}`,
80
+ ]
92
81
  }
93
82
  </script>
94
83