@policystudio/policy-studio-ui-vue 1.1.90-beta.12 → 1.1.90-beta.17

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 (224) hide show
  1. package/.eslintrc.js +2 -1
  2. package/.github/workflows/deploy-storybook.yml +4 -4
  3. package/.nvmrc +1 -0
  4. package/dist/css/psui_styles_output.css +6986 -0
  5. package/package.json +9 -23
  6. package/src/assets/scss/components/PsDataTable.scss +1 -1
  7. package/src/components/accordion/PsAccordionItem.vue +75 -75
  8. package/src/components/badges-and-tags/PsBadgeWithIcon.vue +31 -34
  9. package/src/components/badges-and-tags/PsCardInfos.vue +40 -41
  10. package/src/components/badges-and-tags/PsChartLegend.vue +47 -51
  11. package/src/components/badges-and-tags/PsClimateZoneBadge.vue +14 -19
  12. package/src/components/badges-and-tags/PsCostEffectBar.vue +24 -56
  13. package/src/components/badges-and-tags/PsDateCardInfo.vue +17 -18
  14. package/src/components/badges-and-tags/PsHighlightRippleDot.vue +3 -2
  15. package/src/components/badges-and-tags/PsMiniTag.vue +39 -41
  16. package/src/components/badges-and-tags/PsProgressBar.vue +72 -68
  17. package/src/components/badges-and-tags/PsTagScope.vue +17 -22
  18. package/src/components/badges-and-tags/PsTestimonialCard.vue +20 -26
  19. package/src/components/buttons/PsButton.vue +61 -62
  20. package/src/components/chips/PsChips.vue +98 -101
  21. package/src/components/controls/PsCheckbox.vue +84 -84
  22. package/src/components/controls/PsCheckboxSimple.vue +95 -95
  23. package/src/components/controls/PsDraggable.vue +53 -55
  24. package/src/components/controls/PsInlineSelector.vue +99 -99
  25. package/src/components/controls/PsRadioButton.vue +59 -58
  26. package/src/components/controls/PsRadioButtonSimple.vue +79 -75
  27. package/src/components/controls/PsSlider.vue +185 -176
  28. package/src/components/controls/PsSwitch.vue +51 -52
  29. package/src/components/controls/PsToggle.vue +53 -50
  30. package/src/components/data-graphics/PsBarChart.vue +19 -21
  31. package/src/components/datatable/PsDataTable.vue +56 -60
  32. package/src/components/datatable/PsDataTableItem.vue +14 -28
  33. package/src/components/forms/PsDropdown.vue +164 -162
  34. package/src/components/forms/PsDropdownList.vue +132 -129
  35. package/src/components/forms/PsInput.vue +155 -153
  36. package/src/components/forms/PsInputSelect.vue +91 -92
  37. package/src/components/forms/PsInputTextArea.vue +71 -71
  38. package/src/components/navigations/PsBreadcrumb.vue +26 -34
  39. package/src/components/notifications/PsDialog.vue +57 -56
  40. package/src/components/notifications/PsSimpleAlert.vue +28 -29
  41. package/src/components/notifications/PsToast.vue +40 -39
  42. package/src/components/table-results/PsTableResults.vue +452 -458
  43. package/src/components/table-results/PsTableResultsBody.vue +66 -67
  44. package/src/components/table-results/PsTableResultsHead.vue +62 -56
  45. package/src/components/table-results/PsTableResultsHeadComparison.vue +62 -56
  46. package/src/components/table-results/PsTableResultsHeadFlexible.vue +63 -56
  47. package/src/components/table-results/PsTableResultsRow.vue +55 -56
  48. package/src/components/tabs/PsTabHeader.vue +106 -100
  49. package/src/components/tooltip/PsDialogTooltip.vue +96 -101
  50. package/src/components/tooltip/PsRichTooltip.vue +42 -45
  51. package/src/components/tooltip/PsTooltip.vue +111 -116
  52. package/src/components/ui/PsDotLoader.vue +1 -5
  53. package/src/components/ui/PsIcon.vue +126 -129
  54. package/src/index.ts +57 -71
  55. package/src/tsconfig.json +12 -0
  56. package/src/{shims-vue.d.ts → types/index.d.ts} +0 -5
  57. package/src/util/{GeneralFunctions.ts → GeneralFunctions.js} +0 -3
  58. package/src/util/directives.ts +24 -0
  59. package/src/util/eventBus.js +10 -0
  60. package/src/util/{imageLoader.ts → imageLoader.js} +7 -8
  61. package/tailwind.config.js +1 -1
  62. package/tsconfig.json +15 -17
  63. package/.storybook/PolicyStudio.ts +0 -11
  64. package/.storybook/eventBus.ts +0 -26
  65. package/.storybook/main.ts +0 -21
  66. package/.storybook/manager.ts +0 -7
  67. package/.storybook/preview.ts +0 -17
  68. package/dist/contents/ComparisonData.js +0 -376
  69. package/dist/contents/ComparisonData.js.map +0 -1
  70. package/dist/contents/FlexibleData.js +0 -501
  71. package/dist/contents/FlexibleData.js.map +0 -1
  72. package/dist/contents/ResultsData.js +0 -530
  73. package/dist/contents/ResultsData.js.map +0 -1
  74. package/dist/css/psui_styles.css +0 -4647
  75. package/dist/index.js +0 -114
  76. package/dist/index.js.map +0 -1
  77. package/dist/stories/Accordion.stories.js +0 -56
  78. package/dist/stories/Accordion.stories.js.map +0 -1
  79. package/dist/stories/BadgeWithIcon.stories.js +0 -28
  80. package/dist/stories/BadgeWithIcon.stories.js.map +0 -1
  81. package/dist/stories/BarChart.stories.js +0 -16
  82. package/dist/stories/BarChart.stories.js.map +0 -1
  83. package/dist/stories/Breadcrumb.stories.js +0 -21
  84. package/dist/stories/Breadcrumb.stories.js.map +0 -1
  85. package/dist/stories/Button.stories.js +0 -44
  86. package/dist/stories/Button.stories.js.map +0 -1
  87. package/dist/stories/CardInfos.stories.js +0 -13
  88. package/dist/stories/CardInfos.stories.js.map +0 -1
  89. package/dist/stories/ChartLegend.stories.js +0 -13
  90. package/dist/stories/ChartLegend.stories.js.map +0 -1
  91. package/dist/stories/Checkbox.stories.js +0 -44
  92. package/dist/stories/Checkbox.stories.js.map +0 -1
  93. package/dist/stories/CheckboxSimple.stories.js +0 -48
  94. package/dist/stories/CheckboxSimple.stories.js.map +0 -1
  95. package/dist/stories/Chips.stories.js +0 -27
  96. package/dist/stories/Chips.stories.js.map +0 -1
  97. package/dist/stories/ClimateZoneBadge.stories.js +0 -15
  98. package/dist/stories/ClimateZoneBadge.stories.js.map +0 -1
  99. package/dist/stories/CostEffectBar.stories.js +0 -21
  100. package/dist/stories/CostEffectBar.stories.js.map +0 -1
  101. package/dist/stories/Datatable.stories.js +0 -45
  102. package/dist/stories/Datatable.stories.js.map +0 -1
  103. package/dist/stories/DateCardInfo.stories.js +0 -18
  104. package/dist/stories/DateCardInfo.stories.js.map +0 -1
  105. package/dist/stories/Dialog.stories.js +0 -127
  106. package/dist/stories/Dialog.stories.js.map +0 -1
  107. package/dist/stories/Draggable.stories.js +0 -20
  108. package/dist/stories/Draggable.stories.js.map +0 -1
  109. package/dist/stories/Dropdown.stories.js +0 -98
  110. package/dist/stories/Dropdown.stories.js.map +0 -1
  111. package/dist/stories/DropdownList.stories.js +0 -208
  112. package/dist/stories/DropdownList.stories.js.map +0 -1
  113. package/dist/stories/Header.stories.js +0 -39
  114. package/dist/stories/Header.stories.js.map +0 -1
  115. package/dist/stories/HighlightRippleDot.stories.js +0 -13
  116. package/dist/stories/HighlightRippleDot.stories.js.map +0 -1
  117. package/dist/stories/Icon.stories.js +0 -19
  118. package/dist/stories/Icon.stories.js.map +0 -1
  119. package/dist/stories/InlineSelector.stories.js +0 -16
  120. package/dist/stories/InlineSelector.stories.js.map +0 -1
  121. package/dist/stories/Input.stories.js +0 -235
  122. package/dist/stories/Input.stories.js.map +0 -1
  123. package/dist/stories/InputSelect.stories.js +0 -28
  124. package/dist/stories/InputSelect.stories.js.map +0 -1
  125. package/dist/stories/InputTextArea.stories.js +0 -23
  126. package/dist/stories/InputTextArea.stories.js.map +0 -1
  127. package/dist/stories/MiniTag.stories.js +0 -44
  128. package/dist/stories/MiniTag.stories.js.map +0 -1
  129. package/dist/stories/Playground.stories.js +0 -14
  130. package/dist/stories/Playground.stories.js.map +0 -1
  131. package/dist/stories/ProgressBar.stories.js +0 -21
  132. package/dist/stories/ProgressBar.stories.js.map +0 -1
  133. package/dist/stories/RadioButton.stories.js +0 -36
  134. package/dist/stories/RadioButton.stories.js.map +0 -1
  135. package/dist/stories/RadioButtonSimple.stories.js +0 -40
  136. package/dist/stories/RadioButtonSimple.stories.js.map +0 -1
  137. package/dist/stories/SimpleAlert.stories.js +0 -19
  138. package/dist/stories/SimpleAlert.stories.js.map +0 -1
  139. package/dist/stories/Slider.stories.js +0 -70
  140. package/dist/stories/Slider.stories.js.map +0 -1
  141. package/dist/stories/Switch.stories.js +0 -35
  142. package/dist/stories/Switch.stories.js.map +0 -1
  143. package/dist/stories/TabHeader.stories.js +0 -48
  144. package/dist/stories/TabHeader.stories.js.map +0 -1
  145. package/dist/stories/TableResults.stories.js +0 -717
  146. package/dist/stories/TableResults.stories.js.map +0 -1
  147. package/dist/stories/TagScope.stories.js +0 -16
  148. package/dist/stories/TagScope.stories.js.map +0 -1
  149. package/dist/stories/TestimonialCard.stories.js +0 -24
  150. package/dist/stories/TestimonialCard.stories.js.map +0 -1
  151. package/dist/stories/Toast.stories.js +0 -51
  152. package/dist/stories/Toast.stories.js.map +0 -1
  153. package/dist/stories/Toggle.stories.js +0 -42
  154. package/dist/stories/Toggle.stories.js.map +0 -1
  155. package/dist/stories/Tooltip.stories.js +0 -108
  156. package/dist/stories/Tooltip.stories.js.map +0 -1
  157. package/dist/util/GeneralFunctions.js +0 -29
  158. package/dist/util/GeneralFunctions.js.map +0 -1
  159. package/dist/util/imageLoader.js +0 -52
  160. package/dist/util/imageLoader.js.map +0 -1
  161. package/postcss.config.js +0 -8
  162. package/src/assets/images/multifamily-units.svg +0 -10
  163. package/src/assets/images/policy-studio.svg +0 -15
  164. package/src/components/playground/PsScrollBar.vue +0 -320
  165. package/src/contents/ComparisonData.ts +0 -378
  166. package/src/contents/FlexibleData.ts +0 -502
  167. package/src/contents/ResultsData.ts +0 -531
  168. package/src/stories/Accordion.stories.ts +0 -59
  169. package/src/stories/BadgeWithIcon.stories.ts +0 -31
  170. package/src/stories/BarChart.stories.ts +0 -17
  171. package/src/stories/Breadcrumb.stories.ts +0 -22
  172. package/src/stories/Button.stories.ts +0 -48
  173. package/src/stories/Button.vue +0 -59
  174. package/src/stories/CardInfos.stories.ts +0 -15
  175. package/src/stories/ChartLegend.stories.ts +0 -15
  176. package/src/stories/Checkbox.stories.ts +0 -45
  177. package/src/stories/CheckboxSimple.stories.ts +0 -49
  178. package/src/stories/Chips.stories.ts +0 -33
  179. package/src/stories/ClimateZoneBadge.stories.ts +0 -18
  180. package/src/stories/Colors.mdx +0 -70
  181. package/src/stories/CostEffectBar.stories.ts +0 -24
  182. package/src/stories/Datatable.stories.ts +0 -53
  183. package/src/stories/DateCardInfo.stories.ts +0 -20
  184. package/src/stories/Dialog.stories.ts +0 -131
  185. package/src/stories/Draggable.stories.ts +0 -23
  186. package/src/stories/Dropdown.stories.ts +0 -100
  187. package/src/stories/DropdownList.stories.ts +0 -213
  188. package/src/stories/ElevationSystem.mdx +0 -41
  189. package/src/stories/Header.stories.ts +0 -42
  190. package/src/stories/Header.vue +0 -77
  191. package/src/stories/HighlightRippleDot.stories.ts +0 -16
  192. package/src/stories/Icon.stories.ts +0 -23
  193. package/src/stories/InlineSelector.stories.ts +0 -18
  194. package/src/stories/Input.stories.ts +0 -243
  195. package/src/stories/InputSelect.stories.ts +0 -31
  196. package/src/stories/InputTextArea.stories.ts +0 -25
  197. package/src/stories/Introduction.mdx +0 -211
  198. package/src/stories/MiniTag.stories.ts +0 -59
  199. package/src/stories/Playground.stories.ts +0 -16
  200. package/src/stories/ProgressBar.stories.ts +0 -24
  201. package/src/stories/RadioButton.stories.ts +0 -40
  202. package/src/stories/RadioButtonSimple.stories.ts +0 -43
  203. package/src/stories/SimpleAlert.stories.ts +0 -22
  204. package/src/stories/Slider.stories.ts +0 -79
  205. package/src/stories/Switch.stories.ts +0 -39
  206. package/src/stories/TabHeader.stories.ts +0 -57
  207. package/src/stories/TableResults.stories.ts +0 -728
  208. package/src/stories/TagScope.stories.ts +0 -17
  209. package/src/stories/TestimonialCard.stories.ts +0 -27
  210. package/src/stories/Toast.stories.ts +0 -52
  211. package/src/stories/Toggle.stories.ts +0 -48
  212. package/src/stories/Tooltip.stories.ts +0 -114
  213. package/src/stories/Typography.mdx +0 -212
  214. package/src/stories/assets/code-brackets.svg +0 -1
  215. package/src/stories/assets/colors.svg +0 -1
  216. package/src/stories/assets/comments.svg +0 -1
  217. package/src/stories/assets/direction.svg +0 -1
  218. package/src/stories/assets/flow.svg +0 -1
  219. package/src/stories/assets/plugin.svg +0 -1
  220. package/src/stories/assets/repo.svg +0 -1
  221. package/src/stories/assets/stackalt.svg +0 -1
  222. package/src/stories/button.css +0 -30
  223. package/src/stories/header.css +0 -32
  224. package/webpack.config.js +0 -36
