@policystudio/policy-studio-ui-vue 1.1.88 → 1.1.90-access.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 (170) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.js +75 -67
  3. package/.github/workflows/deploy-storybook.yml +5 -5
  4. package/.nvmrc +1 -0
  5. package/dist/css/psui_styles_output.css +6617 -0
  6. package/dist/index.d.ts +51 -0
  7. package/dist/index.js +106 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/util/GeneralFunctions.d.ts +3 -0
  10. package/dist/util/GeneralFunctions.js +35 -0
  11. package/dist/util/GeneralFunctions.js.map +1 -0
  12. package/dist/util/directives.d.ts +1 -0
  13. package/dist/util/directives.js +22 -0
  14. package/dist/util/directives.js.map +1 -0
  15. package/dist/util/imageLoader.d.ts +6 -0
  16. package/dist/util/imageLoader.js +52 -0
  17. package/dist/util/imageLoader.js.map +1 -0
  18. package/doc/.nvmrc +1 -0
  19. package/doc/.storybook/PolicyStudio.ts +11 -0
  20. package/doc/.storybook/main.ts +27 -0
  21. package/doc/.storybook/manager.ts +7 -0
  22. package/{.storybook/preview.js → doc/.storybook/preview.ts} +2 -3
  23. package/doc/package-lock.json +22653 -0
  24. package/doc/package.json +71 -0
  25. package/doc/shims-vue.d.ts +6 -0
  26. package/{src/stories/Accordion.stories.js → doc/src/stories/Accordion.stories.ts} +4 -5
  27. package/{src/stories/BadgeWithIcon.stories.js → doc/src/stories/BadgeWithIcon.stories.ts} +2 -2
  28. package/{src/stories/BarChart.stories.js → doc/src/stories/BarChart.stories.ts} +2 -2
  29. package/{src/stories/Breadcrumb.stories.js → doc/src/stories/Breadcrumb.stories.ts} +2 -5
  30. package/{src/stories/Button.stories.js → doc/src/stories/Button.stories.ts} +130 -130
  31. package/{src/stories/CardInfos.stories.js → doc/src/stories/CardInfos.stories.ts} +2 -3
  32. package/{src/stories/ChartLegend.stories.js → doc/src/stories/ChartLegend.stories.ts} +2 -3
  33. package/{src/stories/Checkbox.stories.js → doc/src/stories/Checkbox.stories.ts} +2 -2
  34. package/{src/stories/CheckboxSimple.stories.js → doc/src/stories/CheckboxSimple.stories.ts} +2 -2
  35. package/{src/stories/Chips.stories.js → doc/src/stories/Chips.stories.ts} +22 -23
  36. package/{src/stories/ClimateZoneBadge.stories.js → doc/src/stories/ClimateZoneBadge.stories.ts} +3 -2
  37. package/doc/src/stories/Collapse.stories.ts +46 -0
  38. package/{src/stories/CostEffectBar.stories.js → doc/src/stories/CostEffectBar.stories.ts} +3 -2
  39. package/{src/stories/Datatable.stories.js → doc/src/stories/Datatable.stories.ts} +7 -4
  40. package/{src/stories/DateCardInfo.stories.js → doc/src/stories/DateCardInfo.stories.ts} +2 -6
  41. package/{src/stories/Dialog.stories.js → doc/src/stories/Dialog.stories.ts} +2 -2
  42. package/{src/stories/Draggable.stories.js → doc/src/stories/Draggable.stories.ts} +3 -2
  43. package/{src/stories/Dropdown.stories.js → doc/src/stories/Dropdown.stories.ts} +4 -3
  44. package/{src/stories/DropdownList.stories.js → doc/src/stories/DropdownList.stories.ts} +4 -2
  45. package/{src/stories/ElevationSystem.stories.mdx → doc/src/stories/ElevationSystem.mdx} +1 -1
  46. package/{src/stories/HighlightRippleDot.stories.js → doc/src/stories/HighlightRippleDot.stories.ts} +3 -2
  47. package/{src/stories/Icon.stories.js → doc/src/stories/Icon.stories.ts} +3 -1
  48. package/{src/stories/InlineSelector.stories.js → doc/src/stories/InlineSelector.stories.ts} +2 -2
  49. package/{src/stories/Input.stories.js → doc/src/stories/Input.stories.ts} +7 -4
  50. package/{src/stories/InputSelect.stories.js → doc/src/stories/InputSelect.stories.ts} +3 -2
  51. package/{src/stories/InputTextArea.stories.js → doc/src/stories/InputTextArea.stories.ts} +2 -2
  52. package/{src/stories/Introduction.stories.mdx → doc/src/stories/Introduction.mdx} +101 -101
  53. package/{src/stories/MiniTag.stories.js → doc/src/stories/MiniTag.stories.ts} +9 -2
  54. package/{src/stories/ProgressBar.stories.js → doc/src/stories/ProgressBar.stories.ts} +3 -2
  55. package/{src/stories/RadioButton.stories.js → doc/src/stories/RadioButton.stories.ts} +2 -2
  56. package/{src/stories/RadioButtonSimple.stories.js → doc/src/stories/RadioButtonSimple.stories.ts} +2 -2
  57. package/{src/stories/SimpleAlert.stories.js → doc/src/stories/SimpleAlert.stories.ts} +3 -2
  58. package/{src/stories/Slider.stories.js → doc/src/stories/Slider.stories.ts} +6 -2
  59. package/{src/stories/Switch.stories.js → doc/src/stories/Switch.stories.ts} +2 -2
  60. package/{src/stories/TabHeader.stories.js → doc/src/stories/TabHeader.stories.ts} +6 -1
  61. package/{src/stories/TableResults.stories.js → doc/src/stories/TableResults.stories.ts} +11 -7
  62. package/{src/stories/TagScope.stories.js → doc/src/stories/TagScope.stories.ts} +3 -2
  63. package/{src/stories/TestimonialCard.stories.js → doc/src/stories/TestimonialCard.stories.ts} +3 -3
  64. package/{src/stories/Toast.stories.js → doc/src/stories/Toast.stories.ts} +2 -2
  65. package/{src/stories/Toggle.stories.js → doc/src/stories/Toggle.stories.ts} +7 -4
  66. package/{src/stories/Tooltip.stories.js → doc/src/stories/Tooltip.stories.ts} +6 -6
  67. package/{src/stories/Typography.stories.mdx → doc/src/stories/Typography.mdx} +107 -105
  68. package/doc/tsconfig.json +17 -0
  69. package/package.json +43 -39
  70. package/scripts/gulp.js +11 -0
  71. package/scripts/kill-port.sh +12 -0
  72. package/src/App.vue +30 -0
  73. package/src/assets/scss/base.scss +3 -30
  74. package/src/assets/scss/components/PsAccordion.scss +2 -2
  75. package/src/assets/scss/components/PsButton.scss +7 -1
  76. package/src/assets/scss/components/PsChips.scss +12 -7
  77. package/src/assets/scss/components/PsCollapse.scss +71 -0
  78. package/src/assets/scss/components/PsCostEffectBar.scss +4 -4
  79. package/src/assets/scss/components/PsDataTable.scss +1 -1
  80. package/src/assets/scss/components/PsDateCardInfo.scss +4 -5
  81. package/src/assets/scss/components/PsDialog.scss +7 -0
  82. package/src/assets/scss/components/PsDropdownList.scss +1 -1
  83. package/src/assets/scss/components/PsInput.scss +9 -0
  84. package/src/assets/scss/components/PsProgressBar.scss +4 -4
  85. package/src/assets/scss/components/PsTabHeader.scss +57 -2
  86. package/src/assets/scss/components/PsTableResults.scss +53 -22
  87. package/src/assets/scss/components/PsTestimonialCard.scss +1 -1
  88. package/src/assets/scss/components/PsTooltip.scss +149 -145
  89. package/src/components/accordion/PsAccordion.vue +20 -21
  90. package/src/components/accordion/PsAccordionItem.vue +121 -81
  91. package/src/components/badges-and-tags/PsBadgeWithIcon.vue +37 -36
  92. package/src/components/badges-and-tags/PsCardInfos.vue +40 -40
  93. package/src/components/badges-and-tags/PsChartLegend.vue +50 -41
  94. package/src/components/badges-and-tags/PsClimateZoneBadge.vue +13 -19
  95. package/src/components/badges-and-tags/PsCostEffectBar.vue +28 -61
  96. package/src/components/badges-and-tags/PsDateCardInfo.vue +17 -18
  97. package/src/components/badges-and-tags/PsHighlightRippleDot.vue +4 -3
  98. package/src/components/badges-and-tags/PsMiniTag.vue +39 -41
  99. package/src/components/badges-and-tags/PsProgressBar.vue +72 -68
  100. package/src/components/badges-and-tags/PsTagScope.vue +17 -22
  101. package/src/components/badges-and-tags/PsTestimonialCard.vue +25 -30
  102. package/src/components/buttons/PsButton.vue +90 -98
  103. package/src/components/chips/PsChips.vue +118 -103
  104. package/src/components/collapse/PsCollapse.vue +124 -0
  105. package/src/components/controls/PsCheckbox.vue +86 -83
  106. package/src/components/controls/PsCheckboxSimple.vue +97 -97
  107. package/src/components/controls/PsDraggable.vue +100 -99
  108. package/src/components/controls/PsInlineSelector.vue +111 -113
  109. package/src/components/controls/PsRadioButton.vue +72 -60
  110. package/src/components/controls/PsRadioButtonSimple.vue +81 -77
  111. package/src/components/controls/PsSlider.vue +190 -181
  112. package/src/components/controls/PsSwitch.vue +63 -54
  113. package/src/components/controls/PsToggle.vue +62 -57
  114. package/src/components/data-graphics/PsBarChart.vue +22 -23
  115. package/src/components/datatable/PsDataTable.vue +70 -65
  116. package/src/components/datatable/PsDataTableItem.vue +30 -32
  117. package/src/components/forms/PsDropdown.vue +173 -166
  118. package/src/components/forms/PsDropdownList.vue +133 -130
  119. package/src/components/forms/PsInput.vue +163 -146
  120. package/src/components/forms/PsInputSelect.vue +121 -100
  121. package/src/components/forms/PsInputTextArea.vue +84 -74
  122. package/src/components/navigations/PsBreadcrumb.vue +25 -34
  123. package/src/components/notifications/PsDialog.vue +67 -60
  124. package/src/components/notifications/PsSimpleAlert.vue +47 -37
  125. package/src/components/notifications/PsToast.vue +48 -42
  126. package/src/components/table-results/PsTableResults.vue +534 -506
  127. package/src/components/table-results/PsTableResultsBody.vue +69 -68
  128. package/src/components/table-results/PsTableResultsHead.vue +108 -69
  129. package/src/components/table-results/PsTableResultsHeadComparison.vue +88 -69
  130. package/src/components/table-results/PsTableResultsHeadFlexible.vue +112 -72
  131. package/src/components/table-results/PsTableResultsRow.vue +61 -58
  132. package/src/components/tabs/PsTabHeader.vue +138 -116
  133. package/src/components/tooltip/PsDialogTooltip.vue +112 -107
  134. package/src/components/tooltip/PsRichTooltip.vue +46 -43
  135. package/src/components/tooltip/PsTooltip.vue +126 -122
  136. package/src/components/ui/PsDotLoader.vue +6 -10
  137. package/src/components/ui/PsIcon.vue +149 -134
  138. package/src/index.ts +159 -0
  139. package/src/tsconfig.json +12 -0
  140. package/src/types/index.d.ts +6 -0
  141. package/src/util/GeneralFunctions.js +16 -7
  142. package/src/util/directives.ts +24 -0
  143. package/src/util/imageLoader.js +14 -7
  144. package/tailwind.config.js +12 -3
  145. package/tsconfig.json +47 -0
  146. package/.storybook/PolicyStudio.js +0 -10
  147. package/.storybook/eventBus.js +0 -3
  148. package/.storybook/main.js +0 -25
  149. package/.storybook/manager.js +0 -6
  150. package/babel.config.js +0 -3
  151. package/backup-package-lock.json +0 -37194
  152. package/dist/css/psui_styles.css +0 -110890
  153. package/postcss.config.js +0 -8
  154. package/src/components/playground/PsScrollBar.vue +0 -248
  155. package/src/index.js +0 -167
  156. package/src/stories/Playground.stories.js +0 -16
  157. /package/{src → doc/src}/assets/images/multifamily-units.svg +0 -0
  158. /package/{src → doc/src}/assets/images/policy-studio.svg +0 -0
  159. /package/{src/contents/ComparisonData.js → doc/src/contents/ComparisonData.ts} +0 -0
  160. /package/{src/contents/FlexibleData.js → doc/src/contents/FlexibleData.ts} +0 -0
  161. /package/{src/contents/ResultsData.js → doc/src/contents/ResultsData.ts} +0 -0
  162. /package/{src/stories/Colors.stories.mdx → doc/src/stories/Colors.mdx} +0 -0
  163. /package/{src → doc/src}/stories/assets/code-brackets.svg +0 -0
  164. /package/{src → doc/src}/stories/assets/colors.svg +0 -0
  165. /package/{src → doc/src}/stories/assets/comments.svg +0 -0
  166. /package/{src → doc/src}/stories/assets/direction.svg +0 -0
  167. /package/{src → doc/src}/stories/assets/flow.svg +0 -0
  168. /package/{src → doc/src}/stories/assets/plugin.svg +0 -0
  169. /package/{src → doc/src}/stories/assets/repo.svg +0 -0
  170. /package/{src → doc/src}/stories/assets/stackalt.svg +0 -0
