Skip to content

Commit f062747

Browse files
committed
Thinking through styles.
1 parent c3348bc commit f062747

File tree

9 files changed

+55
-13
lines changed

9 files changed

+55
-13
lines changed

src/pg/menu/README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
# `<pg-menu>`
22

3-
The `pg-menu` component renders a menu list.
3+
The `pg-menu` component renders a menu list. Menus can be used inline, but are usually created by a parent component. For example:
4+
5+
- `button-menu` - Button Menu
6+
- `button-icon-menu` - Button Icon Menu
7+
- `PgMenuOverlay` Utility overlay for menus.
48

59
```typescript
610
import '@pictogrammers/components/pgMenu.js';
711
```
812

913
```html
10-
<pg-menu></pg-menu>
14+
<pg-menu part="menu"></pg-menu>
1115
```
1216

1317
| Attributes | Tested | Description |
1418
| ---------- | -------- | ----------- |
15-
| `items` | | Set items list. |
19+
| `items` | | Set items list. |
20+
21+
```typescript
22+
@Part() $menu: PgMenu;
23+
24+
connectedCallback() {
25+
this.$menu.items = [{
26+
label: 'Item 1',
27+
value: 'item1'
28+
}];
29+
}
30+
```

src/pg/menu/menu.css

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22
display: contents;
33
}
44

5-
[part="items"] {
5+
[part=items] {
66
display: flex;
77
flex-direction: column;
8+
padding: var(--pg-menu-padding, 0);
9+
border-width: var(--pg-menu-border-width, 0);
10+
border-style: solid;
11+
border-radius: 0.25rem;
12+
}
13+
14+
[part=items] > *:first-child {
15+
--pg-menu-item-border-radius-top: var(--pg-menu-border-radius, 0.25rem);
16+
}
17+
18+
[part=items] > *:last-child {
19+
--pg-menu-item-border-radius-bottom: var(--pg-menu-border-radius, 0.25rem);
820
}

src/pg/menu/menu.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ export default class PgMenu extends HTMLElement {
2222
container: this.$items,
2323
items: this.items,
2424
type: (item) => {
25-
return PgMenuItem;
25+
return item.type ?? PgMenuItem;
2626
},
27-
create: ($item) => {
27+
create: ($item, item) => {
2828
$item.addEventListener('select', (e: any) => {
2929
const { index } = e.detail;
3030
this.dispatchEvent(new CustomEvent('select', {
31-
detail: { index }
31+
detail: { index, item }
3232
}))
3333
});
3434
}

src/pg/menuItem/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# `<pg-menu>`
22

3-
The `pg-menu` component renders a menu list.
3+
The `pg-menu-item` is usually rendered as a child of the `pg-menu`.
44

55
```typescript
6-
import '@pictogrammers/components/pgMenu.js';
6+
import '@pictogrammers/components/pgMenuItem.js';
77
```
88

99
```html
10-
<pg-menu></pg-menu>
10+
<pg-menu-item></pg-menu-item>
1111
```
1212

1313
| Attributes | Tested | Description |
1414
| ---------- | -------- | ----------- |
15-
| `items` | | Set items list. |
15+
| `label` | | Item label. |

src/pg/menuItem/menuItem.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,14 @@
33
}
44

55
[part=label] {
6-
text-align: left;
6+
text-align: var(--pg-menu-item-text-align, left);
7+
background: var(--pg-menu-item-background, #FFFFFF);
8+
padding: var(--pg-menu-padding, 0.25rem 0.5rem);
9+
border-color: #453C4F;
10+
border-width: 1px;
11+
border-style: solid;
12+
border-top-left-radius: var(--pg-menu-item-border-radius-top, 0);
13+
border-top-right-radius: var(--pg-menu-item-border-radius-top, 0);
14+
border-bottom-left-radius: var(--pg-menu-item-border-radius-bottom, 0);
15+
border-bottom-right-radius: var(--pg-menu-item-border-radius-bottom, 0);
716
}

src/pg/overlayMenu/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
The `PgOverlayMenu` creates a menu.
44

55
```typescript
6+
if (this.#isOpen) { return; }
7+
this.#isOpen = true;
68
const result = await PgOverlayMenu.open({
79
source: this.$element,
810
items: [{
@@ -13,4 +15,5 @@ const result = await PgOverlayMenu.open({
1315
value: 'item2'
1416
}]
1517
});
18+
console.log(result);
1619
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<div class="example">
22
<button part="button">Create Menu Overlay</button>
3+
<p>Result: <code part="result"></code></p></p>
34
</div>

src/pg/overlayMenu/__examples__/basic/basic.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import style from './basic.css';
1111
})
1212
export default class XPgOverlayMenuBasic extends HTMLElement {
1313
@Part() $button: HTMLButtonElement;
14+
@Part() $result: HTMLSpanElement;
1415

1516
connectedCallback() {
1617
this.$button.addEventListener('click', this.#handleClick.bind(this));
@@ -31,7 +32,7 @@ export default class XPgOverlayMenuBasic extends HTMLElement {
3132
value: 'item2'
3233
}]
3334
});
34-
console.log(result);
35+
this.$result.textContent = result;
3536
this.#menuOpen = false;
3637
}
3738
}

src/pg/overlayMenu/overlayMenu.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
min-width: anchor-size();
99
padding: 0;
1010
border: 0;
11+
position-try-fallbacks: flip-block;
1112
}

0 commit comments

Comments
 (0)