|
1 | | -import { WebCellProps, createCell } from 'web-cell'; |
| 1 | +import { |
| 2 | + WebCellProps, |
| 3 | + component, |
| 4 | + mixin, |
| 5 | + watch, |
| 6 | + attribute, |
| 7 | + createCell, |
| 8 | + Fragment |
| 9 | +} from 'web-cell'; |
2 | 10 | import { HTMLHyperLinkProps } from 'web-utility/source/DOM-type'; |
3 | 11 | import { Button } from 'boot-cell/source/Form/Button'; |
| 12 | +import { HeaderList } from 'boot-cell/source/Navigator/HeaderList'; |
4 | 13 |
|
5 | 14 | import { SideNav } from './SideNav'; |
6 | 15 |
|
7 | 16 | interface PageFrameProps extends WebCellProps { |
8 | 17 | menu: { [key: string]: HTMLHyperLinkProps[] }; |
9 | | - title: string; |
| 18 | + header: string; |
10 | 19 | description: string; |
11 | 20 | } |
12 | 21 |
|
13 | | -export function PageFrame({ |
14 | | - menu, |
15 | | - title, |
16 | | - description, |
17 | | - defaultSlot |
18 | | -}: PageFrameProps) { |
19 | | - const API = `https://web-cell.dev/BootCell/interfaces/${title |
20 | | - .replace(' ', '') |
21 | | - .toLowerCase()}props.html`; |
22 | | - |
23 | | - return ( |
24 | | - <div className="d-flex"> |
25 | | - <SideNav className="border-right p-4" menu={menu} /> |
26 | | - |
27 | | - <div className="flex-fill p-4"> |
28 | | - <h1 className="d-flex justify-content-between align-items-center"> |
29 | | - {title} |
30 | | - <Button size="sm" href={API}> |
31 | | - API |
32 | | - </Button> |
33 | | - </h1> |
34 | | - <p className="lead">{description}</p> |
35 | | - |
36 | | - {defaultSlot} |
37 | | - </div> |
38 | | - </div> |
39 | | - ); |
| 22 | +@component({ |
| 23 | + tagName: 'page-frame', |
| 24 | + renderTarget: 'children' |
| 25 | +}) |
| 26 | +export class PageFrame extends mixin<PageFrameProps>() { |
| 27 | + @watch |
| 28 | + menu = []; |
| 29 | + |
| 30 | + @attribute |
| 31 | + @watch |
| 32 | + header = ''; |
| 33 | + |
| 34 | + @attribute |
| 35 | + @watch |
| 36 | + description = ''; |
| 37 | + |
| 38 | + private box: HTMLElement; |
| 39 | + private nav: HeaderList; |
| 40 | + |
| 41 | + connectedCallback() { |
| 42 | + this.classList.add('d-flex', 'align-items-start'); |
| 43 | + |
| 44 | + super.connectedCallback(); |
| 45 | + } |
| 46 | + |
| 47 | + updatedCallback() { |
| 48 | + if (this.box && this.nav) this.nav.spy(this.box); |
| 49 | + } |
| 50 | + |
| 51 | + render({ header, menu, description, defaultSlot }: PageFrameProps) { |
| 52 | + const API = `https://web-cell.dev/BootCell/interfaces/${header |
| 53 | + .replace(' ', '') |
| 54 | + .toLowerCase()}props.html`; |
| 55 | + |
| 56 | + return ( |
| 57 | + <Fragment> |
| 58 | + <SideNav |
| 59 | + className="sticky-top" |
| 60 | + style={{ top: '3.5rem', height: 'calc(100vh - 3.5rem)' }} |
| 61 | + menu={menu} |
| 62 | + /> |
| 63 | + |
| 64 | + <div className="flex-fill p-4 border-left"> |
| 65 | + <h1 className="d-flex justify-content-between align-items-center"> |
| 66 | + {header} |
| 67 | + <Button size="sm" href={API}> |
| 68 | + API |
| 69 | + </Button> |
| 70 | + </h1> |
| 71 | + <p className="lead">{description}</p> |
| 72 | + |
| 73 | + <div ref={(node: HTMLElement) => (this.box = node)}> |
| 74 | + {defaultSlot} |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + |
| 78 | + <HeaderList |
| 79 | + className="p-4 d-none d-md-block" |
| 80 | + style={{ top: '3.5rem' }} |
| 81 | + ref={(node: HeaderList) => (this.nav = node)} |
| 82 | + /> |
| 83 | + </Fragment> |
| 84 | + ); |
| 85 | + } |
40 | 86 | } |
0 commit comments