-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
91 additions
and
0 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
69 changes: 69 additions & 0 deletions
69
packages/core/src/components/discord-header/DiscordHeader.ts
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,69 @@ | ||
import { css, html, LitElement } from 'lit'; | ||
import { customElement, property } from 'lit/decorators.js'; | ||
|
||
@customElement('discord-header') | ||
export class DiscordHeader extends LitElement { | ||
public static override styles = css` | ||
:host { | ||
margin: 16px 0 8px; | ||
font-weight: 700; | ||
line-height: 1.375em; | ||
} | ||
:host([level='1']) { | ||
font-size: 1.5rem; | ||
} | ||
:host([level='2']) { | ||
font-size: 1.25rem; | ||
} | ||
:host([level='3']) { | ||
font-size: 1rem; | ||
} | ||
:host([level='1']):first-child(), | ||
:host([level='2']):first-child() { | ||
margin-top: 8px; | ||
} | ||
:host([level='3']):first-child() { | ||
margin-top: 4px; | ||
} | ||
`; | ||
|
||
/** | ||
* The header level, this should be a number between 1 and 3 (inclusive). | ||
* If a number outside of this range is provided, an error is thrown. | ||
*/ | ||
@property({ type: Number, reflect: true }) | ||
public accessor level: 1 | 2 | 3 = 1; | ||
|
||
public checkLevel() { | ||
if (this.level < 1 || this.level > 3) { | ||
throw new RangeError('The level property must be a number between 1 and 3 (inclusive)'); | ||
} | ||
} | ||
|
||
protected override render() { | ||
this.checkLevel(); | ||
|
||
switch (this.level) { | ||
case 1: { | ||
return html`<h1><slot></slot></h1>`; | ||
} | ||
case 2: { | ||
return html`<h2><slot></slot></h2>`; | ||
} | ||
case 3: { | ||
return html`<h3><slot></slot></h3>`; | ||
} | ||
} | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'discord-header': DiscordHeader; | ||
} | ||
} |
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