MCPcopy Create free account
hub / github.com/adobe/react-spectrum / css

Function css

packages/@react-spectrum/s2/style/style-macro.ts:1103–1131  ·  view source on GitHub ↗
(this: MacroContext | void, content: string, layer = '_.a')

Source from the content-addressed store, hash-verified

1101 * @returns The generated class name that applies the styles.
1102 */
1103export function css(this: MacroContext | void, content: string, layer = '_.a'): string {
1104 // Check if `this` is undefined, which means style was not called as a macro but as a normal function.
1105 // We also check if this is globalThis, which happens in non-strict mode bundles.
1106 // Also allow style to be called as a normal function in tests.
1107 // @ts-ignore
1108
1109 if ((this == null || this === globalThis) && process.env.NODE_ENV !== 'test') {
1110 throw new Error('The css macro must be imported with {type: "macro"}.');
1111 }
1112 let className = generateArbitraryValueSelector(content, true);
1113 content = `@layer ${layer} {
1114 .${className} {
1115 ${content}
1116 }
1117}`;
1118
1119 // Ensure layer is always declared after the _ layer used by style macro.
1120 if (!layer.startsWith('_.')) {
1121 content = `@layer _, ${layer};\n` + content;
1122 }
1123
1124 if (this && typeof this.addAsset === 'function') {
1125 this.addAsset({
1126 type: 'css',
1127 content
1128 });
1129 }
1130 return className;
1131}
1132
1133export function keyframes(this: MacroContext | void, css: string): string {
1134 // Check if `this` is undefined, which means style was not called as a macro but as a normal function.

Callers 14

CounterFunction · 0.90
PromptTokenFieldFunction · 0.90
TreeView.tsxFile · 0.90
PickerFunction · 0.90
CenterBaseline.tsxFile · 0.90
CoachMark.tsxFile · 0.90
SearchField.tsxFile · 0.90
TableView.tsxFile · 0.90
ListView.tsxFile · 0.90
Picker.tsxFile · 0.90
Skeleton.tsxFile · 0.90

Calls 2

addAssetMethod · 0.65

Tested by

no test coverage detected