@@ -1,29 +1,29 @@
1
1
  <template>
2
- <div
2
+ <div
3
3
  ref="PSDropdown"
4
- class="psui-el-dropdown-menu"
5
- :class="{ 'is-open' : show }"
4
+ class="psui-el-dropdown-menu"
5
+ :class="{ 'is-open': show.value }"
6
6
  v-click-outside="close"
7
7
  >
8
8
  <div
9
9
  ref="PSDropdownTrigger"
10
10
  v-if="$slots.dropdownTrigger"
11
- @click="show && !toggleWhenActive ? '' : toggle()"
11
+ @click="show.value && !toggleWhenActive ? '' : toggle()"
12
12
  >
13
13
  <slot name="dropdownTrigger" />
14
14
  </div>
15
15
 
16
16
  <button
17
17
  v-else
18
- @click="show && !toggleWhenActive ? '' : toggle()"
18
+ @click="show.value && !toggleWhenActive ? '' : toggle()"
19
19
  type="button"
20
- :id="id"
20
+ :id="id.value"
21
21
  aria-haspopup="true"
22
22
  aria-expanded="true"
23
23
  ref="PSDropdownTrigger"
24
24
  >
25
25
  <slot
26
- v-if="show && $slots.buttonLabelOnShow"
26
+ v-if="show.value && $slots.buttonLabelOnShow"
27
27
  name="buttonLabelOnShow"
