Skip to content

Commit bd5876f

Browse files
authored
Merge pull request #109 from amir78729/docs/jsdoc/progress-indicator
docs: add JSDoc to`progress-indicator` component
2 parents 86dbba9 + 200ad80 commit bd5876f

8 files changed

+154
-75
lines changed

src/pinwheel/index.ts

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { customElement } from "lit/decorators.js";
2-
import { Pinwheel } from "./pinwheel";
3-
import styles from "./pinwheel.style";
1+
import { customElement } from 'lit/decorators.js';
2+
import { Pinwheel } from './pinwheel';
3+
import styles from './pinwheel.style';
44

55
/**
66
* ### Example
@@ -11,34 +11,34 @@ import styles from "./pinwheel.style";
1111
*
1212
* @summary A pinwheel component for selecting items by scrolling through a list.
1313
*
14-
* @prop {Array.<string>} items - An array of strings that contains pinwheel items.
14+
* @prop {`string[]`} [`items`=`[]`] - An array of strings that contains pinwheel items.
1515
*
16-
* @csspart pinwheel - The container that wraps the pinwheel component.
17-
* @csspart pinwheel-item - The item that rendered in pinwheel.
16+
* @csspart `pinwheel` - The container that wraps the pinwheel component.
17+
* @csspart `pinwheel-item` - The item that rendered in pinwheel.
1818
*
19-
* @cssprop [--tap-pinwheel-spacing-0=--tap-sys-spacing-0]
20-
* @cssprop [--tap-pinwheel-spacing-6=--tap-sys-spacing-6]
21-
* @cssprop [--tap-pinwheel-spacing-11=--tap-sys-spacing-11]
19+
* @cssprop [`--tap-pinwheel-spacing-0`=`--tap-sys-spacing-0`]
20+
* @cssprop [`--tap-pinwheel-spacing-6`=`--tap-sys-spacing-6`]
21+
* @cssprop [`--tap-pinwheel-spacing-11`=`--tap-sys-spacing-11`]
2222
*
23-
* @cssprop [--tap-font-family=--tap-sys-font-family]
24-
* @cssprop [--tap-pinwheel-typography-body-md-height=--tap-sys-typography-body-md-height]
25-
* @cssprop [--tap-pinwheel-typography-body-md-size=--tap-sys-typography-body-md-size]
26-
* @cssprop [--tap-pinwheel-typography-body-md-weight=--tap-sys-typography-body-md-weight]
27-
* @cssprop [--tap-pinwheel-color-content-tertiary=--tap-sys-color-content-tertiary]
23+
* @cssprop [`--tap-font-family`=`--tap-sys-font-family`]
24+
* @cssprop [`--tap-pinwheel-typography-body-md-height`=`--tap-sys-typography-body-md-height`]
25+
* @cssprop [`--tap-pinwheel-typography-body-md-size`=`--tap-sys-typography-body-md-size`]
26+
* @cssprop [`--tap-pinwheel-typography-body-md-weight`=`--tap-sys-typography-body-md-weight`]
27+
* @cssprop [`--tap-pinwheel-color-content-tertiary`=`--tap-sys-color-content-tertiary`]
2828
*
29-
* @cssprop [--tap-pinwheel-typography-label-md-height=--tap-sys-typography-label-md-height]
30-
* @cssprop [--tap-pinwheel-typography-label-md-size=--tap-sys-typography-label-md-size]
31-
* @cssprop [--tap-pinwheel-typography-label-md-weight=--tap-sys-typography-label-md-weight]
32-
* @cssprop [--tap-pinwheel-color-content-primary=--tap-sys-color-content-primary]
29+
* @cssprop [`--tap-pinwheel-typography-label-md-height`=`--tap-sys-typography-label-md-height`]
30+
* @cssprop [`--tap-pinwheel-typography-label-md-size`=`--tap-sys-typography-label-md-size`]
31+
* @cssprop [`--tap-pinwheel-typography-label-md-weight`=`--tap-sys-typography-label-md-weight`]
32+
* @cssprop [`--tap-pinwheel-color-content-primary`=`--tap-sys-color-content-primary`]
3333
*
3434
*/
35-
@customElement("tap-pinwheel")
35+
@customElement('tap-pinwheel')
3636
export class TapPinwheel extends Pinwheel {
3737
static readonly styles = [styles];
3838
}
3939

