mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 17:47:15 +00:00 
			
		
		
		
	Improve labels-list rendering (#34846)
				
					
				
			Make labels list use consistent gap --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		| @@ -122,8 +122,23 @@ func (ut *RenderUtils) RenderIssueSimpleTitle(text string) template.HTML { | ||||
| 	return ret | ||||
| } | ||||
|  | ||||
| // RenderLabel renders a label | ||||
| func (ut *RenderUtils) RenderLabelWithLink(label *issues_model.Label, link any) template.HTML { | ||||
| 	var attrHref template.HTML | ||||
| 	switch link.(type) { | ||||
| 	case template.URL, string: | ||||
| 		attrHref = htmlutil.HTMLFormat(`href="%s"`, link) | ||||
| 	default: | ||||
| 		panic(fmt.Sprintf("unexpected type %T for link", link)) | ||||
| 	} | ||||
| 	return ut.renderLabelWithTag(label, "a", attrHref) | ||||
| } | ||||
|  | ||||
| func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML { | ||||
| 	return ut.renderLabelWithTag(label, "span", "") | ||||
| } | ||||
|  | ||||
| // RenderLabel renders a label | ||||
| func (ut *RenderUtils) renderLabelWithTag(label *issues_model.Label, tagName, tagAttrs template.HTML) template.HTML { | ||||
| 	locale := ut.ctx.Value(translation.ContextKey).(translation.Locale) | ||||
| 	var extraCSSClasses string | ||||
| 	textColor := util.ContrastColor(label.Color) | ||||
| @@ -137,8 +152,8 @@ func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML { | ||||
|  | ||||
| 	if labelScope == "" { | ||||
| 		// Regular label | ||||
| 		return htmlutil.HTMLFormat(`<div class="ui label %s" style="color: %s !important; background-color: %s !important;" data-tooltip-content title="%s">%s</div>`, | ||||
| 			extraCSSClasses, textColor, label.Color, descriptionText, ut.RenderEmoji(label.Name)) | ||||
| 		return htmlutil.HTMLFormat(`<%s %s class="ui label %s" style="color: %s !important; background-color: %s !important;" data-tooltip-content title="%s"><span class="gt-ellipsis">%s</span></%s>`, | ||||
| 			tagName, tagAttrs, extraCSSClasses, textColor, label.Color, descriptionText, ut.RenderEmoji(label.Name), tagName) | ||||
| 	} | ||||
|  | ||||
| 	// Scoped label | ||||
| @@ -152,7 +167,7 @@ func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML { | ||||
| 	// Ensure we add the same amount of contrast also near 0 and 1. | ||||
| 	darken := contrast + math.Max(luminance+contrast-1.0, 0.0) | ||||
| 	lighten := contrast + math.Max(contrast-luminance, 0.0) | ||||
| 	// Compute factor to keep RGB values proportional. | ||||
| 	// Compute the factor to keep RGB values proportional. | ||||
| 	darkenFactor := math.Max(luminance-darken, 0.0) / math.Max(luminance, 1.0/255.0) | ||||
| 	lightenFactor := math.Min(luminance+lighten, 1.0) / math.Max(luminance, 1.0/255.0) | ||||
|  | ||||
| @@ -173,26 +188,29 @@ func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML { | ||||
|  | ||||
| 	if label.ExclusiveOrder > 0 { | ||||
| 		// <scope> | <label> | <order> | ||||
| 		return htmlutil.HTMLFormat(`<span class="ui label %s scope-parent" data-tooltip-content title="%s">`+ | ||||
| 		return htmlutil.HTMLFormat(`<%s %s class="ui label %s scope-parent" data-tooltip-content title="%s">`+ | ||||
| 			`<div class="ui label scope-left" style="color: %s !important; background-color: %s !important">%s</div>`+ | ||||
| 			`<div class="ui label scope-middle" style="color: %s !important; background-color: %s !important">%s</div>`+ | ||||
| 			`<div class="ui label scope-right">%d</div>`+ | ||||
| 			`</span>`, | ||||
| 			`</%s>`, | ||||
| 			tagName, tagAttrs, | ||||
| 			extraCSSClasses, descriptionText, | ||||
| 			textColor, scopeColor, scopeHTML, | ||||
| 			textColor, itemColor, itemHTML, | ||||
| 			label.ExclusiveOrder) | ||||
| 			label.ExclusiveOrder, | ||||
| 			tagName) | ||||
| 	} | ||||
|  | ||||
| 	// <scope> | <label> | ||||
| 	return htmlutil.HTMLFormat(`<span class="ui label %s scope-parent" data-tooltip-content title="%s">`+ | ||||
| 	return htmlutil.HTMLFormat(`<%s %s class="ui label %s scope-parent" data-tooltip-content title="%s">`+ | ||||
| 		`<div class="ui label scope-left" style="color: %s !important; background-color: %s !important">%s</div>`+ | ||||
| 		`<div class="ui label scope-right" style="color: %s !important; background-color: %s !important">%s</div>`+ | ||||
| 		`</span>`, | ||||
| 		`</%s>`, | ||||
| 		tagName, tagAttrs, | ||||
| 		extraCSSClasses, descriptionText, | ||||
| 		textColor, scopeColor, scopeHTML, | ||||
| 		textColor, itemColor, itemHTML, | ||||
| 	) | ||||
| 		tagName) | ||||
| } | ||||
|  | ||||
| // RenderEmoji renders html text with emoji post processors | ||||
| @@ -235,7 +253,8 @@ func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink strin | ||||
| 		if label == nil { | ||||
| 			continue | ||||
| 		} | ||||
| 		htmlCode += fmt.Sprintf(`<a href="%s?labels=%d">%s</a>`, baseLink, label.ID, ut.RenderLabel(label)) | ||||
| 		link := fmt.Sprintf("%s?labels=%d", baseLink, label.ID) | ||||
| 		htmlCode += string(ut.RenderLabelWithLink(label, template.URL(link))) | ||||
| 	} | ||||
| 	htmlCode += "</span>" | ||||
| 	return template.HTML(htmlCode) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user