diff --git a/packages/duoyun-ui/package.json b/packages/duoyun-ui/package.json index af249097..2371999a 100644 --- a/packages/duoyun-ui/package.json +++ b/packages/duoyun-ui/package.json @@ -1,6 +1,6 @@ { "name": "duoyun-ui", - "version": "1.1.6", + "version": "1.1.7", "description": "A lightweight desktop UI component library, implemented using Gem", "keywords": [ "frontend", @@ -48,7 +48,7 @@ "elkjs": "^0.7.1" }, "peerDependencies": { - "@mantou/gem": "^1.7.2" + "@mantou/gem": "^1.7.6" }, "devDependencies": { "@esm-bundle/chai": "^4.3.4-fix.0", diff --git a/packages/gem-book/src/element/elements/icons.ts b/packages/gem-book/src/element/elements/icons.ts index de7a415a..d0ece9f9 100644 --- a/packages/gem-book/src/element/elements/icons.ts +++ b/packages/gem-book/src/element/elements/icons.ts @@ -1,6 +1,23 @@ import { raw } from '@mantou/gem'; export const icons = { + github: raw` + + + + `, + menu: raw` + + + + + `, + close: raw` + + + + + `, i18n: raw` diff --git a/packages/gem-book/src/element/elements/nav-logo.ts b/packages/gem-book/src/element/elements/nav-logo.ts index 57925d24..522c1ae7 100644 --- a/packages/gem-book/src/element/elements/nav-logo.ts +++ b/packages/gem-book/src/element/elements/nav-logo.ts @@ -14,7 +14,9 @@ const style = createCSSSheet(css` flex-shrink: 0; } gem-link { - display: contents; + display: flex; + align-items: center; + height: 100%; text-decoration: none; color: inherit; } diff --git a/packages/gem-book/src/element/elements/nav.ts b/packages/gem-book/src/element/elements/nav.ts index dee9c51a..65aba691 100644 --- a/packages/gem-book/src/element/elements/nav.ts +++ b/packages/gem-book/src/element/elements/nav.ts @@ -16,6 +16,7 @@ import { capitalize, isSameOrigin } from '../lib/utils'; import { bookStore } from '../store'; import { icons } from './icons'; +import { sidebarStore, toggleSidebar } from './sidebar'; import '@mantou/gem/elements/link'; import '@mantou/gem/elements/use'; @@ -28,6 +29,7 @@ import './nav-logo'; */ @customElement('gem-book-nav') @connectStore(bookStore) +@connectStore(sidebarStore) export class Nav extends GemElement { @boolattribute logo: boolean; @@ -38,10 +40,8 @@ export class Nav extends GemElement { renderI18nSelect = () => { const { langList = [], lang } = bookStore; if (lang) { - const name = langList.find(({ code }) => code === lang)?.name; return html` - - ${mediaQuery.isPhone ? '' : name || lang} + this.i18nRef.element?.click()} .element=${icons.i18n}> { + if (link) { + return html` + + + + `; + } + }; + render() { const { config, nav = [] } = bookStore; const { github = '' } = config || {}; - const githubLink = config ? this.renderExternalItem({ title: 'github', link: github }) : null; + const githubLink = config ? this.renderIcon({ title: 'github', link: github }, icons.github) : null; const internals = nav?.filter((e) => isSameOrigin(e.link)) || []; const externals = nav?.filter((e) => !isSameOrigin(e.link)) || []; @@ -101,8 +111,8 @@ export class Nav extends GemElement { cursor: pointer; overflow: hidden; } - .item gem-use { - margin-left: 0.3rem; + .item + .item { + margin-left: 1rem; } .item select { -webkit-appearance: none; @@ -119,20 +129,15 @@ export class Nav extends GemElement { .internals .item { padding: 0 1rem; } - :where(.item + .item:not(.slot)), - .slot::slotted(*) { - margin-left: 1rem; - display: block; - } gem-link, gem-active-link { text-decoration: none; color: inherit; } - gem-active-link:active { + gem-active-link:not(.icon):active { background: rgba(${theme.primaryColorRGB}, 0.1); } - gem-active-link:hover, + gem-active-link:not(.icon):hover, gem-active-link:where(:state(active), [data-active]) { color: ${theme.primaryColor}; } @@ -145,26 +150,56 @@ export class Nav extends GemElement { background: currentColor; width: 100%; } - gem-use { + .item:not(.icon) gem-use { width: 1em; + margin-left: 0.3rem; + } + .icon gem-use { + opacity: 0.6; + width: 1.5em; + } + .icon:hover gem-use { + opacity: 0.8; + } + .menu { + display: none; + opacity: 0.8; + width: 2rem; + margin-inline-end: 1rem; } @media ${mediaQuery.PHONE} { + :host(:not([logo])) .menu { + display: block; + } gem-book-nav-logo + .item { margin-left: 0; } - .internals .item { - padding: 0 0.3rem; + .internals { + align-items: center; + } + .internals gem-active-link { + border-radius: 100em; + margin-left: 0; + height: 2em; + } + .internals gem-active-link:where(:state(active), [data-active]) { + background: rgba(${theme.primaryColorRGB}, 0.1); + } + .internals gem-active-link:where(:state(active), [data-active])::after { + content: none; } + gem-book-nav-logo, .external { display: none; } } + ${this.logo ? html`` : ''} ${internals.map(this.renderInternalItem)} - ${externals.map(this.renderExternalItem)} ${githubLink} ${this.renderI18nSelect()} - + + ${this.renderI18nSelect()}${githubLink}${externals.map(this.renderExternalItem)} `; } diff --git a/packages/gem-book/src/element/elements/sidebar.ts b/packages/gem-book/src/element/elements/sidebar.ts index e4c3a74b..d77e6cbb 100644 --- a/packages/gem-book/src/element/elements/sidebar.ts +++ b/packages/gem-book/src/element/elements/sidebar.ts @@ -1,4 +1,17 @@ -import { html, GemElement, customElement, TemplateResult, connectStore, classMap } from '@mantou/gem'; +import { + html, + GemElement, + customElement, + TemplateResult, + connectStore, + classMap, + state, + createStore, + connect, + updateStore, + history, + disconnect, +} from '@mantou/gem'; import { mediaQuery } from '@mantou/gem/helper/mediaquery'; import { NavItem } from '../../common/config'; @@ -13,9 +26,17 @@ import '@mantou/gem/elements/use'; import './side-link'; import './nav-logo'; +export const sidebarStore = createStore({ open: false }); + +const closeSidebar = () => updateStore(sidebarStore, { open: false }); +export const toggleSidebar = () => updateStore(sidebarStore, { open: !sidebarStore.open }); + @customElement('gem-book-sidebar') @connectStore(bookStore) +@connectStore(sidebarStore) export class SideBar extends GemElement { + @state open: boolean; + #toggleLinks = (e: MouseEvent) => { const ele = e.target as HTMLDivElement; ele.classList.toggle('close'); @@ -72,6 +93,7 @@ export class SideBar extends GemElement { }; render() { + this.open = sidebarStore.open; return html`