Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: basic navigation component #4

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/pages/components/mf-navigation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
meta:
title: Mf Navigation
description: simple navigation component for static websites
layout: component
---

```html:preview
<mf-navigation>
<a slot="logo" name="logo">
<img src="https://placehold.co/100x100" alt="logo" />
</a>
</mf-navigation>
```

## Examples

### First Example

TODO

### Second Example

TODO

[component-metadata:mf-navigation]
63 changes: 63 additions & 0 deletions src/components/mf-navigation/mf-navigation.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { classMap } from 'lit/directives/class-map.js';
import { HasSlotController } from '../../internal/slot.js';
import { html } from 'lit';
import { LocalizeController } from '../../utilities/localize.js';
import { property } from 'lit/decorators.js';
import { watch } from '../../internal/watch.js';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import styles from './mf-navigation.styles.js';
import type { CSSResultGroup } from 'lit';

/**
* @summary Short summary of the component's intended use.
* @documentation https://shoelace.style/components/mf-navigation
* @status experimental
* @since 2.0
*
* @dependency sl-example
*
*
*
* @slot - The default slot.
* @slot example - An example slot.
*
* @csspart base - The component's base wrapper.
*
* @cssproperty --example - An example CSS custom property.
*/
export default class MfNavigation extends ShoelaceElement {
static styles: CSSResultGroup = [componentStyles, styles];

private readonly localize = new LocalizeController(this);

/** An example attribute. */
@property() attr = 'example';

@watch('example')
handleExampleChange() {
// do something
}
private readonly hasSlotController = new HasSlotController(this, 'action');

render() {
const isRtl = this.localize.dir() === 'rtl';

return html`
<header
part="base"
class=${classMap({
navigation: true,
'navigation--has-action': this.hasSlotController.test('action'),
'navigation--is-Rtl': isRtl
})}
>
<div class="navigation__container">
<slot name="logo" part="logo" class="navigation__logo"></slot>
<slot name="menu" part="menu" class="navigation__menu"></slot>
<slot name="action" part="action" class="navigation__action"></slot>
</div>
</header>
`;
}
}
11 changes: 11 additions & 0 deletions src/components/mf-navigation/mf-navigation.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { css } from 'lit';

export default css`
:host {
display: block;
}
.navigation {
display: flex;
border-radius: 0;
}
`;
10 changes: 10 additions & 0 deletions src/components/mf-navigation/mf-navigation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import '../../../dist/shoelace.js';
import { expect, fixture, html } from '@open-wc/testing';

describe('<mf-navigation>', () => {
it('should render a component', async () => {
const el = await fixture(html` <mf-navigation></mf-navigation> `);

expect(el).to.exist;
});
});
12 changes: 12 additions & 0 deletions src/components/mf-navigation/mf-navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import MfNavigation from './mf-navigation.component.js';

export * from './mf-navigation.component.js';
export default MfNavigation;

MfNavigation.define('mf-navigation');

declare global {
interface HTMLElementTagNameMap {
'mf-navigation': MfNavigation;
}
}
1 change: 1 addition & 0 deletions src/shoelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export { default as SlTooltip } from './components/tooltip/tooltip.js';
export { default as SlTree } from './components/tree/tree.js';
export { default as SlTreeItem } from './components/tree-item/tree-item.js';
export { default as SlVisuallyHidden } from './components/visually-hidden/visually-hidden.js';
export { default as MfNavigation } from './components/mf-navigation/mf-navigation.js';
/* plop:component */

// Utilities
Expand Down