1+ import components
2+ import gleam/int
13import redraw
4+ import redraw/attribute as a
25import redraw/handler
36import redraw/html as h
47import redraw_dom/client
5- import sketch as s
68import sketch/redraw as sr
7- import sketch/redraw/html as sh
8- import sketch/size . { px , vh }
99
1010pub fn main ( ) {
1111 let app = app ( )
@@ -14,99 +14,62 @@ pub fn main() {
1414}
1515
1616fn app ( ) {
17+ let view_counter_description = view_counter_description ( )
18+ let view_counter = view_counter ( )
19+ let showcase = showcase ( )
1720 use <- redraw . component__ ( "App" )
1821 let # ( count , set_count ) = redraw . use_state_ ( 0 )
19- let on_click = handler . on_click ( fn ( _ ) { set_count ( fn ( c ) { c + 1 } ) } )
20- sh . div ( body ( ) , [ ] , [
21- sh . div ( wrapper ( ) , [ ] , [
22- sh . h1 ( main_title ( ) , [ ] , [ h . text ( "Sketch" ) ] ) ,
23- sh . div ( subtitle ( ) , [ ] , [ h . text ( "CSS-in-Gleam, made simple" ) ] ) ,
22+ let increment = handler . on_click ( fn ( _ ) { set_count ( fn ( c ) { c + 1 } ) } )
23+ let decrement = handler . on_click ( fn ( _ ) { set_count ( fn ( c ) { c - 1 } ) } )
24+ components . body ( [ ] , [
25+ components . topbar ( [ ] , [ h . text ( "Sketch" ) ] ) ,
26+ components . headline ( count , [ ] , [
27+ components . headline_subtitle ( [ ] , [ h . text ( "CSS-in-Gleam" ) ] ) ,
28+ components . headline_emphasize ( [ ] , [
29+ h . text ( "Improve your CSS" ) ,
30+ h . br ( [ ] ) ,
31+ h . text ( "with Sketch" ) ,
32+ ] ) ,
2433 ] ) ,
25- sh . div ( button_wrapper ( ) , [ ] , [
26- sh . button ( button ( ) , [ on_click ] , [ h . text ( "Change color" ) ] ) ,
27- sh . div ( square_wrapper ( ) , [ ] , [
28- sh . div ( square_behind ( count + 1 ) , [ ] , [ ] ) ,
29- sh . div ( square ( count ) , [ ] , [ ] ) ,
34+ components . counter ( [ ] , [
35+ components . counter_body ( [ ] , [
36+ components . counter_body_title ( [ ] , [
37+ view_counter_description ( ) ,
38+ view_counter ( # ( count , increment , decrement ) ) ,
39+ ] ) ,
3040 ] ) ,
41+ components . card_title ( [ ] , [ h . text ( "See it in action" ) ] ) ,
3142 ] ) ,
43+ showcase ( ) ,
3244 ] )
3345}
3446
35- fn body ( ) {
36- s . class ( [
37- s . height ( vh ( 100 ) ) ,
38- s . display ( "flex" ) ,
39- s . flex_direction ( "column" ) ,
40- s . justify_content ( "center" ) ,
41- s . align_items ( "center" ) ,
42- s . gap ( px ( 24 ) ) ,
43- ] )
44- }
45-
46- fn wrapper ( ) {
47- s . class ( [ s . display ( "flex" ) , s . gap ( px ( 12 ) ) , s . align_items ( "baseline" ) ] )
48- }
49-
50- fn main_title ( ) {
51- s . class ( [ s . margin ( px ( 0 ) ) ] )
52- }
53-
54- fn subtitle ( ) {
55- s . class ( [ ] )
56- }
57-
58- fn button_wrapper ( ) {
59- s . class ( [ s . display ( "flex" ) , s . gap ( px ( 40 ) ) , s . align_items ( "center" ) ] )
60- }
61-
62- fn square_wrapper ( ) {
63- s . class ( [ s . position ( "relative" ) ] )
64- }
65-
66- fn square_base ( count ) {
67- s . class ( [
68- s . background ( compute_bg ( count ) ) ,
69- s . width ( px ( 80 ) ) ,
70- s . height ( px ( 80 ) ) ,
71- s . border_radius ( px ( 10 ) ) ,
72- s . transition ( "all .3s" ) ,
47+ fn view_counter_description ( ) {
48+ use <- redraw . component__ ( "CounterDescription" )
49+ let use_counter = "Use the counter, and see the site changing with the model!"
50+ let now_edit = "Now, try to edit the code to see the modifications live!"
51+ h . div ( [ ] , [
52+ h . text ( "Counter" ) ,
53+ components . counter_subtitle ( [ ] , [ h . text ( use_counter ) ] ) ,
54+ components . counter_subtitle ( [ ] , [ h . text ( now_edit ) ] ) ,
7355 ] )
7456}
7557
76- fn square ( count ) {
77- s . class ( [ s . compose ( square_base ( count ) ) , s . position ( "relative" ) , s . z_index ( 1 ) ] )
78- }
79-
80- fn square_behind ( count ) {
81- s . class ( [
82- s . compose ( square_base ( count ) ) ,
83- s . position ( "absolute" ) ,
84- s . bottom ( px ( - 40) ) ,
85- s . right ( px ( - 40) ) ,
86- s . z_index ( 0 ) ,
58+ fn view_counter ( ) {
59+ use # ( count , increment , decrement ) <- redraw . component_ ( "Counter" )
60+ let disabled = a . disabled ( count <= 0 )
61+ let model = int . to_string ( count )
62+ components . counter_counter ( [ ] , [
63+ components . button ( [ decrement , disabled ] , [ h . text ( "-" ) ] ) ,
64+ components . value ( [ ] , [ components . value_content ( [ ] , [ h . text ( model ) ] ) ] ) ,
65+ components . button ( [ increment ] , [ h . text ( "+" ) ] ) ,
8766 ] )
8867}
8968
90- fn compute_bg ( count ) {
91- case count % 2 == 0 {
92- True -> "red"
93- False -> "blue"
94- }
95- }
96-
97- fn button ( ) {
98- s . class ( [
99- s . margin_top ( px ( 40 ) ) ,
100- s . background ( "#ddd" ) ,
101- s . color ( "black" ) ,
102- s . border_radius ( px ( 8 ) ) ,
103- s . transition ( "all .3s" ) ,
104- s . border ( "none" ) ,
105- s . appearance ( "none" ) ,
106- s . font_family ( "inherit" ) ,
107- s . font_size ( px ( 16 ) ) ,
108- s . padding ( px ( 12 ) ) ,
109- s . font_weight ( "bold" ) ,
110- s . cursor ( "pointer" ) ,
69+ fn showcase ( ) {
70+ use <- redraw . component__ ( "Showcase" )
71+ components . showcase ( [ ] , [
72+ components . showcase_body ( [ ] , [ h . text ( "Coming soon..." ) ] ) ,
73+ components . card_title ( [ ] , [ h . text ( "Showcase" ) ] ) ,
11174 ] )
11275}
0 commit comments