This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathif-attr.ftd
301 lines (160 loc) · 4.78 KB
/
if-attr.ftd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
-- boolean present: false
-- my-ds.page: Conditional Attributes
-- ds.markdown:
`ftd` supports `if` expression to decide the value of attribute, based on the
arguments, or global variables.
-- ds.h2: Priority Order
The priority of conditional attributes is in increasing order (low -> high) i.e.
the condition at bottom has higher priority than the above conditions. The value of
attribute with no condition is taken as default.
-- ds.h2: Examples
Lets understand it better with few examples
-- ds.h3: Example 1:
-- ds.code: Conditional Attribute using variable
lang: ftd
\-- boolean present: false
\-- component foo1:
caption name:
\-- ftd.text:
color: $inherited.colors.text
color if { $present }: $inherited.colors.cta-primary.text
color if { !$present }: $inherited.colors.error.text
text: $foo1.name
\-- end: foo1
\-- foo1: hello
-- ds.markdown:
Output:
-- ftd.row:
border-width.px: 1
border-color: $inherited.colors.text
padding.px: 10
width: fill-container
-- foo1: hello
-- end: ftd.row
-- ds.markdown:
Here, in above sample code, the attribute or style `color` has default value as
`grey` and it follows the conditional statements. According to the value of the
variable `present` (in this case, it is `false`), the value of the style `color`
is set (in this case, it's `red`).
-- ds.h3: Example 2:
-- ds.code: Conditional Attribute with default
lang: ftd
\-- boolean present: false
\-- component foo2:
caption name:
\-- ftd.text:
color: $inherited.colors.text
color if { $present }: $inherited.colors.error.text
text: $foo2.name
\-- end: foo2
\-- foo2: hello
-- ds.markdown:
Output:
-- ftd.row:
border-width.px: 1
border-color: $inherited.colors.text
padding.px: 10
width: fill-container
-- foo2: hello
-- end: ftd.row
-- ds.markdown:
Here, in above sample code, no conditional statement is satisfied, so the value of
style `color` is set to its default value (i.e. `grey`).
-- ds.h3: Example 3:
-- ds.code: Conditional Attribute using arguments
lang: ftd
\-- component foo3:
caption name:
optional string yes:
\-- ftd.text:
color: $inherited.colors.text
color if { foo3.yes != NULL }: $inherited.colors.cta-secondary.base
text: $foo3.name
\-- end: foo3
\-- foo3: hello
yes: world
-- ds.markdown:
Output:
-- ftd.row:
border-width.px: 1
border-color: $inherited.colors.text
padding.px: 10
width: fill-container
-- foo3: hello
yes: world
-- end: ftd.row
-- ds.markdown:
Here, in above sample code, we have defined the argument `yes` of optional string
type. If `yes` is passed then `color if $yes is not null` condition would be
satisfied and the `color` gets set to `blue`.
-- ds.h3: Example 4:
-- ds.code: Conditional Attribute deciding priority
lang: ftd
\-- boolean present: false
\-- component foo4:
caption name:
optional string yes:
\-- ftd.text:
color: $inherited.colors.text
color if { $present }: $inherited.colors.cta-primary.text
color if { !$present}: $inherited.colors.cta-secondary.base
color if { foo4.yes != NULL }: $inherited.colors.success.text
text: $foo4.name
\-- end: foo4
\-- foo4: hello
yes: world
-- ds.markdown:
Output:
-- ftd.row:
border-width.px: 1
border-color: $inherited.colors.text
padding.px: 10
width: fill-container
;; This one is not working as expected
;; Text color should be green but showing blue
-- foo4: hello
yes: world
-- end: ftd.row
-- ds.markdown:
Here, in above sample code, both `color if not present: blue` and
`color if $yes is not null: green` are satisfied, so according to the precedence
rule, the value of attribute/style is set to value in last satisfied condition,
i.e., `color if $yes is not null: green` has highest priority. So the `color` gets
set to `green`.
-- ds.h1: Note: Does not yet work well with event handling
Conditional attributes only work with the variables defined in the document, and
do not get updated when the value of the variable changes as a response to events.
-- end: my-ds.page
-- component foo1:
caption name:
-- ftd.text:
color: $inherited.colors.text
color if { $present }: $inherited.colors.cta-primary.text
color if { !$present }: $inherited.colors.error.text
text: $foo1.name
-- end: foo1
-- component foo2:
caption name:
-- ftd.text:
color: $inherited.colors.text
color if { $present }: $inherited.colors.error.text
text: $foo2.name
-- end: foo2
-- component foo3:
caption name:
optional string yes:
-- ftd.text:
color: $inherited.colors.text
color if { foo3.yes != NULL }: $inherited.colors.cta-secondary.base
text: $foo3.name
-- end: foo3
-- component foo4:
caption name:
optional string yes:
-- ftd.text:
color: $inherited.colors.text
color if { $present }: $inherited.colors.cta-primary.text
color if { !$present}: $inherited.colors.cta-secondary.base
color if { foo4.yes != NULL }: $inherited.colors.success.text
text: $foo4.name
-- end: foo4