@@ -1,97 +1,101 @@
1
1
  <template>
2
- <div
3
- class='psui-el-radio'
4
- :class="[getComponentClass, {'disabled':disabled}]"
2
+ <div
3
+ class="psui-el-radio"
4
+ :class="[getComponentClass, { disabled: disabled }]"
5
5
  v-bind="getComponentAttrs"
6
- >
7
- <input
8
- type="radio"
9
- :checked="checked"
6
+ >
7
+ <input
8
+ type="radio"
9
+ :checked="checked"
10
10
  :disabled="disabled"
11
11
  :label="label"
12
12
  :name="name"
13
13
  :id="getInputId"
14
14
  v-bind="inputAttrs"
15
- @change="$emit('change')"
16
- />
17
- <label
15
+ @change="emit('change')"
16
+ >
17
+ <label
18
18
  :for="getInputId"
19
19
  class="psui-el-checkmark"
20
20
  >
21
21
  <slot name="content">
22
22
  <span>{{ label }}</span>
23
23
  </slot>
24
- </label>
24
+ </label>
25
25
  </div>
26
26
  </template>
27
27
 
28
- <script>
29
- import { randomString } from '../../util/GeneralFunctions'
28
+ <script setup>
29
+ import { randomString } from '../../util/GeneralFunctions.js'
30
+ import { computed, useAttrs } from 'vue'
31
+
32
+ const emit = defineEmits(['change'])
30
33
 