4040
declare global {
4141
interface HTMLElementTagNameMap {
42-
"tap-pinwheel": TapPinwheel;
42+
'tap-pinwheel': TapPinwheel;
4343
}
4444
}

src/pinwheel/pinwheel.stories.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
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: "Pinwheel",
6-
component: "tap-pinwheel",
5+
title: 'Pinwheel',
6+
component: 'tap-pinwheel',
77
argTypes: {},
88
};
99

@@ -15,7 +15,17 @@ interface Story<T> {
1515

1616
interface ArgTypes {}
1717

18-
const items = ['عنوان ۱', 'عنوان ۲', 'عنوان ۳', 'عنوان ۴', 'عنوان ۵', 'عنوان ۶', 'عنوان ۷', 'عنوان ۸', 'عنوان ۹']
18+
const items = [
19+
'عنوان ۱',
20+
'عنوان ۲',
21+
'عنوان ۳',
22+
'عنوان ۴',
23+
'عنوان ۵',
24+
'عنوان ۶',
25+
'عنوان ۷',
26+
'عنوان ۸',
27+
'عنوان ۹',
28+
];
1929

2030
const Template: Story<ArgTypes> = ({}: ArgTypes) => html`
2131
<tap-pinwheel .items=${items}></tap-pinwheel>

src/pinwheel/pinwheel.style.ts

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

33
export default css`
44
:host {
@@ -7,7 +7,7 @@ export default css`
77
height: 144px;
88
overflow: hidden;
99
overflow-y: auto;
10-
-ms-overflow-style: none; /* IE and Edge */
10+
-ms-overflow-style: none; /* IE and Edge */
1111
scrollbar-width: none; /* Firefox */
1212
}
1313
@@ -17,15 +17,28 @@ export default css`
1717
}
1818
1919
.pinwheel > div {
20-
padding: var(--tap-pinwheel-spacing-0, var(--tap-sys-spacing-0)) var(--tap-pinwheel-spacing-6, var(--tap-sys-spacing-6));
20+
padding: var(--tap-pinwheel-spacing-0, var(--tap-sys-spacing-0))
21+
var(--tap-pinwheel-spacing-6, var(--tap-sys-spacing-6));
2122
/* FIXME: we dont have sizing tokens yet */
2223
height: 48px;
2324
font: inherit;
2425
font-family: var(--tap-font-family, var(--tap-sys-font-family));
25-
line-height: var(--tap-pinwheel-typography-body-md-height, var(--tap-sys-typography-body-md-height));
26-
font-size: var(--tap-pinwheel-typography-body-md-size, var(--tap-sys-typography-body-md-size));
27-
font-weight: var(--tap-pinwheel-typography-body-md-weight, var(--tap-sys-typography-body-md-weight));
28-
color: var(--tap-pinwheel-color-content-tertiary, var(--tap-sys-color-content-tertiary));
26+
line-height: var(
27+
--tap-pinwheel-typography-body-md-height,
28+
var(--tap-sys-typography-body-md-height)
29+
);
30+
font-size: var(
31+
--tap-pinwheel-typography-body-md-size,
32+
var(--tap-sys-typography-body-md-size)
33+
);
34+
font-weight: var(
35+
--tap-pinwheel-typography-body-md-weight,
36+
var(--tap-sys-typography-body-md-weight)
37+
);
38+
color: var(
39+
--tap-pinwheel-color-content-tertiary,
40+
var(--tap-sys-color-content-tertiary)
41+
);
2942
}
3043
3144
.pinwheel div:first-child {
@@ -37,9 +50,21 @@ export default css`
3750
}
3851
3952
.pinwheel .active {
40-
line-height: var(--tap-pinwheel-typography-label-md-height, var(--tap-sys-typography-label-md-height));
41-
font-size: var(--tap-pinwheel-typography-label-md-size, var(--tap-sys-typography-label-md-size));
42-
font-weight: var(--tap-pinwheel-typography-label-md-weight, var(--tap-sys-typography-label-md-weight));
43-
color: var(--tap-pinwheel-color-content-primary, var(--tap-sys-color-content-primary));
53+
line-height: var(
54+
--tap-pinwheel-typography-label-md-height,
55+
var(--tap-sys-typography-label-md-height)
56+
);
57+
font-size: var(
58+
--tap-pinwheel-typography-label-md-size,
59+
var(--tap-sys-typography-label-md-size)
60+
);
61+
font-weight: var(
62+
--tap-pinwheel-typography-label-md-weight,
63+
var(--tap-sys-typography-label-md-weight)
64+
);
65+
color: var(
66+
--tap-pinwheel-color-content-primary,
67+
var(--tap-sys-color-content-primary)
68+
);
4469
}
4570
`;

src/pinwheel/pinwheel.ts

+19-16
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,70 @@ import { debounce } from '../utils/utils';
44

55
export class Pinwheel extends LitElement {
66
@state() private selectedIndex = 0;
7-
@property({ type: Array , attribute:false}) items: Array<string> = [];
7+
@property({ type: Array, attribute: false }) items: Array<string> = [];
88

99
private itemHeight = 48;
1010

1111
connectedCallback() {
1212
super.connectedCallback();
13-
this.addEventListener('scroll', (event) => this.handleScroll(event.target as HTMLElement));
13+
this.addEventListener('scroll', (event) =>
14+
this.handleScroll(event.target as HTMLElement),
15+
);
1416
}
1517

1618
disconnectedCallback() {
17-
this.removeEventListener('scroll', (event) => this.handleScroll(event.target as HTMLElement))
19+
this.removeEventListener('scroll', (event) =>
20+
this.handleScroll(event.target as HTMLElement),
21+
);
1822
super.disconnectedCallback();
1923
}
2024

2125
private dispatchChangeEvent = () => {
2226
this.dispatchEvent(
23-
new CustomEvent("pinwheel-change", {
27+
new CustomEvent('pinwheel-change', {
2428
detail: {
2529
selectedIndex: this.selectedIndex,
2630
},
2731
bubbles: true,
2832
composed: true,
29-
})
33+
}),
3034
);
31-
}
35+
};
3236

3337
private handleScroll = debounce((target: HTMLElement) => {
3438
this.selectedIndex = Math.round(target?.scrollTop / this.itemHeight);
3539
if (target?.scrollTop % this.itemHeight) {
3640
this.scrollToActiveItem();
37-
}
38-
else {
41+
} else {
3942
this.dispatchChangeEvent();
4043
}
4144
}, 100);
4245

4346
private handleClickItem = (index: number) => {
4447
this.selectedIndex = index;
4548
this.scrollToActiveItem();
46-
}
49+
};
4750

4851
private scrollToActiveItem = () => {
4952
const scrollTopPosition = this.selectedIndex * this.itemHeight;
50-
this.scrollTo({ top: scrollTopPosition, behavior: 'smooth' })
51-
}
53+
this.scrollTo({ top: scrollTopPosition, behavior: 'smooth' });
54+
};
5255

