initial
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import { html } from '@design.estate/dees-element';
|
||||
import { injectCssVariables } from '../../00variables.js';
|
||||
|
||||
export const demoFunc = () => {
|
||||
injectCssVariables();
|
||||
return html`
|
||||
<style>
|
||||
.demo-section {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
.demo-section h3 {
|
||||
margin: 0 0 1rem 0;
|
||||
font-size: 0.875rem;
|
||||
color: var(--dees-muted-foreground);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
.nav-container {
|
||||
border: 1px solid var(--dees-border);
|
||||
border-radius: var(--dees-radius);
|
||||
overflow: hidden;
|
||||
}
|
||||
.demo-note {
|
||||
font-size: 0.875rem;
|
||||
color: var(--dees-muted-foreground);
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="demo-section">
|
||||
<h3>Bottom Navigation</h3>
|
||||
<div class="nav-container">
|
||||
<dees-mobile-navigation
|
||||
activeTab="home"
|
||||
.tabs=${[
|
||||
{ id: 'home', icon: 'home', label: 'Home' },
|
||||
{ id: 'search', icon: 'search', label: 'Search' },
|
||||
{ id: 'favorites', icon: 'heart', label: 'Favorites' },
|
||||
{ id: 'profile', icon: 'user', label: 'Profile' }
|
||||
]}
|
||||
@tab-change=${(e: CustomEvent) => {
|
||||
const nav = e.target as any;
|
||||
nav.activeTab = e.detail.tab;
|
||||
}}
|
||||
></dees-mobile-navigation>
|
||||
</div>
|
||||
<p class="demo-note">Click tabs to switch between them.</p>
|
||||
</div>
|
||||
|
||||
<div class="demo-section">
|
||||
<h3>Navigation with Badges</h3>
|
||||
<div class="nav-container">
|
||||
<dees-mobile-navigation
|
||||
activeTab="inbox"
|
||||
.tabs=${[
|
||||
{ id: 'inbox', icon: 'inbox', label: 'Inbox', badge: 3 },
|
||||
{ id: 'sent', icon: 'send', label: 'Sent' },
|
||||
{ id: 'drafts', icon: 'file-text', label: 'Drafts', badge: 1 },
|
||||
{ id: 'trash', icon: 'trash-2', label: 'Trash' }
|
||||
]}
|
||||
@tab-change=${(e: CustomEvent) => {
|
||||
const nav = e.target as any;
|
||||
nav.activeTab = e.detail.tab;
|
||||
}}
|
||||
></dees-mobile-navigation>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="demo-section">
|
||||
<h3>Three Tab Navigation</h3>
|
||||
<div class="nav-container">
|
||||
<dees-mobile-navigation
|
||||
activeTab="lists"
|
||||
.tabs=${[
|
||||
{ id: 'lists', icon: 'list', label: 'Lists' },
|
||||
{ id: 'coupons', icon: 'ticket', label: 'Coupons' },
|
||||
{ id: 'settings', icon: 'settings', label: 'Settings' }
|
||||
]}
|
||||
@tab-change=${(e: CustomEvent) => {
|
||||
const nav = e.target as any;
|
||||
nav.activeTab = e.detail.tab;
|
||||
}}
|
||||
></dees-mobile-navigation>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
};
|
||||
@@ -0,0 +1,180 @@
|
||||
import {
|
||||
DeesElement,
|
||||
css,
|
||||
cssManager,
|
||||
customElement,
|
||||
html,
|
||||
property,
|
||||
type TemplateResult,
|
||||
} from '@design.estate/dees-element';
|
||||
|
||||
import { mobileComponentStyles } from '../../00componentstyles.js';
|
||||
import '../../00group-ui/dees-mobile-icon/dees-mobile-icon.js';
|
||||
import { demoFunc } from './dees-mobile-navigation.demo.js';
|
||||
|
||||
export interface INavigationTab {
|
||||
id: string;
|
||||
icon: string;
|
||||
label: string;
|
||||
badge?: number | string;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
'dees-mobile-navigation': DeesMobileNavigation;
|
||||
}
|
||||
}
|
||||
|
||||
@customElement('dees-mobile-navigation')
|
||||
export class DeesMobileNavigation extends DeesElement {
|
||||
public static demo = demoFunc;
|
||||
|
||||
@property({ type: String })
|
||||
accessor activeTab: string = '';
|
||||
|
||||
@property({ type: Array })
|
||||
accessor tabs: INavigationTab[] = [];
|
||||
|
||||
public static styles = [
|
||||
cssManager.defaultStyles,
|
||||
mobileComponentStyles,
|
||||
css`
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.container {
|
||||
border-top: 1px solid ${cssManager.bdTheme('#e4e4e7', '#27272a')};
|
||||
/* Mobile-first defaults */
|
||||
padding: 0.375rem 0;
|
||||
padding-bottom: calc(0.375rem + var(--safe-area-inset-bottom, 0px));
|
||||
background: ${cssManager.bdTheme('#ffffff', '#09090b')};
|
||||
}
|
||||
|
||||
/* Desktop enhancements */
|
||||
@media (min-width: 641px) {
|
||||
.container {
|
||||
padding: 0.5rem 0;
|
||||
padding-bottom: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
max-width: 400px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.tab {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.25rem;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border: none;
|
||||
background: none;
|
||||
color: ${cssManager.bdTheme('#71717a', '#a1a1aa')};
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
text-decoration: none;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
-webkit-touch-callout: none;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
position: relative;
|
||||
/* Mobile-first: 44px touch target */
|
||||
min-height: 44px;
|
||||
}
|
||||
|
||||
/* Desktop enhancements */
|
||||
@media (min-width: 641px) {
|
||||
.tab {
|
||||
min-height: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.tab:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
color: #3b82f6;
|
||||
}
|
||||
|
||||
.tab-icon {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.tab-label {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
line-height: 1;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.badge {
|
||||
position: absolute;
|
||||
top: -4px;
|
||||
right: -8px;
|
||||
background: #ef4444;
|
||||
color: white;
|
||||
font-size: 0.625rem;
|
||||
font-weight: 600;
|
||||
padding: 0.125rem 0.375rem;
|
||||
border-radius: 999px;
|
||||
min-width: 16px;
|
||||
text-align: center;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
/* Hover effect */
|
||||
@media (hover: hover) {
|
||||
.tab:hover:not(.active) {
|
||||
color: ${cssManager.bdTheme('#09090b', '#fafafa')};
|
||||
}
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
||||
private handleTabClick(tabId: string) {
|
||||
this.dispatchEvent(new CustomEvent('tab-change', {
|
||||
detail: { tab: tabId },
|
||||
bubbles: true,
|
||||
composed: true
|
||||
}));
|
||||
}
|
||||
|
||||
public render(): TemplateResult {
|
||||
return html`
|
||||
<div class="container">
|
||||
<nav class="tabs" role="tablist">
|
||||
${this.tabs.map(tab => html`
|
||||
<button
|
||||
class="tab ${this.activeTab === tab.id ? 'active' : ''}"
|
||||
role="tab"
|
||||
aria-selected=${this.activeTab === tab.id}
|
||||
@click=${() => this.handleTabClick(tab.id)}
|
||||
>
|
||||
<div class="tab-icon">
|
||||
<dees-mobile-icon icon=${tab.icon} size="24"></dees-mobile-icon>
|
||||
${tab.badge !== undefined ? html`
|
||||
<span class="badge">${tab.badge}</span>
|
||||
` : ''}
|
||||
</div>
|
||||
<span class="tab-label">${tab.label}</span>
|
||||
</button>
|
||||
`)}
|
||||
</nav>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './dees-mobile-navigation.js';
|
||||
Reference in New Issue
Block a user