@bildvitta/quasar-ui-asteroid 3.11.0 → 3.12.0-beta.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bildvitta/quasar-ui-asteroid",
3
3
  "description": "Asteroid",
4
- "version": "3.11.0",
4
+ "version": "3.12.0-beta.0",
5
5
  "author": "Bild & Vitta <systemteam@bild.com.br>",
6
6
  "license": "MIT",
7
7
  "main": "dist/asteroid.cjs.min.js",
@@ -115,7 +115,7 @@ export default {
115
115
  },
116
116
 
117
117
  hasCompaniesSelect () {
118
- return this.companiesOptions.length > 1
118
+ return !!this.companiesOptions.length
119
119
  }
120
120
  },
121
121
 
@@ -1,16 +1,26 @@
1
1
  <template>
2
- <div ref="parent" class="full-width">
3
- <div class="justify-between no-wrap row text-no-wrap">
4
- <div ref="truncate" :class="truncateTextClass">
5
- <slot>{{ text }}</slot>
2
+ <div ref="parent" :class="classes">
3
+ <div class="no-wrap row text-no-wrap">
4
+ <div ref="truncate" class="ellipsis">
5
+ <slot>{{ displayText }}</slot>
6
6
  </div>
7
7
 
8
- <div v-if="isTruncated" class="cursor-pointer text-primary" @click.stop.prevent="toggle">
9
- {{ seeMoreLabel }}
10
- </div>
8
+ <qas-btn v-if="hasButton" class="q-ml-sm" :label="buttonLabel" @click.stop.prevent="toggle" />
11
9
  </div>
12
10
 
13
- <qas-dialog v-model="show" v-bind="defaultProps" aria-label="Diálogo de texto completo" role="dialog" />
11
+ <qas-dialog v-model="show" v-bind="defaultProps" aria-label="Diálogo de texto completo" role="dialog">
12
+ <template v-if="isCounterMode" #description>
13
+ <div class="q-col-gutter-y-md row">
14
+ <div
15
+ v-for="(item, index) in normalizedList"
16
+ :key="index"
17
+ class="col-12"
18
+ >
19
+ {{ item }}
20
+ </div>
21
+ </div>
22
+ </template>
23
+ </qas-dialog>
14
24
  </div>
15
25
  </template>
16
26
 
@@ -23,8 +33,6 @@ import {
23
33
  watch
24
34
  } from 'vue'
25
35
 
26
- import useScreen from '../../composables/use-screen'
27
-
28
36
  import QasDialog from '../dialog/QasDialog.vue'
29
37
 
30
38
  // define component name
@@ -32,6 +40,11 @@ defineOptions({ name: 'QasTextTruncate' })
32
40
 
33
41
  // props
