Skip to content

Commit 9b8b94b

Browse files
black7375Jeong-jj
andcommitted
Feat: rulesVariant Funtion #154
Co-authored-by: Jeong-jj <rgfdds98@gmail.com>
1 parent 97e3666 commit 9b8b94b

File tree

3 files changed

+328
-15
lines changed

3 files changed

+328
-15
lines changed

packages/css/src/css/index.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ function cssWith<const T extends CSSRule>(
123123
return cssRaw(cssFunction(style));
124124
}
125125

126-
function cssWithVariants<
126+
function cssWithMultiple<
127127
StyleMap extends Record<string | number, RestrictedCSSRule>
128128
>(styleMap: StyleMap, debugId?: string): Record<keyof StyleMap, string>;
129-
function cssWithVariants<
129+
function cssWithMultiple<
130130
Data extends Record<string | number, RestrictedCSSRule>,
131131
Key extends keyof Data,
132132
MapData extends (value: Data[Key], key: Key) => ComplexCSSRule
133133
>(data: Data, mapData: MapData, debugId?: string): Record<keyof Data, string>;
134-
function cssWithVariants<
134+
function cssWithMultiple<
135135
Data extends Record<string | number, RestrictedCSSRule>,
136136
MapData extends (
137137
value: unknown,
@@ -155,7 +155,7 @@ function cssWith<const T extends CSSRule>(
155155

156156
return Object.assign(cssWithImpl, {
157157
raw: cssWithRaw,
158-
multiple: cssWithVariants
158+
multiple: cssWithMultiple
159159
});
160160
}
161161

@@ -165,7 +165,7 @@ export const css = Object.assign(cssImpl, {
165165
with: cssWith
166166
});
167167

168-
// == CSS Variants =============================================================
168+
// == CSS Multiple =============================================================
169169
// TODO: Need to optimize
170170
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#smart_self-overwriting_lazy_getters
171171
// https://github.com/vanilla-extract-css/vanilla-extract/blob/master/packages/css/src/style.ts
@@ -174,8 +174,7 @@ export function cssMultiple<
174174
>(styleMap: StyleMap, debugId?: string): Record<keyof StyleMap, string>;
175175
export function cssMultiple<
176176
Data extends Record<string | number, unknown>,
177-
Key extends keyof Data,
178-
MapData extends (value: Data[Key], key: Key) => ComplexCSSRule
177+
MapData extends (value: Data[keyof Data], key: keyof Data) => ComplexCSSRule
179178
>(data: Data, mapData: MapData, debugId?: string): Record<keyof Data, string>;
180179
export function cssMultiple<
181180
StyleMap extends Record<string | number, ComplexCSSRule>,
@@ -192,22 +191,21 @@ export function cssMultiple<
192191
if (isMapDataFunction(mapDataOrDebugId)) {
193192
const data = styleMapOrData as Data;
194193
const mapData = mapDataOrDebugId;
195-
return processVariants(data, mapData, debugId);
194+
return processMultiple(data, mapData, debugId);
196195
} else {
197196
const styleMap = styleMapOrData as StyleMap;
198197
const debugId = mapDataOrDebugId;
199-
return processVariants(styleMap, (style) => style, debugId);
198+
return processMultiple(styleMap, (style) => style, debugId);
200199
}
201200
}
202201

203202
function isMapDataFunction<
204203
Data extends Record<string | number, unknown>,
205-
Key extends keyof Data,
206-
MapData extends (value: Data[Key], key: Key) => ComplexCSSRule
204+
MapData extends (value: Data[keyof Data], key: keyof Data) => ComplexCSSRule
207205
>(mapDataOrDebugId?: MapData | string): mapDataOrDebugId is MapData {
208206
return typeof mapDataOrDebugId === "function";
209207
}
210-
function processVariants<T>(
208+
function processMultiple<T>(
211209
items: Record<string | number, T>,
212210
transformItem: (item: T, key: string | number) => ComplexCSSRule,
213211
debugId?: string

0 commit comments

Comments
 (0)