MCPcopy
hub / github.com/adobe/react-spectrum / GroupRule

Class GroupRule

packages/@react-spectrum/s2/style/style-macro.ts:961–1015  ·  view source on GitHub ↗

Base class for rules that contain other rules.

Source from the content-addressed store, hash-verified

959
960/** Base class for rules that contain other rules. */
961class GroupRule implements Rule {
962 rules: Rule[];
963 layer: string | null;
964
965 constructor(rules: Rule[], layer?: string | null) {
966 this.rules = rules;
967 this.layer = layer ?? null;
968 }
969
970 copy(): Rule {
971 return new GroupRule(
972 this.rules.map(rule => rule.copy()),
973 this.layer
974 );
975 }
976
977 addPseudo(prelude: string) {
978 for (let rule of this.rules) {
979 rule.addPseudo(prelude);
980 }
981 }
982
983 getStaticClassName(): string {
984 return this.rules.map(rule => rule.getStaticClassName()).join('');
985 }
986
987 toCSS(rulesByLayer: Map<string, string[]>, preludes?: string[], layer?: string) {
988 for (let rule of this.rules) {
989 rule.toCSS(rulesByLayer, preludes, this.layer || layer);
990 }
991 }
992
993 toJS(allowedOverridesSet: Set<string>, indent = ''): string {
994 let rules = this.rules.slice();
995 let conditional = rules
996 .filter(rule => rule instanceof ConditionalRule)
997 .reverse()
998 .map((rule, i) => {
999 return `${i > 0 ? ' else ' : ''}${rule.toJS(allowedOverridesSet, indent)}`;
1000 });
1001
1002 let elseCases = rules
1003 .filter(rule => !(rule instanceof ConditionalRule))
1004 .map(rule => rule.toJS(allowedOverridesSet, indent));
1005 if (conditional.length && elseCases.length) {
1006 return `${conditional.join('')} else {\n${indent} ${elseCases.join('\n' + indent + ' ')}\n${indent}}`;
1007 }
1008
1009 if (conditional.length) {
1010 return conditional.join('');
1011 }
1012
1013 return elseCases.join('\n' + indent);
1014 }
1015}
1016
1017/** A rule that applies conditionally in CSS (e.g. @media). */
1018class AtRule extends GroupRule {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected