@@ -20,7 +20,7 @@ export default ({
20
20
content : html `
21
21
${ Heading ( page . name ) }
22
22
< p >
23
- You cannot use template literal value to define attributes directly on the
23
+ Markup does not allow you to use template literal value to define attributes directly on the
24
24
tag.
25
25
</ p >
26
26
${ CodeSnippet (
@@ -30,49 +30,33 @@ export default ({
30
30
'// renders <button>click me</button>' ,
31
31
'typescript'
32
32
) }
33
- < p >
34
- This means that you need another way to dynamically render
35
- attributes and that way is the Markup < code > attr</ code > attribute's name prefixer.
36
- </ p >
37
- ${ CodeSnippet (
38
- 'const disabled = true;\n' +
39
- '\n' +
40
- 'html`<button attr.disabled="${disabled}">click me</button>`;' ,
41
- 'typescript'
42
- ) }
43
- < p >
44
- In the above example the < code > disabled</ code > attribute
45
- was prefixed with < code > attr.</ code > then provided the condition(boolean) as
46
- value to whether include that attribute.
47
- </ p >
48
- < div class ="info ">
49
- The < code > attr.</ code > is not always needed. Attributes like < code > class</ code > , < code > style</ code > , < code > data</ code > ,
50
- and < a href ="https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML " target ="_blank "> HTML boolean
51
- attributes</ a >
52
- work without it or can have the condition specified after the pipe < code > |</ code > as the value. Everything
53
- else requires it.
54
- </ div >
33
+ < p > There is a different way to go about conditionally set attributes.</ p >
55
34
${ Heading ( 'Boolean attributes' , 'h3' ) }
35
+ < p >
36
+ By default, Markup handles all boolean attributes based on value.
37
+ </ p >
38
+ ${ CodeSnippet (
39
+ 'const disabled = true;\n' +
40
+ '\n' +
41
+ 'html`<button disabled="${disabled}">click me</button>`;' ,
42
+ 'typescript'
43
+ ) }
44
+ < p > < a
45
+ href ="https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML "
46
+ > Boolean attributes</ a
47
+ > values in native HTML does not matter in whether the attribute
48
+ should have an effect or be included. In Markup, if you set boolean attribute values
49
+ to < code > FALSY</ code > it will not be included.</ p >
56
50
< p >
57
- < a
58
- href ="https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML "
59
- > Boolean attributes</ a
60
- >
61
- are attributes that affect the element by
62
- simply being on the tag or whether they have value of
63
- < code > true</ code > or < code > false</ code > . HTML natively have these.
64
- </ p >
65
- < p >
66
- The boolean attribute pattern is simple: < code > NAME="CONDITION"</ code > . The < code > attr.</ code > prefix is NOT
67
- required.
51
+ The boolean attribute pattern is simply: < code > NAME="CONDITION"</ code > .
68
52
</ p >
69
53
${ CodeSnippet (
70
54
'html`<input type="checkbox" checked="true"/>`;' ,
71
55
'typescript'
72
56
) }
73
57
< p >
74
58
You may directly set the value as < code > true</ code > or
75
- < code > false</ code > string values or add a variable.
59
+ < code > false</ code > string or inject a variable.
76
60
</ p >
77
61
${ CodeSnippet (
78
62
'const checked = false;\n\n' +
@@ -82,7 +66,7 @@ export default ({
82
66
${ Heading ( 'The class attribute' , 'h3' ) }
83
67
< p >
84
68
The class attribute has a special handle that allows you to
85
- dynamically set specific classes more elegantly .
69
+ dynamically target single classes to be conditionally set .
86
70
</ p >
87
71
< p >
88
72
The class attribute pattern can be a key-value type
@@ -97,8 +81,7 @@ export default ({
97
81
'// renders: <button class="primary btn">click me</button>\n' ,
98
82
'typescript'
99
83
) }
100
- < div class ="info "> You need to use the < code > |</ code > (pipe symbol) to separate the value from the condition
101
- and the < code > attr.</ code > prefix is not required.
84
+ < div class ="info "> You need to use the < code > |</ code > (pipe) to separate the value from the condition.
102
85
</ div >
103
86
${ Heading ( 'The style attribute' , 'h3' ) }
104
87
< p >
@@ -118,7 +101,6 @@ export default ({
118
101
'// renders: <button style="color: orange">click me</button>\n' ,
119
102
'typescript'
120
103
) }
121
- < p > The < code > attr.</ code > prefix is not required for style attributes.</ p >
122
104
${ Heading ( 'The data attribute' , 'h3' ) }
123
105
< p > Data attributes follow the pattern: < code > data.NAME="VALUE | CONDITION"</ code > and
124
106
can also be < code > data.NAME="CONDITION"</ code > if value is same as the condition value.
@@ -129,21 +111,15 @@ export default ({
129
111
'html`<button data.loading="${loading}" data.btn="true">click me</button>`' ,
130
112
'typescript'
131
113
) }
132
- < p > The < code > attr.</ code > prefix is not required for data attributes.</ p >
133
114
${ Heading ( 'Other attributes' , 'h3' ) }
134
- < p >
135
- Everything else will fall into the category of a key-value pairs
136
- which is a collection of attributes that require specific values or
137
- work as "prop" for a tag to pass data or set configurations.
138
- </ p >
139
- < p > All other attributes follow the pattern: < code > attr.NAME="VALUE | CONDITION"</ code > or
140
- < code > attr.NAME="CONDITION"</ code > if value is same as the condition value.
141
- The template will evaluate if the value is truthy or falsy to decide
115
+ < p > For any other attribute you will need to either prefix the attribute with < code > attr.</ code > or < code > |</ code > (pipe) the value to a condition.</ p >
116
+ < p > These follow the pattern: < code > NAME="VALUE | CONDITION"</ code > or < code > attr.NAME="VALUE_SAME_AS_CONDITION"</ code > .
117
+ The template will evaluate if the condition is truthy or falsy to decide
142
118
whether the attribute should be set.</ p >
143
119
${ CodeSnippet (
144
120
'const label = "action button";\n\n' +
145
121
'// will not render if label is an empty string\n' +
146
- 'html`<button attr.aria-label="${label}">click me</button>`' ,
122
+ 'html`<button attr.aria-label="${label}" formenctype="multipart/form-data | ${isFormData}" >click me</button>`' ,
147
123
'typescript'
148
124
) }
149
125
` ,
0 commit comments