Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

user-pills: Improve user pill styling and open popover on pill click in profile modal.

Raj Vishwakarma8b325c083f6f
diff --git a/web/src/custom_profile_fields_ui.ts b/web/src/custom_profile_fields_ui.ts
index 7ff64ca87e7..a49ffe2fa20 100644
--- a/web/src/custom_profile_fields_ui.ts
+++ b/web/src/custom_profile_fields_ui.ts
@@ -3,6 +3,7 @@ import $ from "jquery";
import * as z from "zod/mini";
import render_settings_custom_user_profile_field from "../templates/settings/custom_user_profile_field.hbs";
+import render_user_display_only_pill from "../templates/user_display_only_pill.hbs";
import {Typeahead} from "./bootstrap_typeahead.ts";
import * as bootstrap_typeahead from "./bootstrap_typeahead.ts";
@@ -201,6 +202,39 @@ export function initialize_custom_user_type_fields(
return user_pills;
}
+export function initialize_profile_user_type_pills(user_id: number): void {
+ const field_types = realm.custom_profile_field_types;
+
+ for (const field of realm.custom_profile_fields) {
+ if (field.type !== field_types.USER.id) {
+ continue;
+ }
+ const raw_field_value = people.get_custom_profile_data(user_id, field.id)?.value;
+ if (!raw_field_value) {
+ continue;
+ }
+ const field_value = user_value_schema.parse(JSON.parse(raw_field_value));
+
+ const selector = `.custom_user_field[data-field-id="${field.id}"] .user-type-custom-field-pill-container`;
+ const $pill_container = $("#user-profile-modal #content").find(selector).expectOne();
+ $pill_container.empty();
+
+ for (const user_id of field_value) {
+ const user = people.get_user_by_id_assert_valid(user_id);
+ const pill_html = render_user_display_only_pill({
+ display_value: user.full_name,
+ user_id: user.user_id,
+ img_src: people.small_avatar_url_for_person(user),
+ is_active: people.is_person_active(user.user_id),
+ is_current_user: people.is_my_user_id(user.user_id),
+ is_bot: user.is_bot,
+ });
+
+ $pill_container.append($(pill_html));
+ }
+ }
+}
+
export function format_date(date: Date | undefined, format: string): string {
if (date === undefined || date.toString() === "Invalid Date") {
return "Invalid Date";
diff --git a/web/src/user_profile.ts b/web/src/user_profile.ts
index 0b37fcc26f4..c7b9efd34d3 100644
--- a/web/src/user_profile.ts
+++ b/web/src/user_profile.ts
@@ -525,11 +525,7 @@ export function update_user_custom_profile_fields(user: User): void {
const profile_data = {profile_fields};
$custom_profile_field.html(render_user_custom_profile_fields(profile_data));
- custom_profile_fields_ui.initialize_custom_user_type_fields(
- "#user-profile-modal #content",
- user.user_id,
- false,
- );
+ custom_profile_fields_ui.initialize_profile_user_type_pills(user.user_id);
}
export function hide_user_profile(): void {
@@ -555,11 +551,7 @@ function initialize_user_type_fields(user: User): void {
// Avoid duplicate pill fields, by removing existing ones.
$("#user-profile-modal .pill").remove();
if (!user.is_bot) {
- custom_profile_fields_ui.initialize_custom_user_type_fields(
- "#user-profile-modal #content",
- user.user_id,
- false,
- );
+ custom_profile_fields_ui.initialize_profile_user_type_pills(user.user_id);
} else {
initialize_bot_owner("#user-profile-modal #content", user.user_id);
}
diff --git a/web/styles/input_pill.css b/web/styles/input_pill.css
index 601ad64fff6..6037a236eba 100644
--- a/web/styles/input_pill.css
+++ b/web/styles/input_pill.css
@@ -343,6 +343,7 @@
/* These pill are similar to .not-editable, but are meant to show
profile cards when clicked. */
+.user-type-custom-field-pill-container > .display_only_pill,
.panel_user_list > .pill-container,
.creator_details > .display_only_pill {
gap: 2px;
@@ -357,6 +358,13 @@
color: inherit;
}
+ /* `settings.css` applies a :focus-within box-shadow to `.custom_user_field .pill-container`
+ and `.bot_owner_user_field .pill-container`.That effect conflicts with the unified pill
+ styling (no shadow), so we override it here. */
+ &:focus-within {
+ box-shadow: none;
+ }
+
> .pill {
border: none;
text-decoration: none;
@@ -376,6 +384,30 @@
}
}
+#user-profile-modal {
+ .user-type-custom-field-pill-container {
+ display: inline-flex;
+ gap: var(--vertical-spacing-input-pill)
+ var(--horizontal-spacing-input-pill);
+ max-width: 100%;
+ flex-wrap: wrap;
+
+ /* We override the `.pill-container` style defined in
+ `settings.css` to ensure it expands to full width, preventing
+ names in the pill from being cut off in the user profile modal. */
+ .pill-container {
+ max-width: 100%;
+ }
+
+ /* We're overriding the `.pill-value` style defined
+ in `settings.css` to ensure that names inside the pill
+ render fully and aren't cut off in the user profile modal. */
+ .pill-value {
+ max-width: 100%;
+ }
+ }
+}
+
.creator_details > .display_only_pill {
/* On channel and group creation details,
align the pill contents better with
diff --git a/web/templates/user_custom_profile_fields.hbs b/web/templates/user_custom_profile_fields.hbs
index cfac527b412..e9c29413c35 100644
--- a/web/templates/user_custom_profile_fields.hbs
+++ b/web/templates/user_custom_profile_fields.hbs
@@ -20,9 +20,7 @@
{{this.value}}
</a>
{{else if this.is_user_field}}
- <div class="pill-container not-editable" data-field-id="{{this.id}}">
- <div class="input" contenteditable="false" style="display: none;"></div>
- </div>
+ <div class="user-type-custom-field-pill-container" data-field-id="{{this.id}}"></div>
{{else}}
{{#if this.rendered_value}}
<span class="value rendered_markdown {{#if ../for_user_card_popover}}tippy-zulip-tooltip{{/if}}" data-tippy-content="{{this.name}}">{{rendered_markdown this.rendered_value}}</span>