MCPcopy
hub / github.com/microsoft/rushstack / resolveThemableArray

Function resolveThemableArray

src/index.ts:145–177  ·  view source on GitHub ↗

* Resolves ThemingInstruction objects in an array and joins the result into a string. * @param {ThemableArray} splitStyleArray ThemableArray to resolve and join.

(splitStyleArray: ThemableArray)

Source from the content-addressed store, hash-verified

143 * @param {ThemableArray} splitStyleArray ThemableArray to resolve and join.
144 */
145function resolveThemableArray(splitStyleArray: ThemableArray): string {
146 const { theme }: IThemeState = _themeState;
147 let resolvedCss: string;
148 if (splitStyleArray) {
149 // Resolve the array of theming instructions to an array of strings.
150 // Then join the array to produce the final CSS string.
151 const resolvedArray: string[] = splitStyleArray.map((currentValue: IThemingInstruction) => {
152 const themeSlot: string = currentValue.theme;
153 if (themeSlot) {
154 // A theming annotation. Resolve it.
155 const themedValue: string = theme ? theme[themeSlot] : undefined;
156 const defaultValue: string = currentValue.defaultValue;
157
158 // Warn to console if we hit an unthemed value even when themes are provided.
159 // Allow the themedValue to be undefined to explicitly request the default value.
160 if (theme && !themedValue && console && !(themeSlot in theme)) {
161 /* tslint:disable: max-line-length */
162 console.warn(`Theming value not provided for "${themeSlot}". Falling back to "${defaultValue || 'inherit'}".`);
163 /* tslint:enable: max-line-length */
164 }
165
166 return themedValue || defaultValue || 'inherit';
167 } else {
168 // A non-themable string. Preserve it.
169 return currentValue.rawString;
170 }
171 });
172
173 resolvedCss = resolvedArray.join('');
174 }
175
176 return resolvedCss;
177}
178
179/**
180 * Split tokenized CSS into an array of strings and theme specification objects

Callers 4

applyThemableStylesFunction · 0.85
detokenizeFunction · 0.85
registerStylesFunction · 0.85
registerStylesIEFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected