@policystudio/policy-studio-ui-vue 1.1.90-beta.5 → 1.1.90-beta.51

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 +2 -8
  2. package/.github/workflows/deploy-storybook.yml +4 -4
  3. package/.nvmrc +1 -0
  4. package/dist/css/psui_styles_output.css +6639 -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/{.storybook → doc/.storybook}/main.ts +8 -2
  19. package/{.storybook → doc/.storybook}/preview.ts +2 -3
  20. package/doc/package-lock.json +22653 -0
  21. package/doc/package.json +71 -0
  22. package/{src → doc}/shims-vue.d.ts +0 -5
  23. package/{src → doc/src}/stories/Accordion.stories.ts +2 -3
  24. package/{src → doc/src}/stories/BadgeWithIcon.stories.ts +1 -1
  25. package/{src → doc/src}/stories/BarChart.stories.ts +1 -1
  26. package/{src → doc/src}/stories/Breadcrumb.stories.ts +1 -1
  27. package/doc/src/stories/Button.stories.ts +130 -0
  28. package/{src → doc/src}/stories/CardInfos.stories.ts +1 -1
  29. package/{src → doc/src}/stories/ChartLegend.stories.ts +1 -1
  30. package/{src → doc/src}/stories/Checkbox.stories.ts +1 -1
  31. package/{src → doc/src}/stories/CheckboxSimple.stories.ts +1 -1
  32. package/{src → doc/src}/stories/Chips.stories.ts +1 -4
  33. package/{src → doc/src}/stories/ClimateZoneBadge.stories.ts +2 -1
  34. package/doc/src/stories/Collapse.stories.ts +46 -0
  35. package/{src → doc/src}/stories/CostEffectBar.stories.ts +2 -1
  36. package/{src → doc/src}/stories/Datatable.stories.ts +5 -2
  37. package/{src → doc/src}/stories/DateCardInfo.stories.ts +1 -1
  38. package/{src → doc/src}/stories/Dialog.stories.ts +2 -2
  39. package/{src → doc/src}/stories/Draggable.stories.ts +3 -2
  40. package/{src → doc/src}/stories/Dropdown.stories.ts +4 -3
  41. package/{src → doc/src}/stories/DropdownList.stories.ts +4 -2
  42. package/{src → doc/src}/stories/HighlightRippleDot.stories.ts +3 -2
  43. package/{src → doc/src}/stories/Icon.stories.ts +3 -1
  44. package/{src → doc/src}/stories/InlineSelector.stories.ts +1 -1
  45. package/{src → doc/src}/stories/Input.stories.ts +7 -4
  46. package/{src → doc/src}/stories/InputSelect.stories.ts +3 -2
  47. package/{src → doc/src}/stories/InputTextArea.stories.ts +1 -1
  48. package/{src → doc/src}/stories/MiniTag.stories.ts +9 -2
  49. package/{src → doc/src}/stories/ProgressBar.stories.ts +3 -2
  50. package/{src → doc/src}/stories/RadioButton.stories.ts +2 -2
  51. package/{src → doc/src}/stories/RadioButtonSimple.stories.ts +1 -1
  52. package/{src → doc/src}/stories/SimpleAlert.stories.ts +3 -2
  53. package/{src → doc/src}/stories/Slider.stories.ts +6 -2
  54. package/{src → doc/src}/stories/Switch.stories.ts +2 -2
  55. package/{src → doc/src}/stories/TabHeader.stories.ts +6 -1
  56. package/{src → doc/src}/stories/TableResults.stories.ts +11 -7
  57. package/{src → doc/src}/stories/TagScope.stories.ts +3 -2
  58. package/{src → doc/src}/stories/TestimonialCard.stories.ts +3 -3
  59. package/{src → doc/src}/stories/Toast.stories.ts +2 -2
  60. package/{src → doc/src}/stories/Toggle.stories.ts +6 -3
  61. package/{src → doc/src}/stories/Tooltip.stories.ts +3 -3
  62. package/doc/tsconfig.json +17 -0
  63. package/package.json +13 -28
  64. package/scripts/gulp.js +11 -0
  65. package/src/assets/scss/base.scss +3 -34
  66. package/src/assets/scss/components/PsAccordion.scss +1 -1
  67. package/src/assets/scss/components/PsChips.scss +9 -3
  68. package/src/assets/scss/components/PsCollapse.scss +71 -0
  69. package/src/assets/scss/components/PsDataTable.scss +1 -1
  70. package/src/assets/scss/components/PsDropdownList.scss +1 -1
  71. package/src/assets/scss/components/PsTableResults.scss +28 -1
  72. package/src/assets/scss/components/PsTooltip.scss +2 -1
  73. package/src/components/accordion/PsAccordionItem.vue +88 -74
  74. package/src/components/badges-and-tags/PsBadgeWithIcon.vue +31 -34
  75. package/src/components/badges-and-tags/PsCardInfos.vue +39 -41
  76. package/src/components/badges-and-tags/PsChartLegend.vue +46 -51
  77. package/src/components/badges-and-tags/PsClimateZoneBadge.vue +13 -19
  78. package/src/components/badges-and-tags/PsCostEffectBar.vue +24 -56
  79. package/src/components/badges-and-tags/PsDateCardInfo.vue +17 -18
  80. package/src/components/badges-and-tags/PsHighlightRippleDot.vue +3 -2
  81. package/src/components/badges-and-tags/PsMiniTag.vue +39 -41
  82. package/src/components/badges-and-tags/PsProgressBar.vue +72 -68
  83. package/src/components/badges-and-tags/PsTagScope.vue +17 -22
  84. package/src/components/badges-and-tags/PsTestimonialCard.vue +19 -26
  85. package/src/components/buttons/PsButton.vue +61 -62
  86. package/src/components/chips/PsChips.vue +112 -101
  87. package/src/components/collapse/PsCollapse.vue +124 -0
  88. package/src/components/controls/PsCheckbox.vue +84 -84
  89. package/src/components/controls/PsCheckboxSimple.vue +95 -95
  90. package/src/components/controls/PsDraggable.vue +53 -55
  91. package/src/components/controls/PsInlineSelector.vue +98 -99
  92. package/src/components/controls/PsRadioButton.vue +65 -58
  93. package/src/components/controls/PsRadioButtonSimple.vue +79 -75
  94. package/src/components/controls/PsSlider.vue +185 -176
  95. package/src/components/controls/PsSwitch.vue +51 -52
  96. package/src/components/controls/PsToggle.vue +52 -50
  97. package/src/components/data-graphics/PsBarChart.vue +18 -21
  98. package/src/components/datatable/PsDataTable.vue +56 -60
  99. package/src/components/datatable/PsDataTableItem.vue +13 -28
  100. package/src/components/forms/PsDropdown.vue +166 -162
  101. package/src/components/forms/PsDropdownList.vue +133 -130
  102. package/src/components/forms/PsInput.vue +154 -153
  103. package/src/components/forms/PsInputSelect.vue +91 -92
  104. package/src/components/forms/PsInputTextArea.vue +70 -71
  105. package/src/components/navigations/PsBreadcrumb.vue +25 -34
  106. package/src/components/notifications/PsDialog.vue +57 -56
  107. package/src/components/notifications/PsSimpleAlert.vue +27 -29
  108. package/src/components/notifications/PsToast.vue +40 -39
  109. package/src/components/table-results/PsTableResults.vue +461 -468
  110. package/src/components/table-results/PsTableResultsBody.vue +66 -67
  111. package/src/components/table-results/PsTableResultsHead.vue +70 -67
  112. package/src/components/table-results/PsTableResultsHeadComparison.vue +67 -64
  113. package/src/components/table-results/PsTableResultsHeadFlexible.vue +94 -67
  114. package/src/components/table-results/PsTableResultsRow.vue +55 -56
  115. package/src/components/tabs/PsTabHeader.vue +106 -100
  116. package/src/components/tooltip/PsDialogTooltip.vue +96 -101
  117. package/src/components/tooltip/PsRichTooltip.vue +41 -45
  118. package/src/components/tooltip/PsTooltip.vue +111 -116
  119. package/src/components/ui/PsDotLoader.vue +1 -5
  120. package/src/components/ui/PsIcon.vue +143 -132
  121. package/src/index.ts +60 -67
  122. package/src/tsconfig.json +12 -0
  123. package/src/types/index.d.ts +6 -0
  124. package/src/util/{GeneralFunctions.ts → GeneralFunctions.js} +12 -3
  125. package/src/util/directives.ts +24 -0
  126. package/src/util/{imageLoader.ts → imageLoader.js} +7 -0
  127. package/tailwind.config.js +1 -1
  128. package/tsconfig.json +18 -13
  129. package/.storybook/eventBus.ts +0 -26
  130. package/babel.config.js +0 -17
  131. package/dist/css/psui_styles.css +0 -4647
  132. package/postcss.config.js +0 -8
  133. package/src/components/playground/PsScrollBar.vue +0 -320
  134. package/src/stories/Button.stories.ts +0 -48
  135. package/src/stories/Button.vue +0 -59
  136. package/src/stories/Header.stories.ts +0 -41
  137. package/src/stories/Header.vue +0 -77
  138. package/src/stories/Playground.stories.ts +0 -16
  139. package/src/stories/button.css +0 -30
  140. package/src/stories/header.css +0 -32
  141. package/webpack.config.js +0 -22
  142. /package/{.storybook → doc/.storybook}/PolicyStudio.ts +0 -0
  143. /package/{.storybook → doc/.storybook}/manager.ts +0 -0
  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 → doc/src}/contents/ComparisonData.ts +0 -0
  147. /package/{src → doc/src}/contents/FlexibleData.ts +0 -0
  148. /package/{src → 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,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
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
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
43
  />
44
-
44
+
45
45
  <input
46
46
  ref="slider"
47
47
  type="range"
@@ -54,11 +54,11 @@
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"
@@ -69,8 +69,8 @@
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
- unmounted() {
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)
253
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
+ }
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>
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <div
3
3
  class="psui-el-switch"
