@@ -882,12 +882,17 @@ and a [=mixin body=].
882
882
save that it lacks a [=custom function/return type=] .)
883
883
884
884
<pre class="prod def">
885
- <<@mixin>> = @mixin <<function-token>> <<function-parameter>> #? )
885
+ <<@mixin>> = @mixin <<function-token>> <<function-parameter>> #? , @contents? )
886
886
{
887
887
<<declaration-rule-list>>
888
888
}
889
889
</pre>
890
890
891
+ Differing from the ''@function'' rule,
892
+ the final item in the parameters list
893
+ can be the <<at-keyword-token>> ''@contents'' ,
894
+ indicating that this [=mixin=] accepts a ''@contents'' block.
895
+
891
896
If a [=default value=] and a [=parameter type=] are both provided,
892
897
then the default value must parse successfully according to that parameter type’s syntax.
893
898
Otherwise, the ''@mixin'' rule is invalid.
@@ -1039,6 +1044,76 @@ aren't visible to anything outside of the [=mixin body=].
1039
1044
and the ''.warning'' rule would not be able to use them.
1040
1045
</div>
1041
1046
1047
+ <h3 id='contents-rule'>
1048
+ The <dfn>@contents</dfn> Rule</h3>
1049
+
1050
+ In addition to accepting arguments passed by the <<dashed-function>> in the ''@apply'' rule,
1051
+ a [=mixin=] can accept a <dfn>contents block</dfn> .
1052
+ This is indicated by the mixin using a final ''@contents'' <<at-keyword-token>> in its parameter list,
1053
+ and is passed by giving the ''@apply'' rule invoking the mixin
1054
+ a block.
1055
+
1056
+ This allows the invoker of the [=mixin=] to pass an entire style block,
1057
+ which the [=mixin=] can then substitute into itself.
1058
+ This is useful, for example,
1059
+ if the [=mixin=] handles some common conditions for the author,
1060
+ and substitutes the [=contents block=] into a predefined ''@media'' or ''@container'' rule.
1061
+
1062
+ The syntax of a ''@contents'' at-rule is:
1063
+
1064
+ <pre class="prod def">
1065
+ <<@contents>> = @contents [ { <<declaration-list>> } ]?
1066
+ </pre>
1067
+
1068
+ That is, it is either an <em> empty</em> statement ended immediately by a semicolon,
1069
+ or a block treated as a [=nested declarations rule=] .
1070
+ The empty statement form behaves identically to passing an empty block.
1071
+
1072
+ If the [=mixin=] did not declare a ''@contents'' parameter,
1073
+ the ''@contents'' rule is ignored,
1074
+ substituting with nothing.
1075
+ Otherwise, if the ''@apply'' rule invoking the [=mixin=] passed a [=contents block=] ,
1076
+ the ''@contents'' is replaced with the [=contents block=] ,
1077
+ treating it as a [=nested declarations rule=] .
1078
+ Otherwise, if the ''@apply'' rule did not pass a [=contents block=] ,
1079
+ the ''@contents'' rule is replaced with its own <<declaration-list>> ,
1080
+ treated as a [=nested declarations rule=] .
1081
+
1082
+ Outside of a [=mixin body=] ,
1083
+ the ''@contents'' rule is invalid and ignored.
1084
+
1085
+ <div class=example>
1086
+ For example, the following mixins
1087
+ abstracts the cases that the page would consider to be appropriate
1088
+ for a "single column" layout,
1089
+ allowing the rest of the page to handle the case without worrying about the details,
1090
+ so the conditions can be adjusted in the future if necessary:
1091
+
1092
+ <pre highlight=css>
1093
+ @mixin --one-column(@contents) {
1094
+ @media (width <= 800px) {
1095
+ @contents;
1096
+ }
1097
+ }
1098
+ @mixin --two-column(@contents) {
1099
+ @media (width > 800px) {
1100
+ @contents;
1101
+ }
1102
+ }
1103
+ body {
1104
+ @apply --one-column {
1105
+ display: flex;
1106
+ flex-flow: column;
1107
+ }
1108
+ @apply --two-column {
1109
+ display: grid;
1110
+ grid-template-columns: ;
1111
+ }
1112
+ }
1113
+ </pre>
1114
+ </div>
1115
+
1116
+
1042
1117
1043
1118
Using Mixins {#using-mixins}
1044
1119
============================
@@ -1058,7 +1133,7 @@ in place of the ''@apply'' rule itself.
1058
1133
Its grammar is:
1059
1134
1060
1135
<pre class="prod">
1061
- <<@apply>> = @apply <<dashed-function>> ;
1136
+ <<@apply>> = @apply <<dashed-function>> [ { <<declaration-list>> } ]? ;
1062
1137
</pre>
1063
1138
1064
1139
The ''@apply'' rule is only valid
@@ -1084,6 +1159,13 @@ the ''@apply'' application does nothing.
1084
1159
(Passing too few arguments is fine;
1085
1160
the missing arguments take their default values instead.)
1086
1161
1162
+ If the [=mixin=] declares a ''@contents'' parameter,
1163
+ and the ''@apply'' rule has a <<declaration-list>> block,
1164
+ that block is passed as its [=contents block=] .
1165
+ If the [=mixin=] did not declare a ''@contents'' parameter,
1166
+ having a <<declaration-list>> block makes the ''@apply'' rule invalid
1167
+ (similar to passing too many arguments).
1168
+
1087
1169
1088
1170
<!-- Big Text: @env
1089
1171
0 commit comments