@policystudio/policy-studio-ui-vue 1.1.90-beta.3 → 1.1.90-beta.31

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 (160) hide show
  1. package/.eslintrc.js +13 -8
  2. package/.github/workflows/deploy-storybook.yml +4 -4
  3. package/.nvmrc +1 -0
  4. package/dist/css/psui_styles_output.css +7090 -0
  5. package/dist/index.d.ts +51 -0
  6. package/dist/index.js +106 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/util/GeneralFunctions.d.ts +3 -0
  9. package/dist/util/GeneralFunctions.js +35 -0
  10. package/dist/util/GeneralFunctions.js.map +1 -0
  11. package/dist/util/directives.d.ts +1 -0
  12. package/dist/util/directives.js +22 -0
  13. package/dist/util/directives.js.map +1 -0
  14. package/dist/util/imageLoader.d.ts +6 -0
  15. package/dist/util/imageLoader.js +52 -0
  16. package/dist/util/imageLoader.js.map +1 -0
  17. package/doc/.nvmrc +1 -0
  18. package/doc/.storybook/PolicyStudio.ts +11 -0
  19. package/{.storybook/main.js → doc/.storybook/main.ts} +8 -2
  20. package/doc/.storybook/manager.ts +7 -0
  21. package/{.storybook/preview.js → doc/.storybook/preview.ts} +2 -3
  22. package/doc/package-lock.json +22653 -0
  23. package/doc/package.json +71 -0
  24. package/doc/shims-vue.d.ts +6 -0
  25. package/{src/stories/Accordion.stories.js → doc/src/stories/Accordion.stories.ts} +4 -5
  26. package/{src/stories/BadgeWithIcon.stories.js → doc/src/stories/BadgeWithIcon.stories.ts} +2 -2
  27. package/{src/stories/BarChart.stories.js → doc/src/stories/BarChart.stories.ts} +2 -2
  28. package/{src/stories/Breadcrumb.stories.js → doc/src/stories/Breadcrumb.stories.ts} +2 -5
  29. package/doc/src/stories/Button.stories.ts +130 -0
  30. package/{src/stories/CardInfos.stories.js → doc/src/stories/CardInfos.stories.ts} +2 -3
  31. package/{src/stories/ChartLegend.stories.js → doc/src/stories/ChartLegend.stories.ts} +2 -3
  32. package/{src/stories/Checkbox.stories.js → doc/src/stories/Checkbox.stories.ts} +2 -2
  33. package/{src/stories/CheckboxSimple.stories.js → doc/src/stories/CheckboxSimple.stories.ts} +2 -2
  34. package/{src/stories/Chips.stories.js → doc/src/stories/Chips.stories.ts} +22 -23
  35. package/{src/stories/ClimateZoneBadge.stories.js → doc/src/stories/ClimateZoneBadge.stories.ts} +3 -2
  36. package/doc/src/stories/Collapse.stories.ts +46 -0
  37. package/{src/stories/CostEffectBar.stories.js → doc/src/stories/CostEffectBar.stories.ts} +3 -2
  38. package/{src/stories/Datatable.stories.js → doc/src/stories/Datatable.stories.ts} +7 -4
  39. package/{src/stories/DateCardInfo.stories.js → doc/src/stories/DateCardInfo.stories.ts} +2 -6
  40. package/{src/stories/Dialog.stories.js → doc/src/stories/Dialog.stories.ts} +2 -2
  41. package/{src/stories/Draggable.stories.js → doc/src/stories/Draggable.stories.ts} +3 -2
  42. package/{src/stories/Dropdown.stories.js → doc/src/stories/Dropdown.stories.ts} +4 -3
  43. package/{src/stories/DropdownList.stories.js → doc/src/stories/DropdownList.stories.ts} +4 -2
  44. package/{src/stories/HighlightRippleDot.stories.js → doc/src/stories/HighlightRippleDot.stories.ts} +3 -2
  45. package/{src/stories/Icon.stories.js → doc/src/stories/Icon.stories.ts} +3 -1
  46. package/{src/stories/InlineSelector.stories.js → doc/src/stories/InlineSelector.stories.ts} +2 -2
  47. package/{src/stories/Input.stories.js → doc/src/stories/Input.stories.ts} +7 -4
  48. package/{src/stories/InputSelect.stories.js → doc/src/stories/InputSelect.stories.ts} +3 -2
  49. package/{src/stories/InputTextArea.stories.js → doc/src/stories/InputTextArea.stories.ts} +2 -2
  50. package/{src/stories/MiniTag.stories.js → doc/src/stories/MiniTag.stories.ts} +9 -2
  51. package/{src/stories/ProgressBar.stories.js → doc/src/stories/ProgressBar.stories.ts} +3 -2
  52. package/{src/stories/RadioButton.stories.js → doc/src/stories/RadioButton.stories.ts} +2 -2
  53. package/{src/stories/RadioButtonSimple.stories.js → doc/src/stories/RadioButtonSimple.stories.ts} +2 -2
  54. package/{src/stories/SimpleAlert.stories.js → doc/src/stories/SimpleAlert.stories.ts} +3 -2
  55. package/{src/stories/Slider.stories.js → doc/src/stories/Slider.stories.ts} +6 -2
  56. package/{src/stories/Switch.stories.js → doc/src/stories/Switch.stories.ts} +2 -2
  57. package/{src/stories/TabHeader.stories.js → doc/src/stories/TabHeader.stories.ts} +6 -1
  58. package/{src/stories/TableResults.stories.js → doc/src/stories/TableResults.stories.ts} +11 -7
  59. package/{src/stories/TagScope.stories.js → doc/src/stories/TagScope.stories.ts} +3 -2
  60. package/{src/stories/TestimonialCard.stories.js → doc/src/stories/TestimonialCard.stories.ts} +3 -3
  61. package/{src/stories/Toast.stories.js → doc/src/stories/Toast.stories.ts} +2 -2
  62. package/{src/stories/Toggle.stories.js → doc/src/stories/Toggle.stories.ts} +7 -4
  63. package/{src/stories/Tooltip.stories.js → doc/src/stories/Tooltip.stories.ts} +6 -6
  64. package/doc/tsconfig.json +17 -0
  65. package/package.json +24 -37
  66. package/src/App.vue +30 -0
  67. package/src/assets/scss/base.scss +3 -34
  68. package/src/assets/scss/components/PsAccordion.scss +1 -1
  69. package/src/assets/scss/components/PsCollapse.css +74 -0
  70. package/src/assets/scss/components/PsDataTable.scss +1 -1
  71. package/src/assets/scss/components/PsDropdownList.scss +1 -1
  72. package/src/components/accordion/PsAccordionItem.vue +88 -74
  73. package/src/components/badges-and-tags/PsBadgeWithIcon.vue +31 -33
  74. package/src/components/badges-and-tags/PsCardInfos.vue +39 -41
  75. package/src/components/badges-and-tags/PsChartLegend.vue +46 -51
  76. package/src/components/badges-and-tags/PsClimateZoneBadge.vue +13 -19
  77. package/src/components/badges-and-tags/PsCostEffectBar.vue +24 -56
  78. package/src/components/badges-and-tags/PsDateCardInfo.vue +17 -18
  79. package/src/components/badges-and-tags/PsHighlightRippleDot.vue +3 -2
  80. package/src/components/badges-and-tags/PsMiniTag.vue +39 -41
  81. package/src/components/badges-and-tags/PsProgressBar.vue +72 -68
  82. package/src/components/badges-and-tags/PsTagScope.vue +17 -22
  83. package/src/components/badges-and-tags/PsTestimonialCard.vue +19 -26
  84. package/src/components/buttons/PsButton.vue +60 -61
  85. package/src/components/chips/PsChips.vue +98 -101
  86. package/src/components/collapse/PsCollapse.vue +121 -0
  87. package/src/components/controls/PsCheckbox.vue +84 -84
  88. package/src/components/controls/PsCheckboxSimple.vue +95 -95
  89. package/src/components/controls/PsDraggable.vue +53 -55
  90. package/src/components/controls/PsInlineSelector.vue +98 -99
  91. package/src/components/controls/PsRadioButton.vue +59 -58
  92. package/src/components/controls/PsRadioButtonSimple.vue +79 -75
  93. package/src/components/controls/PsSlider.vue +185 -176
  94. package/src/components/controls/PsSwitch.vue +51 -52
  95. package/src/components/controls/PsToggle.vue +52 -50
  96. package/src/components/data-graphics/PsBarChart.vue +18 -21
  97. package/src/components/datatable/PsDataTable.vue +56 -60
  98. package/src/components/datatable/PsDataTableItem.vue +13 -28
  99. package/src/components/forms/PsDropdown.vue +165 -162
  100. package/src/components/forms/PsDropdownList.vue +133 -130
  101. package/src/components/forms/PsInput.vue +154 -153
  102. package/src/components/forms/PsInputSelect.vue +91 -92
  103. package/src/components/forms/PsInputTextArea.vue +70 -71
  104. package/src/components/navigations/PsBreadcrumb.vue +25 -34
  105. package/src/components/notifications/PsDialog.vue +57 -56
  106. package/src/components/notifications/PsSimpleAlert.vue +27 -29
  107. package/src/components/notifications/PsToast.vue +40 -39
  108. package/src/components/table-results/PsTableResults.vue +456 -466
  109. package/src/components/table-results/PsTableResultsBody.vue +66 -67
  110. package/src/components/table-results/PsTableResultsHead.vue +67 -61
  111. package/src/components/table-results/PsTableResultsHeadComparison.vue +62 -56
  112. package/src/components/table-results/PsTableResultsHeadFlexible.vue +68 -61
  113. package/src/components/table-results/PsTableResultsRow.vue +55 -56
  114. package/src/components/tabs/PsTabHeader.vue +106 -100
  115. package/src/components/tooltip/PsDialogTooltip.vue +96 -101
  116. package/src/components/tooltip/PsRichTooltip.vue +41 -45
  117. package/src/components/tooltip/PsTooltip.vue +111 -116
  118. package/src/components/ui/PsDotLoader.vue +1 -5
  119. package/src/components/ui/PsIcon.vue +131 -129
  120. package/src/index.ts +159 -0
  121. package/src/tsconfig.json +12 -0
  122. package/src/types/index.d.ts +6 -0
  123. package/src/util/GeneralFunctions.js +16 -7
  124. package/src/util/directives.ts +24 -0
  125. package/src/util/imageLoader.js +14 -7
  126. package/tailwind.config.js +1 -1
  127. package/tsconfig.json +47 -0
  128. package/.storybook/PolicyStudio.js +0 -10
  129. package/.storybook/eventBus.js +0 -26
  130. package/.storybook/manager.js +0 -6
  131. package/babel.config.js +0 -17
  132. package/dist/css/psui_styles.css +0 -4647
  133. package/postcss.config.js +0 -8
  134. package/src/components/playground/PsScrollBar.vue +0 -320
  135. package/src/index.js +0 -166
  136. package/src/stories/Button.stories.js +0 -48
  137. package/src/stories/Button.vue +0 -59
  138. package/src/stories/Header.stories.js +0 -41
  139. package/src/stories/Header.vue +0 -77
  140. package/src/stories/Playground.stories.js +0 -16
  141. package/src/stories/button.css +0 -30
  142. package/src/stories/header.css +0 -32
  143. package/webpack.config.js +0 -22
  144. /package/{src → doc/src}/assets/images/multifamily-units.svg +0 -0
  145. /package/{src → doc/src}/assets/images/policy-studio.svg +0 -0
  146. /package/{src/contents/ComparisonData.js → doc/src/contents/ComparisonData.ts} +0 -0
  147. /package/{src/contents/FlexibleData.js → doc/src/contents/FlexibleData.ts} +0 -0
  148. /package/{src/contents/ResultsData.js → doc/src/contents/ResultsData.ts} +0 -0
  149. /package/{src → doc/src}/stories/Colors.mdx +0 -0
  150. /package/{src → doc/src}/stories/ElevationSystem.mdx +0 -0
  151. /package/{src → doc/src}/stories/Introduction.mdx +0 -0
  152. /package/{src → doc/src}/stories/Typography.mdx +0 -0
  153. /package/{src → doc/src}/stories/assets/code-brackets.svg +0 -0
  154. /package/{src → doc/src}/stories/assets/colors.svg +0 -0
  155. /package/{src → doc/src}/stories/assets/comments.svg +0 -0
  156. /package/{src → doc/src}/stories/assets/direction.svg +0 -0
  157. /package/{src → doc/src}/stories/assets/flow.svg +0 -0
  158. /package/{src → doc/src}/stories/assets/plugin.svg +0 -0
  159. /package/{src → doc/src}/stories/assets/repo.svg +0 -0
  160. /package/{src → doc/src}/stories/assets/stackalt.svg +0 -0