28
28
  />
29
29
  <slot
@@ -36,7 +36,7 @@
36
36
  role="menu"
37
37
  class="psui-el-dropdown-menu-dialog-wrapper psui-duration-300"
38
38
  aria-orientation="vertical"
39
- :aria-labelledby="id"
39
+ :aria-labelledby="id.value"
40
40
  :style="{ minWidth: minWidthDropDown }"
41
41
  >
42
42
  <div class="psui-el-dropdown-menu-dialog">
@@ -46,169 +46,171 @@
46
46
  </div>
47
47
  </template>
48
48
 
49
- <script>
49
+ <script setup>
50
50
  // Figma - 2.3 Dropdown with category divider https://www.figma.com/file/Tto8hrNlSfuPcwd1pfqogF/%E2%9A%A1%EF%B8%8F-Design-System?node-id=1768%3A64886
51
51
 
52
- import {
53
- randomString,
54
- getParentScrollableEl,
55
- } from '../../util/GeneralFunctions'
52
+ import { randomString, getParentScrollableEl } from '../../util/GeneralFunctions.js'
56
53
 
57
- export default {
58
- name: 'PsDropdown',
59
- props: {
54
+ import { defineProps, ref, onBeforeUnmount, defineEmits, defineExpose } from 'vue'
55
+
56
+ defineExpose({
57
+ close:() => close()
58
+ })
59
+
60
+ const props = defineProps({
60
61
  /**
61
- * It sets a minimun width for the dropdown menu.
62
+ * It sets a minimun width for the dropdown menu.
62
63
  */
63
- minWidthDropDown: {
64
- type: String,
65
- default: '240px',
66
- },
67
- /**
68
- * It's a boolean responsible for showing a slot within the html tag button.
69
- */
70
- buttonLabelOnShow: {
71
- type: Boolean,
72
- default: false,
73
- },
74
- /**
75
- * It's a property responsible for toggling the dropdown menu. default: true.
76
- */
77
- toggleWhenActive: {
78
- type: Boolean,
79
- default: true,
80
- },
81
- /**
82
- * Disable the toogle on click. default: false.
83
- */
84
- disabled: {
85
- type: Boolean,
86
- default: false,
87
- },
88
- /**
89
- * It sets the vertical and horizontal position.
90
- */
91
- position: {
92
- type: String,
93
- validator: (value)=> ['custom'].includes(value)
94
- },
64
+ minWidthDropDown: {
65
+ type: String,
66
+ default: '240px',
95
67
  },
96
- data() {
97
- return {
98
- show: false,
99
- id: randomString(8),
100
- marginLeft: '-0px',
101
- scrollableParentEl: null,
102
- }
68
+ /**
69
+ * It's a boolean responsible for showing a slot within the html tag button.
70
+ */
71
+ buttonLabelOnShow: {
72
+ type: Boolean,
73
+ default: false,
103
74
  },
104
- computed: {
105
- getMaxWidth() {
106
- let bounds = this.$refs.PSDropdown.getBoundingClientRect()
107
- return document.documentElement.clientWidth - bounds['left'] - 30
108
- },
75
+ /**
76
+ * It's a property responsible for toggling the dropdown menu. default: true.
77
+ */
78
+ toggleWhenActive: {
79
+ type: Boolean,
80
+ default: true,
109
81
  },
110
- beforeUnmount() {
111
- this.unwatchParentScrolling()
82
+ /**
83
+ * Disable the toogle on click. default: false.
84
+ */
85
+ disabled: {
86
+ type: Boolean,
87
+ default: false,
112
88
  },
113
- methods: {
114
- toggle() {
115
- if (this.disabled) return
116
-
117
- if (!this.show) {
118
- this.open()
119
- } else {
120
- this.close()
121
- }
122
- },
123
- watchParentScrolling() {
124
- this.scrollableParentEl = getParentScrollableEl(this.$refs.PSDropdown)
125
- if (this.scrollableParentEl) {
126
- this.scrollableParentEl.addEventListener('scroll', this.updatePosition)
127
- }
128
- },
129
- unwatchParentScrolling() {
130
- if (this.scrollableParentEl) {
131
- this.scrollableParentEl.removeEventListener(
132
- 'scroll',
133
- this.updatePosition
134
- )
135
- }
136
- },
137
- updatePosition() {
138
- const PSDropdownDialog = this.$refs.PSDropdownDialog
139
- const PSDropdownTrigger = this.$refs.PSDropdownTrigger
140
- if (!PSDropdownDialog || !PSDropdownTrigger) return
141
-
142
- const rectTrigger = PSDropdownTrigger.getBoundingClientRect()
143
- const rectDialog = PSDropdownDialog.getBoundingClientRect()
144
- const windowWidth = document.documentElement.clientWidth
145
-
146
- PSDropdownDialog.style.position = 'fixed'
147
- PSDropdownDialog.style.top = `${rectTrigger.y + rectTrigger.height}px`
148
-
149
- PSDropdownDialog.style.minWidth = `${rectTrigger.width}px`
150
-
151
- if (rectTrigger.x + rectDialog.width + 20 > windowWidth) {
152
- PSDropdownDialog.style.left = `${
153
- windowWidth - rectDialog.width - 30
154
- }px`
155
- } else {
156
- PSDropdownDialog.style.left = `${rectTrigger.x}px`
157
- }
158
-
159
- if(this.position == 'custom') {
160
- PSDropdownDialog.style.top = `${rectTrigger.y}px`
161
- PSDropdownDialog.style.left = `${rectTrigger.x + 100}px`
162
- }
163
-
164
- if (rectTrigger.top < 10) {
165
- this.close()
166
- console.warn('The dropdown are too close from the top of the page')
167
- return
168
- }
169
-
170
- setTimeout(() => {
171
- PSDropdownDialog.style.opacity = 1
172
- }, 10)
173
- },
174
- open() {
175
- this.$emit('open')
176
- this.show = true
177
- if(this.$refs.PSDropdownDialog){
178
- this.$refs.PSDropdownDialog.style.opacity = 0
179
- this.$refs.PSDropdownDialog.style.display = 'block'
180
- }
181
- setTimeout(() => {
182
- this.updatePosition()
183
- this.watchParentScrolling()
184
- document.addEventListener('keyup', this.handleEsc)
185
- window.addEventListener('resize', this.updatePosition)
186
- window.addEventListener('click', this.clickOutside)
187
- }, 10)
188
- },
189
- close() {
190
- if (this.show) {
191
- this.$emit('close')
192
- if(this.$refs.PSDropdownDialog){
193
- this.$refs.PSDropdownDialog.style.display = 'none'
194
- this.$refs.PSDropdownDialog.style.opacity = 0
195
- }
196
- this.show = false
197
- this.unwatchParentScrolling()
198
- }
199
- document.removeEventListener('keyup', this.handleEsc)
200
- document.removeEventListener('resize', this.updatePosition)
201
- document.removeEventListener('click', this.clickOutside)
202
- },
203
- handleEsc(evt) {
204
- if (this.show && evt.keyCode === 27) this.close()
205
- },
206
- clickOutside(event) {
207
- if (!this.show) return
208
- if (!this.$refs.PSDropdown == event.target || !this.$refs.PSDropdown?.contains(event.target)) {
209
- this.close()
210
- }
211
- },
89
+ /**
90
+ * It sets the vertical and horizontal position.
91
+ */
92
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment, vue/require-default-prop
93
+ position: {
94
+ type: String,
95
+ validator: (value) => ['custom'].includes(value),
212
96
  },
97
+ })
98
+
99
+ const emit = defineEmits(['open', 'close'])
100
+
101
+ const show = ref(false)
102
+ const id = ref(randomString(8))
103
+ // const marginLeft = ref('-0px')
104
+ const scrollableParentEl = ref(null)
105
+ const PSDropdown = ref(null)
106
+ const PSDropdownDialog = ref(null)
107
+ const PSDropdownTrigger = ref(null)
108
+
109
+ // const getMaxWidth = computed(() => {
110
+ // let bounds = PSDropdown.getBoundingClientRect()
111
+ // return document.documentElement.clientWidth - bounds['left'] - 30
112
+ // })
113
+
114
+ onBeforeUnmount(() => {
115
+ unwatchParentScrolling()
116
+ })
117
+
118
+ const toggle = () => {
119
+ if (props.disabled) return
120
+ if (!show.value) {
121
+ open()
122
+ } else {
123
+ close()
124
+ }
125
+ }
126
+
127
+ const handleEsc = (evt) => {
128
+ if (show.value && evt.keyCode === 27) close()
129
+ }
130
+
131
+ const open = () => {
132
+ emit('open')
133
+ show.value = true
134
+ if (PSDropdownDialog.value) {
135
+ PSDropdownDialog.value.style.opacity = 0
136
+ PSDropdownDialog.value.style.display = 'block'
137
+ }
138
+ setTimeout(() => {
139
+ updatePosition()
140
+ watchParentScrolling()
141
+ document.addEventListener('keyup', handleEsc)
142
+ window.addEventListener('resize', updatePosition)
143
+ // window.addEventListener('click', clickOutside)
144
+ }, 10)
145
+ }
146
+
147
+ const close = () => {
148
+ if (show.value == true) {
149
+ emit('close')
150
+ if (PSDropdownDialog.value !== null) {
151
+ PSDropdownDialog.value.style.display = 'none'
152
+ PSDropdownDialog.value.style.opacity = 0
153
+ }
154
+ show.value = false
155
+ unwatchParentScrolling()
156
+ }
157
+ document.removeEventListener('keyup', handleEsc)
158
+ document.removeEventListener('resize', updatePosition)
159
+ // document.removeEventListener('click', clickOutside)
160
+ }
161
+
162
+ const watchParentScrolling = () => {
163
+ scrollableParentEl.value = getParentScrollableEl(PSDropdown.value)
164
+ if (scrollableParentEl.value) {
165
+ scrollableParentEl.value.addEventListener('scroll', updatePosition)
166
+ }
167
+ }
168
+
169
+ const unwatchParentScrolling = () => {
170
+ if (scrollableParentEl.value) {
171
+ scrollableParentEl.value.removeEventListener('scroll', updatePosition())
172
+ }
173
+ }
174
+
175
+ const updatePosition = () => {
176
+ if (PSDropdownDialog.value === null || PSDropdownTrigger.value === null) return
177
+
178
+ const rectTrigger = PSDropdownTrigger.value.getBoundingClientRect()
179
+ const rectDialog = PSDropdownDialog.value.getBoundingClientRect()
180
+ const windowWidth = document.documentElement.clientWidth
181
+
182
+ PSDropdownDialog.value.style.position = 'fixed'
183
+ PSDropdownDialog.value.style.top = `${rectTrigger.y + rectTrigger.height}px`
184
+ PSDropdownDialog.value.style.minWidth = `${rectTrigger.width}px`
185
+
186
+ if (rectTrigger.x + rectDialog.width + 20 > windowWidth) {
187
+ PSDropdownDialog.value.style.left = `${windowWidth - rectDialog.width + 15}px`
188
+ } else {
189
+ PSDropdownDialog.value.style.left = `${rectTrigger.x}px`
190
+ }
191
+
192
+ if (props.position == 'custom') {
193
+ PSDropdownDialog.value.style.top = `${rectTrigger.y}px`
194
+ PSDropdownDialog.value.style.left = `${rectTrigger.x + 100}px`
195
+ }
196
+
197
+ if (rectTrigger.top < 10) {
198
+ close()
199
+ console.warn('The dropdown are too close from the top of the page')
200
+ return
201
+ }
202
+
203
+ setTimeout(() => {
204
+ if(PSDropdownDialog.value){
205
+ PSDropdownDialog.value.style.opacity = 1
206
+ }
207
+ }, 10)
208
+ }
209
+
210
+ const clickOutside = (event) => {
211
+ if (!show.value) return
212
+ if (!PSDropdown.value == event.target || !PSDropdown.value?.contains(event.target)) {
213
+ close()
214
+ }
213
215
  }
214
216
  </script>
@@ -1,25 +1,25 @@
1
1
  <template>
2
- <ul
2
+ <ul
3
3
  class="psui-el-dropdown-menu-list"
4
4
  :class="`layout-${layout}`"
5
5
  >
6
- <li
7
- v-for="(item, index) in getItems"
6
+ <li
7
+ v-for="(item, index) in getItems"
8
8
  :key="`${index}-${getKeyValue(item)}`"
9
9
  :id="`${index}-${getKeyValue(item)}`"
10
- :class="{ 'is-selected psui-bg-blue-10 psui-text-blue-60 hover:psui-bg-blue-10 hover:psui-text-blue-60' : getSelected === getKeyValue(item) }"
10
+ :class="{ 'is-selected psui-bg-blue-10 psui-text-blue-60 hover:psui-bg-blue-10 hover:psui-text-blue-60': getSelected === getKeyValue(item) }"
11
11
  class="psui-el-dropdown-menu-list-item"
12
- @mouseover="isHovering = index"
12
+ @mouseover="isHovering = index"
13
13
  @mouseout="isHovering = false"
14
14
  @click="selectItem(item)"
15
15
  >
16
16
  <div class="psui-el-dropdown-menu-list-item-left-label">
17
17
  {{ getLeftLabel(item) }}
18
-
18
+
19
19
  <div
20
20
  v-if="item.description"
21
21
  class="psui-font-normal psui-text-gray-50 psui-ml-1"
22
- :class="{ 'psui-text-blue-60' : item.key == getItems.key }"
22
+ :class="{ 'psui-text-blue-60': item.key == getItems.key }"
23
23
  >
24
24
  {{ item.description }}
25
25
  </div>
@@ -35,13 +35,13 @@
35
35
 
36
36
  <template v-if="layout == 'rich'">
37
37
  <div class="psui-el-dropdown-menu-list-item-line" />
38
- <div
38
+ <div
39
39
  v-if="rightLabelFormatter"
40
40
  class="psui-el-dropdown-menu-list-item-rigth-label"
41
41
  >
42
42
  {{ rightLabelFormatter(item.key, getStudyDataLevel[item.key], getStudyDataLevel) }}
43
43
  </div>
44
- <div
44
+ <div
45
45
  v-else
46
46
  class="psui-el-dropdown-menu-list-item-rigth-label"
47
47
  >
@@ -49,132 +49,135 @@
49
49
  </div>
50
50
  </template>
51
51
  </li>
52
- </ul>
52
+ </ul>
53
53
  </template>
54
54
 
55
- <script>
55
+ <script setup>
56
56
  import PsIcon from '../ui/PsIcon.vue'
57
- export const itemStyle = ['onlytext', 'radio', 'icon', 'checkbox', 'switch', 'rich']
57
+ import { defineProps, ref, computed, defineEmits } from 'vue'
58
58
 
59
- export default {
60
- name: 'PsDropdownList',
61
- components: { PsIcon },
62
- props: {
63
- /**
64
- * It sets the style of items
65
- */
66
- layout: {
67
- type: String,
68
- default: 'onlytext',
69
- validator: (value) => {
70
- return itemStyle.indexOf(value) !== -1
71
- }
72
- },
73
- /**
74
- * It sets the text key which will retrieve a icon from Google Fonts. Make sure to get the correct description of your icon on https://fonts.google.com/.
75
- */
76
- icon: {
77
- type: String,
78
- },
79
- /**
80
- * It sets the items which will be displayed on the dropdown menu.
81
- */
82
- items: {
83
- type: [Array, Object],
84
- required: true
85
- },
86
- /**
87
- * It sets the left key label of your items if needed.
88
- */
89
- leftLabel: {
90
- type: [String, Function],
91
- default: 'left_label'
92
- },
93
- /**
94
- * It sets the right key label of your items if needed.
95
- */
96
- rightLabel: {
97
- type: [String, Function],
98
- default: 'right_label'
99
- },
100
- /**
101
- * It sets the key label of your items if needed.
102
- */
103
- label: {
104
- type: [String, Function],
105
- default: 'label'
106
- },
107
- /**
108
- * It sets the key value of your items if needed.
109
- */
110
- keyValue: {
111
- type: [String, Function],
112
- default: 'value'
113
- },
114
- /**
115
- * It sets the format function to display values.
116
- */
117
- rightLabelFormatter: {
118
- type: Function
59
+ const props = defineProps({
60
+ /**
61
+ * It sets the style of items
62
+ */
63
+ layout: {
64
+ type: String,
65
+ default: 'onlytext',
66
+ validator: (value) => {
67
+ return ['onlytext', 'radio', 'icon', 'checkbox', 'switch', 'rich'].indexOf(value) !== -1
119
68
  },
120
- /**
121
- * It sets the format function to display values.
122
- */
123
- studyData: {
124
- type: [String, Object]
125
- },
126
- /**
127
- * It sets the item selected on the dropdown menu.
128
- */
129
- selected: {},
130
69
  },
131
- data: () => ({
132
- isHovering: false
133
- }),
134
- computed: {
135
- getSelected() {
136
- if (this.selected !== undefined) {
137
- if (typeof this.selected === 'object' && this.selected[this.keyValue] ) {
138
- return this.selected[this.keyValue]
139
- } else {
140
- return this.selected
141
- }
142
- } else {
143
- return false
144
- }
145
- },
146
- getItems() {
147
- return this.items
148
- },
149
- getStudyDataLevel() {
150
- return this.studyData?.data || this.studyData
151
- },
70
+ /**
71
+ * It sets the text key which will retrieve a icon from Google Fonts. Make sure to get the correct description of your icon on https://fonts.google.com/.
72
+ */
73
+ icon: {
74
+ type: String,
75
+ default: '',
152
76
  },
153
- methods: {
154
- selectItem(item) {
155
- this.$emit('update:selected', this.getKeyValue(item) )
156
- this.$emit('change', item )
157
- },
158
- getLeftLabel(item) {
159
- if(typeof this.leftLabel == 'function') return this.leftLabel(item)
160
- if(typeof item === 'string') return item
161
- return item[this.leftLabel]
162
- },
163
- getRightLabel(item) {
164
- if(typeof this.rightLabel == 'function') return this.rightLabel(item)
165
- if(typeof item === 'string') return item
166
- return item[this.rightLabel]
167
- },
168
- getLabel(item) {
169
- if(typeof this.label == 'function') return this.label(item)
170
- if(typeof item === 'string') return item
171
- return item[this.label]
172
- },
173
- getKeyValue(item) {
174
- if(typeof this.keyValue == 'function') return this.keyValue(item)
175
- if(typeof item === 'string') return item
176
- return item[this.keyValue]
177
- },
77
+ /**
78
+ * It sets the items which will be displayed on the dropdown menu.
79
+ */
80
+ items: {
81
+ type: [Array, Object],
82
+ required: true,
83
+ },
84
+ /**
85
+ * It sets the left key label of your items if needed.
86
+ */
87
+ leftLabel: {
88
+ type: [String, Function],
89
+ default: 'left_label',
90
+ },
91
+ /**
92
+ * It sets the right key label of your items if needed.
93
+ */
94
+ rightLabel: {
95
+ type: [String, Function],
96
+ default: 'right_label',
97
+ },
98
+ /**
99
+ * It sets the key label of your items if needed.
100
+ */
101
+ label: {
102
+ type: [String, Function],
103
+ default: 'label',
104
+ },
105
+ /**
106
+ * It sets the key value of your items if needed.
107
+ */
108
+ keyValue: {
109
+ type: [String, Function],
110
+ default: 'value',
111
+ },
112
+ /**
113
+ * It sets the format function to display values.
114
+ */
115
+ rightLabelFormatter: {
116
+ type: Function,
117
+ default: () => '',
118
+ },
119
+ /**
120
+ * It sets the format function to display values.
121
+ */
122
+ studyData: {
123
+ type: [String, Object],
124
+ default: '',
125
+ },
126
+ /**
127
+ * It sets the item selected on the dropdown menu.
128
+ */
129
+ selected: {},
130
+ })
131
+ const emit = defineEmits(['update:selected', 'change'])
132
+
133
+ const isHovering = ref(false)
134
+
135
+ const getSelected = computed(() => {
136
+ if (props.selected !== undefined) {
137
+ if (typeof props.selected === 'object' && props.selected[props.keyValue]) {
138
+ return props.selected[props.keyValue]
139
+ } else {
140
+ return props.selected
141
+ }
142
+ } else {
143
+ return false
178
144
  }
145
+ })
146
+
147
+ const getItems = computed(() => {
148
+ return props.items
149
+ })
150
+
151
+ const getStudyDataLevel = computed(() => {
152
+ return props.studyData?.data || props.studyData
153
+ })
154
+
155
+ const selectItem = (item) => {
156
+ emit('update:selected', getKeyValue(item))
157
+ emit('change', item)
158
+ }
159
+
160
+ const getLeftLabel = (item) => {
161
+ if (typeof props.leftLabel == 'function') return props.leftLabel(item)
162
+ if (typeof item === 'string') return item
163
+ return item[props.leftLabel]
164
+ }
165
+
166
+ const getRightLabel = (item) => {
167
+ if (typeof props.rightLabel == 'function') return props.rightLabel(item)
168
+ if (typeof item === 'string') return item
169
+ return item[props.rightLabel]
170
+ }
171
+
172
+ // const getLabel = (item) => {
173
+ // if(typeof props.label == 'function') return props.label(item)
174
+ // if(typeof item === 'string') return item
175
+ // return item[props.label]
176
+ // }
177
+
178
+ const getKeyValue = (item) => {
179
+ if (typeof props.keyValue == 'function') return props.keyValue(item)
180
+ if (typeof item === 'string') return item
181
+ return item[props.keyValue]
179
182
  }
180
- </script>
183
+ </script>