@kiva/kv-components 3.57.0 → 3.59.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/CHANGELOG.md +27 -0
- package/package.json +2 -2
- package/tests/unit/specs/components/KvCommentsReplyButton.spec.js +8 -0
- package/tests/unit/specs/utils/imageUtils.spec.js +29 -0
- package/utils/imageUtils.js +43 -0
- package/vue/KvCommentsListItem.vue +5 -0
- package/vue/KvCommentsReplyButton.vue +15 -1
- package/vue/KvUserAvatar.vue +132 -0
- package/vue/stories/KvCommentsReplyButton.stories.js +23 -0
- package/vue/stories/KvUserAvatar.stories.js +47 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.59.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.58.0...@kiva/kv-components@3.59.0) (2024-03-04)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* replies count added to reply commenting button ([#359](https://github.com/kiva/kv-ui-elements/issues/359)) ([87e4b01](https://github.com/kiva/kv-ui-elements/commit/87e4b01022641e774203274a0b3a353d1b2a37bc))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [3.58.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.57.0...@kiva/kv-components@3.58.0) (2024-03-01)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* fallback to kiva logo if no image or name ([74cdc90](https://github.com/kiva/kv-ui-elements/commit/74cdc900a8c1f9783771a7428f2722f59f5edf09))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* port avatar component from cps to cover different avatar situations ([036506f](https://github.com/kiva/kv-ui-elements/commit/036506f7680646c8e432af1842fb55851a5c6b2c))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
6
33
|
# [3.57.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.56.1...@kiva/kv-components@3.57.0) (2024-03-01)
|
|
7
34
|
|
|
8
35
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiva/kv-components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.59.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"optional": true
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "26d0e3f17353ef2a4f9a634a22ea335789a0252d"
|
|
79
79
|
}
|
|
@@ -12,6 +12,14 @@ describe('KvCommentsReplyButton', () => {
|
|
|
12
12
|
expect(replyButton).toBeDefined();
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
+
it('should render number of replies', () => {
|
|
16
|
+
const { getByTestId } = render(KvCommentsReplyButton, { props: { numberOfReplies: 6 } });
|
|
17
|
+
const replyCount = getByTestId('reply-count');
|
|
18
|
+
|
|
19
|
+
expect(replyCount).toBeDefined();
|
|
20
|
+
expect(replyCount).toHaveTextContent(6);
|
|
21
|
+
});
|
|
22
|
+
|
|
15
23
|
it('should emit click event when clicked', async () => {
|
|
16
24
|
const { getByRole, emitted } = render(KvCommentsReplyButton);
|
|
17
25
|
const replyButton = getByRole('button', { name: 'Reply' });
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isLegacyPlaceholderAvatar, randomizedUserAvatarClass } from '../../../../utils/imageUtils';
|
|
2
|
+
|
|
3
|
+
describe('imageUtils.ts', () => {
|
|
4
|
+
describe('isLegacyPlaceholderAvatar', () => {
|
|
5
|
+
it('should return true when filename is default kiva user avatar.', () => {
|
|
6
|
+
expect(isLegacyPlaceholderAvatar('726677.jpg')).toBe(true);
|
|
7
|
+
expect(isLegacyPlaceholderAvatar('315726.jpg')).toBe(true);
|
|
8
|
+
expect(isLegacyPlaceholderAvatar('4d844ac2c0b77a8a522741b908ea5c32.jpg')).toBe(true);
|
|
9
|
+
expect(isLegacyPlaceholderAvatar('726677.png')).toBe(true);
|
|
10
|
+
expect(isLegacyPlaceholderAvatar('315726.gif')).toBe(true);
|
|
11
|
+
expect(isLegacyPlaceholderAvatar('4d844ac2c0b77a8a522741b908ea5c32.png')).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should return false when filename is not default kiva user avatar.', () => {
|
|
15
|
+
expect(isLegacyPlaceholderAvatar('')).toBe(false);
|
|
16
|
+
expect(isLegacyPlaceholderAvatar('test')).toBe(false);
|
|
17
|
+
expect(isLegacyPlaceholderAvatar('123abc.jpg')).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('randomizedUserAvatarClass', () => {
|
|
22
|
+
it('should return random classes', () => {
|
|
23
|
+
const class1 = randomizedUserAvatarClass();
|
|
24
|
+
|
|
25
|
+
expect(class1).toContain('tw-text-');
|
|
26
|
+
expect(class1).toContain('tw-bg-');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if the users avatar is the default legacy placeholder image from the monolith.
|
|
3
|
+
* The legacy avatars are found exclusively at the following urls:
|
|
4
|
+
* <domain>/img/<size param>/726677.jpg
|
|
5
|
+
* <domain>/img/<size param>/315726.jpg
|
|
6
|
+
* for images from Fastly, urls, like: <domain>/img/s100/4d844ac2c0b77a8a522741b908ea5c32.jpg
|
|
7
|
+
* are the default placeholder image.
|
|
8
|
+
*
|
|
9
|
+
* @param filename The filename of the avatar
|
|
10
|
+
* @returns Whether the file is a legacy placeholder image
|
|
11
|
+
*/
|
|
12
|
+
export function isLegacyPlaceholderAvatar(filename) {
|
|
13
|
+
// if filename is empty or undefined, return false
|
|
14
|
+
if (!filename) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
// convert filename to string if it is a number
|
|
18
|
+
let filenameCleaned = filename.toString();
|
|
19
|
+
// remove file extension from filename if it exists
|
|
20
|
+
if (filenameCleaned.includes('.')) {
|
|
21
|
+
[filenameCleaned] = filenameCleaned.split('.');
|
|
22
|
+
}
|
|
23
|
+
const defaultProfileIds = ['726677', '315726', '4d844ac2c0b77a8a522741b908ea5c32'];
|
|
24
|
+
return defaultProfileIds.includes(filenameCleaned);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns a class string to style a user avatar
|
|
29
|
+
* @returns Random user avatar class string
|
|
30
|
+
*/
|
|
31
|
+
export function randomizedUserAvatarClass() {
|
|
32
|
+
const userCardStyleOptions = [
|
|
33
|
+
{ color: 'tw-text-action', bg: 'tw-bg-brand-100' },
|
|
34
|
+
{ color: 'tw-text-black', bg: 'tw-bg-brand-100' },
|
|
35
|
+
{ color: 'tw-text-white', bg: 'tw-bg-action' },
|
|
36
|
+
{ color: 'tw-text-brand-100', bg: 'tw-bg-action' },
|
|
37
|
+
{ color: 'tw-text-primary-inverse', bg: 'tw-bg-action' },
|
|
38
|
+
{ color: 'tw-text-white', bg: 'tw-bg-black' },
|
|
39
|
+
{ color: 'tw-text-action', bg: 'tw-bg-black' },
|
|
40
|
+
];
|
|
41
|
+
const randomStyle = userCardStyleOptions[Math.floor(Math.random() * userCardStyleOptions.length)];
|
|
42
|
+
return `${randomStyle.color} ${randomStyle.bg}`;
|
|
43
|
+
}
|
|
@@ -40,11 +40,13 @@
|
|
|
40
40
|
<p
|
|
41
41
|
v-if="numberOfLikes"
|
|
42
42
|
data-testid="like-count"
|
|
43
|
+
class="tw-font-medium"
|
|
43
44
|
>
|
|
44
45
|
{{ numberOfLikes }}
|
|
45
46
|
</p>
|
|
46
47
|
</div>
|
|
47
48
|
<kv-comments-reply-button
|
|
49
|
+
:number-of-replies="numberOfReplies"
|
|
48
50
|
@click="replyClick"
|
|
49
51
|
/>
|
|
50
52
|
</div>
|
|
@@ -188,6 +190,8 @@ export default {
|
|
|
188
190
|
|
|
189
191
|
const numberOfLikes = computed(() => comment?.value?.children_counts?.like ?? 0);
|
|
190
192
|
|
|
193
|
+
const numberOfReplies = computed(() => comment?.value?.children_counts?.like ?? 0);
|
|
194
|
+
|
|
191
195
|
return {
|
|
192
196
|
hideInput,
|
|
193
197
|
showInput,
|
|
@@ -203,6 +207,7 @@ export default {
|
|
|
203
207
|
childComments,
|
|
204
208
|
isLiked,
|
|
205
209
|
numberOfLikes,
|
|
210
|
+
numberOfReplies,
|
|
206
211
|
};
|
|
207
212
|
},
|
|
208
213
|
};
|
|
@@ -17,7 +17,12 @@
|
|
|
17
17
|
fill="#1C1B1F"
|
|
18
18
|
/>
|
|
19
19
|
</svg>
|
|
20
|
-
|
|
20
|
+
<span
|
|
21
|
+
v-if="numberOfReplies"
|
|
22
|
+
data-testid="reply-count"
|
|
23
|
+
>
|
|
24
|
+
{{ numberOfReplies }}
|
|
25
|
+
</span>
|
|
21
26
|
<span>
|
|
22
27
|
Reply
|
|
23
28
|
</span>
|
|
@@ -27,6 +32,15 @@
|
|
|
27
32
|
<script>
|
|
28
33
|
export default {
|
|
29
34
|
name: 'KvCommentsReplyButton',
|
|
35
|
+
props: {
|
|
36
|
+
/**
|
|
37
|
+
* The number of replies to the comment.
|
|
38
|
+
*/
|
|
39
|
+
numberOfReplies: {
|
|
40
|
+
type: Number,
|
|
41
|
+
default: 0,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
30
44
|
emits: [
|
|
31
45
|
'click',
|
|
32
46
|
],
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="data-hj-suppress"
|
|
4
|
+
:class="{ 'tw-w-3': isSmall, 'tw-w-6': !isSmall }"
|
|
5
|
+
>
|
|
6
|
+
<!-- User is anonymous or data is missing -->
|
|
7
|
+
<div
|
|
8
|
+
v-if="isAnonymousUser"
|
|
9
|
+
class="
|
|
10
|
+
tw-rounded-full
|
|
11
|
+
tw-bg-brand
|
|
12
|
+
tw-inline-flex tw-align-center tw-justify-center
|
|
13
|
+
"
|
|
14
|
+
:class="{ 'tw-w-3 tw-h-3': isSmall, 'tw-w-6 tw-h-6': !isSmall }"
|
|
15
|
+
>
|
|
16
|
+
<!-- Kiva K logo -->
|
|
17
|
+
<!-- eslint-disable max-len -->
|
|
18
|
+
<svg
|
|
19
|
+
class="tw-h-full tw-text-brand"
|
|
20
|
+
:class="{ 'tw-w-3 tw-h-3': isSmall }"
|
|
21
|
+
width="25"
|
|
22
|
+
height="37"
|
|
23
|
+
viewBox="0 0 25 37"
|
|
24
|
+
fill="none"
|
|
25
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
26
|
+
>
|
|
27
|
+
<path
|
|
28
|
+
d="M8.22861 0.875H0.857178V36.3125H8.22861V0.875Z"
|
|
29
|
+
fill="white"
|
|
30
|
+
/>
|
|
31
|
+
<path
|
|
32
|
+
d="M10.1143 23.2751C21.9428 23.2751 24.6857 13.2126 24.6857 11.4626H23.6571C11.8286 11.4626 9.08569 21.5251 9.08569 23.2751H10.1143Z"
|
|
33
|
+
fill="white"
|
|
34
|
+
/>
|
|
35
|
+
<path
|
|
36
|
+
d="M9.08569 24.2376C9.08569 26.0751 11.1428 36.3126 23.8285 36.3126H24.8571C24.8571 34.4751 22.8 24.2376 10.1143 24.2376H9.08569Z"
|
|
37
|
+
fill="white"
|
|
38
|
+
/>
|
|
39
|
+
</svg>
|
|
40
|
+
<!-- eslint-enable max-len -->
|
|
41
|
+
</div>
|
|
42
|
+
<!-- User is not anonymous and has an image -->
|
|
43
|
+
<div
|
|
44
|
+
v-else-if="!isLegacyPlaceholderAvatar(imageFilename) && imageFilename"
|
|
45
|
+
>
|
|
46
|
+
<img
|
|
47
|
+
:src="lenderImageUrl"
|
|
48
|
+
alt="Image of lender"
|
|
49
|
+
class="tw-rounded-full tw-inline-block"
|
|
50
|
+
:class="{ 'tw-w-3 tw-h-3': isSmall, 'tw-w-6 tw-h-6': !isSmall }"
|
|
51
|
+
>
|
|
52
|
+
</div>
|
|
53
|
+
<!-- User is not anonymous and does not have an image -->
|
|
54
|
+
<div
|
|
55
|
+
v-else-if="isLegacyPlaceholderAvatar(imageFilename) || !imageFilename"
|
|
56
|
+
class="
|
|
57
|
+
tw-rounded-full
|
|
58
|
+
tw-inline-flex tw-align-center tw-justify-center
|
|
59
|
+
"
|
|
60
|
+
:class="avatarClass()"
|
|
61
|
+
>
|
|
62
|
+
<!-- First Letter of lender name -->
|
|
63
|
+
<span class="tw-self-center">
|
|
64
|
+
{{ lenderNameFirstLetter }}
|
|
65
|
+
</span>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</template>
|
|
69
|
+
|
|
70
|
+
<script>
|
|
71
|
+
import { computed, toRefs } from 'vue-demi';
|
|
72
|
+
import { isLegacyPlaceholderAvatar, randomizedUserAvatarClass } from '../utils/imageUtils';
|
|
73
|
+
|
|
74
|
+
export default {
|
|
75
|
+
name: 'KvUserAvatar',
|
|
76
|
+
props: {
|
|
77
|
+
/**
|
|
78
|
+
* The name of the lender
|
|
79
|
+
*/
|
|
80
|
+
lenderName: {
|
|
81
|
+
type: String,
|
|
82
|
+
default: '',
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* The image of the lender
|
|
86
|
+
*/
|
|
87
|
+
lenderImageUrl: {
|
|
88
|
+
type: String,
|
|
89
|
+
default: '',
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* The image of the lender
|
|
93
|
+
*/
|
|
94
|
+
isSmall: {
|
|
95
|
+
type: Boolean,
|
|
96
|
+
default: false,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
setup(props) {
|
|
100
|
+
const {
|
|
101
|
+
lenderName,
|
|
102
|
+
lenderImageUrl,
|
|
103
|
+
isSmall,
|
|
104
|
+
} = toRefs(props);
|
|
105
|
+
|
|
106
|
+
const isAnonymousUser = computed(() => {
|
|
107
|
+
return (lenderName.value === '' && lenderImageUrl.value === '') || lenderName.value === 'Anonymous';
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const avatarClass = () => {
|
|
111
|
+
const smallClass = isSmall?.value ? 'tw-w-3 tw-h-3 tw-text-h4' : 'tw-w-6 tw-h-6 tw-text-h2';
|
|
112
|
+
return `${randomizedUserAvatarClass()} ${smallClass}`;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const imageFilename = computed(() => {
|
|
116
|
+
return lenderImageUrl?.value?.split('/').pop() ?? '';
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const lenderNameFirstLetter = computed(() => {
|
|
120
|
+
return lenderName?.value?.substring(0, 1).toUpperCase();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
isAnonymousUser,
|
|
125
|
+
avatarClass,
|
|
126
|
+
imageFilename,
|
|
127
|
+
lenderNameFirstLetter,
|
|
128
|
+
isLegacyPlaceholderAvatar,
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
</script>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import KvCommentsReplyButton from '../KvCommentsReplyButton.vue';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
title: 'KvCommentsReplyButton',
|
|
5
|
+
component: KvCommentsReplyButton,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const story = (args) => {
|
|
9
|
+
const template = (templateArgs, { argTypes }) => ({
|
|
10
|
+
props: Object.keys(argTypes),
|
|
11
|
+
components: { KvCommentsReplyButton },
|
|
12
|
+
setup() { return { args: templateArgs }; },
|
|
13
|
+
template: `
|
|
14
|
+
<KvCommentsReplyButton v-bind="args" />
|
|
15
|
+
`,
|
|
16
|
+
});
|
|
17
|
+
template.args = args;
|
|
18
|
+
return template;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const Default = story({});
|
|
22
|
+
|
|
23
|
+
export const ReplyCount = story({ numberOfReplies: 6 });
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import KvUserAvatar from '../KvUserAvatar.vue';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
title: 'KvUserAvatar',
|
|
5
|
+
component: KvUserAvatar,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const story = (args) => {
|
|
9
|
+
const template = (templateArgs, { argTypes }) => ({
|
|
10
|
+
props: Object.keys(argTypes),
|
|
11
|
+
components: { KvUserAvatar },
|
|
12
|
+
setup() { return { args: templateArgs }; },
|
|
13
|
+
template: `
|
|
14
|
+
<KvUserAvatar v-bind="args" />
|
|
15
|
+
`,
|
|
16
|
+
});
|
|
17
|
+
template.args = args;
|
|
18
|
+
return template;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const Default = story({
|
|
22
|
+
lenderImageUrl: 'https://www.development.kiva.org/img/s100/26e15431f51b540f31cd9f011cc54f31.jpg',
|
|
23
|
+
lenderName: 'Roger',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const NoImage = story({
|
|
27
|
+
lenderImageUrl: '',
|
|
28
|
+
lenderName: 'Roger',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const Anonymous = story({
|
|
32
|
+
lenderImageUrl: 'https://www.development.kiva.org/img/s100/26e15431f51b540f31cd9f011cc54f31.jpg',
|
|
33
|
+
lenderName: 'Anonymous',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const DefaultProfile = story({
|
|
37
|
+
lenderImageUrl: 'https://www.development.kiva.org/img/s100/4d844ac2c0b77a8a522741b908ea5c32.jpg',
|
|
38
|
+
lenderName: 'Default Profile',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const IsSmall = story({
|
|
42
|
+
lenderImageUrl: 'https://www.development.kiva.org/img/s100/26e15431f51b540f31cd9f011cc54f31.jpg',
|
|
43
|
+
lenderName: 'Roger',
|
|
44
|
+
isSmall: true,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const Fallback = story();
|