181
181
</ li >
182
182
< li class ="nav-item ">
183
183
< a class ="nav-link " href ="#migration "> Migration</ a >
184
- < ul class ="nav flex-column ">
185
- < li class ="nav-item ">
186
- < a class ="nav-link " href ="#posthtml-include "> PostHTML Include</ a >
187
- </ li >
188
- < li class ="nav-item ">
189
- < a class ="nav-link " href ="#posthtml-modules "> PostHTML Modules</ a >
190
- </ li >
191
- < li class ="nav-item ">
192
- < a class ="nav-link " href ="#posthtml-extends "> PostHTML Extends</ a >
193
- </ li >
194
- </ ul >
195
- </ li >
196
- < li class ="nav-item ">
197
- < a class ="nav-link " href ="#contributing "> Contributing</ a >
198
- </ li >
199
- < li class ="nav-item ">
200
- < a class ="nav-link " href ="#credits "> Credits</ a >
201
184
</ li >
202
185
</ ul >
203
186
</ nav >
@@ -562,11 +545,11 @@ <h2 id="options" tabindex="-1">
562
545
< td style ="text-align:left ">
563
546
Function callback passed to lodash
564
547
< code > mergeWith</ code >
565
- for attribute
548
+ for merge
549
+ < code > options.expressions.locals</ code >
550
+ and locals passed via attribute
566
551
< code > locals</ code >
567
- and
568
- < code > merge:attribute</ code >
569
- . By default it's used to concat array.
552
+ .
570
553
</ td >
571
554
</ tr >
572
555
</ tbody >
@@ -1006,18 +989,16 @@ <h3 id="props" tabindex="-1">
1006
989
< a href ="https://github.com/posthtml/posthtml-expressions "> posthtml-expressions</ a >
1007
990
plugin, with feature to pass
1008
991
< code > props</ code >
1009
- (locals) via attributes, define default via
1010
- < code > <script props></ code >
1011
- , merge with default and use
992
+ (locals) via attributes and manipulate them via
1012
993
< code > <script props></ code >
1013
- as computed .
994
+ .
1014
995
</ p >
1015
996
< p > Let's see how it works with a few examples starting with a basic one.</ p >
1016
997
< p > Create the component:</ p >
1017
998
< pre > < code class ="language-html "> <!-- src/my-component.html -->
1018
999
<script props>
1019
1000
module.exports = {
1020
- prop: 'Default prop value'
1001
+ prop: locals.prop || 'Default prop value'
1021
1002
}
1022
1003
</script>
1023
1004
<div>
@@ -1051,24 +1032,19 @@ <h3 id="props" tabindex="-1">
1051
1032
More details on this in the next section.
1052
1033
</ p >
1053
1034
< p >
1054
- So by default
1035
+ So in the
1055
1036
< code > <script props></ code >
1056
- act as default value, like the
1057
- < code > @props</ code >
1058
- you define with Laravel Blade.
1059
- You can change this behaviour by prepending
1060
- < code > computed</ code >
1061
- or
1062
- < code > merge</ code >
1063
- to the attribute name like shown below.
1037
+ you have access to passed props via object
1038
+ < code > locals</ code >
1039
+ , and you can add any logic you need inside of it.
1064
1040
</ p >
1065
1041
< p > Create the component:</ p >
1066
1042
< pre > < code class ="language-html "> <!-- src/modal.html -->
1067
1043
<script props>
1068
1044
module.exports = {
1069
- title: 'Default title', // This will be the default value
1070
- size: locals.size ? `modal-${locals.size}` : '', // This will be a computed value, so it's always used
1071
- items: ['first', 'second'] // This will be merged
1045
+ title: locals.title || 'Default title',
1046
+ size: locals.size ? `modal-${locals.size}` : '',
1047
+ items: Array.isArray(locals.items) ? locals.items.concat( ['first', 'second']) : ['first', 'second']
1072
1048
}
1073
1049
</script>
1074
1050
<div class="modal {{ size }}">
@@ -1080,7 +1056,7 @@ <h3 id="props" tabindex="-1">
1080
1056
</div>
1081
1057
</div></ code > </ pre >
1082
1058
< p > Use:</ p >
1083
- < pre > < code class ="language-html "> <x-modal computed: size="xl" title="My modal title" merge: items='["third", "fourth"]' class="modal-custom"></x-modal></ code > </ pre >
1059
+ < pre > < code class ="language-html "> <x-modal size="xl" title="My modal title" items='["third", "fourth"]' class="modal-custom"></x-modal></ code > </ pre >
1084
1060
< p > The output will be:</ p >
1085
1061
< pre > < code class ="language-html "> <div class="modal modal-custom modal-xl">
1086
1062
<div class="modal-header">
@@ -1094,27 +1070,16 @@ <h3 id="props" tabindex="-1">
1094
1070
</div>
1095
1071
</div></ code > </ pre >
1096
1072
< p >
1097
- So the prop
1098
- < code > size</ code >
1099
- is not override since we prepend
1100
- < code > computed:</ code >
1101
- to the attribute, while the prop
1102
- < code > title</ code >
1103
- is override.
1104
- And the prop
1105
- < code > items</ code >
1106
- is merged and not override.
1107
- You can also notice how the
1073
+ You can also notice how the
1108
1074
< code > class</ code >
1109
1075
attribute is merged with
1110
1076
< code > class</ code >
1111
1077
attribute of the first node. Let's see in next section more about this.
1112
1078
</ p >
1113
1079
< p >
1114
- You can change how attributes are merged by passing via options a callback function used by lodash method
1080
+ You can change how attributes are merged with global locals defined via options by passing a callback function used by lodash method
1115
1081
< a href ="https://lodash.com/docs/4.17.15#mergeWith "> mergeWith</ a >
1116
1082
.
1117
- By default, it's used to concat array.
1118
1083
</ p >
1119
1084
< p >
1120
1085
By default, all props are scoped to the component, and are not available to nested components. You can however change this accordingly to your need.
@@ -1124,7 +1089,7 @@ <h3 id="props" tabindex="-1">
1124
1089
< pre > < code class ="language-html "> <!-- src/child.html -->
1125
1090
<script props>
1126
1091
module.exports = {
1127
- prop: 'Default prop value'
1092
+ prop: locals.prop || 'Default prop value'
1128
1093
}
1129
1094
</script>
1130
1095
<div>
@@ -1134,7 +1099,7 @@ <h3 id="props" tabindex="-1">
1134
1099
< pre > < code class ="language-html "> <!-- src/parent.html -->
1135
1100
<script props>
1136
1101
module.exports = {
1137
- prop: 'Default prop value'
1102
+ prop: locals.prop || 'Default prop value'
1138
1103
}
1139
1104
</script>
1140
1105
<div>
@@ -1195,7 +1160,7 @@ <h3 id="attributes" tabindex="-1">
1195
1160
< pre > < code class ="language-html "> <!-- src/button.html -->
1196
1161
<script props>
1197
1162
module.exports = {
1198
- label: 'A button'
1163
+ label: locals.label || 'A button'
1199
1164
}
1200
1165
</script>
1201
1166
<button type="button" class="btn">
@@ -1437,97 +1402,10 @@ <h2 id="migration" tabindex="-1">
1437
1402
< code > posthtml-extend</ code >
1438
1403
and/or
1439
1404
< code > posthtml-modules</ code >
1440
- then you can continue to keep them until you migrate all of your components.
1441
- For continue to use current code with this plugin without changing it, see below examples. Any more updates on this will be added in this issue:
1405
+ please to follow updates here:
1442
1406
< a href ="https://github.com/thewebartisan7/posthtml-components/issues/16 "> posthtml-components/issues/16</ a >
1443
1407
.
1444
1408
</ p >
1445
- < h3 id ="posthtml-include " tabindex ="-1 ">
1446
- < a class ="header-anchor " href ="#posthtml-include "> #</ a >
1447
- PostHTML Include
1448
- </ h3 >
1449
- < p >
1450
- PostHTML Include plugin can work when passed via
1451
- < code > options.plugins</ code >
1452
- like below example:
1453
- </ p >
1454
- < pre > < code class ="language-js "> require("posthtml-component")({
1455
- root: "./src",
1456
- folders: ["components", "layouts"],
1457
- plugins: [
1458
- require("posthtml-include")({
1459
- encoding: "utf8",
1460
- root: "./src"
1461
- }),
1462
- ]
1463
- })</ code > </ pre >
1464
- < h3 id ="posthtml-modules " tabindex ="-1 ">
1465
- < a class ="header-anchor " href ="#posthtml-modules "> #</ a >
1466
- PostHTML Modules
1467
- </ h3 >
1468
- < p >
1469
- At the moment doesn't work when nested inside PostHTML Components plugin since it use
1470
- < code > tree.match</ code >
1471
- and even trying with something like PostHTML Include is doing here https://github.com/posthtml/posthtml-include/blob/master/lib/index.js#L16 doesn't work. But a workaround is to use PostHTML Components custom tag and attributes like below:
1472
- </ p >
1473
- < pre > < code class ="language-js "> require("posthtml-component")({
1474
- root: "./src",
1475
- folders: ["components", "layouts"],
1476
- tag: 'module',
1477
- attribute: 'href',
1478
- yield: 'content',
1479
- plugins: [
1480
- require("posthtml-include")({
1481
- encoding: "utf8",
1482
- root: "./src/www/posthtml-templates/"
1483
- }),
1484
- ]
1485
- })</ code > </ pre >
1486
- < p >
1487
- NOTE: If you change
1488
- < code > <yield></ code >
1489
- tag to
1490
- < code > <content></ code >
1491
- to support your existing code, then you need to use it always. Maybe you can just replace all
1492
- < code > <content></ code >
1493
- with
1494
- < code > <yield></ code >
1495
- and it should works fine.
1496
- </ p >
1497
- < h3 id ="posthtml-extends " tabindex ="-1 ">
1498
- < a class ="header-anchor " href ="#posthtml-extends "> #</ a >
1499
- PostHTML Extends
1500
- </ h3 >
1501
- < p >
1502
- So far it works fine together with
1503
- < code > posthtml-components</ code >
1504
- plugin.
1505
- </ p >
1506
- < h2 id ="contributing " tabindex ="-1 ">
1507
- < a class ="header-anchor " href ="#contributing "> #</ a >
1508
- Contributing
1509
- </ h2 >
1510
- < p >
1511
- See
1512
- < a href ="https://github.com/posthtml/posthtml/tree/master/docs "> PostHTML Guidelines</ a >
1513
- and
1514
- < a href ="CONTRIBUTING.md "> contribution guide</ a >
1515
- .
1516
- </ p >
1517
- < h2 id ="credits " tabindex ="-1 ">
1518
- < a class ="header-anchor " href ="#credits "> #</ a >
1519
- Credits
1520
- </ h2 >
1521
- < p >
1522
- Thanks to all PostHTML contributors and especially to
1523
- < code > posthtml-extend</ code >
1524
- and
1525
- < code > posthtml-modules</ code >
1526
- contributors, as part of code are
1527
- < s > stolen</ s >
1528
- inspired from these plugins.
1529
- Huge thanks also to Laravel Blade template engine.
1530
- </ p >
1531
1409
</ div >
1532
1410
</ div >
1533
1411
</ div >
@@ -1549,9 +1427,9 @@ <h2 id="credits" tabindex="-1">
1549
1427
</ div >
1550
1428
</ div >
1551
1429
</ footer >
1552
- < div class ="modal fade " id ="modalWithComponents " data-bs-backdrop ="true " data-bs-keyboard ="true " aria-labelledby ="modalWithComponents " tabindex ="-1 " aria-hidden ="true " aria-modal ="true " role ="dialog ">
1553
- < div class ="modal-dialog modal-lg modal-fullscreen-lg-down modal-dialog-centered modal-dialog-custom ">
1554
- < div class ="modal-content modal-content-custom ">
1430
+ < div class ="modal fade " id ="modalWithComponents " data-bs-backdrop ="true " data-bs-keyboard ="true " aria-labelledby ="modalWithComponents " tabindex ="-1 " aria-hidden ="true " aria-modal ="true " role ="dialog " dialogclass =" modal-dialog-custom " contentclass =" modal-content-custom " >
1431
+ < div class ="modal-dialog modal-lg modal-fullscreen-lg-down modal-dialog-centered ">
1432
+ < div class ="modal-content ">
1555
1433
< div class ="modal-header ">
1556
1434
< h5 class ="modal-title " id ="modalWithComponentsLabel "> Changelog</ h5 >
1557
1435
< button type ="button " class ="btn-close " data-bs-dismiss ="modal " aria-label ="Close "> </ button >
0 commit comments