5356
private renderItem = (item: string, index: number) => {
5457
return html`<div
5558
part="pinwheel-item"
56-
class=${this.selectedIndex === index ? 'active': null}
57-
@click='${() => this.handleClickItem(index)}'
59+
class=${this.selectedIndex === index ? 'active' : null}
60+
@click="${() => this.handleClickItem(index)}"
5861
>
5962
${item}
60-
</div>`
61-
}
63+
</div>`;
64+
};
6265

6366
render() {
6467
return html`
6568
<div class="pinwheel" part="pinwheel">
6669
${this.items.map(this.renderItem)}
6770
</div>
68-
`
71+
`;
6972
}
7073
}

src/progress-indicator/index.ts

+28-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
1-
import { customElement } from "lit/decorators.js";
2-
import { ProgressIndicator } from "./progress-indicator.js";
3-
import styles from "./progress-indicator.style.js";
1+
import { customElement } from 'lit/decorators.js';
2+
import { ProgressIndicator } from './progress-indicator.js';
3+
import styles from './progress-indicator.style.js';
44

5-
@customElement("tap-progress-indicator")
5+
/**
6+
* ### Example
7+
*
8+
*
9+
* ##### Simple
10+
*
11+
* ```html
12+
* <tap-progress-indicator max="4" current="2"></tap-progress-indicator>
13+
* ```
14+
*
15+
* @summary A progress indicator component displaying multiple steps.
16+
*
17+
* @prop {`number`} [`max`=`2`] - The total number of steps.
18+
* @prop {`number`} [`current`=`0`] - The current step index.
19+
*
20+
* @csspart [`progressbar`] - The container for the progress bar.
21+
* @csspart [`step`] - Each individual step in the progress bar.
22+
*
23+
* @cssprop [`--tap-progress-indicator-progressbar-color`=`--tap-sys-spacing-3`] - The gap between steps.
24+
* @cssprop [`--tap-progress-indicator-step-height`=`--tap-sys-spacing-3`] - The height of each step.
25+
* @cssprop [`--tap-progress-indicator-step-background-color`=`--tap-sys-color-surface-tertiary`] - The background color of each step.
26+
* @cssprop [`--tap-progress-indicator-active-step-background-color`=`--tap-sys-color-border-inverse-primary`] - The background color of active steps.
27+
*/
28+
@customElement('tap-progress-indicator')
629
export class TapProgressIndicator extends ProgressIndicator {
730
static readonly styles = [styles];
831
}
932