34
42
  const props = defineProps({
43
+ color: {
44
+ type: String,
45
+ default: 'grey-8'
46
+ },
47
+
35
48
  dialogProps: {
36
49
  type: Object,
37
50
  default: () => ({ persistent: false })
@@ -47,6 +60,11 @@ const props = defineProps({
47
60
  default: 0
48
61
  },
49
62
 
63
+ maxVisibleItem: {
64
+ type: Number,
65
+ default: 1
66
+ },
67
+
50
68
  seeMoreLabel: {
51
69
  type: String,
52
70
  default: 'Ver mais'
@@ -55,6 +73,20 @@ const props = defineProps({
55
73
  text: {
56
74
  type: String,
57
75
  default: ''
76
+ },
77
+
78
+ typography: {
79
+ type: String,
80
+ default: 'body1'
81
+ },
82
+
83
+ list: {
84
+ type: Array,
85
+ default: () => []
86
+ },
87
+
88
+ useObjectList: {
89
+ type: Boolean
58
90
  }
59
91
  })
60
92
 
@@ -66,8 +98,6 @@ const parent = ref(null)
66
98
  const {
67
99
  textContent,
68
100
  isTruncated,
69
- truncateTextClass,
70
-
71
101
  truncateText
72
102
  } = useTruncate({ parent, props })
73
103
 
@@ -77,8 +107,18 @@ const {
77
107
  toggle
78
108
  } = useDialog({ props, textContent })
79
109
 
110
+ const {
111
+ buttonLabel,
112
+ displayText,
113
+ hasButton,
114
+ isCounterMode,
115
+ normalizedList
116
+ } = useTemplate()
117
+
80
118
  useMutationObserver({ truncate, callbackFn: truncateText })
81
119
 
120
+ const classes = computed(() => [`text-${props.color}`, `text-${props.typography}`])
121
+
82
122
  // composable functions
83
123
  function useDialog ({ props, textContent }) {
84
124
  // reactive vars
@@ -136,9 +176,6 @@ function useMutationObserver ({ truncate, callbackFn = () => {} }) {
136
176
  }
137
177
 
138
178
  function useTruncate ({ parent, props }) {
139
- // global
140
- const screen = useScreen()
141
-
142
179
  // reactive vars
143
180
  const maxPossibleWidth = ref('')
144
181
  const textContent = ref('')
@@ -153,10 +190,6 @@ function useTruncate ({ parent, props }) {
153
190
  // computed
154
191
  const isTruncated = computed(() => textWidth.value > maxPossibleWidth.value)
155
192
 
156
- const truncateTextClass = computed(() => {
157
- return (isTruncated.value || screen.isSmall) && 'ellipsis q-pr-sm'
158
- })
159
-
160
193
  // methods
161
194
  function truncateText () {
162
195
  parent.value.style.maxWidth = '100%'
@@ -174,9 +207,61 @@ function useTruncate ({ parent, props }) {
174
207
  textWidth,
175
208
 
176
209
  isTruncated,
177
- truncateTextClass,
178
210
 
179
211
  truncateText
180
212
  }
181
213
  }
214
+
215
+ function useTemplate () {
216
+ const {
217
+ counterLabel,
218
+ normalizedList,
219
+ normalizedCounterText
220
+ } = useCounter()
221
+
222
+ const isCounterMode = computed(() => !!props.list.length)
223
+
224
+ const hasButton = computed(() => {
225
+ return isCounterMode.value ? normalizedList.value.length > props.maxVisibleItem : isTruncated.value
226
+ })
227
+
228
+ const displayText = computed(() => {
229
+ return isCounterMode.value ? normalizedCounterText.value : props.text
230
+ })
231
+
232
+ const buttonLabel = computed(() => {
233
+ return isCounterMode.value ? counterLabel.value : props.seeMoreLabel
234
+ })
235
+
236
+ return {
237
+ buttonLabel,
238
+ displayText,
239
+ hasButton,
240
+ isCounterMode,
241
+ normalizedList
242
+ }
243
+ }
244
+
245
+ function useCounter () {
246
+ const normalizedList = computed(() => {
247
+ return props.useObjectList ? props.list.map(({ label }) => label) : props.list
248
+ })
249
+
250
+ const counterText = computed(() => {
251
+ return props.maxVisibleItem > 1
252
+ ? normalizedList.value.slice(0, props.maxVisibleItem).join(', ')
253
+ : normalizedList.value[0]
254
+ })
255
+
256
+ const normalizedCounterText = computed(() => counterText.value || '-')
257
+
258
+ const counter = computed(() => (normalizedList.value.length || 1) - props.maxVisibleItem)
259
+ const counterLabel = computed(() => `+${counter.value}`)
260
+
261
+ return {
262
+ normalizedList,
263
+ normalizedCounterText,
264
+ counterLabel
265
+ }
266
+ }
182
267
  </script>
@@ -4,6 +4,11 @@ meta:
4
4
  desc: Trunca um texto baseado no tamanho do elemento pai e adiciona um rotulo "ver mais" que quando clicado mostra um dialog com o texto original completo (sem ser truncado).
5
5
 
6
6
  props:
7
+ color:
8
+ desc: Cor do texto.
9
+ type: String
10
+ default: grey-8
11
+
7
12
  dialog-props:
8
13
  desc: Repassa todas props e eventos para o componente `QasDialog`.
9
14
  type: Object
@@ -18,6 +23,11 @@ props:
18
23
  type: Number
19
24
  default: 0
20
25
 
26
+ max-visible-item:
27
+ desc: Quantidade de itens a serem exibidos fora do dialog (uso junto a prop list).
28
+ type: Number
29
+ default: 0
30
+
21
31
  see-more-label:
22
32
  desc: Texto que vai aparecer para ser clicado quando o texto original for truncado.
23
33
  type: String
@@ -27,6 +37,20 @@ props:
27
37
  desc: Texto a ser truncado.
28
38
  type: String
29
39
 
40
+ typography:
41
+ desc: Tipografia.
42
+ default: body1
43
+ type: String
44
+
45
+ list:
46
+ desc: Lista de itens a serem exibidos (uso junto a prop list).
47
+ default: []
48
+ type: Array
49
+
50
+ use-object-list:
51
+ desc: Utiliza a propriedade "list" como array de objeto contendo label (uso junto a prop list).
52
+ type: Boolean
53
+
30
54
  slots:
31
55
  default:
32
56
  desc: slot padrão que é utilizado para acessar o texto original (tanto o que é truncado quando o de dentro do dialog)