From 12cacb9db429cd5f8629ac6c1868e13b30460dc0 Mon Sep 17 00:00:00 2001 From: yutent Date: Mon, 10 Apr 2023 17:14:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=9D=A2=E5=8C=85=E5=B1=91?= =?UTF-8?q?=E5=AF=BC=E8=88=AA=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/breadcrumb/index.js | 89 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/breadcrumb/index.js diff --git a/src/breadcrumb/index.js b/src/breadcrumb/index.js new file mode 100644 index 0000000..535f256 --- /dev/null +++ b/src/breadcrumb/index.js @@ -0,0 +1,89 @@ +/** + * {} + * @author yutent + * @date 2023/04/10 16:12:33 + */ + +import { css, html, Component, bind, styleMap } from '@bd/core' + +const last = Symbol('last') + +class Breadcrumb extends Component { + static styles = [ + css` + :host { + display: flex; + align-items: center; + width: 100%; + height: 32px; + font-size: 14px; + } + ` + ] + + #updateChildrenStat(checkAll) { + let list = Array.from(this.children) + list.forEach((it, i) => { + if (it.tagName === 'WC-BREADCRUMB-ITEM') { + if (list.length === i + 1) { + it.last = true + } + } else { + it.remove() + } + }) + } + + mounted() { + this.#updateChildrenStat() + } +} + +class Item extends Component { + static props = { + path: '', + separator: '/' + } + + static styles = [ + css` + :host, + .breadcrumb-item { + display: inline-flex; + align-items: center; + height: 32px; + font-size: 14px; + } + .separator { + margin: 0 8px; + user-select: none; + } + ` + ] + + get last() { + return this[last] || false + } + + set last(val) { + this[last] = !!val + this.$requestUpdate() + } + + render() { + return html` + + ` + } +} + +Breadcrumb.reg('breadcrumb') +Item.reg('breadcrumb-item')