31
- export default {
32
- name: 'PsRadioButtonSimple',
33
- props: {
34
- /**
35
- * It sets the label of the checkbox input.
36
- */
37
- label: {
38
- type: String,
39
- },
40
- name:{
41
- type: String,
42
- },
43
- /**
44
- * It disables the checkbox input.
45
- */
46
- disabled: {
47
- type: Boolean,
48
- default: false,
49
- },
50
- /**
51
- * Sets the input as checked
52
- */
53
- checked: {
54
- type: Boolean,
55
- default: false
56
- },
57
- /**
58
- * Add html attributes to the element input
59
- */
60
- inputAttrs: {
61
- type: Object,
62
- default: () => ({})
63
- },
64
- /**
65
- * It set the of the checkbox input. eg: big and small.
66
- */
67
- size: {
68
- type: String,
69
- default: 'big',
70
- validator: (value)=> ['big', 'small'].includes(value)
71
- },
72
- /**
73
- * It set the layout of the checkbox input. eg: default and mixed.
74
- */
34
+ const props = defineProps({
35
+ /**
36
+ * It sets the label of the checkbox input.
37
+ */
38
+ label: {
39
+ type: String,
40
+ default: '',
41
+ },
42
+ name: {
43
+ type: String,
44
+ default: '',
45
+ },
46
+ /**
47
+ * It disables the checkbox input.
48
+ */
49
+ disabled: {
50
+ type: Boolean,
51
+ default: false,
52
+ },
53
+ /**
54
+ * Sets the input as checked
55
+ */
56
+ checked: {
57
+ type: Boolean,
58
+ default: false,
75
59
  },
76
- inheritAttrs: false,
77
- computed:{
78
- getComponentClass(){
79
- return `size-${this.size}`
80
- },
81
- getInputId() {
82
- if (this?.inputAttrs?.id) {
83
- return this.inputAttrs.id
84
- } else if (this?.$attrs?.id) {
85
- return this.$attrs.id
86
- } else {
87
- return randomString(16)
88
- }
89
- },
90
- getComponentAttrs() {
91
- let componentAttrs = { ... this.$attrs }
92
- delete componentAttrs.id
93
- return componentAttrs
94
- }
60
+ /**
61
+ * Add html attributes to the element input
62
+ */
63
+ inputAttrs: {
64
+ type: Object,
65
+ default: () => ({}),
95
66
  },
96
- }
67
+ /**
68
+ * It set the of the checkbox input. eg: big and small.
69
+ */
70
+ size: {
71
+ type: String,
72
+ default: 'big',
73
+ validator: (value) => ['big', 'small'].includes(value),
74
+ },
75
+ /**
76
+ * It set the layout of the checkbox input. eg: default and mixed.
77
+ */
78
+ })
79
+
80
+ const attrs = useAttrs()
81
+
82
+ const getComponentClass = computed(() => {
83
+ return `size-${props.size}`
84
+ })
85
+
86
+ const getInputId = computed(() => {
87
+ if (props?.inputAttrs?.id) {
88
+ return props.inputAttrs.id
89
+ } else if (attrs?.id) {
90
+ return attrs.id
91
+ } else {
92
+ return randomString(16)
93
+ }
94
+ })
95
+
96
+ const getComponentAttrs = computed(() => {
97
+ let componentAttrs = { ...attrs }
98
+ delete componentAttrs.id
99
+ return componentAttrs
100
+ })
97
101
  </script>
@@ -1,18 +1,18 @@
1
1
  <template>
2
- <div
2
+ <div
3
3
  class="psui-el-slider"
4
4
  :class="`layout-${layout}`"
5
5
  >
6
- <div
7
- v-if="label"
6
+ <div
7
+ v-if="label"
8
8
  class="psui-el-slider-label"
9
9
  >
10
- <span>{{ label }}</span>
10
+ <span>{{ label }}</span>
11
11
  </div>
12
12
 
13
- <div
13
+ <div
14
14
  class="psui-el-slider-wrapper"
15
- :class="{ 'psui-flex psui-items-center' : !label && !bubble }"
15
+ :class="{ 'psui-flex psui-items-center': !label && !bubble }"
16
16
  >
17
17
  <div class="psui-el-slider-wrapper-input">
18
18
  <div
@@ -23,25 +23,25 @@
23
23
  {{ sliderValue }}
24
24
  </div>
25
25
 
26
- <div
27
- class="slider-bar"
26
+ <div
27
+ class="slider-bar"
28
28
  :style="{ width: progressWidth }"
29
- ></div>
29
+ />
30
30
 
31
- <div
31
+ <div
32
32
  v-for="(barStyle, index) in bgBarStyles"
33
33
  :key="index"
34
34
  class="slider-bar-bg"
35
35
  :style="bgBarStyles[index]"
36
- ></div>
36
+ />
37
37
 
38
- <div
38
+ <div
39
39
  v-for="(bar, index) in barStyles"
40
40
  :key="index"
41
41
  class="slider-bar-dynamic"
42
42
  :style="barStyles[index]"
43
- ></div>
44
-
43
+ />
44
+
45
45
  <input
46
46
  ref="slider"
47
47
  type="range"
@@ -51,26 +51,26 @@
51
51
  class="psui-el-slider-input psui-float-left"
52
52
  v-model="sliderValue"
53
53
  @input="updateSlider($event)"
54
- />
54
+ >
55
55
  </div>
56
56
 
57
- <div
57
+ <div
58
58
  v-if="dividers"
59
59
  class="psui-el-slider-grid"
60
60
  >
61
- <div
61
+ <div
62
62
  v-for="(grid, index) in gridData"
63
63
  :key="index"
64
64
  class="line"
65
65
  :style="{ left: `${grid}%` }"
66
- ></div>
66
+ />
67
67
 
68
68
  <span class="info info-min">{{ min }}</span>
69
69
  <span class="info info-max">{{ max }}</span>
70
70
  </div>
71
71
 
72
- <span
73
- v-if="!label && !bubble"
72
+ <span
73
+ v-if="!label && !bubble"
74
74
  class="psui-el-slider-bubble"
75
75
  >
76
76
  {{ sliderValue }}
@@ -79,177 +79,186 @@
79
79
  </div>
80
80
  </template>
81
81
 
82
- <script>
83
- export const sliderLayout = ['default', 'rich']
84
-
85
- export default {
86
- name: 'PsSlider',
87
- props: {
88
- layout: {
89
- type: String,
90
- default: 'default',
91
- validator: (value) => {
92
- return sliderLayout.indexOf(value) !== -1
93
- }
94
- },
95
- min: {
96
- type: Number,
97
- default: 0,
98
- },
99
- max: {
100
- type: Number,
101
- default: 100,
102
- required: true,
103
- },
104
- maxValue: {
105
- type: Number,
106
- default: 100,
107
- required: true,
108
- },
109
- label: {
110
- type: String,
111
- },
112
- value: {
113
- type: [Number, String],
114
- default: 0,
115
- },
116
- baseValue: {
117
- type: [Number, Boolean]
118
- },
119
- labelPosition: {
120
- type: String
121
- },
122
- step: {
123
- type: Number,
124
- default: 1
125
- },
126
- bubble: {
127
- type: Boolean
128
- },
129
- dividers: {
130
- type: Boolean,
131
- default: false
132
- },
133
- modelValue: {
134
- type: Number,
135
- default: 50,
136
- },
137
- gridData: {
138
- type: Array,
139
- default() {
140
- return [0, 30, 55, 80, 100]
141
- }
142
- },
143
- sliderColors: {
144
- type: Array,
145
- default() {
146
- return [
147
- { start: 140, end: 170, bgColor: '#FF906D' },
148
- { start: 170, end: 200, bgColor: '#D65C5A' },
149
- ]
150
- }
82
+ <script setup>
83
+ import { computed, ref, watch, onUnmounted, onMounted } from 'vue'
84
+
85
+ const props = defineProps({
86
+ layout: {
87
+ type: String,
88
+ default: 'default',
89
+ validator: (value) => {
90
+ return ['default', 'rich'].indexOf(value) !== -1
151
91
  },
152
- bgColors: {
153
- type: Array,
154
- default() {
155
- return [
156
- { start: 0, end: 170, bgColor: '#D6DDE5' },
157
- { start: 170, end: 200, bgColor: '#A2ACB7' },
158
- ]
159
- }
160
- }
161
92
  },
162
- data: () => ({
163
- isMounted: false,
164
- sliderWidth: 0,
165
- sliderValue: 0,
166
- progress: 0,
167
- barStyles: [],
168
- bgBarStyles: []
169
- }),
170
- computed: {
171
- positionBubble() {
172
- const val = this.sliderValue
173
- const width = this.sliderWidth - 24
174
- const percent = (val - this.min) / (this.max - this.min)
175
- const offset = -2
176
- const position = width * percent + offset
177
-
178
- return `${position}px`
179
- },
180
- progressWidth() {
181
- if (this.sliderValue > this.maxValue) {
182
- return '100%'
183
- }
184
- return ((this.sliderValue - this.min) / (this.max - this.min)) * 100 + '%'
185
- },
93
+ min: {
94
+ type: Number,
95
+ default: 0,
186
96
  },
187
- watch: {
188
- sliderValue(newValue) {
189
- this.updateProgress()
190
- this.$emit('input', newValue)
191
- this.updateBarStyles()
192
- },
193
- value(newValue) {
194
- this.sliderValue = newValue
195
- },
196
- sliderColors: {
197
- immediate: true,
198
- handler() {
199
- this.updateBarStyles()
200
- },
201
- },
97
+ max: {
98
+ type: Number,
99
+ default: 100,
100
+ required: true,
202
101
  },
203
- created() {
204
- window.addEventListener('resize', this.resizeHandler)
102
+ maxValue: {
103
+ type: Number,
104
+ default: 100,
105
+ required: true,
205
106
  },
206
- destroyed() {
207
- window.removeEventListener('resize', this.resizeHandler)
107
+ label: {
108
+ type: String,
109
+ default: '',
208
110
  },
209
- mounted() {
210
- this.isMounted = true
211
- this.updateProgress()
212
- this.updateBarStyles()
111
+ value: {
112
+ type: [Number, String],
113
+ default: 0,
213
114
  },
214
- methods: {
215
- updateProgress() {
216
- this.progress = Math.round(
217
- ((this.sliderValue - this.min) / (this.max - this.min)) * 100
218
- )
219
- },
220
- updateSlider(event) {
221
- this.sliderValue = Math.min(event.target.value, this.maxValue)
115
+ baseValue: {
116
+ type: [Number, Boolean],
117
+ default: false,
118
+ },
119
+ labelPosition: {
120
+ type: String,
121
+ default: '',
122
+ },
123
+ step: {
124
+ type: Number,
125
+ default: 1,
126
+ },
127
+ bubble: {
128
+ type: Boolean,
129
+ },
130
+ dividers: {
131
+ type: Boolean,
132
+ default: false,
133
+ },
134
+ modelValue: {
135
+ type: Number,
136
+ default: 50,
137
+ },
138
+ gridData: {
139
+ type: Array,
140
+ default() {
141
+ return [0, 30, 55, 80, 100]
222
142
  },
223
- updateBarStyles() {
224
- this.barStyles = this.sliderColors.map((bar) => this.getBarStyle(bar))
225
- this.bgBarStyles = this.bgColors.map((bar) => this.getBarStyle(bar, false))
143
+ },
144
+ sliderColors: {
145
+ type: Array,
146
+ default() {
147
+ return [
148
+ { start: 140, end: 170, bgColor: '#FF906D' },
149
+ { start: 170, end: 200, bgColor: '#D65C5A' },
150
+ ]
226
151
  },
227
- resizeHandler() {
228
- this.sliderWidth = this.$refs.slider.clientWidth
152
+ },
153
+ bgColors: {
154
+ type: Array,
155
+ default() {
156
+ return [
157
+ { start: 0, end: 170, bgColor: '#D6DDE5' },
158
+ { start: 170, end: 200, bgColor: '#A2ACB7' },
159
+ ]
229
160
  },
230
- getBarStyle(bar, normalizeByProgress = true) {
231
- const start = (bar.start / this.max) * 100
232
- const end = (bar.end / this.max) * 100
233
- const progress = parseFloat(this.progressWidth)
234
- let barWidth = end - start
235
- let barLeft = start
236
-
237
- if (normalizeByProgress) {
238
- if (progress < start) {
239
- barWidth = 0
240
- } else if (progress < end) {
241
- barWidth = progress - start
242
- }
243
- }
244
-
245
- return {
246
- left: `${barLeft}%`,
247
- backgroundColor: bar.bgColor,
248
- width: `${barWidth}%`
249
- }
250
- }
251
161
  },
252
-
162
+ })
163
+
164
+ const isMounted = ref(false)
165
+ const sliderWidth = ref(0)
166
+ const sliderValue = ref(0)
167
+ const progress = ref(0)
168
+ const barStyles = ref([])
169
+ const bgBarStyles = ref([])
170
+ const slider = ref(null)
171
+ const emit = defineEmits(['input'])
172
+
173
+
174
+ const positionBubble = computed(() => {
175
+ const val = sliderValue.value
176
+ const width = sliderWidth.value - 24
177
+ const percent = (val - props.min) / (props.max - props.min)
178
+ const offset = -2
179
+ const position = width * percent + offset
180
+ return `${position}px`
181
+ })
182
+
183
+ const progressWidth = computed(() => {
184
+ if (sliderValue.value > props.maxValue) {
185
+ return '100%'
186
+ }
187
+ return ((sliderValue.value - props.min) / (props.max - props.min)) * 100 + '%'
188
+ })
189
+
190
+ const updateProgress = () => {
191
+ progress.value = Math.round(((sliderValue.value - props.min) / (props.max - props.min)) * 100)
192
+ }
193
+
194
+ const updateSlider = (event) => {
195
+ sliderValue.value = Math.min(event.target.value, props.maxValue)
196
+ }
197
+
198
+ const updateBarStyles = () => {
199
+ barStyles.value = props.sliderColors.map((bar) => getBarStyle(bar))
200
+ bgBarStyles.value = props.bgColors.map((bar) => getBarStyle(bar, false))
201
+ }
202
+
203
+ const resizeHandler = () => {
204
+ sliderWidth.value = slider.value.clientWidth
205
+ }
206
+
207
+ const getBarStyle = (bar, normalizeByProgress = true) => {
208
+ const start = (bar.start / props.max) * 100
209
+ const end = (bar.end / props.max) * 100
210
+ const progress = parseFloat(progressWidth.value)
211
+ let barWidth = end - start
212
+ let barLeft = start
213
+ if (normalizeByProgress) {
214
+ if (progress < start) {
215
+ barWidth = 0
216
+ } else if (progress < end) {
217
+ barWidth = progress - start
218
+ }
219
+
220
+ return {
221
+ left: `${barLeft}%`,
222
+ backgroundColor: bar.bgColor,
223
+ width: `${barWidth}%`,
224
+ }
225
+ }
253
226
  }
227
+
228
+ watch(sliderValue, (newValue) => {
229
+ updateProgress()
230
+ emit('input', newValue)
231
+ updateBarStyles()
232
+ })
233
+
234
+ watch(
235
+ () => props.value,
236
+ (newValue) => {
237
+ sliderValue.value = newValue
238
+ }
239
+ )
240
+
241
+ watch(
242
+ () => props.sliderColors,
243
+ () => {
244
+ updateBarStyles()
245
+ },
246
+ { immediate: true }
247
+ )
248
+
249
+ window.addEventListener('resize', resizeHandler)
250
+
251
+ onUnmounted(() => {
252
+ window.removeEventListener('resize', resizeHandler)
253
+ })
254
+
255
+ onMounted(() => {
256
+ isMounted.value = true
257
+ updateProgress()
258
+ updateBarStyles()
259
+ })
254
260
  </script>
255
- <style> /* Please, use the file src/assets/scss/components/PsSlider.scss */ </style>
261
+
262
+ <style>
263
+ /* Please, use the file src/assets/scss/components/PsSlider.scss */
264
+ </style>