@@ -1,36 +1,33 @@
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
+
19
+ defineProps({
20
+ showNumber: {
21
+ type: Boolean,
22
+ default: true,
23
+ },
24
+ total: {
25
+ type: [String, Number],
26
+ default: '5,0',
27
+ },
28
+ fillWidth: {
29
+ type: Number,
30
+ default: 50,
33
31
  },
34
- computed: {}
35
- }
32
+ })
36
33
  </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 { 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,26 @@
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
+
39
+ defineProps({
40
+ data: {
41
+ type: Array,
42
+ required: true,
43
+ default: () => {
44
+ return []
60
45
  },
61
46
  },
62
- }
47
+ })
63
48
  </script>
64
49
 
65
50
  <style scoped>
@@ -67,4 +52,4 @@ export default {
67
52
  font-size: 15px;
68
53
  margin-bottom: 2px;
69
54
  }
70
- </style>
55
+ </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 && !toggleWhenActive ? '' : toggle($event)"
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 && !toggleWhenActive ? '' : toggle($event)"
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,172 @@
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 { ref, onBeforeUnmount } 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 = (event) => {
119
+ if (props.disabled) return
120
+ if (!show.value) {
121
+ open()
122
+ } else {
123
+ close()
124
+ }
125
+ event.stopPropagation()
126
+ }
127
+
128
+ const handleEsc = (evt) => {
129
+ if (show.value && evt.keyCode === 27) close()
130
+ }
131
+
132
+ const open = () => {
133
+ emit('open')
134
+ show.value = true
135
+ if (PSDropdownDialog.value) {
136
+ PSDropdownDialog.value.style.opacity = 0
137
+ PSDropdownDialog.value.style.display = 'block'
138
+ }
139
+ setTimeout(() => {
140
+ updatePosition()
141
+ watchParentScrolling()
142
+ document.addEventListener('keyup', handleEsc)
143
+ window.addEventListener('resize', updatePosition)
144
+ // window.addEventListener('click', clickOutside)
145
+ }, 10)
146
+ }
147
+
148
+ const close = () => {
149
+ if (show.value == true) {
150
+ emit('close')
151
+ if (PSDropdownDialog.value !== null) {
152
+ PSDropdownDialog.value.style.display = 'none'
153
+ PSDropdownDialog.value.style.opacity = 0
154
+ }
155
+ show.value = false
156
+ unwatchParentScrolling()
157
+ }
158
+ document.removeEventListener('keyup', handleEsc)
159
+ document.removeEventListener('resize', updatePosition)
160
+ // document.removeEventListener('click', clickOutside)
161
+ }
162
+
163
+ const watchParentScrolling = () => {
164
+ scrollableParentEl.value = getParentScrollableEl(PSDropdown.value)
165
+ if (scrollableParentEl.value) {
166
+ scrollableParentEl.value.addEventListener('scroll', updatePosition)
167
+ }
168
+ }
169
+
170
+ const unwatchParentScrolling = () => {
171
+ if (scrollableParentEl.value) {
172
+ scrollableParentEl.value.removeEventListener('scroll', updatePosition())
173
+ }
174
+ }
175
+
176
+ const updatePosition = () => {
177
+ if (PSDropdownDialog.value === null || PSDropdownTrigger.value === null) return
178
+
179
+ const rectTrigger = PSDropdownTrigger.value.getBoundingClientRect()
180
+ const rectDialog = PSDropdownDialog.value.getBoundingClientRect()
181
+ const windowWidth = document.documentElement.clientWidth
182
+
183
+ PSDropdownDialog.value.style.position = 'fixed'
184
+ PSDropdownDialog.value.style.top = `${rectTrigger.y + rectTrigger.height}px`
185
+ PSDropdownDialog.value.style.minWidth = `${rectTrigger.width}px`
186
+
187
+ if (rectTrigger.x + rectDialog.width + 20 > windowWidth) {
188
+ PSDropdownDialog.value.style.left = `${windowWidth - rectDialog.width - 30}px`
189
+ } else {
190
+ PSDropdownDialog.value.style.left = `${rectTrigger.x}px`
191
+ }
192
+
193
+ if (props.position == 'custom') {
194
+ PSDropdownDialog.value.style.top = `${rectTrigger.y}px`
195
+ PSDropdownDialog.value.style.left = `${rectTrigger.x + 100}px`
196
+ }
197
+
198
+ if (rectTrigger.top < 10) {
199
+ close()
200
+ console.warn('The dropdown are too close from the top of the page')
201
+ return
202
+ }
203
+
204
+ setTimeout(() => {
205
+ if(PSDropdownDialog.value){
206
+ PSDropdownDialog.value.style.opacity = 1
207
+ }
208
+ }, 10)
209
+ }
210
+
211
+ const clickOutside = (event) => {
212
+ if (!show.value) return
213
+ if (!PSDropdown.value == event.target || !PSDropdown.value?.contains(event.target)) {
214
+ close()
215
+ }
213
216
  }
214
217
  </script>