完成面包屑组件的简化

master
yutent 2023-11-24 14:59:53 +08:00
parent 545661ed60
commit f281cd5dec
2 changed files with 12 additions and 25 deletions

View File

@ -64,7 +64,7 @@ class Badge extends Component {
css` css`
$colors: ( $colors: (
info: 'blue', info: 'blue',
success: 'teal', success: 'green',
warning: 'orange' warning: 'orange'
); );

View File

@ -1,12 +1,10 @@
/** /**
* {} * {面包屑导航}
* @author yutent<yutent.io@gmail.com> * @author yutent<yutent.io@gmail.com>
* @date 2023/04/10 16:12:33 * @date 2023/04/10 16:12:33
*/ */
import { css, html, Component, bind, styleMap } from 'wkit' import { css, html, Component, styleMap } from 'wkit'
const last = Symbol('last')
class Breadcrumb extends Component { class Breadcrumb extends Component {
static styles = [ static styles = [
@ -25,9 +23,7 @@ class Breadcrumb extends Component {
let list = Array.from(this.children) let list = Array.from(this.children)
list.forEach((it, i) => { list.forEach((it, i) => {
if (it.tagName === 'WC-BREADCRUMB-ITEM') { if (it.tagName === 'WC-BREADCRUMB-ITEM') {
if (list.length === i + 1) { it.last = list.length === i + 1
it.last = true
}
} else { } else {
it.remove() it.remove()
} }
@ -41,42 +37,33 @@ class Breadcrumb extends Component {
class Item extends Component { class Item extends Component {
static props = { static props = {
path: '', separator: '/',
separator: '/' last: 'bool!'
} }
static styles = [ static styles = [
css` css`
:host, :host,
.breadcrumb-item { .item {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
height: 32px; height: 32px;
font-size: 14px; font-size: 14px;
} }
.separator { .pipe {
margin: 0 8px; margin: 0 8px;
user-select: none; user-select: none;
} }
` `
] ]
get last() {
return this[last] || false
}
set last(val) {
this[last] = !!val
this.$requestUpdate()
}
render() { render() {
return html` return html`
<label class="breadcrumb-item"> <label class="item">
<slot></slot> <slot></slot>
<span <span
class="separator" class="pipe"
style=${styleMap({ display: this[last] ? 'none' : '' })} style=${styleMap({ display: this.last ? 'none' : '' })}
> >
<slot name="separator">${this.separator || '/'}</slot> <slot name="separator">${this.separator || '/'}</slot>
</span> </span>