Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item sheet trait tooltip #17685

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions src/module/sheet/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ function createTagifyTraits(traits: Iterable<string>, { sourceTraits, record }:
return [...traitSlugs, ...hiddenTraits]
.map((slug) => {
const label = game.i18n.localize(record?.[slug] ?? slug);
const traitDescriptions: Record<string, string | undefined> = CONFIG.PF2E.traitsDescriptions;
const tooltip = traitDescriptions[slug];
return {
id: slug,
value: label,
readonly: readonlyTraits.has(slug),
// Must be undefined for tagify to work
hidden: !traitSlugs.has(slug) || undefined,
"data-tooltip": tooltip,
};
})
.sort((t1, t2) => t1.value.localeCompare(t2.value));
Expand Down Expand Up @@ -229,6 +232,7 @@ interface TagifyEntry {
* Tagify treats any value as true, even false or null.
*/
hidden?: true;
"data-tooltip"?: string;
}

export {
Expand Down
10 changes: 10 additions & 0 deletions src/styles/_tags.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@
}
}

// Allow tags to recieve events and disable just the rarity dropdown
tags.tagify {
&[disabled] {
pointer-events: inherit;
select.tag.rarity {
pointer-events: none;
}
}
}

// Tagify and non-tagify paizo style main traits row
.tags.paizo-style {
border: none;
Expand Down
16 changes: 16 additions & 0 deletions src/util/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ function tagify(
editTags,
delimiters,
whitelist: whitelistTransformed,
templates: {
tag(tagData: TagRecord) {
// Default template without title to prevent the default tag tooltip from showing.
return `<tag
contenteditable='false'
spellcheck='false'
tabIndex="${this.settings.a11y.focusableTags ? 0 : -1}"
class="${this.settings.classNames.tag}"
${this.getAttributes(tagData)}>
<x title='' class="${this.settings.classNames.tagX}" role='button' aria-label='remove tag'></x>
<div>
<span class="${this.settings.classNames.tagText}">${tagData[this.settings.tagTextProp] || tagData.value}</span>
</div>
</tag>`;
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No inline HTML

Copy link
Author

@Kulkodar Kulkodar Dec 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stwlam i might need help since i'm not that familiar with type script.
As far as i can see i cant use renderTemplate since an async function can't be assigned to tag: string.
I could use createElements, but then i have to either extend the function to allow custom tags and attributes or change the custom tags to html compliant tags and adjust the styling.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stwlam fixed now with the help of @ricardoSlv.

},
});

DestroyableManager.instance.observe(tagify);
Expand Down
Loading