@@ -20,7 +20,7 @@ export default ({
2020 content : html `
2121 ${ Heading ( page . name ) }
2222 < 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
2424 tag.
2525 </ p >
2626 ${ CodeSnippet (
@@ -30,49 +30,33 @@ export default ({
3030 '// renders <button>click me</button>' ,
3131 'typescript'
3232 ) }
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 >
5534 ${ 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 >
5650 < 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 > .
6852 </ p >
6953 ${ CodeSnippet (
7054 'html`<input type="checkbox" checked="true"/>`;' ,
7155 'typescript'
7256 ) }
7357 < p >
7458 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.
7660 </ p >
7761 ${ CodeSnippet (
7862 'const checked = false;\n\n' +
@@ -82,7 +66,7 @@ export default ({
8266 ${ Heading ( 'The class attribute' , 'h3' ) }
8367 < p >
8468 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 .
8670 </ p >
8771 < p >
8872 The class attribute pattern can be a key-value type
@@ -97,8 +81,7 @@ export default ({
9781 '// renders: <button class="primary btn">click me</button>\n' ,
9882 'typescript'
9983 ) }
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.
10285 </ div >
10386 ${ Heading ( 'The style attribute' , 'h3' ) }
10487 < p >
@@ -118,7 +101,6 @@ export default ({
118101 '// renders: <button style="color: orange">click me</button>\n' ,
119102 'typescript'
120103 ) }
121- < p > The < code > attr.</ code > prefix is not required for style attributes.</ p >
122104 ${ Heading ( 'The data attribute' , 'h3' ) }
123105 < p > Data attributes follow the pattern: < code > data.NAME="VALUE | CONDITION"</ code > and
124106 can also be < code > data.NAME="CONDITION"</ code > if value is same as the condition value.
@@ -129,21 +111,15 @@ export default ({
129111 'html`<button data.loading="${loading}" data.btn="true">click me</button>`' ,
130112 'typescript'
131113 ) }
132- < p > The < code > attr.</ code > prefix is not required for data attributes.</ p >
133114 ${ 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
142118 whether the attribute should be set.</ p >
143119 ${ CodeSnippet (
144120 'const label = "action button";\n\n' +
145121 '// 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>`' ,
147123 'typescript'
148124 ) }
149125 ` ,
0 commit comments