11<!DOCTYPE HTML>
22< html lang ="en ">
3+
34< head >
4- < meta charset ='UTF-8 '>
5- < title > solid-ui UI.widgets.header examples page</ title >
6- < script type ="text/javascript " src ="../../lib/webpack-bundle.js "> </ script >
7- < script >
8- const $ = document . querySelector . bind ( document )
9- function showSource ( widgetName ) {
10- $ ( `#viewSource-${ widgetName } ` ) . innerHTML = $ ( `#script-${ widgetName } ` ) . innerText
11- . replace ( / & / g, "&" )
12- . replace ( / < / g, "<" )
13- . replace ( / > / g, ">" )
14- . replace ( / " / g, """ )
15- . replace ( / ' / g, "'" )
16- }
17- </ script >
5+ < meta charset ='UTF-8 '>
6+ < title > solid-ui UI.widgets.header examples page</ title >
7+ < script type ="text/javascript " src ="../../lib/webpack-bundle.js "> </ script >
8+ < script src ="https://solid.github.io/solid-auth-client/dist/solid-auth-client.bundle.js "> </ script >
9+ < script >
10+ const $ = document . querySelector . bind ( document )
11+ function showSource ( widgetName ) {
12+ $ ( `#viewSource-${ widgetName } ` ) . innerHTML = $ ( `#script-${ widgetName } ` ) . innerText
13+ . replace ( / & / g, "&" )
14+ . replace ( / < / g, "<" )
15+ . replace ( / > / g, ">" )
16+ . replace ( / " / g, """ )
17+ . replace ( / ' / g, "'" )
18+ }
19+ </ script >
20+ < style >
21+ .loginButton {
22+ border-radius : 0.2em ;
23+ margin : 1em ;
24+ font-size : 85% ;
25+ background-color : # fff ;
26+ border-style : .01em solid # 7C4DFF ;
27+ color : # 7C4DFF ;
28+ }
29+
30+ .loginButton : hover {
31+ background-color : # 7C4DFF ;
32+ color : # fff ;
33+ }
34+ </ style >
1835</ head >
36+
1937< body >
2038
21- < h2 id ="header "> < a href ="#header "> Header</ a > </ h2 >
22- < div id ='PageHeader '> </ div >
23- < script id ="script-header ">
24- window . addEventListener ( 'DOMContentLoaded' , async ( ) => {
25- try {
26- await UI . initHeader ( UI . store )
27- } catch ( error ) {
28- window . alert ( `Error loading header. You need to have a div with id = PageHeader on your page.` )
29- }
30- } ) ;
31- </ script >
32- < pre id ="viewSource-header "> </ pre > < script > showSource ( 'header' ) </ script >
33- < div id ="div-header "> </ div >
34-
35- < h2 id ="headerNotLoggedIn "> < a href ="#headerNotLoggedIn "> Header</ a > </ h2 >
36- < div id ='PageHeader2 '> </ div >
37- < script id ="script-headerNotLoggedIn ">
38- window . addEventListener ( 'DOMContentLoaded' , async ( ) => {
39- try {
40- await UI . initHeader ( UI . store )
41- } catch ( error ) {
42- window . alert ( `Error loading header. You need to have a div with id = PageHeader on your page.` )
39+ < h2 id ="header "> < a href ="#header "> Header</ a >
40+ < button class ="loginButton " onclick ="login('https://solid.community') "> Login</ button >
41+ < script >
42+ async function login ( idp ) {
43+ const session = await solid . auth . currentSession ( ) ;
44+ if ( ! session )
45+ await solid . auth . login ( idp ) ;
46+ }
47+ </ script >
48+ </ h2 >
49+ < p > This example demonstrates how to use the header component. The header has a different view depending
50+ on whether or not you are logged in. </ p >
51+ < p > Unless you are already logged into your pod identity provider you
52+ should see the logged out view. To see the logged in view click the login button above. </ p >
53+ < p > The header is customizable through the options parameter.</ p >
54+ < p > The logo can be a url of your personalized logo, otherwise it will default to Solid. </ p >
55+ < p > The menu list is an array of either links or buttons. </ p >
56+ < p > The details are below. </ p >
57+ < p > < strong > options:</ strong >
58+ < code >
59+ type HeaderOptions {
60+ logo?: string,
61+ menuList?: MenuItems[]
62+ }</ code > </ p >
63+ < p > < strong > MenuItems</ strong > can be either a MenuItemLink or a MenuItemButton:
64+ < code >
65+ < p > type MenuItemLink = {
66+ label: string,
67+ url: string
4368 }
44- } ) ;
45- </ script >
46- < pre id ="viewSource-headerNotLoggedIn "> </ pre > < script > showSource ( 'headerNotLoggedIn' ) </ script >
47- < div id ="div-headerNotLoggedIn "> </ div >
69+ </ p >
70+ < p > type MenuItemButton = {
71+ label: string,
72+ onclick: () => {}
73+ }
74+ </ p >
75+
76+ </ code >
77+ </ p >
78+
79+
80+ < div id ='PageHeader '> </ div >
81+ < p > In the code below you can see that you can have a mixture of buttons and links. When you pass in an onclick
82+ initHeader will create a
83+ button, however if you pass in a url it will create a link. Either way, as you can see, they appear the same in the
84+ menu.
85+ </ p >
86+ < script id ="script-header ">
87+ window . addEventListener ( 'DOMContentLoaded' , async ( ) => {
88+ try {
89+ options = { menuList : [ { label : "Testing Button" , onclick : ( ) => { alert ( 'hello' ) } } , { label : "Testing Link" , url : 'https://reflectechblog.wordpress.com/' } ] }
90+ await UI . initHeader ( UI . store , options )
91+ } catch ( error ) {
92+ window . alert ( `Error loading header. You need to have a div with id = PageHeader on your page.` )
93+ }
94+ } ) ;
95+ </ script >
96+ < pre id ="viewSource-header "> </ pre >
97+ < script > showSource ( 'header' ) </ script >
98+ < div id ="div-header "> </ div >
99+
48100</ body >
101+
49102</ html >
0 commit comments