@@ -9,14 +9,18 @@ function App () {
99 const [ count , setCount ] = useState ( 0 )
1010
1111 return pug `
12- Div(gap=2 align='center')
12+ Div.root (gap=2 align='center')
1313 Span.title(h1) CSSX Demo Page
1414 Div(row gap=2 vAlign='center')
1515 Button.down(onPress=() => setCount(c => c - 1)) -1
1616 Span(bold) Count: #{count}
1717 Button.up(onPress=() => setCount(c => c + 1)) +1
18+ Div(full)
19+ MediaRuler
1820 `
1921 styl `
22+ .root
23+ height 100%
2024 .title
2125 color: purple
2226 .down
@@ -33,25 +37,28 @@ function App () {
3337interface DivProps {
3438 children : React . ReactNode // The content to be displayed inside the div
3539 row ?: boolean // Arrange children in a row; otherwise, in a column
40+ full ?: boolean // Make the div take full available space
3641 gap ?: number | string // The gap between children, in pixels or CSS units
3742 align ?: 'left' | 'center' | 'right' // The alignment of children
3843 vAlign ?: 'top' | 'center' | 'bottom' // The vertical alignment of children
3944 onPress ?: ( ) => void // The function to call when the div is pressed
4045}
41- function Div ( { children, row, gap, align, vAlign, onPress } : DivProps ) {
46+ function Div ( { children, row, gap, align, vAlign, full , onPress } : DivProps ) {
4247 const style : React . CSSProperties = { }
4348 if ( gap ) style . gap = typeof gap === 'number' ? gap + 'u' : gap
4449 if ( align ) Object . assign ( style , getAlignStyle ( align , row ) )
4550 if ( vAlign ) Object . assign ( style , getVerticalAlignStyle ( vAlign , row ) )
4651 return pug `
47- div.root(part='root' styleName={row} style=style onClick=onPress)= children
52+ div.root(part='root' styleName={row, full } style=style onClick=onPress)= children
4853 `
4954 styl `
5055 .root
5156 display: flex
5257 flex-direction: column
5358 &.row
5459 flex-direction: row
60+ &.full
61+ flex: 1
5562 `
5663}
5764
@@ -116,6 +123,42 @@ function Button ({ children, ...props }: ButtonProps) {
116123 `
117124}
118125
126+ /**
127+ * Demo changing styles based on media queries. Changes width and background color based on screen width.
128+ */
129+ function MediaRuler ( ) {
130+ return pug `
131+ Div.root(part='root' align='center' vAlign='center')
132+ Span.text @media ruler - resize window and change count to see the color change
133+ `
134+ styl `
135+ .root
136+ height: 2u
137+ border-radius: 1u
138+ width: 100%
139+ background-color: red
140+ @media (min-width: 768px)
141+ max-width: 768px
142+ background-color: orange
143+ @media (min-width: 1024px)
144+ max-width: 1024px
145+ background-color: yellow
146+ @media (min-width: 1280px)
147+ max-width: 1280px
148+ background-color: green
149+ @media (min-width: 1536px)
150+ max-width: 1536px
151+ background-color: blue
152+ @media (min-width: 1920px)
153+ max-width: 1920px
154+ background-color: purple
155+ .text
156+ color: white
157+ font-family: monospace
158+ font-size: 1.5u
159+ `
160+ }
161+
119162function getAlignStyle ( align : string , row ?: boolean ) {
120163 const style : React . CSSProperties = { }
121164 if ( row ) {
0 commit comments