MCPcopy Index your code
hub / github.com/adobe/react-spectrum / mergeStyles

Function mergeStyles

packages/@react-spectrum/s2/style/runtime.ts:53–82  ·  view source on GitHub ↗
(...styles: (StyleString | null | undefined)[])

Source from the content-addressed store, hash-verified

51 * // merged has `padding: 16` and `color: heading`.
52 */
53export function mergeStyles(...styles: (StyleString | null | undefined)[]): StyleString {
54 let definedStyles = styles.filter(Boolean) as StyleString[];
55 if (definedStyles.length === 1) {
56 let first = definedStyles[0];
57 if (typeof first !== 'string') {
58 // static macro has a toString method so that we generate the style macro map for the entry
59 // it's automatically called in other places, but for our merging, we have to call it ourselves
60 return (first as StyleString).toString() as StyleString;
61 }
62 return first;
63 }
64
65 let map = new Map<string, string>();
66
67 for (let style of definedStyles) {
68 // must call toString here for the static macro
69 let str = style.toString();
70
71 for (let [k, v] of parse(str)) {
72 map.set(k, v);
73 }
74 }
75
76 let res = '';
77 for (let value of map.values()) {
78 res += value;
79 }
80
81 return res as StyleString;
82}
83
84function parse(s: string) {
85 let properties = new Map<string, string>();

Callers 15

FeatureFunction · 0.90
WrapperFunction · 0.90
HeaderLinkFunction · 0.90
TableCellFunction · 0.90
AdobeLogoFunction · 0.90
ReactAriaLogoFunction · 0.90
PromptFieldFunction · 0.90
Popover.tsxFile · 0.90
createIconFunction · 0.90
SliderBaseFunction · 0.90
ProviderInnerFunction · 0.90

Calls 4

parseFunction · 0.70
filterMethod · 0.65
toStringMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected