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

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 (231) 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/dist/index.d.ts +50 -0
  6. package/dist/index.js +53 -63
  7. package/dist/index.js.map +1 -1
  8. package/dist/util/GeneralFunctions.d.ts +3 -0
  9. package/dist/util/GeneralFunctions.js.map +1 -1
  10. package/dist/util/directives.d.ts +1 -0
  11. package/dist/util/directives.js +22 -0
  12. package/dist/util/directives.js.map +1 -0
  13. package/dist/util/eventBus.d.ts +7 -0
  14. package/dist/util/eventBus.js +8 -0
  15. package/dist/util/eventBus.js.map +1 -0
  16. package/dist/util/imageLoader.d.ts +6 -0
  17. package/dist/util/imageLoader.js.map +1 -1
  18. package/package.json +9 -23
  19. package/src/assets/scss/components/PsDataTable.scss +1 -1
  20. package/src/components/accordion/PsAccordionItem.vue +75 -75
  21. package/src/components/badges-and-tags/PsBadgeWithIcon.vue +31 -34
  22. package/src/components/badges-and-tags/PsCardInfos.vue +40 -41
  23. package/src/components/badges-and-tags/PsChartLegend.vue +47 -51
  24. package/src/components/badges-and-tags/PsClimateZoneBadge.vue +14 -19
  25. package/src/components/badges-and-tags/PsCostEffectBar.vue +24 -56
  26. package/src/components/badges-and-tags/PsDateCardInfo.vue +17 -18
  27. package/src/components/badges-and-tags/PsHighlightRippleDot.vue +3 -2
  28. package/src/components/badges-and-tags/PsMiniTag.vue +39 -41
  29. package/src/components/badges-and-tags/PsProgressBar.vue +72 -68
  30. package/src/components/badges-and-tags/PsTagScope.vue +17 -22
  31. package/src/components/badges-and-tags/PsTestimonialCard.vue +20 -26
  32. package/src/components/buttons/PsButton.vue +61 -62
  33. package/src/components/chips/PsChips.vue +98 -101
  34. package/src/components/controls/PsCheckbox.vue +84 -84
  35. package/src/components/controls/PsCheckboxSimple.vue +95 -95
  36. package/src/components/controls/PsDraggable.vue +53 -55
  37. package/src/components/controls/PsInlineSelector.vue +99 -99
  38. package/src/components/controls/PsRadioButton.vue +59 -58
  39. package/src/components/controls/PsRadioButtonSimple.vue +79 -75
  40. package/src/components/controls/PsSlider.vue +185 -176
  41. package/src/components/controls/PsSwitch.vue +51 -52
  42. package/src/components/controls/PsToggle.vue +53 -50
  43. package/src/components/data-graphics/PsBarChart.vue +19 -21
  44. package/src/components/datatable/PsDataTable.vue +56 -60
  45. package/src/components/datatable/PsDataTableItem.vue +14 -28
  46. package/src/components/forms/PsDropdown.vue +164 -162
  47. package/src/components/forms/PsDropdownList.vue +132 -129
  48. package/src/components/forms/PsInput.vue +155 -153
  49. package/src/components/forms/PsInputSelect.vue +91 -92
  50. package/src/components/forms/PsInputTextArea.vue +71 -71
  51. package/src/components/navigations/PsBreadcrumb.vue +26 -34
  52. package/src/components/notifications/PsDialog.vue +57 -56
  53. package/src/components/notifications/PsSimpleAlert.vue +28 -29
  54. package/src/components/notifications/PsToast.vue +40 -39
  55. package/src/components/table-results/PsTableResults.vue +452 -458
  56. package/src/components/table-results/PsTableResultsBody.vue +66 -67
  57. package/src/components/table-results/PsTableResultsHead.vue +62 -56
  58. package/src/components/table-results/PsTableResultsHeadComparison.vue +62 -56
  59. package/src/components/table-results/PsTableResultsHeadFlexible.vue +63 -56
  60. package/src/components/table-results/PsTableResultsRow.vue +55 -56
  61. package/src/components/tabs/PsTabHeader.vue +106 -100
  62. package/src/components/tooltip/PsDialogTooltip.vue +96 -101
  63. package/src/components/tooltip/PsRichTooltip.vue +42 -45
  64. package/src/components/tooltip/PsTooltip.vue +111 -116
  65. package/src/components/ui/PsDotLoader.vue +1 -5
  66. package/src/components/ui/PsIcon.vue +126 -129
  67. package/src/index.ts +57 -71
  68. package/src/tsconfig.json +12 -0
  69. package/src/{shims-vue.d.ts → types/index.d.ts} +0 -5
  70. package/src/util/{GeneralFunctions.ts → GeneralFunctions.js} +0 -3
  71. package/src/util/directives.ts +24 -0
  72. package/src/util/eventBus.js +10 -0
  73. package/src/util/{imageLoader.ts → imageLoader.js} +7 -8
  74. package/tailwind.config.js +1 -1
  75. package/tsconfig.json +15 -17
  76. package/.storybook/PolicyStudio.ts +0 -11
  77. package/.storybook/eventBus.ts +0 -26
  78. package/.storybook/main.ts +0 -21
  79. package/.storybook/manager.ts +0 -7
  80. package/.storybook/preview.ts +0 -17
  81. package/dist/contents/ComparisonData.js +0 -376
  82. package/dist/contents/ComparisonData.js.map +0 -1
  83. package/dist/contents/FlexibleData.js +0 -501
  84. package/dist/contents/FlexibleData.js.map +0 -1
  85. package/dist/contents/ResultsData.js +0 -530
  86. package/dist/contents/ResultsData.js.map +0 -1
  87. package/dist/css/psui_styles.css +0 -4647
  88. package/dist/stories/Accordion.stories.js +0 -56
  89. package/dist/stories/Accordion.stories.js.map +0 -1
  90. package/dist/stories/BadgeWithIcon.stories.js +0 -28
  91. package/dist/stories/BadgeWithIcon.stories.js.map +0 -1
  92. package/dist/stories/BarChart.stories.js +0 -16
  93. package/dist/stories/BarChart.stories.js.map +0 -1
  94. package/dist/stories/Breadcrumb.stories.js +0 -21
  95. package/dist/stories/Breadcrumb.stories.js.map +0 -1
  96. package/dist/stories/Button.stories.js +0 -44
  97. package/dist/stories/Button.stories.js.map +0 -1
  98. package/dist/stories/CardInfos.stories.js +0 -13
  99. package/dist/stories/CardInfos.stories.js.map +0 -1
  100. package/dist/stories/ChartLegend.stories.js +0 -13
  101. package/dist/stories/ChartLegend.stories.js.map +0 -1
  102. package/dist/stories/Checkbox.stories.js +0 -44
  103. package/dist/stories/Checkbox.stories.js.map +0 -1
  104. package/dist/stories/CheckboxSimple.stories.js +0 -48
  105. package/dist/stories/CheckboxSimple.stories.js.map +0 -1
  106. package/dist/stories/Chips.stories.js +0 -27
  107. package/dist/stories/Chips.stories.js.map +0 -1
  108. package/dist/stories/ClimateZoneBadge.stories.js +0 -15
  109. package/dist/stories/ClimateZoneBadge.stories.js.map +0 -1
  110. package/dist/stories/CostEffectBar.stories.js +0 -21
  111. package/dist/stories/CostEffectBar.stories.js.map +0 -1
  112. package/dist/stories/Datatable.stories.js +0 -45
  113. package/dist/stories/Datatable.stories.js.map +0 -1
  114. package/dist/stories/DateCardInfo.stories.js +0 -18
  115. package/dist/stories/DateCardInfo.stories.js.map +0 -1
  116. package/dist/stories/Dialog.stories.js +0 -127
  117. package/dist/stories/Dialog.stories.js.map +0 -1
  118. package/dist/stories/Draggable.stories.js +0 -20
  119. package/dist/stories/Draggable.stories.js.map +0 -1
  120. package/dist/stories/Dropdown.stories.js +0 -98
  121. package/dist/stories/Dropdown.stories.js.map +0 -1
  122. package/dist/stories/DropdownList.stories.js +0 -208
  123. package/dist/stories/DropdownList.stories.js.map +0 -1
  124. package/dist/stories/Header.stories.js +0 -39
  125. package/dist/stories/Header.stories.js.map +0 -1
  126. package/dist/stories/HighlightRippleDot.stories.js +0 -13
  127. package/dist/stories/HighlightRippleDot.stories.js.map +0 -1
  128. package/dist/stories/Icon.stories.js +0 -19
  129. package/dist/stories/Icon.stories.js.map +0 -1
  130. package/dist/stories/InlineSelector.stories.js +0 -16
  131. package/dist/stories/InlineSelector.stories.js.map +0 -1
  132. package/dist/stories/Input.stories.js +0 -235
  133. package/dist/stories/Input.stories.js.map +0 -1
  134. package/dist/stories/InputSelect.stories.js +0 -28
  135. package/dist/stories/InputSelect.stories.js.map +0 -1
  136. package/dist/stories/InputTextArea.stories.js +0 -23
  137. package/dist/stories/InputTextArea.stories.js.map +0 -1
  138. package/dist/stories/MiniTag.stories.js +0 -44
  139. package/dist/stories/MiniTag.stories.js.map +0 -1
  140. package/dist/stories/Playground.stories.js +0 -14
  141. package/dist/stories/Playground.stories.js.map +0 -1
  142. package/dist/stories/ProgressBar.stories.js +0 -21
  143. package/dist/stories/ProgressBar.stories.js.map +0 -1
  144. package/dist/stories/RadioButton.stories.js +0 -36
  145. package/dist/stories/RadioButton.stories.js.map +0 -1
  146. package/dist/stories/RadioButtonSimple.stories.js +0 -40
  147. package/dist/stories/RadioButtonSimple.stories.js.map +0 -1
  148. package/dist/stories/SimpleAlert.stories.js +0 -19
  149. package/dist/stories/SimpleAlert.stories.js.map +0 -1
  150. package/dist/stories/Slider.stories.js +0 -70
  151. package/dist/stories/Slider.stories.js.map +0 -1
  152. package/dist/stories/Switch.stories.js +0 -35
  153. package/dist/stories/Switch.stories.js.map +0 -1
  154. package/dist/stories/TabHeader.stories.js +0 -48
  155. package/dist/stories/TabHeader.stories.js.map +0 -1
  156. package/dist/stories/TableResults.stories.js +0 -717
  157. package/dist/stories/TableResults.stories.js.map +0 -1
  158. package/dist/stories/TagScope.stories.js +0 -16
  159. package/dist/stories/TagScope.stories.js.map +0 -1
  160. package/dist/stories/TestimonialCard.stories.js +0 -24
  161. package/dist/stories/TestimonialCard.stories.js.map +0 -1
  162. package/dist/stories/Toast.stories.js +0 -51
  163. package/dist/stories/Toast.stories.js.map +0 -1
  164. package/dist/stories/Toggle.stories.js +0 -42
  165. package/dist/stories/Toggle.stories.js.map +0 -1
  166. package/dist/stories/Tooltip.stories.js +0 -108
  167. package/dist/stories/Tooltip.stories.js.map +0 -1
  168. package/postcss.config.js +0 -8
  169. package/src/assets/images/multifamily-units.svg +0 -10
  170. package/src/assets/images/policy-studio.svg +0 -15
  171. package/src/components/playground/PsScrollBar.vue +0 -320
  172. package/src/contents/ComparisonData.ts +0 -378
  173. package/src/contents/FlexibleData.ts +0 -502
  174. package/src/contents/ResultsData.ts +0 -531
  175. package/src/stories/Accordion.stories.ts +0 -59
  176. package/src/stories/BadgeWithIcon.stories.ts +0 -31
  177. package/src/stories/BarChart.stories.ts +0 -17
  178. package/src/stories/Breadcrumb.stories.ts +0 -22
  179. package/src/stories/Button.stories.ts +0 -48
  180. package/src/stories/Button.vue +0 -59
  181. package/src/stories/CardInfos.stories.ts +0 -15
  182. package/src/stories/ChartLegend.stories.ts +0 -15
  183. package/src/stories/Checkbox.stories.ts +0 -45
  184. package/src/stories/CheckboxSimple.stories.ts +0 -49
  185. package/src/stories/Chips.stories.ts +0 -33
  186. package/src/stories/ClimateZoneBadge.stories.ts +0 -18
  187. package/src/stories/Colors.mdx +0 -70
  188. package/src/stories/CostEffectBar.stories.ts +0 -24
  189. package/src/stories/Datatable.stories.ts +0 -53
  190. package/src/stories/DateCardInfo.stories.ts +0 -20
  191. package/src/stories/Dialog.stories.ts +0 -131
  192. package/src/stories/Draggable.stories.ts +0 -23
  193. package/src/stories/Dropdown.stories.ts +0 -100
  194. package/src/stories/DropdownList.stories.ts +0 -213
  195. package/src/stories/ElevationSystem.mdx +0 -41
  196. package/src/stories/Header.stories.ts +0 -42
  197. package/src/stories/Header.vue +0 -77
  198. package/src/stories/HighlightRippleDot.stories.ts +0 -16
  199. package/src/stories/Icon.stories.ts +0 -23
  200. package/src/stories/InlineSelector.stories.ts +0 -18
  201. package/src/stories/Input.stories.ts +0 -243
  202. package/src/stories/InputSelect.stories.ts +0 -31
  203. package/src/stories/InputTextArea.stories.ts +0 -25
  204. package/src/stories/Introduction.mdx +0 -211
  205. package/src/stories/MiniTag.stories.ts +0 -59
  206. package/src/stories/Playground.stories.ts +0 -16
  207. package/src/stories/ProgressBar.stories.ts +0 -24
  208. package/src/stories/RadioButton.stories.ts +0 -40
  209. package/src/stories/RadioButtonSimple.stories.ts +0 -43
  210. package/src/stories/SimpleAlert.stories.ts +0 -22
  211. package/src/stories/Slider.stories.ts +0 -79
  212. package/src/stories/Switch.stories.ts +0 -39
  213. package/src/stories/TabHeader.stories.ts +0 -57
  214. package/src/stories/TableResults.stories.ts +0 -728
  215. package/src/stories/TagScope.stories.ts +0 -17
  216. package/src/stories/TestimonialCard.stories.ts +0 -27
  217. package/src/stories/Toast.stories.ts +0 -52
  218. package/src/stories/Toggle.stories.ts +0 -48
  219. package/src/stories/Tooltip.stories.ts +0 -114
  220. package/src/stories/Typography.mdx +0 -212
  221. package/src/stories/assets/code-brackets.svg +0 -1
  222. package/src/stories/assets/colors.svg +0 -1
  223. package/src/stories/assets/comments.svg +0 -1
  224. package/src/stories/assets/direction.svg +0 -1
  225. package/src/stories/assets/flow.svg +0 -1
  226. package/src/stories/assets/plugin.svg +0 -1
  227. package/src/stories/assets/repo.svg +0 -1
  228. package/src/stories/assets/stackalt.svg +0 -1
  229. package/src/stories/button.css +0 -30
  230. package/src/stories/header.css +0 -32
  231. package/webpack.config.js +0 -36
