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

Class StyleRule

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

A CSS style rule.

Source from the content-addressed store, hash-verified

858
859/** A CSS style rule. */
860class StyleRule implements Rule {
861 className: string;
862 pseudos: string;
863 property: string;
864 value: string;
865 themeProperty: string | undefined;
866 themeValue: Value | undefined;
867
868 constructor(
869 className: string,
870 property: string,
871 value: string,
872 themeProperty: string | undefined,
873 themeValue: Value | undefined
874 ) {
875 this.className = className;
876 this.pseudos = '';
877 this.property = property;
878 this.value = value;
879 if (process.env.NODE_ENV !== 'production' && isCompilingDependencies !== null) {
880 this.themeProperty = themeProperty;
881 this.themeValue = themeValue;
882 }
883 }
884
885 copy(): Rule {
886 let rule = new StyleRule(
887 this.className,
888 this.property,
889 this.value,
890 this.themeProperty,
891 this.themeValue
892 );
893 rule.pseudos = this.pseudos;
894 return rule;
895 }
896
897 addPseudo(prelude: string) {
898 this.pseudos += prelude;
899 }
900
901 getStaticClassName(): string {
902 return ' ' + this.className;
903 }
904
905 toCSS(rulesByLayer: Map<string, string[]>, preludes: string[] = [], layer = 'a') {
906 let prelude = `.${this.className}${this.pseudos}`;
907 preludes.push(prelude);
908
909 // Nest rule in our stack of preludes (e.g. media queries/selectors).
910 let content = ' ';
911 preludes.forEach((p, i) => {
912 content += `${p} {\n${' '.repeat((i + 2) * 2)}`;
913 });
914 content += `${kebab(this.property)}: ${this.value};\n`;
915 preludes.map((_, i) => {
916 content += `${' '.repeat((preludes.length - i) * 2)}}\n`;
917 });

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected