@dataloop-ai/components 0.18.99 → 0.18.100

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataloop-ai/components",
3
- "version": "0.18.99",
3
+ "version": "0.18.100",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -27,7 +27,7 @@
27
27
  >
28
28
  <div
29
29
  ref="dlChipRef"
30
- class="dl-chip--ellipsis"
30
+ :class="{ 'dl-chip--ellipsis': overflow }"
31
31
  >
32
32
  <slot>
33
33
  {{ hasLabel ? label : null }}
@@ -49,7 +49,7 @@
49
49
  </template>
50
50
 
51
51
  <script lang="ts">
52
- import { PropType, defineComponent, ref } from 'vue-demi'
52
+ import { PropType, defineComponent, ref, watch } from 'vue-demi'
53
53
  import { DlTooltip } from '../../shared'
54
54
  import { DlIcon } from '../../essential'
55
55
  import { useSizeObserver } from '../../../hooks/use-size-observer'
@@ -92,11 +92,16 @@ export default defineComponent({
92
92
  overflow: { type: Boolean, default: false },
93
93
  fit: { type: Boolean, default: false }
94
94
  },
95
- emits: ['remove'],
96
- setup() {
95
+ emits: ['remove', 'ellipsis'],
96
+ setup(props, ctx) {
97
97
  const isVisible = ref(true)
98
98
  const dlChipRef = ref(null)
99
- const { hasEllipsis } = useSizeObserver(dlChipRef)
99
+ const label = ref(props.label)
100
+ const { hasEllipsis } = useSizeObserver(dlChipRef, label)
101
+
102
+ watch(hasEllipsis, () => {
103
+ ctx.emit('ellipsis', hasEllipsis.value)
104
+ })
100
105
 
101
106
  return {
102
107
  isVisible,
@@ -1,22 +1,36 @@
1
- import { onBeforeUnmount, onMounted, ref, Ref } from 'vue-demi'
1
+ import { onBeforeUnmount, onMounted, ref, Ref, watch } from 'vue-demi'
2
2
  import { isEllipsisActive } from '../utils/is-ellipsis-active'
3
3
  import { get } from 'lodash'
4
4
 
5
- export function useSizeObserver(elRef: Ref, entryLevel = 'target') {
5
+ export function useSizeObserver(elRef: Ref, ...refsToWatch: any[]) {
6
+ const entryLevel = 'target'
6
7
  const widthRef = ref(0)
7
8
  const heightRef = ref(0)
8
9
  const hasEllipsis = ref(false)
9
10
  const borderBoxSize = ref(null)
10
- const resizeObserver = new ResizeObserver((entries) => {
11
- for (const entry of entries) {
12
- hasEllipsis.value = isEllipsisActive(get(entry, entryLevel))
13
- widthRef.value = entry.contentRect.width
14
- heightRef.value = entry.contentRect.height
15
- borderBoxSize.value = entry.borderBoxSize
11
+ const calcEllipsis = (el: HTMLElement) => {
12
+ hasEllipsis.value = isEllipsisActive(el)
13
+ }
14
+ const resizeObserver = new ResizeObserver(
15
+ (entries: ResizeObserverEntry[]) => {
16
+ for (const entry of entries) {
17
+ hasEllipsis.value = isEllipsisActive(get(entry, entryLevel))
18
+ widthRef.value = entry.contentRect.width
19
+ heightRef.value = entry.contentRect.height
20
+ borderBoxSize.value = entry.borderBoxSize
21
+ }
16
22
  }
17
- })
23
+ )
18
24
 
19
25
  onMounted(() => elRef.value && resizeObserver.observe(elRef.value))
26
+ watch(elRef, () => {
27
+ elRef.value && calcEllipsis(elRef.value)
28
+ })
29
+ for (const ref of refsToWatch) {
30
+ watch(ref, () => {
31
+ elRef.value && calcEllipsis(elRef.value)
32
+ })
33
+ }
20
34
  onBeforeUnmount(() => elRef.value && resizeObserver.unobserve(elRef.value))
21
35
 
22
36
  return {
@@ -1,6 +1,3 @@
1
1
  export const isEllipsisActive = (e: Element) => {
2
- return (
3
- (e as HTMLElement).offsetWidth < e.scrollWidth ||
4
- (e as HTMLElement).offsetHeight < e.scrollHeight
5
- )
2
+ return (e as HTMLElement).offsetWidth < e.scrollWidth
6
3
  }