@@ -1,36 +1,34 @@
1
1
  <template>
2
2
  <div class="psui-el-bar-chart">
3
- <p
3
+ <p
4
4
  v-if="showNumber"
5
5
  class="psui-el-bar-chart-total"
6
6
  >
7
7
  {{ total }}
8
8
  </p>
9
9
 
10
- <div
10
+ <div
11
11
  class="psui-el-bar-chart-bar"
12
- :style="{width: `${fillWidth}%`}"
12
+ :style="{ width: `${fillWidth}%` }"
13
13
  />
14
14
  </div>
15
15
  </template>
16
16
 
17
- <script>
18
- export default {
19
- name: 'PsBarChart',
20
- props: {
21
- showNumber: {
22
- type: Boolean,
23
- default: true
24
- },
25
- total: {
26
- type: [String, Number],
27
- default: '5,0',
28
- },
29
- fillWidth: {
30
- type: Number,
31
- default: 50
32
- },
17
+ <script setup>
18
+ import { defineProps } from 'vue'
19
+
20
+ defineProps({
21
+ showNumber: {
22
+ type: Boolean,
23
+ default: true,
24
+ },
25
+ total: {
26
+ type: [String, Number],
27
+ default: '5,0',
28
+ },
29
+ fillWidth: {
30
+ type: Number,
31
+ default: 50,
33
32
  },
34
- computed: {}
35
- }
33
+ })
36
34
  </script>
@@ -37,70 +37,66 @@
37
37
  </table>
38
38
  </template>
39
39
 
40
- <script>
41
- export const type = ['simple', 'rich']
42
- export const alignment = ['center', 'right', 'left']
40
+ <script setup>
41
+ import { defineProps, computed } from 'vue'
43
42
 
44
- export default {
45
- name: 'PsDataTable',
46
- props: {
47
- /**
48
- * It sets the type of the data table. eg: simple or rich.
49
- */
50
- type: {
51
- type: String,
52
- required: true,
53
- validator: (value) => {
54
- return ['simple', 'rich'].indexOf(value) !== -1
55
- },
43
+ const props = defineProps({
44
+ type: {
45
+ type: String,
46
+ required: true,
47
+ validator: (value) => {
48
+ return ['simple', 'rich'].indexOf(value) !== -1
56
49
  },
57
- /**
58
- * It sets the values which will be use to render the header.
59
- */
60
- header: {
61
- type: Array,
62
- required: true,
63
- },
64
- /**
65
- * It sets the values which will be use to render the body.
66
- */
67
- data: {
68
- type: Array,
69
- default() {
70
- return []
71
- }
72
- },
73
- /**
74
- * It sets the values which will be use to render the footer.
75
- */
76
- footer: {
77
- type: Array,
78
- },
79
- /**
80
- * It sets the alignment of the whole context.
81
- */
82
- align: {
83
- type: String,
84
- default: 'left',
85
- validator: (value) => {
86
- return ['center', 'right', 'left'].indexOf(value) !== -1
87
- }
50
+ },
51
+ /**
52
+ * It sets the values which will be use to render the header.
53
+ */
54
+ header: {
55
+ type: Array,
56
+ required: true,
57
+ },
58
+ /**
59
+ * It sets the values which will be use to render the body.
60
+ */
61
+ data: {
62
+ type: Array,
63
+ default() {
64
+ return []
88
65
  },
89
- /**
90
- * It sets additional styling if needed.
91
- */
92
- cssStyle: {
93
- type: String,
94
- default: 'psui-text-gray-60'
95
- }
96
66
  },
97
- computed: {
98
- cssAlign() {
99
- if (this.align === 'right') return `psui-text-right ${this.cssStyle}`
100
- if (this.align === 'center') return `psui-text-center ${this.cssStyle}`
101
- return `psui-text-left ${this.cssStyle}`
67
+ /**
68
+ * It sets the values which will be use to render the footer.
69
+ */
70
+ footer: {
71
+ type: Array,
72
+ default: () => [],
73
+ },
74
+ /**
75
+ * It sets the alignment of the whole context.
76
+ */
77
+ align: {
78
+ type: String,
79
+ default: 'left',
80
+ validator: (value) => {
81
+ return ['center', 'right', 'left'].indexOf(value) !== -1
102
82
  },
103
83
  },
104
- }
84
+ /**
85
+ * It sets additional styling if needed.
86
+ */
87
+ cssStyle: {
88
+ type: String,
89
+ default: 'psui-text-gray-60',
90
+ },
91
+ })
92
+
93
+ const cssAlign = computed(() => {
94
+ if (props.align === 'right') return `psui-text-right ${props.cssStyle}`
95
+ if (props.align === 'center') return `psui-text-center ${props.cssStyle}`
96
+ return `psui-text-left ${props.cssStyle}`
97
+ })
105
98
  </script>
106
- <style> /* Please, use the file src/assets/scss/components/PsDataTable.scss */</style>
99
+
100
+ <style>
101
+ /* Please, use the file src/assets/scss/components/PsDataTable.scss */
102
+ </style>
@@ -15,11 +15,7 @@
15
15
  </span>
16
16
  <div
17
17
  class="psui-flex psui-items-center"
18
- :class="
19
- el[Object.keys(el)[1]] >= 0
20
- ? 'psui-text-green-70'
21
- : 'psui-text-red-70'
22
- "
18
+ :class="el[Object.keys(el)[1]] >= 0 ? 'psui-text-green-70' : 'psui-text-red-70'"
23
19
  >
24
20
  <i
25
21
  v-if="el[Object.keys(el)[1]] >= 0"
@@ -29,37 +25,27 @@
29
25
  v-else
30
26
  class="material-icons"
31
27
  >arrow_downward</i>
32
- <span>
33
- {{
34
- (
35
- (el[Object.keys(el)[1]] / el[Object.keys(el)[0]]) *
36
- 100
37
- ).toFixed(2)
38
- }}%
39
- </span>
28
+ <span> {{ ((el[Object.keys(el)[1]] / el[Object.keys(el)[0]]) * 100).toFixed(2) }}% </span>
40
29
  </div>
41
30
  </div>
42
- <span class="psui-text-gray-50">{{
43
- el[Object.keys(el)[0]].toFixed(6)
44
- }}</span>
31
+ <span class="psui-text-gray-50">{{ el[Object.keys(el)[0]].toFixed(6) }}</span>
45
32
  </td>
46
33
  </tr>
47
34
  </tbody>
48
35
  </template>
49
36
 
50
- <script>
51
- export default {
52
- name: 'PsDataTableItem',
53
- props: {
54
- data: {
55
- type: Array,
56
- required: true,
57
- default: () => {
58
- return []
59
- },
37
+ <script setup>
38
+ import { defineProps } from 'vue'
39
+
40
+ defineProps({
41
+ data: {
42
+ type: Array,
43
+ required: true,
44
+ default: () => {
45
+ return []
60
46
  },
61
47
  },
62
- }
48
+ })
63
49
  </script>
64
50
 
65
51
  <style scoped>
@@ -67,4 +53,4 @@ export default {
67
53
  font-size: 15px;
68
54
  margin-bottom: 2px;
69
55
  }
70
- </style>
56
+ </style>
@@ -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>