Skip to content

Commit 2ce0bd1

Browse files
authored
Fixes for popupcards and project avatar in popupcard (#543)
- Fixes #389 - Fixes issue with project popupcard, where we were still using Dicebear ---- - Reorder data binding in popupcards to use loading state on correct element - Update project popupcard to use readthedocs-avatar instead of dicebear - Alter CSS rules to support readthedocs-avatar in FUI better [Screencast From 2024-12-11 20-10-34.webm](https://github.com/user-attachments/assets/e7311057-a6f4-4d13-b92b-f561e18bf266) ![image](https://github.com/user-attachments/assets/d611010b-d8fd-42c7-90fa-b506228c12d2)
1 parent bee623b commit 2ce0bd1

File tree

8 files changed

+68
-45
lines changed

8 files changed

+68
-45
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ repos:
44
hooks:
55
- id: prettier
66
args: ["--write", "."]
7-
types_or: [css, javascript, json]
7+
# Prettier should already do this for us, see `.prettierignore`.
8+
#types_or: [css, javascript, json]
89

910
- repo: https://github.com/ambv/black
1011
rev: "23.9.1"

readthedocsext/theme/static/readthedocsext/theme/css/site.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readthedocsext/theme/static/readthedocsext/theme/js/site.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readthedocsext/theme/templates/includes/elements/chips/base.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@
6767
</div>
6868
{% endblock chip_detail %}
6969
</a>
70-
<div class="ui flowing popup"
71-
data-bind="using: data, css: { loading: is_loading() }">
70+
<div class="ui flowing popup" data-bind="using: data">
7271
<div class="ui small basic horizontal card"
73-
data-bind="if: $parent.is_loaded()">
72+
data-bind="css: { loading: $parent.is_loading() }">
7473

7574
{% comment "rst" %}
7675

@@ -83,7 +82,7 @@
8382
{% block popupcard_image %}
8483
{% endblock popupcard_image %}
8584

86-
<div class="content">
85+
<div class="content" data-bind="if: $parent.is_loaded()">
8786

8887
{% comment "rst" %}
8988

@@ -136,7 +135,7 @@
136135
</div>
137136
</div>
138137

139-
<div class="extra content">
138+
<div class="extra content" data-bind="if: $parent.is_loaded()">
140139
{% comment "rst" %}
141140

142141
.. describe:: popupcard_extra

readthedocsext/theme/templates/includes/elements/chips/project.html

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{% extends "includes/elements/chips/base.html" %}
22

3-
{% load i18n %}
4-
{% load humanize %}
5-
{% load ext_theme_tags %}
3+
{% load trans from i18n %}
4+
{% load readthedocs_language_name from ext_theme_tags %}
65

76
{% block chip_view_params %}
87
'{% url "projects-detail" project.slug %}'
@@ -17,19 +16,7 @@
1716
{% endblock chip_classes %}
1817

1918
{% block chip_icon %}
20-
{% if project.remote_repository %}
21-
<img alt="{% blocktrans with name=project.name %}Project {{ name }} avatar{% endblocktrans %}"
22-
src="{{ project.remote_repository.avatar_url }}" />
23-
{% else %}
24-
{% comment %}
25-
For now, this is using Dicebear, which has a few random generators for
26-
user/project icons. We don't need to use Dicebear, but could use this or
27-
similar to generate files on disk and use an md5 hash or similar to link
28-
to the same image always.
29-
{% endcomment %}
30-
<img alt="{% blocktrans with name=project.name %}Project {{ name }} avatar{% endblocktrans %}"
31-
src="https://api.dicebear.com/5.x/shapes/svg?size=64&backgroundColor=b8abd4&shape1Color=8c74c1&shape2Color=7854c5&shape3Color=f0f0ff&seed={{ project.pk }}" />
32-
{% endif %}
19+
{% include "projects/includes/project_image.html" with project=project classes="micro rounded" %}
3320
{% endblock chip_icon %}
3421

3522
{% block chip_text %}
@@ -48,21 +35,7 @@
4835
{% endblock popupcard_header %}
4936

5037
{% block popupcard_right %}
51-
{% if project.remote_repository %}
52-
<img alt="{% blocktrans with name=project.name %}Project {{ name }} avatar{% endblocktrans %}"
53-
class="ui mini right floated rounded image"
54-
src="{{ project.remote_repository.avatar_url }}" />
55-
{% else %}
56-
{% comment %}
57-
For now, this is using Dicebear, which has a few random generators for
58-
user/project icons. We don't need to use Dicebear, but could use this or
59-
similar to generate files on disk and use an md5 hash or similar to link
60-
to the same image always.
61-
{% endcomment %}
62-
<img alt="{% blocktrans with name=project.name %}Project {{ name }} avatar{% endblocktrans %}"
63-
class="ui mini right floated rounded image"
64-
src="https://api.dicebear.com/5.x/shapes/svg?size=64&backgroundColor=b8abd4&shape1Color=8c74c1&shape2Color=7854c5&shape3Color=f0f0ff&seed={{ project.pk }}" />
65-
{% endif %}
38+
{% include "projects/includes/project_image.html" with project=project classes="mini right floated rounded" %}
6639
{% endblock popupcard_right %}
6740

6841
{% block popupcard_meta %}
@@ -79,7 +52,9 @@
7952
<div class="header">{% trans "Repository" %}</div>
8053
<div class="description">
8154
{% if project.remote_repository %}
82-
{% with repo=project.remote_repository %}<a href="{{ repo.html_url }}">{{ repo.full_name }}</a>{% endwith %}
55+
{% with repo=project.remote_repository %}
56+
<a href="{{ repo.html_url }}">{{ repo.full_name }}</a>
57+
{% endwith %}
8358
{% else %}
8459
<a href="{{ project.repo }}">{{ project.repo }}</a>
8560
{% endif %}

src/js/modules/avatar.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ export class AvatarElement extends LitElement {
3434
width: calc(var(--avatar-scale) * -4);
3535
height: calc(var(--avatar-scale) * -4);
3636
}
37-
38-
:host(.micro.image) > div {
39-
--avatar-scale: -6px;
40-
}
4137
`;
4238

4339
render() {

src/sui/themes/rtd-application/elements/image.overrides

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,46 @@
1414
width: @microWidth;
1515
height: auto;
1616
}
17+
18+
// Support web component for avatar
19+
.avatarWidth(@size) {
20+
width: @size;
21+
// This adjusts the variable that determines the width the avatar sprite is render at
22+
--avatar-scale: @size / -4;
23+
}
24+
25+
readthedocs-avatar.ui.image {
26+
display: inline-block;
27+
height: auto;
28+
&.rounded {
29+
overflow: hidden;
30+
}
31+
32+
&.micro {
33+
.avatarWidth(@microWidth);
34+
}
35+
&.mini {
36+
.avatarWidth(@miniWidth);
37+
}
38+
&.tiny {
39+
.avatarWidth(@tinyWidth);
40+
}
41+
&.small {
42+
.avatarWidth(@smallWidth);
43+
}
44+
&.medium {
45+
.avatarWidth(@mediumWidth);
46+
}
47+
&.large {
48+
.avatarWidth(@largeWidth);
49+
}
50+
&.big {
51+
.avatarWidth(@bigWidth);
52+
}
53+
&.huge {
54+
.avatarWidth(@hugeWidth);
55+
}
56+
&.massive {
57+
.avatarWidth(@massiveWidth);
58+
}
59+
}

src/sui/themes/rtd-application/elements/label.overrides

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@
1111
text-overflow: ellipsis;
1212
max-width: 100%;
1313
}
14+
15+
.ui.image.label > readthedocs-avatar {
16+
width: auto;
17+
margin: (-1 * @verticalPadding) @imageLabelTextDistance
18+
(-1 * @verticalPadding) (-1 * @verticalPadding);
19+
border-radius: @imageLabelBorderRadius 0 0 @imageLabelBorderRadius;
20+
overflow: hidden;
21+
vertical-align: top;
22+
}

0 commit comments

Comments
 (0)