Skip to content

Commit 09cba16

Browse files
committed
test: Update snapshots
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent f01dc51 commit 09cba16

File tree

51 files changed

+47
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import type { VNode, VNodeChildren } from 'vue'
7+
import { computed, onBeforeMount, ref, useSlots } from 'vue'
8+
9+
function slotText(slot: VNode): string {
10+
const extractText = (child?: VNodeChildren): string => {
11+
if (typeof child === 'string') {
12+
return child.trim()
13+
} else if (Array.isArray(child)) {
14+
return child
15+
.map((c) => extractText(c))
16+
.join('')
17+
}
18+
return ''
19+
}
20+
21+
return extractText(slot.children)
22+
}
23+
24+
export const useActionText = () => {
25+
const slots = useSlots()
26+
const text = ref('')
27+
const isLongText = computed(() => text.value && text.value.trim().length > 20)
28+
29+
function getText() {
30+
return (slots.default?.() ?? [])
31+
.map(slotText)
32+
.join('')
33+
}
34+
35+
onBeforeMount(() => { text.value = getText() })
36+
37+
return {
38+
/**
39+
* The current text from the default slot as $slots is not reactive
40+
*/
41+
text,
42+
/**
43+
* Check if the passed text is considered long (currently > 20 characters)
44+
*/
45+
isLongText,
46+
}
47+
}

0 commit comments

Comments
 (0)