Skip to content

Commit c2766ee

Browse files
authored
Merge pull request #108 from amir78729/docs/jsdoc/modal
docs: add JSDoc to `modal` component
2 parents bd5876f + dabd5ff commit c2766ee

File tree

4 files changed

+57
-28
lines changed

4 files changed

+57
-28
lines changed

src/modal/index.ts

+35-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,43 @@
1-
import { customElement } from "lit/decorators.js";
2-
import { Modal } from "./modal";
3-
import styles from "./modal.style";
1+
import { customElement } from 'lit/decorators.js';
2+
import { Modal } from './modal';
3+
import styles from './modal.style';
44

5-
@customElement("tap-modal")
5+
/**
6+
* ### Example
7+
*
8+
*
9+
* ##### Simple
10+
*
11+
* ```html
12+
* <tap-modal></tap-modal>
13+
* ```
14+
*
15+
* ##### Open Modal
16+
*
17+
* ```html
18+
* <tap-modal open></tap-modal>
19+
* ```
20+
*
21+
* @summary A modal dialog component.
22+
*
23+
* @prop {`boolean`} [`open`=`false`] - Indicates whether the modal is open.
24+
*
25+
* @csspart [`overlay`] - The overlay background when the modal is open.
26+
* @csspart [`dialog`] - The main container for the modal dialog.
27+
*
28+
* @cssprop [`--tap-dialog-color-surface-overlay`=`--tap-sys-color-surface-overlay-dark`] - The background color of the overlay.
29+
* @cssprop [`--tap-dialog-color-surface-primary`=`--tap-sys-color-surface-primary`] - The background color of the modal dialog.
30+
* @cssprop [`--tap-dialog-padding`=`--tap-sys-spacing-6`] - The padding inside the modal dialog.
31+
* @cssprop [`--tap-dialog-radius`=`--tap-sys-radius-6`] - The border radius of the modal dialog.
32+
*
33+
*/
34+
@customElement('tap-modal')
635
export class TapModal extends Modal {
736
static readonly styles = [styles];
837
}
938

1039
declare global {
1140
interface HTMLElementTagNameMap {
12-
"tap-modal": TapModal;
41+
'tap-modal': TapModal;
1342
}
14-
}
43+
}

src/modal/modal.stories.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { html, TemplateResult } from "lit";
2-
import "./index.js";
1+
import { html, TemplateResult } from 'lit';
2+
import './index.js';
33

44
export default {
5-
title: "Modal",
6-
component: "tap-modal",
5+
title: 'Modal',
6+
component: 'tap-modal',
77
argTypes: {
8-
open: { control: "boolean" },
8+
open: { control: 'boolean' },
99
},
1010
};
1111

src/modal/modal.style.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { css } from "lit";
1+
import { css } from 'lit';
22

33
// tokens
44
// --tap-dialog-color-surface-overlay
@@ -31,9 +31,9 @@ export default css`
3131
}
3232
.dialog {
3333
position: fixed;
34-
left: var(--tap-sys-spacing-6);
35-
right: var(--tap-sys-spacing-6);
36-
bottom: var(--tap-sys-spacing-6);
34+
left: var(--tap-dialog-left, var(--tap-sys-spacing-6));
35+
right: var(--tap-dialog-right, var(--tap-sys-spacing-6));
36+
bottom: var(--tap-dialog-bottom, var(--tap-sys-spacing-6));
3737
background-color: var(
3838
--tap-dialog-color-surface-primary,
3939
var(--tap-sys-color-surface-primary)

src/modal/modal.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { LitElement, PropertyValues, html, nothing } from "lit";
2-
import { property, query } from "lit/decorators.js";
1+
import { LitElement, PropertyValues, html, nothing } from 'lit';
2+
import { property, query } from 'lit/decorators.js';
33

44
export class Modal extends LitElement implements HTMLDialogElement {
55
static readonly shadowRootOptions = {
@@ -10,13 +10,13 @@ export class Modal extends LitElement implements HTMLDialogElement {
1010
@property({ type: Boolean, reflect: true })
1111
open: boolean = false;
1212

13-
@query("#dialog")
13+
@query('#dialog')
1414
private dialog?: HTMLElement | null;
1515

16-
@query("#overlay")
16+
@query('#overlay')
1717
private overlay?: HTMLElement | null;
1818

19-
returnValue: string = "";
19+
returnValue: string = '';
2020

2121
constructor() {
2222
super();
@@ -27,12 +27,12 @@ export class Modal extends LitElement implements HTMLDialogElement {
2727

2828
connectedCallback() {
2929
super.connectedCallback();
30-
this.addEventListener("keydown", this.handleKeydown);
31-
this.addEventListener("click", this.handleClick);
30+
this.addEventListener('keydown', this.handleKeydown);
31+
this.addEventListener('click', this.handleClick);
3232
}
3333

3434
protected updated(changed: PropertyValues): void {
35-
const oldValue = changed.get("open");
35+
const oldValue = changed.get('open');
3636
const newValue = this.open;
3737
const openChanged = oldValue !== undefined && oldValue !== newValue;
3838

@@ -41,19 +41,19 @@ export class Modal extends LitElement implements HTMLDialogElement {
4141
this.dialog?.focus();
4242

4343
this.dispatchEvent(
44-
new Event("open", {
44+
new Event('open', {
4545
bubbles: true,
4646
composed: true,
4747
cancelable: true,
48-
})
48+
}),
4949
);
5050
} else {
5151
this.dispatchEvent(
52-
new Event("close", {
52+
new Event('close', {
5353
bubbles: true,
5454
composed: true,
5555
cancelable: true,
56-
})
56+
}),
5757
);
5858
}
5959
}
@@ -72,7 +72,7 @@ export class Modal extends LitElement implements HTMLDialogElement {
7272

7373
private handleKeydown(event: KeyboardEvent) {
7474
// TODO: handle `Tab`, `Shift + Tab`.
75-
if (["Escape", "Esc"].includes(event.key)) {
75+
if (['Escape', 'Esc'].includes(event.key)) {
7676
this.close();
7777
}
7878
}

0 commit comments

Comments
 (0)