-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tabs): implement tabs using slots
- Loading branch information
Showing
10 changed files
with
132 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './tab'; | ||
export * from './tab-content'; | ||
export * from './tab-group'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { consume } from '@lit/context'; | ||
import { LitElement, css, html } from 'lit'; | ||
import { customElement, state } from 'lit/decorators.js'; | ||
import { classMap } from 'lit/directives/class-map.js'; | ||
import { activeIndexContext } from './tab-context'; | ||
|
||
@customElement('cx-tab-content') | ||
export class TabContent extends LitElement { | ||
static styles = css` | ||
div { | ||
transition: opacity 300ms ease, translate 700ms var(--ease-spring-5), visibility 300ms; | ||
} | ||
.tab-content-before { | ||
visibility: hidden; | ||
opacity: 0; | ||
translate: -10px 0; | ||
} | ||
.tab-content-after { | ||
visibility: hidden; | ||
opacity: 0; | ||
translate: 10px 0; | ||
} | ||
`; | ||
|
||
@consume({ context: activeIndexContext, subscribe: true }) | ||
activeTabIndex!: number; | ||
|
||
@state() | ||
index = -1; | ||
|
||
render() { | ||
return html` | ||
<div class=${classMap({ | ||
'tab-content-before': this.index < this.activeTabIndex, | ||
'tab-content-after': this.index > this.activeTabIndex, | ||
})}> | ||
<slot></slot> | ||
</div> | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'cx-tab-content': TabContent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createContext } from '@lit/context'; | ||
|
||
export const activeIndexContext = createContext<number>('activeIndexContext'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters