Skip to content

Commit f70c2b7

Browse files
blueneogeogitbook-bot
authored andcommitted
GitBook: [master] 5 pages and one asset modified
1 parent fc7b34f commit f70c2b7

File tree

6 files changed

+210
-4
lines changed

6 files changed

+210
-4
lines changed
Loading

SUMMARY.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [Test drive](get-started/test-drive.md)
1111
* [VS Code support](get-started/vs-code-support.md)
1212
* [Examples](get-started/examples.md)
13+
* [Styling with CSS](get-started/styling-with-css.md)
1314

1415
## Guide
1516

@@ -20,6 +21,6 @@
2021

2122
## Shortcuts Reference
2223

23-
* [Tag shortcuts](reference/tag-shortcuts.md)
24-
* [Property shortcuts](reference/css-properties.md)
24+
* [Shortcut tags](reference/tag-shortcuts.md)
25+
* [Shortcut properties](reference/css-properties.md)
2526

get-started/styling-with-css.md

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
# Styling with CSS
2+
3+
## Structuring your files for styling
4+
5+
**You can use CSS or Sass to set any property to any class or id in your Pug or HTML file.**
6+
7+
To do so, create a style file with the same name as your Pug or HTML file, in the same directory. For example, if you have a startpage.pug, to style it simply add a startpage.sass in the same directory.
8+
9+
Recommendation: create a directory per layout, with the name of your layout. Then inside, create a pug file, sass file and your model and other supporting files.
10+
11+
Example structure:
12+
13+
![](../.gitbook/assets/screen-shot-2018-12-14-at-11.57.56-am.png)
14+
15+
See the[ example projects](examples.md) for more ideas for structuring your application.
16+
17+
## Applying styles as properties
18+
19+
**You can apply extra properties to html elements by adding them through style rules.**
20+
21+
For example, given the following Pug:
22+
23+
```c
24+
.message hello!
25+
```
26+
27+
This will translate into the following HTML:
28+
29+
```markup
30+
<div class="message">hello!</div>
31+
```
32+
33+
You can then use the `.message` class to assign properties using Sass or CSS:
34+
35+
```css
36+
.message
37+
width: 200
38+
height: 200
39+
```
40+
41+
The resulting Dart will be a combination of your layout and style:
42+
43+
```dart
44+
Container(
45+
child: Text(
46+
'hello!',
47+
),
48+
width: 200,
49+
height: 200,
50+
);
51+
```
52+
53+
## Setting expressions
54+
55+
**You can set an expression in CSS by wrapping the expression in quotes and starting it with a colon.**
56+
57+
It is recommended to keep Dart expressions in your Pug files. However, in some cases it can be practical to be able to set an expression as a value, for example if flutter-view does not have special support for it.
58+
59+
Say you want to achieve the following Dart:
60+
61+
```dart
62+
Table(
63+
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
64+
children: [ ... ]
65+
)
66+
```
67+
68+
Which you can achieve with the following Pug code:
69+
70+
```css
71+
table(:default-verticle-alignment='TableCellVerticalAlignment.middle')
72+
...children...
73+
```
74+
75+
Now let's move the `defaultVerticleAlignment` property into a Sass file:
76+
77+
{% tabs %}
78+
{% tab title="Sass" %}
79+
```css
80+
table
81+
default-verticle-alignment: ':TableCellVerticalAlignment.middle'
82+
```
83+
{% endtab %}
84+
85+
{% tab title="Pug" %}
86+
```css
87+
table
88+
...children...
89+
```
90+
{% endtab %}
91+
{% endtabs %}
92+
93+
Note the colon before `TableCellVerticleAlignment.middle`in the pug file.
94+
95+
## Using shortcut properties in styles
96+
97+
**Flutter-view provides many shortcut properties, that let you style in a CSS-style manner.**
98+
99+
Some examples are [color](../reference/css-properties.md#color-color), [padding](../reference/css-properties.md#padding), [margin](../reference/css-properties.md#margin) and [background-image](../reference/css-properties.md#box-shadow-1).
100+
101+
See the [shortcut properties reference](../reference/css-properties.md) for the full list.
102+
103+
As an example, consider the following Pug layout we want to style \(taken and converted into flutter-view Pug from the [Flutter Card sample](https://docs.flutter.io/flutter/material/Card-class.html)\):
104+
105+
```text
106+
card
107+
column
108+
list-tile
109+
icon(as='leading' :value='Icons.album')
110+
.title(as='title') The Enchanted Nightingale
111+
.subtitle(as='subtitle') Music by Julie Gable. Lyrics by Sidney Stein.
112+
button-theme:bar
113+
button-bar
114+
flat-button.tickets(@on-pressed='...')
115+
.label Buy tickets
116+
flat-button.listen(@on-pressed='...')
117+
.label Listen
118+
```
119+
120+
We have a layout, and now we can style it.
121+
122+
The "buy tickets" and "listen" buttons we want to have uppercase text:
123+
124+
```css
125+
flat-button.tickets, flat-button.listen
126+
.label
127+
text-transform: uppercase
128+
```
129+
130+
We want the card to be blue and the column of the card to have `mainAxisSize: MainAxisSize.min`:
131+
132+
```css
133+
card
134+
color: blue
135+
column
136+
main-axis-size: min
137+
```
138+
139+
We want to give some padding to the title and subtitle, and make the text color grey\[300\]:
140+
141+
```css
142+
card
143+
$title-color: grey[300]
144+
list-tile
145+
.title
146+
color: $title-color
147+
padding: 4 6
148+
.subtitle
149+
color: $title-color
150+
padding: 2 6
151+
```
152+
153+
Note how we use Sass variables to avoid repetition.
154+
155+
Here is the end result:
156+
157+
{% tabs %}
158+
{% tab title="artist-card.pug" %}
159+
```css
160+
card
161+
column
162+
list-tile
163+
icon(as='leading' :value='Icons.album')
164+
.title(as='title') The Enchanted Nightingale
165+
.subtitle(as='subtitle') Music by Julie Gable. Lyrics by Sidney Stein.
166+
button-theme:bar
167+
button-bar
168+
flat-button.tickets(@on-pressed='...')
169+
.label Buy tickets
170+
flat-button.listen(@on-pressed='...')
171+
.label Listen
172+
```
173+
{% endtab %}
174+
175+
{% tab title="artist-card.sass" %}
176+
```css
177+
card
178+
color: blue
179+
column
180+
main-axis-size: min
181+
list-tile
182+
$title-color: grey[300]
183+
.title
184+
color: $title-color
185+
padding: 4 6
186+
.subtitle
187+
color: $title-color
188+
padding: 2 6
189+
flat-button
190+
.label
191+
text-transform: uppercase
192+
```
193+
{% endtab %}
194+
195+
{% tab title="generated artist-card.dart" %}
196+
197+
{% endtab %}
198+
{% endtabs %}
199+
200+
201+

guide/overview.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Other notable examples are:
1515
* **reactive**: lets you write terse reactive code that responds to your model changes
1616
* **assign**: easily assign values with expressions
1717

18+
See the [**shortcut tags reference**](../reference/tag-shortcuts.md) for all tags.
19+
1820
## Shortcut properties
1921

2022
The shortcut properties are macros that insert common layout behavior that take more code in Flutter, such as easily setting a background color to a container or adding text styling. These properties are as much as **CSS** properties as possible. However when there is no direct CSS-like analogy, the **Flutter** names and values are used. They are in **dash case**, since camelcase is not officially supported.
@@ -28,6 +30,8 @@ Some commonly used examples are:
2830
* **font-size, font-family** and **font-weight**: to style text
2931
* any property name ending on [**color**](../reference/css-properties.md#color-color) accepts both color names and hex codes
3032

33+
See the [**shortcut properties reference**](../reference/css-properties.md) for all supported properties.
34+
3135
### Escaping property shortcut processing
3236

3337
If you have to pass a parameter which has the name of a shortcut, and you do not wish to apply the shortcut, you can escape it with the ^ character.

reference/css-properties.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Property shortcuts
1+
# Shortcut properties
22

33
## alignment
44

reference/tag-shortcuts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Tag shortcuts
1+
# Shortcut tags
22

33
## builder
44

0 commit comments

Comments
 (0)