4
- :class="[getComponentClass, {'disabled':disabled}]"
4
+ :class="[getComponentClass, { disabled: disabled }]"
5
5
  @click="change()"
6
6
  >
7
7
  <input
@@ -15,59 +15,58 @@
15
15
  </div>
16
16
  </template>
17
17
 
18
- <script>
18
+ <script setup>
19
19
  //FIGMA CONTROLS & SELECTORS https://www.figma.com/file/Tto8hrNlSfuPcwd1pfqogF/%E2%9A%A1%EF%B8%8F-Design-System?node-id=1768%3A64852
20
+ import { computed } from 'vue'
20
21
 
21
- export default {
22
- name: 'PsSwitch',
23
- props: {
24
- /**
25
- * It sets the label of the switch button.
26
- */
27
- label:{
28
- type: String,
29
- },
30
- /**
31
- * It sets the value of the switch button.
32
- */
33
- value:{
34
- type: Boolean,
35
- },
36
- backgroundColor: {
37
- type: String,
38
- default:'psui-bg-green-20'
39
- },
40
- /**
41
- * It sets disabling mode.
42
- */
43
- disabled:{
44
- type: Boolean,
45
- default: false
46
- },
47
- /**
48
- * It sets the size of the switch button. eg: small and big.
49
- */
50
- size:{
51
- type: String,
52
- default: 'big',
53
- validator: (value)=> ['small', 'big'].includes(value)
54
- }
22
+ const emit = defineEmits('change', 'update:value')
23
+
24
+ const props = defineProps({
25
+ /**
26
+ * It sets the label of the switch button.
27
+ */
28
+ label: {
29
+ type: String,
30
+ default: '',
55
31
  },
56
- computed:{
57
- getToggleClass(){
58
- if(this.disabled) return 'toggle-false'
59
- return this.value ? `toggle-true ${this.backgroundColor}` : 'toggle-false psui-bg-gray-40'
60
- },
61
- getComponentClass(){
62
- return `size-${this.size}`
63
- }
32
+ /**
33
+ * It sets the value of the switch button.
34
+ */
35
+ value: {
36
+ type: Boolean,
64
37
  },
65
- methods: {
66
- change() {
67
- this.$emit('update:value', !this.value)
68
- this.$emit('change', !this.value)
69
- }
70
- }
71
- }
72
- </script>
38
+ backgroundColor: {
39
+ type: String,
40
+ default: 'psui-bg-green-20',
41
+ },
42
+ /**
43
+ * It sets disabling mode.
44
+ */
45
+ disabled: {
46
+ type: Boolean,
47
+ default: false,
48
+ },
49
+ /**
50
+ * It sets the size of the switch button. eg: small and big.
51
+ */
52
+ size: {
53
+ type: String,
54
+ default: 'big',
55
+ validator: (value) => ['small', 'big'].includes(value),
56
+ },
57
+ })
58
+
59
+ const getToggleClass = computed(() => {
60
+ if (props.disabled) return 'toggle-false'
61
+ return props.value ? `toggle-true ${props.backgroundColor}` : 'toggle-false psui-bg-gray-40'
62
+ })
73
63
 
64
+ const getComponentClass = computed(() => {
65
+ return `size-${props.size}`
66
+ })
67
+
68
+ const change = () => {
69
+ emit('update:value', !props.value)
70
+ emit('change', !props.value)
71
+ }
72
+ </script>
@@ -1,9 +1,9 @@
1
1
  <template>
2
- <div
3
- class="psui-el-toggle"
4
- role="group"
2
+ <div
3
+ class="psui-el-toggle"
4
+ role="group"
5
5
  >
6
- <button
6
+ <button
7
7
  type="button"
8
8
  v-for="(item, index) in items"
9
9
  :key="getKeyValue(item) + index"
@@ -15,55 +15,57 @@
15
15
  </div>
16
16
  </template>
17
17
 
18
- <script>
18
+ <script setup>
19
19
  //FIGMA CONTROLS & SELECTORS https://www.figma.com/file/Tto8hrNlSfuPcwd1pfqogF/%E2%9A%A1%EF%B8%8F-Design-System?node-id=1768%3A64852
20
20
 
21
- export default {
22
- name: 'PsToggle',
23
- props: {
24
- /**
25
- * It sets the items which will be used to create the toggle tab. See Figma - Controls & Selector for more information.
26
- */
27
- items: {
28
- type: Array,
29
- required: true
30
- },
31
- /**
32
- * It sets the value selected.
33
- */
34
- selected: {},
35
- /**
36
- * It sets the key label of your items if needed.
37
- */
38
- keyLabel: {
39
- type: [String, Function],
40
- default: 'label'
41
- },
42
- /**
43
- * It sets the key value of your items if needed.
44
- */
45
- keyValue: {
46
- type: [String, Function],
47
- default: 'value'
48
- }
21
+ const emit = defineEmits(['change', 'update:selected'])
22
+
23
+ const props = defineProps({
24
+ /**
25
+ * It sets the items which will be used to create the toggle tab. See Figma - Controls & Selector for more information.
26
+ */
27
+ items: {
28
+ type: Array,
29
+ required: true,
30
+ },
31
+ /**
32
+ * It sets the value selected.
33
+ */
34
+ selected: {},
35
+ /**
36
+ * It sets the key label of your items if needed.
37
+ */
38
+ keyLabel: {
39
+ type: [String, Function],
40
+ default: 'label',
49
41
  },
50
- methods: {
51
- selectOption(item) {
52
- this.$emit('update:selected', item)
53
- this.$emit('change', item)
54
- },
55
- getKeyLabel(item) {
56
- if(typeof this.keyLabel == 'function') return this.keyLabel(item)
57
- if(typeof item === 'object') return item[this.keyLabel]
58
- return item
59
- },
60
- getKeyValue(item) {
61
- if(typeof this.keyValue == 'function') return this.keyValue(item)
62
- if(typeof item === 'object') return item[this.keyLabel]
63
- return item
64
- },
65
- }
42
+ /**
43
+ * It sets the key value of your items if needed.
44
+ */
45
+ keyValue: {
46
+ type: [String, Function],
47
+ default: 'value',
48
+ },
49
+ })
50
+
51
+ const selectOption = (item) => {
52
+ emit('update:selected', item)
53
+ emit('change', item)
54
+ }
55
+
56
+ const getKeyLabel = (item) => {
57
+ if (typeof props.keyLabel == 'function') return props.keyLabel(item)
58
+ if (typeof item === 'object') return item[props.keyLabel]
59
+ return item
60
+ }
61
+
62
+ const getKeyValue = (item) => {
63
+ if (typeof props.keyValue == 'function') return props.keyValue(item)
64
+ if (typeof item === 'object') return item[props.keyLabel]
65
+ return item
66
66
  }
67
67
  </script>
68
68
 
69
- <style> /* Please, use the file src/assets/scss/components/PsToggle.scss */</style>
69
+ <style>
70
+ /* Please, use the file src/assets/scss/components/PsToggle.scss */
71
+ </style>