Skip to content

Commit 7d5e985

Browse files
committed
html examples updated
1 parent 54b294a commit 7d5e985

File tree

1 file changed

+85
-25
lines changed

1 file changed

+85
-25
lines changed

v0.3/handbook/libraries/stdlib.md

Lines changed: 85 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,12 @@ search
731731
header = if tagname = "div" then "true" else "false"
732732
bind
733733
hello <- [class: [header]]
734+
~~~
735+
736+
Commit an element with a greeting
737+
~~~
738+
commit
739+
[#html/element tagname: "div" text: "Hello world!"]
734740
~~~</code>
735741
</td>
736742
</tr>
@@ -755,7 +761,8 @@ commit a div to the browser with the text "Hover over me!" that will change its
755761
~~~
756762
commit
757763
[#ui/div #html/listener/hover text: "Hover over me!"]
758-
~~~</code>
764+
~~~
765+
</code>
759766
</td>
760767
</tr>
761768
</table>
@@ -775,13 +782,20 @@ commit
775782
</td>
776783
<td>
777784
<code>
778-
if a #ui/a element with the hover listener is being hovered over, add a style to make the font bold
785+
commit a div to the browser with the text "Hover over me!" that will change its record if it is hovered over
786+
~~~
787+
commit
788+
[#ui/div #html/listener/hover text: "Hover over me!"]
789+
~~~
790+
791+
Display a message when an element with the #html/listener/hover`
779792
~~~
780793
search
781-
element = [#ui/a #html/hovered]
794+
[#html/hovered]
782795
bind
783-
element.style <- [font-weight: bold]
784-
~~~</code>
796+
[#ui/text text: "an element is being hovered"]
797+
~~~
798+
</code>
785799
</td>
786800
</tr>
787801
</table>
@@ -801,14 +815,21 @@ bind
801815
</td>
802816
<td>
803817
<code>
804-
when the mouse enters an anchor tag, make the color red; the color will not revert when the mouse leaves
818+
Do something on hover-in
805819
~~~
806820
search
807-
[#html/event/hover-in element: anchor]
808-
anchor = [#ui/a]
809-
bind
810-
anchor.style <- [color: red]
811-
~~~</code>
821+
direction = if [#html/event/hover-in] then "in"
822+
else if [#html/event/hover-out] then "out"
823+
commit
824+
[#ui/text text: "Hovered {{direction}}"]
825+
~~~
826+
827+
Monitor hover on an element
828+
~~~
829+
commit
830+
[#ui/text #html/listener/hover text: "Hover over me" style: [width: "100px" height: "100px" background-color: "rgb(226, 79, 94)" display: "block" color: "white" padding: "10px"]]
831+
~~~
832+
</code>
812833
</td>
813834
</tr>
814835
</table>
@@ -872,9 +893,18 @@ bind
872893
looks for a right click in any h1 element and posts the message "Right clicked!"
873894
~~~
874895
search
875-
[#html/event/mouse-up element: [#ui/h1] button: "right"]
896+
event = if [#html/event/mouse-up button] then "up"
897+
else if [#html/event/mouse-down button] then "down"
898+
else if [#html/event/click button] then "click"
899+
else if [#html/event/double-click button] then "double-click"
876900
commit
877-
[#ui/div text: "Right clicked!"]
901+
[#ui/text text: "{{event}}"]
902+
~~~
903+
904+
Monitor clicks on an element
905+
~~~
906+
commit
907+
[#ui/text text: "Click me" style: [width: "100px" height: "100px" background-color: "rgb(226, 79, 94)" display: "block" color: "white" padding: "10px"]]
878908
~~~</code>
879909
</td>
880910
</tr>
@@ -894,11 +924,14 @@ commit
894924
</ul>
895925
</td>
896926
<td>
897-
<code>commits an h1 element whose context menu won’t open if right clicked
927+
<code>
928+
commits an h1 element whose context menu won’t open if right clicked
898929
~~~
899930
commit
900931
[#ui/h1 #html/listener/context-menu text: "Don’t inspect me"]
901-
~~~</code>
932+
[#ui/h1 text: "Inspect me"]
933+
~~~
934+
</code>
902935
</td>
903936
</tr>
904937
</table>
@@ -934,13 +967,21 @@ commit
934967
</td>
935968
<td>
936969
<code>
937-
when the escape key is released, commits a gentle reminder for the user
970+
Prints a message with the code of the key pressed
971+
~~~
972+
search
973+
[#html/event/key-down key-code]
974+
commit
975+
[#ui/div #key-msg key-code text: "Pressed {{key-code}}"]
938976
~~~
939-
search
940-
[#html/event/key-up key: "escape"]
941977
978+
Remove messages for keys that are released
979+
~~~
980+
search
981+
[#html/event/key-up key-code]
982+
message = [#key-msg key-code]
942983
commit
943-
[#ui/div text: "THERE IS NO ESCAPE"]
984+
message := none
944985
~~~</code>
945986
</td>
946987
</tr>
@@ -962,13 +1003,22 @@ commit
9621003
</td>
9631004
<td>
9641005
<code>
965-
when the important element loses focus, commits a message to help the user
1006+
Display a message on focus
9661007
~~~
9671008
search
968-
[#html/event/blur element: [#important]]
1009+
[#html/event/focus element]
1010+
1011+
commit
1012+
[#ui/text text: "{{element.placeholder}} was focused"]
1013+
~~~
1014+
1015+
Monitor clicks on an element
1016+
~~~
9691017
commit
970-
[#ui/text text: "Stay focused!"]
971-
~~~</code>
1018+
[#ui/input placeholder: "First Name"]
1019+
[#ui/input placeholder: "Last Name"]
1020+
~~~
1021+
</code>
9721022
</td>
9731023
</tr>
9741024
</table>
@@ -988,13 +1038,23 @@ commit
9881038
</td>
9891039
<td>
9901040
<code>
1041+
Commit some buttons and form elements
1042+
~~~
1043+
commit
1044+
[#ui/input field: "first-name" placeholder: "First Name"]
1045+
[#ui/input field: "last-name" placeholder: "Last Name"]
1046+
[#ui/button text: "Focus first name" target: "first-name"]
1047+
[#ui/button text: "Focus last name" target: "last-name"]
1048+
~~~
1049+
9911050
when a form element is found in the browser with the name "first-name", focuses on that element
9921051
~~~
9931052
search
994-
first = [#ui/input name: "first-name"]
1053+
[#html/event/click element: [#ui/button target]]
1054+
input = [#ui/input field: target]
9951055

9961056
commit
997-
first <- [#html/trigger/focus]
1057+
input.tag <- [#html/trigger/focus]
9981058
~~~</code>
9991059
</td>
10001060
</tr>

0 commit comments

Comments
 (0)