重构badge组件
							parent
							
								
									63a7892344
								
							
						
					
					
						commit
						c2b963a3be
					
				|  | @ -8,91 +8,87 @@ import { css, html, Component } from 'wkit' | ||||||
| 
 | 
 | ||||||
| class Badge extends Component { | class Badge extends Component { | ||||||
|   static props = { |   static props = { | ||||||
|     value: '', |     value: 0, | ||||||
|     type: 'info', |     max: 0 | ||||||
|     max: { |   } | ||||||
|       type: Number, | 
 | ||||||
|       default: null |   get #value() { | ||||||
|     }, |     if (this.value > 0) { | ||||||
|     hidden: false, |       if (this.max > 0) { | ||||||
|     isDot: false |         if (this.value > this.max) { | ||||||
|  |           return this.max + '+' | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |       return this.value | ||||||
|  |     } | ||||||
|  |     return '' | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   static styles = [ |   static styles = [ | ||||||
|     css` |     css` | ||||||
|       :host { |       :host { | ||||||
|         position: relative; |         display: inline-flex; | ||||||
|         display: inline-block; |  | ||||||
|       } |       } | ||||||
|       .num { | 
 | ||||||
|         z-index: 1; |       .container { | ||||||
|  |         position: relative; | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       .dot { | ||||||
|         position: absolute; |         position: absolute; | ||||||
|  |         z-index: 9; | ||||||
|  |         left: calc(100% - 9px); | ||||||
|  |         top: -8px; | ||||||
|         display: inline-flex; |         display: inline-flex; | ||||||
|         justify-content: center; |         justify-content: center; | ||||||
|         align-items: center; |         align-items: center; | ||||||
|         left: calc(100% - 9px); |         min-width: 14px; | ||||||
|         top: -10px; |         height: 14px; | ||||||
|         height: 18px; |         padding: 0 4px; | ||||||
|         padding: 0 6px; |  | ||||||
|         border-radius: 10px; |         border-radius: 10px; | ||||||
|  |         background: var(--color-red-1); | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       .num { | ||||||
|  |         line-height: 12px; | ||||||
|         font-size: 12px; |         font-size: 12px; | ||||||
|  |         font-style: normal; | ||||||
|         white-space: nowrap; |         white-space: nowrap; | ||||||
|  |         font-family: Tahoma, Verdana, Helvetica, Arial, sans-serif; | ||||||
|         color: #fff; |         color: #fff; | ||||||
|         background: var(--color-blue-3); |  | ||||||
|       } |       } | ||||||
|       :host([is-dot])::after { | 
 | ||||||
|         z-index: 1; |       :host([hidden-value]) .dot { | ||||||
|         position: absolute; |         .num { | ||||||
|         height: 8px; |           display: none; | ||||||
|         width: 8px; |         } | ||||||
|         top: -4px; |  | ||||||
|         left: calc(100% - 4px); |  | ||||||
|         background: var(--color-blue-3); |  | ||||||
|         border-radius: 50%; |  | ||||||
|         content: ''; |  | ||||||
|       } |  | ||||||
|       :host([hidden])::after { |  | ||||||
|         display: none; |  | ||||||
|         content: ''; |  | ||||||
|       } |       } | ||||||
|     `,
 |     `,
 | ||||||
| 
 | 
 | ||||||
|     //配色
 |     //配色
 | ||||||
|     css` |     css` | ||||||
|       $colors: ( |       $colors: ( | ||||||
|         primary: 'teal', |  | ||||||
|         info: 'blue', |         info: 'blue', | ||||||
|         success: 'green', |         success: 'teal', | ||||||
|         warning: 'orange', |         warning: 'orange' | ||||||
|         danger: 'red', |  | ||||||
|         secondary: 'dark', |  | ||||||
|         help: 'grey' |  | ||||||
|       ); |       ); | ||||||
| 
 | 
 | ||||||
|       @loop $t, $c in $colors { |       @loop $t, $c in $colors { | ||||||
|         :host([type='#{$t}']) { |         :host([type='#{$t}']) { | ||||||
|           .num { |           .dot { | ||||||
|             background-color: var(--color-#{$c}-3); |             background-color: var(--color-#{$c}-1); | ||||||
|           } |  | ||||||
|           &::after { |  | ||||||
|             background-color: var(--color-#{$c}-3); |  | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     ` |     ` | ||||||
|   ] |   ] | ||||||
|  | 
 | ||||||
|   render() { |   render() { | ||||||
|     return html` |     return html` | ||||||
|       <div class="badge" ref="bad"> |       <main class="container"> | ||||||
|         <slot></slot> |         <slot></slot> | ||||||
|         ${!this.isDot && !this.hidden |         <span class="dot"><i class="num">${this.#value}</i></span> | ||||||
|           ? html`<div class="num">
 |       </main> | ||||||
|               ${this.max && this.value >= this.max |  | ||||||
|                 ? this.max + '+' |  | ||||||
|                 : this.value} |  | ||||||
|             </div>` |  | ||||||
|           : ''} |  | ||||||
|       </div> |  | ||||||
|     ` |     ` | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue