Skip to content

Commit a71e1e7

Browse files
authored
Feat: Add pinwheel-group Component (#96)
* feat: add pinwheel-group component * Create README.md * Update README.md * fix: update css var names * fix: remove README * doc: add JSDoc * doc: update JSDoc
1 parent fcb0f5d commit a71e1e7

File tree

6 files changed

+124
-12
lines changed

6 files changed

+124
-12
lines changed

src/pinwheel-group/index.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { customElement } from "lit/decorators.js";
2+
import { PinwheelGroup } from "./pinwheel-group";
3+
import styles from "./pinwheel-group.style";
4+
5+
/**
6+
* ### Example
7+
*
8+
* ```html
9+
* <tap-pinwheel-group>
10+
* <tap-pinwheel .items=${["item1", "item2"]}></tap-avatar>
11+
* <tap-pinwheel .items=${["item1", "item2"]}></tap-avatar>
12+
* <tap-pinwheel .items=${["item1", "item2"]}></tap-avatar>
13+
* </tap-pinwheel-group>
14+
* ```
15+
*
16+
* @summary Grouping pinwheel components and attach selector indicator to them.
17+
*
18+
* @slot - The default slot to get pinwheels.
19+
*
20+
* @csspart `pinwheel-group` - The container that wraps the pinwheels.
21+
* @csspart `pinwheel-selector-indicator` - The selector indicator that wraps selected row.
22+
*
23+
* @cssprop [`--tap-pinwheel-group-selector-radius`=`--tap-sys-spacing-4`]
24+
*
25+
* @cssprop [`--tap-pinwheel-group-selector-background-color`=`--tap-sys-color-surface-tertiary`]
26+
*
27+
*/
28+
@customElement("tap-pinwheel-group")
29+
export class TapPinwheelGroup extends PinwheelGroup {
30+
static readonly styles = [styles];
31+
}
32+
33+
declare global {
34+
interface HTMLElementTagNameMap {
35+
"tap-pinwheel-group": TapPinwheelGroup;
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { html, TemplateResult } from "lit";
2+
import "./index.js";
3+
import "../pinwheel"
4+
5+
export default {
6+
title: "Pinwheel",
7+
component: "tap-pinwheel-group",
8+
argTypes: {},
9+
};
10+
11+
interface Story<T> {
12+
(args: T): TemplateResult;
13+
args?: Partial<T>;
14+
argTypes?: Record<string, unknown>;
15+
}
16+
17+
interface ArgTypes {}
18+
19+
const items = ['عنوان ۱', 'عنوان ۲', 'عنوان ۳', 'عنوان ۴', 'عنوان ۵', 'عنوان ۶', 'عنوان ۷', 'عنوان ۸', 'عنوان ۹']
20+
21+
const Template: Story<ArgTypes> = ({}: ArgTypes) => html`
22+
<tap-pinwheel-group>
23+
<tap-pinwheel .items=${items}></tap-pinwheel>
24+
<tap-pinwheel .items=${items}></tap-pinwheel>
25+
<tap-pinwheel .items=${items}></tap-pinwheel>
26+
</tap-pinwheel-group>
27+
`;
28+
29+
export const PinwheelGroup = Template.bind({});
30+
31+
PinwheelGroup.args = {};
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { css } from "lit";
2+
3+
export default css`
4+
:host {
5+
display: inline-flex;
6+
}
7+
8+
.pinwheel-group {
9+
position: relative;
10+
}
11+
12+
.selector-indicator {
13+
/* FIXME: we dont have sizing tokens yet */
14+
height: var(--tap-pinwheel-item-height, 48px);
15+
background-color: var(--tap-pinwheel-group-selector-background-color, var(--tap-sys-color-surface-tertiary));
16+
border-radius: var(--tap-pinwheel-group-selector-radius, var(--tap-sys-spacing-4));
17+
position: absolute;
18+
top: calc(50% - 24px);
19+
left: 0;
20+
right: 0;
21+
z-index: -1;
22+
}
23+
`;

src/pinwheel-group/pinwheel-group.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { html, LitElement, nothing } from 'lit';
2+
3+
export class PinwheelGroup extends LitElement {
4+
render() {
5+
return html`
6+
<div
7+
role="group"
8+
class="pinwheel-group"
9+
part="pinwheel-group"
10+
aria-label=${nothing}
11+
>
12+
<slot></slot>
13+
<div class="selector-indicator" part="pinwheel-selector-indicator"></div>
14+
</div>
15+
`
16+
}
17+
}

src/pinwheel/index.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@ import styles from './pinwheel.style';
1616
* @csspart `pinwheel` - The container that wraps the pinwheel component.
1717
* @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-vertical-padding`=`--tap-sys-spacing-0`]
20+
* @cssprop [`--tap-pinwheel-horizontal-padding`=`--tap-sys-spacing-6`]
21+
*
22+
* @cssprop [`--tap-pinwheel-item-height`=`--tap-sys-spacing-11`]
2223
*
2324
* @cssprop [`--tap-font-family`=`--tap-sys-font-family`]
2425
* @cssprop [`--tap-pinwheel-typography-body-md-height`=`--tap-sys-typography-body-md-height`]
2526
* @cssprop [`--tap-pinwheel-typography-body-md-size`=`--tap-sys-typography-body-md-size`]
2627
* @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`]
28+
* @cssprop [`--tap-pinwheel-item-color`=`--tap-sys-color-content-tertiary`]
2829
*
2930
* @cssprop [`--tap-pinwheel-typography-label-md-height`=`--tap-sys-typography-label-md-height`]
3031
* @cssprop [`--tap-pinwheel-typography-label-md-size`=`--tap-sys-typography-label-md-size`]
3132
* @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`]
33+
* @cssprop [`--tap-pinwheel-active-item-color`=`--tap-sys-color-content-primary`]
3334
*
3435
*/
3536
@customElement('tap-pinwheel')

src/pinwheel/pinwheel.style.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ export default css`
1717
}
1818
1919
.pinwheel > div {
20-
padding: var(--tap-pinwheel-spacing-0, var(--tap-sys-spacing-0))
21-
var(--tap-pinwheel-spacing-6, var(--tap-sys-spacing-6));
20+
display: flex;
21+
align-items: center;
22+
justify-content: center;
23+
padding: var(--tap-pinwheel-vertical-padding, var(--tap-sys-spacing-0))
24+
var(--tap-pinwheel-horizontal-padding, var(--tap-sys-spacing-6));
2225
/* FIXME: we dont have sizing tokens yet */
23-
height: 48px;
26+
height: var(--tap-pinwheel-item-height, 48px);
2427
font: inherit;
2528
font-family: var(--tap-font-family, var(--tap-sys-font-family));
2629
line-height: var(
@@ -36,17 +39,17 @@ export default css`
3639
var(--tap-sys-typography-body-md-weight)
3740
);
3841
color: var(
39-
--tap-pinwheel-color-content-tertiary,
42+
--tap-pinwheel-item-color,
4043
var(--tap-sys-color-content-tertiary)
4144
);
4245
}
4346
4447
.pinwheel div:first-child {
45-
padding-top: var(--tap-pinwheel-spacing-11, var(--tap-sys-spacing-11));
48+
padding-top: var(--tap-pinwheel-item-height, var(--tap-sys-spacing-11));
4649
}
4750
4851
.pinwheel div:last-child {
49-
padding-bottom: var(--tap-pinwheel-spacing-11, var(--tap-sys-spacing-11));
52+
padding-bottom: var(--tap-pinwheel-item-height, var(--tap-sys-spacing-11));
5053
}
5154
5255
.pinwheel .active {
@@ -63,7 +66,7 @@ export default css`
6366
var(--tap-sys-typography-label-md-weight)
6467
);
6568
color: var(
66-
--tap-pinwheel-color-content-primary,
69+
--tap-pinwheel-active-item-color,
6770
var(--tap-sys-color-content-primary)
6871
);
6972
}

0 commit comments

Comments
 (0)