1033
declare global {
1134
interface HTMLElementTagNameMap {
12-
"tap-progress-indicator": TapProgressIndicator;
35+
'tap-progress-indicator': TapProgressIndicator;
1336
}
1437
}

src/progress-indicator/progress-indicator.stories.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
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: "Progress Indicator",
6-
component: "tap-progress-indicator",
5+
title: 'Progress Indicator',
6+
component: 'tap-progress-indicator',
77
argTypes: {
8-
current: { control: { type: 'range', min: 1, max: 10, step: 1 }, description: 'Progress indicator current value' },
9-
max: { control: { type: 'range', min: 1, max: 10, step: 1 }, description: 'Progress indicator max value' },
8+
current: {
9+
control: { type: 'range', min: 1, max: 10, step: 1 },
10+
description: 'Progress indicator current value',
11+
},
12+
max: {
13+
control: { type: 'range', min: 1, max: 10, step: 1 },
14+
description: 'Progress indicator max value',
15+
},
1016
},
1117
};
1218

@@ -21,8 +27,11 @@ interface ArgTypes {
2127
max: number;
2228
}
2329

24-
const Template: Story<ArgTypes> = ({current, max}: ArgTypes) => html`
25-
<tap-progress-indicator current=${current} max=${max}></tap-progress-indicator>
30+
const Template: Story<ArgTypes> = ({ current, max }: ArgTypes) => html`
31+
<tap-progress-indicator
32+
current=${current}
33+
max=${max}
34+
></tap-progress-indicator>
2635
`;
2736

2837
export const ProgressIndicator = Template.bind({});

src/progress-indicator/progress-indicator.style.ts

+13-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
export default css`
44
:host {
@@ -18,17 +18,26 @@ export default css`
1818
.progressbar {
1919
display: flex;
2020
align-items: center;
21-
gap: var(--tap-progress-indicator-progressbar-color, var(--tap-sys-spacing-3));
21+
gap: var(
22+
--tap-progress-indicator-progressbar-color,
23+
var(--tap-sys-spacing-3)
24+
);
2225
}
2326
2427
.step {
2528
display: block;
2629
height: var(--tap-progress-indicator-step-height, var(--tap-sys-spacing-3));
2730
flex: 1;
28-
background-color: var(--tap-progress-indicator-step-background-color, var(--tap-sys-color-surface-tertiary));
31+
background-color: var(
32+
--tap-progress-indicator-step-background-color,
33+
var(--tap-sys-color-surface-tertiary)
34+
);
2935
}
3036
3137
.active {
32-
background-color: var(--tap-progress-indicator-active-step-background-color, var(--tap-sys-color-border-inverse-primary));
38+
background-color: var(
39+
--tap-progress-indicator-active-step-background-color,
40+
var(--tap-sys-color-border-inverse-primary)
41+
);
3342
}
3443
`;

src/progress-indicator/progress-indicator.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { LitElement, html } from "lit";
2-
import { property, queryAll } from "lit/decorators.js";
3-
import { range } from "lit/directives/range.js";
4-
import { map } from "lit/directives/map.js";
5-
import { classMap } from "lit/directives/class-map.js";
1+
import { html, LitElement } from 'lit';
2+
import { property } from 'lit/decorators.js';
3+
import { range } from 'lit/directives/range.js';
4+
import { map } from 'lit/directives/map.js';
5+
import { classMap } from 'lit/directives/class-map.js';
66

77
/**
88
* @prop steps - total steps
@@ -38,7 +38,7 @@ export class ProgressIndicator extends LitElement {
3838
active: index < this.current,
3939
})}
4040
part="step"
41-
></div>`
41+
></div>`,
4242
)}
4343
</div>
4444
`;

0 commit comments

Comments
 (0)