@pandacss/generator 1.4.3 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +141 -50
- package/dist/index.mjs +141 -50
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1158,6 +1158,8 @@ interface Dict {
|
|
|
1158
1158
|
[k: string]: unknown
|
|
1159
1159
|
}
|
|
1160
1160
|
|
|
1161
|
+
export type DataAttrs = Record<\`data-\${string}\`, unknown>
|
|
1162
|
+
|
|
1161
1163
|
export interface UnstyledProps {
|
|
1162
1164
|
/**
|
|
1163
1165
|
* Whether to remove recipe styles
|
|
@@ -1183,7 +1185,7 @@ interface RecipeFn {
|
|
|
1183
1185
|
|
|
1184
1186
|
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
1185
1187
|
dataAttr?: boolean
|
|
1186
|
-
defaultProps?: Partial<TProps>
|
|
1188
|
+
defaultProps?: Partial<TProps> & DataAttrs
|
|
1187
1189
|
shouldForwardProp?: (prop: string, variantKeys: string[]) => boolean
|
|
1188
1190
|
forwardProps?: string[]
|
|
1189
1191
|
}
|
|
@@ -1226,12 +1228,33 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1226
1228
|
${ctx.file.import("cx, css, sva", "../css/index")}
|
|
1227
1229
|
${ctx.file.import(factoryName, "./factory")}
|
|
1228
1230
|
${ctx.file.import("getDisplayName", "./factory-helper")}
|
|
1229
|
-
import { createContext
|
|
1231
|
+
import { createContext } from 'preact'
|
|
1232
|
+
import { useContext } from 'preact/hooks'
|
|
1233
|
+
import { createElement, forwardRef } from 'preact/compat'
|
|
1234
|
+
|
|
1235
|
+
function createSafeContext(contextName) {
|
|
1236
|
+
const Context = createContext(undefined)
|
|
1237
|
+
const useStyleContext = (componentName, slot) => {
|
|
1238
|
+
const context = useContext(Context)
|
|
1239
|
+
if (context === undefined) {
|
|
1240
|
+
const componentInfo = componentName ? \`Component "\${componentName}"\` : 'A component'
|
|
1241
|
+
const slotInfo = slot ? \` (slot: "\${slot}")\` : ''
|
|
1242
|
+
|
|
1243
|
+
throw new Error(
|
|
1244
|
+
\`\${componentInfo}\${slotInfo} cannot access \${contextName} because it's missing its Provider.\`
|
|
1245
|
+
)
|
|
1246
|
+
}
|
|
1247
|
+
return context
|
|
1248
|
+
}
|
|
1249
|
+
return [Context, useStyleContext]
|
|
1250
|
+
}
|
|
1230
1251
|
|
|
1231
|
-
|
|
1232
1252
|
export function createStyleContext(recipe) {
|
|
1233
|
-
const StyleContext = createContext({})
|
|
1234
1253
|
const isConfigRecipe = '__recipe__' in recipe
|
|
1254
|
+
const recipeName = isConfigRecipe && recipe.__name__ ? recipe.__name__ : undefined
|
|
1255
|
+
const contextName = recipeName ? \`createStyleContext("\${recipeName}")\` : 'createStyleContext'
|
|
1256
|
+
|
|
1257
|
+
const [StyleContext, useStyleContext] = createSafeContext(contextName)
|
|
1235
1258
|
const svaFn = isConfigRecipe ? recipe : sva(recipe.config)
|
|
1236
1259
|
|
|
1237
1260
|
const getResolvedProps = (props, slotStyles) => {
|
|
@@ -1271,7 +1294,7 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1271
1294
|
const withProvider = (Component, slot, options) => {
|
|
1272
1295
|
const StyledComponent = ${factoryName}(Component, {}, options)
|
|
1273
1296
|
|
|
1274
|
-
const WithProvider = forwardRef((props, ref)
|
|
1297
|
+
const WithProvider = forwardRef(function WithProvider(props, ref) {
|
|
1275
1298
|
const [variantProps, restProps] = svaFn.splitVariantProps(props)
|
|
1276
1299
|
|
|
1277
1300
|
const slotStyles = isConfigRecipe ? svaFn(variantProps) : svaFn.raw(variantProps)
|
|
@@ -1297,9 +1320,10 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1297
1320
|
|
|
1298
1321
|
const withContext = (Component, slot, options) => {
|
|
1299
1322
|
const StyledComponent = ${factoryName}(Component, {}, options)
|
|
1323
|
+
const componentName = getDisplayName(Component)
|
|
1300
1324
|
|
|
1301
|
-
const WithContext = forwardRef((props, ref)
|
|
1302
|
-
const slotStyles =
|
|
1325
|
+
const WithContext = forwardRef(function WithContext(props, ref) {
|
|
1326
|
+
const slotStyles = useStyleContext(componentName, slot)
|
|
1303
1327
|
|
|
1304
1328
|
const propsWithClass = { ...props, className: props.className ?? options?.defaultProps?.className }
|
|
1305
1329
|
const resolvedProps = getResolvedProps(propsWithClass, slotStyles[slot])
|
|
@@ -1310,7 +1334,6 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1310
1334
|
})
|
|
1311
1335
|
})
|
|
1312
1336
|
|
|
1313
|
-
const componentName = getDisplayName(Component)
|
|
1314
1337
|
WithContext.displayName = \`withContext(\${componentName})\`
|
|
1315
1338
|
|
|
1316
1339
|
return WithContext
|
|
@@ -1326,7 +1349,7 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1326
1349
|
dts: import_outdent17.outdent`
|
|
1327
1350
|
${ctx.file.importType("SlotRecipeRuntimeFn, RecipeVariantProps", "../types/recipe")}
|
|
1328
1351
|
${ctx.file.importType("JsxHTMLProps, JsxStyleProps, Assign", "../types/system-types")}
|
|
1329
|
-
${ctx.file.importType("JsxFactoryOptions", "../types/jsx")}
|
|
1352
|
+
${ctx.file.importType("JsxFactoryOptions, DataAttrs, AsProps", "../types/jsx")}
|
|
1330
1353
|
import type { ComponentType, ComponentProps, JSX } from 'preact/compat'
|
|
1331
1354
|
|
|
1332
1355
|
interface UnstyledProps {
|
|
@@ -1334,7 +1357,7 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1334
1357
|
}
|
|
1335
1358
|
|
|
1336
1359
|
interface WithProviderOptions<P = {}> {
|
|
1337
|
-
defaultProps?: Partial<P> | undefined
|
|
1360
|
+
defaultProps?: (Partial<P> & DataAttrs) | undefined
|
|
1338
1361
|
}
|
|
1339
1362
|
|
|
1340
1363
|
type ElementType = JSX.ElementType
|
|
@@ -1350,7 +1373,7 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1350
1373
|
type InferSlot<R extends SlotRecipe> = R extends SlotRecipeFn ? R['__slot'] : R extends SvaFn<infer S> ? S : never
|
|
1351
1374
|
|
|
1352
1375
|
type StyleContextProvider<T extends ElementType, R extends SlotRecipe> = ComponentType<
|
|
1353
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
1376
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
1354
1377
|
>
|
|
1355
1378
|
|
|
1356
1379
|
type StyleContextRootProvider<T extends ElementType, R extends SlotRecipe> = ComponentType<
|
|
@@ -1358,7 +1381,7 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1358
1381
|
>
|
|
1359
1382
|
|
|
1360
1383
|
type StyleContextConsumer<T extends ElementType> = ComponentType<
|
|
1361
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps, JsxStyleProps>
|
|
1384
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, JsxStyleProps>
|
|
1362
1385
|
>
|
|
1363
1386
|
|
|
1364
1387
|
export interface StyleContext<R extends SlotRecipe> {
|
|
@@ -1689,6 +1712,8 @@ interface Dict {
|
|
|
1689
1712
|
[k: string]: unknown
|
|
1690
1713
|
}
|
|
1691
1714
|
|
|
1715
|
+
export type DataAttrs = Record<\`data-\${string}\`, unknown>
|
|
1716
|
+
|
|
1692
1717
|
export interface UnstyledProps {
|
|
1693
1718
|
/**
|
|
1694
1719
|
* Whether to remove recipe styles
|
|
@@ -1711,7 +1736,7 @@ interface RecipeFn {
|
|
|
1711
1736
|
|
|
1712
1737
|
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
1713
1738
|
dataAttr?: boolean
|
|
1714
|
-
defaultProps?: Partial<TProps>
|
|
1739
|
+
defaultProps?: Partial<TProps> & DataAttrs
|
|
1715
1740
|
shouldForwardProp?: (prop: string, variantKeys: string[]) => boolean
|
|
1716
1741
|
forwardProps?: string[]
|
|
1717
1742
|
}
|
|
@@ -2046,6 +2071,8 @@ interface Dict {
|
|
|
2046
2071
|
[k: string]: unknown
|
|
2047
2072
|
}
|
|
2048
2073
|
|
|
2074
|
+
export type DataAttrs = Record<\`data-\${string}\`, unknown>
|
|
2075
|
+
|
|
2049
2076
|
export interface UnstyledProps {
|
|
2050
2077
|
/**
|
|
2051
2078
|
* Whether to remove recipe styles
|
|
@@ -2075,7 +2102,7 @@ interface RecipeFn {
|
|
|
2075
2102
|
|
|
2076
2103
|
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
2077
2104
|
dataAttr?: boolean
|
|
2078
|
-
defaultProps?: Partial<TProps>
|
|
2105
|
+
defaultProps?: Partial<TProps> & DataAttrs
|
|
2079
2106
|
shouldForwardProp?: (prop: string, variantKeys: string[]) => boolean
|
|
2080
2107
|
forwardProps?: string[]
|
|
2081
2108
|
}
|
|
@@ -2120,9 +2147,29 @@ function generateReactCreateStyleContext(ctx) {
|
|
|
2120
2147
|
${ctx.file.import("getDisplayName", "./factory-helper")}
|
|
2121
2148
|
import { createContext, useContext, createElement, forwardRef } from 'react'
|
|
2122
2149
|
|
|
2150
|
+
function createSafeContext(contextName) {
|
|
2151
|
+
const Context = createContext(undefined)
|
|
2152
|
+
const useStyleContext = (componentName, slot) => {
|
|
2153
|
+
const context = useContext(Context)
|
|
2154
|
+
if (context === undefined) {
|
|
2155
|
+
const componentInfo = componentName ? \`Component "\${componentName}"\` : 'A component'
|
|
2156
|
+
const slotInfo = slot ? \` (slot: "\${slot}")\` : ''
|
|
2157
|
+
|
|
2158
|
+
throw new Error(
|
|
2159
|
+
\`\${componentInfo}\${slotInfo} cannot access \${contextName} because it's missing its Provider.\`
|
|
2160
|
+
)
|
|
2161
|
+
}
|
|
2162
|
+
return context
|
|
2163
|
+
}
|
|
2164
|
+
return [Context, useStyleContext]
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2123
2167
|
export function createStyleContext(recipe) {
|
|
2124
|
-
const StyleContext = createContext({})
|
|
2125
2168
|
const isConfigRecipe = '__recipe__' in recipe
|
|
2169
|
+
const recipeName = isConfigRecipe && recipe.__name__ ? recipe.__name__ : undefined
|
|
2170
|
+
const contextName = recipeName ? \`createStyleContext("\${recipeName}")\` : 'createStyleContext'
|
|
2171
|
+
|
|
2172
|
+
const [StyleContext, useStyleContext] = createSafeContext(contextName)
|
|
2126
2173
|
const svaFn = isConfigRecipe ? recipe : sva(recipe.config)
|
|
2127
2174
|
|
|
2128
2175
|
const getResolvedProps = (props, slotStyles) => {
|
|
@@ -2188,9 +2235,10 @@ function generateReactCreateStyleContext(ctx) {
|
|
|
2188
2235
|
|
|
2189
2236
|
const withContext = (Component, slot, options) => {
|
|
2190
2237
|
const StyledComponent = ${factoryName}(Component, {}, options)
|
|
2238
|
+
const componentName = getDisplayName(Component)
|
|
2191
2239
|
|
|
2192
2240
|
const WithContext = forwardRef((props, ref) => {
|
|
2193
|
-
const slotStyles =
|
|
2241
|
+
const slotStyles = useStyleContext(componentName, slot)
|
|
2194
2242
|
|
|
2195
2243
|
const propsWithClass = { ...props, className: props.className ?? options?.defaultProps?.className }
|
|
2196
2244
|
const resolvedProps = getResolvedProps(propsWithClass, slotStyles[slot])
|
|
@@ -2201,7 +2249,6 @@ function generateReactCreateStyleContext(ctx) {
|
|
|
2201
2249
|
})
|
|
2202
2250
|
})
|
|
2203
2251
|
|
|
2204
|
-
const componentName = getDisplayName(Component)
|
|
2205
2252
|
WithContext.displayName = \`withContext(\${componentName})\`
|
|
2206
2253
|
|
|
2207
2254
|
return WithContext
|
|
@@ -2217,7 +2264,7 @@ function generateReactCreateStyleContext(ctx) {
|
|
|
2217
2264
|
dts: import_outdent28.outdent`
|
|
2218
2265
|
${ctx.file.importType("SlotRecipeRuntimeFn, RecipeVariantProps", "../types/recipe")}
|
|
2219
2266
|
${ctx.file.importType("JsxHTMLProps, JsxStyleProps, Assign", "../types/system-types")}
|
|
2220
|
-
${ctx.file.importType("JsxFactoryOptions, ComponentProps", "../types/jsx")}
|
|
2267
|
+
${ctx.file.importType("JsxFactoryOptions, ComponentProps, DataAttrs, AsProps", "../types/jsx")}
|
|
2221
2268
|
import type { ComponentType, ElementType } from 'react'
|
|
2222
2269
|
|
|
2223
2270
|
interface UnstyledProps {
|
|
@@ -2231,15 +2278,15 @@ function generateReactCreateStyleContext(ctx) {
|
|
|
2231
2278
|
(props?: any): any
|
|
2232
2279
|
}
|
|
2233
2280
|
type SlotRecipe = SvaFn | SlotRecipeFn
|
|
2234
|
-
|
|
2281
|
+
|
|
2235
2282
|
type InferSlot<R extends SlotRecipe> = R extends SlotRecipeFn ? R['__slot'] : R extends SvaFn<infer S> ? S : never
|
|
2236
|
-
|
|
2283
|
+
|
|
2237
2284
|
interface WithProviderOptions<P = {}> {
|
|
2238
|
-
defaultProps?: Partial<P> | undefined
|
|
2285
|
+
defaultProps?: (Partial<P> & DataAttrs) | undefined
|
|
2239
2286
|
}
|
|
2240
2287
|
|
|
2241
2288
|
type StyleContextProvider<T extends ElementType, R extends SlotRecipe> = ComponentType<
|
|
2242
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
2289
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
2243
2290
|
>
|
|
2244
2291
|
|
|
2245
2292
|
type StyleContextRootProvider<T extends ElementType, R extends SlotRecipe> = ComponentType<
|
|
@@ -2247,7 +2294,7 @@ function generateReactCreateStyleContext(ctx) {
|
|
|
2247
2294
|
>
|
|
2248
2295
|
|
|
2249
2296
|
type StyleContextConsumer<T extends ElementType> = ComponentType<
|
|
2250
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps, JsxStyleProps>
|
|
2297
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, JsxStyleProps>
|
|
2251
2298
|
>
|
|
2252
2299
|
|
|
2253
2300
|
export interface StyleContext<R extends SlotRecipe> {
|
|
@@ -2408,12 +2455,15 @@ function generateSolidJsxFactory(ctx) {
|
|
|
2408
2455
|
return forwardFn(prop, cvaFn.variantKeys)
|
|
2409
2456
|
}
|
|
2410
2457
|
|
|
2411
|
-
const
|
|
2412
|
-
options.dataAttr && configOrCva.__name__
|
|
2458
|
+
const getDefaultProps = () => {
|
|
2459
|
+
const baseDefaults = options.dataAttr && configOrCva.__name__
|
|
2413
2460
|
? { 'data-recipe': configOrCva.__name__ }
|
|
2414
|
-
: {}
|
|
2415
|
-
options.defaultProps
|
|
2416
|
-
|
|
2461
|
+
: {}
|
|
2462
|
+
const defaults = typeof options.defaultProps === 'function'
|
|
2463
|
+
? options.defaultProps()
|
|
2464
|
+
: options.defaultProps
|
|
2465
|
+
return Object.assign(baseDefaults, defaults)
|
|
2466
|
+
}
|
|
2417
2467
|
|
|
2418
2468
|
const __cvaFn__ = composeCvaFn(element.__cva__, cvaFn)
|
|
2419
2469
|
const __shouldForwardProps__ = composeShouldForwardProps(
|
|
@@ -2424,7 +2474,7 @@ function generateSolidJsxFactory(ctx) {
|
|
|
2424
2474
|
const ${componentName} = (props) => {
|
|
2425
2475
|
const mergedProps = mergeProps(
|
|
2426
2476
|
{ as: element.__base__ || element },
|
|
2427
|
-
|
|
2477
|
+
getDefaultProps(),
|
|
2428
2478
|
props
|
|
2429
2479
|
)
|
|
2430
2480
|
|
|
@@ -2614,17 +2664,16 @@ ${ctx.file.importType(upperName, "../types/jsx")}
|
|
|
2614
2664
|
export declare const ${factoryName}: ${upperName}
|
|
2615
2665
|
`,
|
|
2616
2666
|
jsxType: import_outdent33.outdent`
|
|
2617
|
-
import type { ComponentProps, Component, JSX } from 'solid-js'
|
|
2667
|
+
import type { Accessor, ComponentProps, Component, JSX } from 'solid-js'
|
|
2618
2668
|
${ctx.file.importType("RecipeDefinition, RecipeSelection, RecipeVariantRecord", "./recipe")}
|
|
2619
|
-
${ctx.file.importType(
|
|
2620
|
-
"Assign, DistributiveOmit, DistributiveUnion, JsxHTMLProps, JsxStyleProps, Pretty",
|
|
2621
|
-
"./system-types"
|
|
2622
|
-
)}
|
|
2669
|
+
${ctx.file.importType("Assign, DistributiveUnion, JsxHTMLProps, JsxStyleProps, Pretty", "./system-types")}
|
|
2623
2670
|
|
|
2624
2671
|
interface Dict {
|
|
2625
2672
|
[k: string]: unknown
|
|
2626
2673
|
}
|
|
2627
2674
|
|
|
2675
|
+
export type DataAttrs = Record<\`data-\${string}\`, unknown>
|
|
2676
|
+
|
|
2628
2677
|
export interface UnstyledProps {
|
|
2629
2678
|
/**
|
|
2630
2679
|
* Whether to remove recipe styles
|
|
@@ -2650,9 +2699,11 @@ interface RecipeFn {
|
|
|
2650
2699
|
__type: any
|
|
2651
2700
|
}
|
|
2652
2701
|
|
|
2702
|
+
export type MaybeAccessor<T> = T | Accessor<T>
|
|
2703
|
+
|
|
2653
2704
|
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
2654
2705
|
dataAttr?: boolean
|
|
2655
|
-
defaultProps?: Partial<TProps>
|
|
2706
|
+
defaultProps?: MaybeAccessor<Partial<TProps> & DataAttrs>
|
|
2656
2707
|
shouldForwardProp?: (prop: string, variantKeys: string[]) => boolean
|
|
2657
2708
|
forwardProps?: string[]
|
|
2658
2709
|
}
|
|
@@ -2698,9 +2749,29 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2698
2749
|
import { createComponent, mergeProps } from 'solid-js/web'
|
|
2699
2750
|
import { createContext, createMemo, splitProps, useContext } from 'solid-js'
|
|
2700
2751
|
|
|
2752
|
+
function createSafeContext(contextName) {
|
|
2753
|
+
const Context = createContext(undefined)
|
|
2754
|
+
const useStyleContext = (componentName, slot) => {
|
|
2755
|
+
const context = useContext(Context)
|
|
2756
|
+
if (context === undefined) {
|
|
2757
|
+
const componentInfo = componentName ? \`Component "\${componentName}"\` : 'A component'
|
|
2758
|
+
const slotInfo = slot ? \` (slot: "\${slot}")\` : ''
|
|
2759
|
+
|
|
2760
|
+
throw new Error(
|
|
2761
|
+
\`\${componentInfo}\${slotInfo} cannot access \${contextName} because it's missing its Provider.\`
|
|
2762
|
+
)
|
|
2763
|
+
}
|
|
2764
|
+
return context
|
|
2765
|
+
}
|
|
2766
|
+
return [Context, useStyleContext]
|
|
2767
|
+
}
|
|
2768
|
+
|
|
2701
2769
|
export function createStyleContext(recipe) {
|
|
2702
|
-
const StyleContext = createContext({})
|
|
2703
2770
|
const isConfigRecipe = '__recipe__' in recipe
|
|
2771
|
+
const recipeName = isConfigRecipe && recipe.__name__ ? recipe.__name__ : undefined
|
|
2772
|
+
const contextName = recipeName ? \`createStyleContext("\${recipeName}")\` : 'createStyleContext'
|
|
2773
|
+
|
|
2774
|
+
const [StyleContext, useStyleContext] = createSafeContext(contextName)
|
|
2704
2775
|
const svaFn = isConfigRecipe ? recipe : sva(recipe.config)
|
|
2705
2776
|
|
|
2706
2777
|
const getResolvedProps = (props, slotStyles) => {
|
|
@@ -2727,7 +2798,10 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2727
2798
|
|
|
2728
2799
|
const mergedProps = createMemo(() => {
|
|
2729
2800
|
if (!options?.defaultProps) return propsWithoutChildren
|
|
2730
|
-
|
|
2801
|
+
const defaults = typeof options.defaultProps === 'function'
|
|
2802
|
+
? options.defaultProps()
|
|
2803
|
+
: options.defaultProps
|
|
2804
|
+
return { ...defaults, ...propsWithoutChildren }
|
|
2731
2805
|
})
|
|
2732
2806
|
|
|
2733
2807
|
return createComponent(StyleContext.Provider, {
|
|
@@ -2799,9 +2873,10 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2799
2873
|
|
|
2800
2874
|
const withContext = (Component, slot, options) => {
|
|
2801
2875
|
const StyledComponent = ${factoryName}(Component, {}, options)
|
|
2876
|
+
const componentName = getDisplayName(Component)
|
|
2802
2877
|
|
|
2803
2878
|
const WithContext = (props) => {
|
|
2804
|
-
const slotStyles =
|
|
2879
|
+
const slotStyles = useStyleContext(componentName, slot)
|
|
2805
2880
|
const [local, propsWithoutChildren] = splitProps(props, ["children"])
|
|
2806
2881
|
|
|
2807
2882
|
const resolvedProps = createMemo(() => {
|
|
@@ -2824,7 +2899,6 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2824
2899
|
)
|
|
2825
2900
|
}
|
|
2826
2901
|
|
|
2827
|
-
const componentName = getDisplayName(Component)
|
|
2828
2902
|
WithContext.displayName = \`withContext(\${componentName})\`
|
|
2829
2903
|
return WithContext
|
|
2830
2904
|
}
|
|
@@ -2839,7 +2913,7 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2839
2913
|
dts: import_outdent34.outdent`
|
|
2840
2914
|
${ctx.file.importType("SlotRecipeRuntimeFn, RecipeVariantProps", "../types/recipe")}
|
|
2841
2915
|
${ctx.file.importType("JsxHTMLProps, JsxStyleProps, Assign", "../types/system-types")}
|
|
2842
|
-
${ctx.file.importType("JsxFactoryOptions", "../types/jsx")}
|
|
2916
|
+
${ctx.file.importType("JsxFactoryOptions, DataAttrs, MaybeAccessor, AsProps", "../types/jsx")}
|
|
2843
2917
|
import type { Component, JSX, ComponentProps } from 'solid-js'
|
|
2844
2918
|
|
|
2845
2919
|
interface UnstyledProps {
|
|
@@ -2847,7 +2921,7 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2847
2921
|
}
|
|
2848
2922
|
|
|
2849
2923
|
interface WithProviderOptions<P> {
|
|
2850
|
-
defaultProps?: Partial<P> | undefined
|
|
2924
|
+
defaultProps?: MaybeAccessor<Partial<P> & DataAttrs> | undefined
|
|
2851
2925
|
}
|
|
2852
2926
|
|
|
2853
2927
|
type ElementType = keyof JSX.IntrinsicElements | Component<any>
|
|
@@ -2867,7 +2941,7 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2867
2941
|
: never
|
|
2868
2942
|
|
|
2869
2943
|
type StyleContextProvider<T extends ElementType, R extends SlotRecipe> = Component<
|
|
2870
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
2944
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
2871
2945
|
>
|
|
2872
2946
|
|
|
2873
2947
|
type StyleContextRootProvider<T extends ElementType, R extends SlotRecipe> = Component<
|
|
@@ -2875,7 +2949,7 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2875
2949
|
>
|
|
2876
2950
|
|
|
2877
2951
|
type StyleContextConsumer<T extends ElementType> = Component<
|
|
2878
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps, JsxStyleProps>
|
|
2952
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, JsxStyleProps>
|
|
2879
2953
|
>
|
|
2880
2954
|
|
|
2881
2955
|
export interface StyleContext<R extends SlotRecipe> {
|
|
@@ -3261,6 +3335,8 @@ interface Dict {
|
|
|
3261
3335
|
[k: string]: unknown
|
|
3262
3336
|
}
|
|
3263
3337
|
|
|
3338
|
+
export type DataAttrs = Record<\`data-\${string}\`, unknown>
|
|
3339
|
+
|
|
3264
3340
|
export interface UnstyledProps {
|
|
3265
3341
|
/**
|
|
3266
3342
|
* Whether to remove recipe styles
|
|
@@ -3285,7 +3361,7 @@ interface RecipeFn {
|
|
|
3285
3361
|
|
|
3286
3362
|
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
3287
3363
|
dataAttr?: boolean
|
|
3288
|
-
defaultProps?: Partial<TProps>
|
|
3364
|
+
defaultProps?: Partial<TProps> & DataAttrs
|
|
3289
3365
|
shouldForwardProp?: (prop: string, variantKeys: string[]) => boolean
|
|
3290
3366
|
forwardProps?: string[]
|
|
3291
3367
|
}
|
|
@@ -3333,7 +3409,22 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3333
3409
|
export function createStyleContext(recipe) {
|
|
3334
3410
|
const StyleContext = Symbol('StyleContext')
|
|
3335
3411
|
const isConfigRecipe = '__recipe__' in recipe
|
|
3412
|
+
const recipeName = isConfigRecipe && recipe.__name__ ? recipe.__name__ : undefined
|
|
3413
|
+
const contextName = recipeName ? \`createStyleContext("\${recipeName}")\` : 'createStyleContext'
|
|
3336
3414
|
const svaFn = isConfigRecipe ? recipe : sva(recipe.config)
|
|
3415
|
+
|
|
3416
|
+
function useStyleContext(componentName, slot) {
|
|
3417
|
+
const context = inject(StyleContext)
|
|
3418
|
+
if (context === undefined) {
|
|
3419
|
+
const componentInfo = componentName ? \`Component "\${componentName}"\` : 'A component'
|
|
3420
|
+
const slotInfo = slot ? \` (slot: "\${slot}")\` : ''
|
|
3421
|
+
|
|
3422
|
+
throw new Error(
|
|
3423
|
+
\`\${componentInfo}\${slotInfo} cannot access \${contextName} because it's missing its Provider.\`
|
|
3424
|
+
)
|
|
3425
|
+
}
|
|
3426
|
+
return context
|
|
3427
|
+
}
|
|
3337
3428
|
|
|
3338
3429
|
const getResolvedProps = (props, slotStyles) => {
|
|
3339
3430
|
const { unstyled, ...restProps } = props
|
|
@@ -3416,6 +3507,7 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3416
3507
|
|
|
3417
3508
|
const withContext = (Component, slot, options) => {
|
|
3418
3509
|
const StyledComponent = ${factoryName}(Component, {}, options)
|
|
3510
|
+
const componentName = getDisplayName(Component)
|
|
3419
3511
|
|
|
3420
3512
|
const WithContext = defineComponent({
|
|
3421
3513
|
props: ["unstyled"],
|
|
@@ -3426,7 +3518,7 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3426
3518
|
propsWithClass.class = propsWithClass.class ?? options?.defaultProps?.class
|
|
3427
3519
|
return propsWithClass
|
|
3428
3520
|
})
|
|
3429
|
-
const slotStyles =
|
|
3521
|
+
const slotStyles = useStyleContext(componentName, slot)
|
|
3430
3522
|
|
|
3431
3523
|
return () => {
|
|
3432
3524
|
const resolvedProps = getResolvedProps(props.value, slotStyles.value[slot])
|
|
@@ -3436,7 +3528,6 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3436
3528
|
},
|
|
3437
3529
|
})
|
|
3438
3530
|
|
|
3439
|
-
const componentName = getDisplayName(Component)
|
|
3440
3531
|
WithContext.displayName = \`withContext(\${componentName})\`
|
|
3441
3532
|
|
|
3442
3533
|
return WithContext
|
|
@@ -3452,7 +3543,7 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3452
3543
|
dts: import_outdent40.outdent`
|
|
3453
3544
|
${ctx.file.importType("SlotRecipeRuntimeFn, RecipeVariantProps", "../types/recipe")}
|
|
3454
3545
|
${ctx.file.importType("JsxHTMLProps, JsxStyleProps, Assign", "../types/system-types")}
|
|
3455
|
-
${ctx.file.importType("JsxFactoryOptions", "../types/jsx")}
|
|
3546
|
+
${ctx.file.importType("JsxFactoryOptions, DataAttrs, AsProps", "../types/jsx")}
|
|
3456
3547
|
import type { Component, FunctionalComponent, NativeElements } from 'vue'
|
|
3457
3548
|
|
|
3458
3549
|
interface UnstyledProps {
|
|
@@ -3460,7 +3551,7 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3460
3551
|
}
|
|
3461
3552
|
|
|
3462
3553
|
interface WithProviderOptions<P = {}> {
|
|
3463
|
-
defaultProps?: Partial<P> | undefined
|
|
3554
|
+
defaultProps?: (Partial<P> & DataAttrs) | undefined
|
|
3464
3555
|
}
|
|
3465
3556
|
|
|
3466
3557
|
// Add v-model support types
|
|
@@ -3489,7 +3580,7 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3489
3580
|
: never
|
|
3490
3581
|
|
|
3491
3582
|
type StyleContextProvider<T extends ElementType, R extends SlotRecipe> = FunctionalComponent<
|
|
3492
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps & VModelProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
3583
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps & VModelProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
3493
3584
|
>
|
|
3494
3585
|
|
|
3495
3586
|
type StyleContextRootProvider<T extends ElementType, R extends SlotRecipe> = FunctionalComponent<
|
|
@@ -3497,7 +3588,7 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3497
3588
|
>
|
|
3498
3589
|
|
|
3499
3590
|
type StyleContextConsumer<T extends ElementType> = FunctionalComponent<
|
|
3500
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps & VModelProps, JsxStyleProps>
|
|
3591
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps & VModelProps, JsxStyleProps>
|
|
3501
3592
|
>
|
|
3502
3593
|
|
|
3503
3594
|
export interface StyleContext<R extends SlotRecipe> {
|
package/dist/index.mjs
CHANGED
|
@@ -1122,6 +1122,8 @@ interface Dict {
|
|
|
1122
1122
|
[k: string]: unknown
|
|
1123
1123
|
}
|
|
1124
1124
|
|
|
1125
|
+
export type DataAttrs = Record<\`data-\${string}\`, unknown>
|
|
1126
|
+
|
|
1125
1127
|
export interface UnstyledProps {
|
|
1126
1128
|
/**
|
|
1127
1129
|
* Whether to remove recipe styles
|
|
@@ -1147,7 +1149,7 @@ interface RecipeFn {
|
|
|
1147
1149
|
|
|
1148
1150
|
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
1149
1151
|
dataAttr?: boolean
|
|
1150
|
-
defaultProps?: Partial<TProps>
|
|
1152
|
+
defaultProps?: Partial<TProps> & DataAttrs
|
|
1151
1153
|
shouldForwardProp?: (prop: string, variantKeys: string[]) => boolean
|
|
1152
1154
|
forwardProps?: string[]
|
|
1153
1155
|
}
|
|
@@ -1190,12 +1192,33 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1190
1192
|
${ctx.file.import("cx, css, sva", "../css/index")}
|
|
1191
1193
|
${ctx.file.import(factoryName, "./factory")}
|
|
1192
1194
|
${ctx.file.import("getDisplayName", "./factory-helper")}
|
|
1193
|
-
import { createContext
|
|
1195
|
+
import { createContext } from 'preact'
|
|
1196
|
+
import { useContext } from 'preact/hooks'
|
|
1197
|
+
import { createElement, forwardRef } from 'preact/compat'
|
|
1198
|
+
|
|
1199
|
+
function createSafeContext(contextName) {
|
|
1200
|
+
const Context = createContext(undefined)
|
|
1201
|
+
const useStyleContext = (componentName, slot) => {
|
|
1202
|
+
const context = useContext(Context)
|
|
1203
|
+
if (context === undefined) {
|
|
1204
|
+
const componentInfo = componentName ? \`Component "\${componentName}"\` : 'A component'
|
|
1205
|
+
const slotInfo = slot ? \` (slot: "\${slot}")\` : ''
|
|
1206
|
+
|
|
1207
|
+
throw new Error(
|
|
1208
|
+
\`\${componentInfo}\${slotInfo} cannot access \${contextName} because it's missing its Provider.\`
|
|
1209
|
+
)
|
|
1210
|
+
}
|
|
1211
|
+
return context
|
|
1212
|
+
}
|
|
1213
|
+
return [Context, useStyleContext]
|
|
1214
|
+
}
|
|
1194
1215
|
|
|
1195
|
-
|
|
1196
1216
|
export function createStyleContext(recipe) {
|
|
1197
|
-
const StyleContext = createContext({})
|
|
1198
1217
|
const isConfigRecipe = '__recipe__' in recipe
|
|
1218
|
+
const recipeName = isConfigRecipe && recipe.__name__ ? recipe.__name__ : undefined
|
|
1219
|
+
const contextName = recipeName ? \`createStyleContext("\${recipeName}")\` : 'createStyleContext'
|
|
1220
|
+
|
|
1221
|
+
const [StyleContext, useStyleContext] = createSafeContext(contextName)
|
|
1199
1222
|
const svaFn = isConfigRecipe ? recipe : sva(recipe.config)
|
|
1200
1223
|
|
|
1201
1224
|
const getResolvedProps = (props, slotStyles) => {
|
|
@@ -1235,7 +1258,7 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1235
1258
|
const withProvider = (Component, slot, options) => {
|
|
1236
1259
|
const StyledComponent = ${factoryName}(Component, {}, options)
|
|
1237
1260
|
|
|
1238
|
-
const WithProvider = forwardRef((props, ref)
|
|
1261
|
+
const WithProvider = forwardRef(function WithProvider(props, ref) {
|
|
1239
1262
|
const [variantProps, restProps] = svaFn.splitVariantProps(props)
|
|
1240
1263
|
|
|
1241
1264
|
const slotStyles = isConfigRecipe ? svaFn(variantProps) : svaFn.raw(variantProps)
|
|
@@ -1261,9 +1284,10 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1261
1284
|
|
|
1262
1285
|
const withContext = (Component, slot, options) => {
|
|
1263
1286
|
const StyledComponent = ${factoryName}(Component, {}, options)
|
|
1287
|
+
const componentName = getDisplayName(Component)
|
|
1264
1288
|
|
|
1265
|
-
const WithContext = forwardRef((props, ref)
|
|
1266
|
-
const slotStyles =
|
|
1289
|
+
const WithContext = forwardRef(function WithContext(props, ref) {
|
|
1290
|
+
const slotStyles = useStyleContext(componentName, slot)
|
|
1267
1291
|
|
|
1268
1292
|
const propsWithClass = { ...props, className: props.className ?? options?.defaultProps?.className }
|
|
1269
1293
|
const resolvedProps = getResolvedProps(propsWithClass, slotStyles[slot])
|
|
@@ -1274,7 +1298,6 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1274
1298
|
})
|
|
1275
1299
|
})
|
|
1276
1300
|
|
|
1277
|
-
const componentName = getDisplayName(Component)
|
|
1278
1301
|
WithContext.displayName = \`withContext(\${componentName})\`
|
|
1279
1302
|
|
|
1280
1303
|
return WithContext
|
|
@@ -1290,7 +1313,7 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1290
1313
|
dts: outdent17`
|
|
1291
1314
|
${ctx.file.importType("SlotRecipeRuntimeFn, RecipeVariantProps", "../types/recipe")}
|
|
1292
1315
|
${ctx.file.importType("JsxHTMLProps, JsxStyleProps, Assign", "../types/system-types")}
|
|
1293
|
-
${ctx.file.importType("JsxFactoryOptions", "../types/jsx")}
|
|
1316
|
+
${ctx.file.importType("JsxFactoryOptions, DataAttrs, AsProps", "../types/jsx")}
|
|
1294
1317
|
import type { ComponentType, ComponentProps, JSX } from 'preact/compat'
|
|
1295
1318
|
|
|
1296
1319
|
interface UnstyledProps {
|
|
@@ -1298,7 +1321,7 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1298
1321
|
}
|
|
1299
1322
|
|
|
1300
1323
|
interface WithProviderOptions<P = {}> {
|
|
1301
|
-
defaultProps?: Partial<P> | undefined
|
|
1324
|
+
defaultProps?: (Partial<P> & DataAttrs) | undefined
|
|
1302
1325
|
}
|
|
1303
1326
|
|
|
1304
1327
|
type ElementType = JSX.ElementType
|
|
@@ -1314,7 +1337,7 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1314
1337
|
type InferSlot<R extends SlotRecipe> = R extends SlotRecipeFn ? R['__slot'] : R extends SvaFn<infer S> ? S : never
|
|
1315
1338
|
|
|
1316
1339
|
type StyleContextProvider<T extends ElementType, R extends SlotRecipe> = ComponentType<
|
|
1317
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
1340
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
1318
1341
|
>
|
|
1319
1342
|
|
|
1320
1343
|
type StyleContextRootProvider<T extends ElementType, R extends SlotRecipe> = ComponentType<
|
|
@@ -1322,7 +1345,7 @@ function generatePreactCreateStyleContext(ctx) {
|
|
|
1322
1345
|
>
|
|
1323
1346
|
|
|
1324
1347
|
type StyleContextConsumer<T extends ElementType> = ComponentType<
|
|
1325
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps, JsxStyleProps>
|
|
1348
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, JsxStyleProps>
|
|
1326
1349
|
>
|
|
1327
1350
|
|
|
1328
1351
|
export interface StyleContext<R extends SlotRecipe> {
|
|
@@ -1653,6 +1676,8 @@ interface Dict {
|
|
|
1653
1676
|
[k: string]: unknown
|
|
1654
1677
|
}
|
|
1655
1678
|
|
|
1679
|
+
export type DataAttrs = Record<\`data-\${string}\`, unknown>
|
|
1680
|
+
|
|
1656
1681
|
export interface UnstyledProps {
|
|
1657
1682
|
/**
|
|
1658
1683
|
* Whether to remove recipe styles
|
|
@@ -1675,7 +1700,7 @@ interface RecipeFn {
|
|
|
1675
1700
|
|
|
1676
1701
|
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
1677
1702
|
dataAttr?: boolean
|
|
1678
|
-
defaultProps?: Partial<TProps>
|
|
1703
|
+
defaultProps?: Partial<TProps> & DataAttrs
|
|
1679
1704
|
shouldForwardProp?: (prop: string, variantKeys: string[]) => boolean
|
|
1680
1705
|
forwardProps?: string[]
|
|
1681
1706
|
}
|
|
@@ -2010,6 +2035,8 @@ interface Dict {
|
|
|
2010
2035
|
[k: string]: unknown
|
|
2011
2036
|
}
|
|
2012
2037
|
|
|
2038
|
+
export type DataAttrs = Record<\`data-\${string}\`, unknown>
|
|
2039
|
+
|
|
2013
2040
|
export interface UnstyledProps {
|
|
2014
2041
|
/**
|
|
2015
2042
|
* Whether to remove recipe styles
|
|
@@ -2039,7 +2066,7 @@ interface RecipeFn {
|
|
|
2039
2066
|
|
|
2040
2067
|
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
2041
2068
|
dataAttr?: boolean
|
|
2042
|
-
defaultProps?: Partial<TProps>
|
|
2069
|
+
defaultProps?: Partial<TProps> & DataAttrs
|
|
2043
2070
|
shouldForwardProp?: (prop: string, variantKeys: string[]) => boolean
|
|
2044
2071
|
forwardProps?: string[]
|
|
2045
2072
|
}
|
|
@@ -2084,9 +2111,29 @@ function generateReactCreateStyleContext(ctx) {
|
|
|
2084
2111
|
${ctx.file.import("getDisplayName", "./factory-helper")}
|
|
2085
2112
|
import { createContext, useContext, createElement, forwardRef } from 'react'
|
|
2086
2113
|
|
|
2114
|
+
function createSafeContext(contextName) {
|
|
2115
|
+
const Context = createContext(undefined)
|
|
2116
|
+
const useStyleContext = (componentName, slot) => {
|
|
2117
|
+
const context = useContext(Context)
|
|
2118
|
+
if (context === undefined) {
|
|
2119
|
+
const componentInfo = componentName ? \`Component "\${componentName}"\` : 'A component'
|
|
2120
|
+
const slotInfo = slot ? \` (slot: "\${slot}")\` : ''
|
|
2121
|
+
|
|
2122
|
+
throw new Error(
|
|
2123
|
+
\`\${componentInfo}\${slotInfo} cannot access \${contextName} because it's missing its Provider.\`
|
|
2124
|
+
)
|
|
2125
|
+
}
|
|
2126
|
+
return context
|
|
2127
|
+
}
|
|
2128
|
+
return [Context, useStyleContext]
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2087
2131
|
export function createStyleContext(recipe) {
|
|
2088
|
-
const StyleContext = createContext({})
|
|
2089
2132
|
const isConfigRecipe = '__recipe__' in recipe
|
|
2133
|
+
const recipeName = isConfigRecipe && recipe.__name__ ? recipe.__name__ : undefined
|
|
2134
|
+
const contextName = recipeName ? \`createStyleContext("\${recipeName}")\` : 'createStyleContext'
|
|
2135
|
+
|
|
2136
|
+
const [StyleContext, useStyleContext] = createSafeContext(contextName)
|
|
2090
2137
|
const svaFn = isConfigRecipe ? recipe : sva(recipe.config)
|
|
2091
2138
|
|
|
2092
2139
|
const getResolvedProps = (props, slotStyles) => {
|
|
@@ -2152,9 +2199,10 @@ function generateReactCreateStyleContext(ctx) {
|
|
|
2152
2199
|
|
|
2153
2200
|
const withContext = (Component, slot, options) => {
|
|
2154
2201
|
const StyledComponent = ${factoryName}(Component, {}, options)
|
|
2202
|
+
const componentName = getDisplayName(Component)
|
|
2155
2203
|
|
|
2156
2204
|
const WithContext = forwardRef((props, ref) => {
|
|
2157
|
-
const slotStyles =
|
|
2205
|
+
const slotStyles = useStyleContext(componentName, slot)
|
|
2158
2206
|
|
|
2159
2207
|
const propsWithClass = { ...props, className: props.className ?? options?.defaultProps?.className }
|
|
2160
2208
|
const resolvedProps = getResolvedProps(propsWithClass, slotStyles[slot])
|
|
@@ -2165,7 +2213,6 @@ function generateReactCreateStyleContext(ctx) {
|
|
|
2165
2213
|
})
|
|
2166
2214
|
})
|
|
2167
2215
|
|
|
2168
|
-
const componentName = getDisplayName(Component)
|
|
2169
2216
|
WithContext.displayName = \`withContext(\${componentName})\`
|
|
2170
2217
|
|
|
2171
2218
|
return WithContext
|
|
@@ -2181,7 +2228,7 @@ function generateReactCreateStyleContext(ctx) {
|
|
|
2181
2228
|
dts: outdent28`
|
|
2182
2229
|
${ctx.file.importType("SlotRecipeRuntimeFn, RecipeVariantProps", "../types/recipe")}
|
|
2183
2230
|
${ctx.file.importType("JsxHTMLProps, JsxStyleProps, Assign", "../types/system-types")}
|
|
2184
|
-
${ctx.file.importType("JsxFactoryOptions, ComponentProps", "../types/jsx")}
|
|
2231
|
+
${ctx.file.importType("JsxFactoryOptions, ComponentProps, DataAttrs, AsProps", "../types/jsx")}
|
|
2185
2232
|
import type { ComponentType, ElementType } from 'react'
|
|
2186
2233
|
|
|
2187
2234
|
interface UnstyledProps {
|
|
@@ -2195,15 +2242,15 @@ function generateReactCreateStyleContext(ctx) {
|
|
|
2195
2242
|
(props?: any): any
|
|
2196
2243
|
}
|
|
2197
2244
|
type SlotRecipe = SvaFn | SlotRecipeFn
|
|
2198
|
-
|
|
2245
|
+
|
|
2199
2246
|
type InferSlot<R extends SlotRecipe> = R extends SlotRecipeFn ? R['__slot'] : R extends SvaFn<infer S> ? S : never
|
|
2200
|
-
|
|
2247
|
+
|
|
2201
2248
|
interface WithProviderOptions<P = {}> {
|
|
2202
|
-
defaultProps?: Partial<P> | undefined
|
|
2249
|
+
defaultProps?: (Partial<P> & DataAttrs) | undefined
|
|
2203
2250
|
}
|
|
2204
2251
|
|
|
2205
2252
|
type StyleContextProvider<T extends ElementType, R extends SlotRecipe> = ComponentType<
|
|
2206
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
2253
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
2207
2254
|
>
|
|
2208
2255
|
|
|
2209
2256
|
type StyleContextRootProvider<T extends ElementType, R extends SlotRecipe> = ComponentType<
|
|
@@ -2211,7 +2258,7 @@ function generateReactCreateStyleContext(ctx) {
|
|
|
2211
2258
|
>
|
|
2212
2259
|
|
|
2213
2260
|
type StyleContextConsumer<T extends ElementType> = ComponentType<
|
|
2214
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps, JsxStyleProps>
|
|
2261
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, JsxStyleProps>
|
|
2215
2262
|
>
|
|
2216
2263
|
|
|
2217
2264
|
export interface StyleContext<R extends SlotRecipe> {
|
|
@@ -2372,12 +2419,15 @@ function generateSolidJsxFactory(ctx) {
|
|
|
2372
2419
|
return forwardFn(prop, cvaFn.variantKeys)
|
|
2373
2420
|
}
|
|
2374
2421
|
|
|
2375
|
-
const
|
|
2376
|
-
options.dataAttr && configOrCva.__name__
|
|
2422
|
+
const getDefaultProps = () => {
|
|
2423
|
+
const baseDefaults = options.dataAttr && configOrCva.__name__
|
|
2377
2424
|
? { 'data-recipe': configOrCva.__name__ }
|
|
2378
|
-
: {}
|
|
2379
|
-
options.defaultProps
|
|
2380
|
-
|
|
2425
|
+
: {}
|
|
2426
|
+
const defaults = typeof options.defaultProps === 'function'
|
|
2427
|
+
? options.defaultProps()
|
|
2428
|
+
: options.defaultProps
|
|
2429
|
+
return Object.assign(baseDefaults, defaults)
|
|
2430
|
+
}
|
|
2381
2431
|
|
|
2382
2432
|
const __cvaFn__ = composeCvaFn(element.__cva__, cvaFn)
|
|
2383
2433
|
const __shouldForwardProps__ = composeShouldForwardProps(
|
|
@@ -2388,7 +2438,7 @@ function generateSolidJsxFactory(ctx) {
|
|
|
2388
2438
|
const ${componentName} = (props) => {
|
|
2389
2439
|
const mergedProps = mergeProps(
|
|
2390
2440
|
{ as: element.__base__ || element },
|
|
2391
|
-
|
|
2441
|
+
getDefaultProps(),
|
|
2392
2442
|
props
|
|
2393
2443
|
)
|
|
2394
2444
|
|
|
@@ -2578,17 +2628,16 @@ ${ctx.file.importType(upperName, "../types/jsx")}
|
|
|
2578
2628
|
export declare const ${factoryName}: ${upperName}
|
|
2579
2629
|
`,
|
|
2580
2630
|
jsxType: outdent33`
|
|
2581
|
-
import type { ComponentProps, Component, JSX } from 'solid-js'
|
|
2631
|
+
import type { Accessor, ComponentProps, Component, JSX } from 'solid-js'
|
|
2582
2632
|
${ctx.file.importType("RecipeDefinition, RecipeSelection, RecipeVariantRecord", "./recipe")}
|
|
2583
|
-
${ctx.file.importType(
|
|
2584
|
-
"Assign, DistributiveOmit, DistributiveUnion, JsxHTMLProps, JsxStyleProps, Pretty",
|
|
2585
|
-
"./system-types"
|
|
2586
|
-
)}
|
|
2633
|
+
${ctx.file.importType("Assign, DistributiveUnion, JsxHTMLProps, JsxStyleProps, Pretty", "./system-types")}
|
|
2587
2634
|
|
|
2588
2635
|
interface Dict {
|
|
2589
2636
|
[k: string]: unknown
|
|
2590
2637
|
}
|
|
2591
2638
|
|
|
2639
|
+
export type DataAttrs = Record<\`data-\${string}\`, unknown>
|
|
2640
|
+
|
|
2592
2641
|
export interface UnstyledProps {
|
|
2593
2642
|
/**
|
|
2594
2643
|
* Whether to remove recipe styles
|
|
@@ -2614,9 +2663,11 @@ interface RecipeFn {
|
|
|
2614
2663
|
__type: any
|
|
2615
2664
|
}
|
|
2616
2665
|
|
|
2666
|
+
export type MaybeAccessor<T> = T | Accessor<T>
|
|
2667
|
+
|
|
2617
2668
|
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
2618
2669
|
dataAttr?: boolean
|
|
2619
|
-
defaultProps?: Partial<TProps>
|
|
2670
|
+
defaultProps?: MaybeAccessor<Partial<TProps> & DataAttrs>
|
|
2620
2671
|
shouldForwardProp?: (prop: string, variantKeys: string[]) => boolean
|
|
2621
2672
|
forwardProps?: string[]
|
|
2622
2673
|
}
|
|
@@ -2662,9 +2713,29 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2662
2713
|
import { createComponent, mergeProps } from 'solid-js/web'
|
|
2663
2714
|
import { createContext, createMemo, splitProps, useContext } from 'solid-js'
|
|
2664
2715
|
|
|
2716
|
+
function createSafeContext(contextName) {
|
|
2717
|
+
const Context = createContext(undefined)
|
|
2718
|
+
const useStyleContext = (componentName, slot) => {
|
|
2719
|
+
const context = useContext(Context)
|
|
2720
|
+
if (context === undefined) {
|
|
2721
|
+
const componentInfo = componentName ? \`Component "\${componentName}"\` : 'A component'
|
|
2722
|
+
const slotInfo = slot ? \` (slot: "\${slot}")\` : ''
|
|
2723
|
+
|
|
2724
|
+
throw new Error(
|
|
2725
|
+
\`\${componentInfo}\${slotInfo} cannot access \${contextName} because it's missing its Provider.\`
|
|
2726
|
+
)
|
|
2727
|
+
}
|
|
2728
|
+
return context
|
|
2729
|
+
}
|
|
2730
|
+
return [Context, useStyleContext]
|
|
2731
|
+
}
|
|
2732
|
+
|
|
2665
2733
|
export function createStyleContext(recipe) {
|
|
2666
|
-
const StyleContext = createContext({})
|
|
2667
2734
|
const isConfigRecipe = '__recipe__' in recipe
|
|
2735
|
+
const recipeName = isConfigRecipe && recipe.__name__ ? recipe.__name__ : undefined
|
|
2736
|
+
const contextName = recipeName ? \`createStyleContext("\${recipeName}")\` : 'createStyleContext'
|
|
2737
|
+
|
|
2738
|
+
const [StyleContext, useStyleContext] = createSafeContext(contextName)
|
|
2668
2739
|
const svaFn = isConfigRecipe ? recipe : sva(recipe.config)
|
|
2669
2740
|
|
|
2670
2741
|
const getResolvedProps = (props, slotStyles) => {
|
|
@@ -2691,7 +2762,10 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2691
2762
|
|
|
2692
2763
|
const mergedProps = createMemo(() => {
|
|
2693
2764
|
if (!options?.defaultProps) return propsWithoutChildren
|
|
2694
|
-
|
|
2765
|
+
const defaults = typeof options.defaultProps === 'function'
|
|
2766
|
+
? options.defaultProps()
|
|
2767
|
+
: options.defaultProps
|
|
2768
|
+
return { ...defaults, ...propsWithoutChildren }
|
|
2695
2769
|
})
|
|
2696
2770
|
|
|
2697
2771
|
return createComponent(StyleContext.Provider, {
|
|
@@ -2763,9 +2837,10 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2763
2837
|
|
|
2764
2838
|
const withContext = (Component, slot, options) => {
|
|
2765
2839
|
const StyledComponent = ${factoryName}(Component, {}, options)
|
|
2840
|
+
const componentName = getDisplayName(Component)
|
|
2766
2841
|
|
|
2767
2842
|
const WithContext = (props) => {
|
|
2768
|
-
const slotStyles =
|
|
2843
|
+
const slotStyles = useStyleContext(componentName, slot)
|
|
2769
2844
|
const [local, propsWithoutChildren] = splitProps(props, ["children"])
|
|
2770
2845
|
|
|
2771
2846
|
const resolvedProps = createMemo(() => {
|
|
@@ -2788,7 +2863,6 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2788
2863
|
)
|
|
2789
2864
|
}
|
|
2790
2865
|
|
|
2791
|
-
const componentName = getDisplayName(Component)
|
|
2792
2866
|
WithContext.displayName = \`withContext(\${componentName})\`
|
|
2793
2867
|
return WithContext
|
|
2794
2868
|
}
|
|
@@ -2803,7 +2877,7 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2803
2877
|
dts: outdent34`
|
|
2804
2878
|
${ctx.file.importType("SlotRecipeRuntimeFn, RecipeVariantProps", "../types/recipe")}
|
|
2805
2879
|
${ctx.file.importType("JsxHTMLProps, JsxStyleProps, Assign", "../types/system-types")}
|
|
2806
|
-
${ctx.file.importType("JsxFactoryOptions", "../types/jsx")}
|
|
2880
|
+
${ctx.file.importType("JsxFactoryOptions, DataAttrs, MaybeAccessor, AsProps", "../types/jsx")}
|
|
2807
2881
|
import type { Component, JSX, ComponentProps } from 'solid-js'
|
|
2808
2882
|
|
|
2809
2883
|
interface UnstyledProps {
|
|
@@ -2811,7 +2885,7 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2811
2885
|
}
|
|
2812
2886
|
|
|
2813
2887
|
interface WithProviderOptions<P> {
|
|
2814
|
-
defaultProps?: Partial<P> | undefined
|
|
2888
|
+
defaultProps?: MaybeAccessor<Partial<P> & DataAttrs> | undefined
|
|
2815
2889
|
}
|
|
2816
2890
|
|
|
2817
2891
|
type ElementType = keyof JSX.IntrinsicElements | Component<any>
|
|
@@ -2831,7 +2905,7 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2831
2905
|
: never
|
|
2832
2906
|
|
|
2833
2907
|
type StyleContextProvider<T extends ElementType, R extends SlotRecipe> = Component<
|
|
2834
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
2908
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
2835
2909
|
>
|
|
2836
2910
|
|
|
2837
2911
|
type StyleContextRootProvider<T extends ElementType, R extends SlotRecipe> = Component<
|
|
@@ -2839,7 +2913,7 @@ function generateSolidCreateStyleContext(ctx) {
|
|
|
2839
2913
|
>
|
|
2840
2914
|
|
|
2841
2915
|
type StyleContextConsumer<T extends ElementType> = Component<
|
|
2842
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps, JsxStyleProps>
|
|
2916
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, JsxStyleProps>
|
|
2843
2917
|
>
|
|
2844
2918
|
|
|
2845
2919
|
export interface StyleContext<R extends SlotRecipe> {
|
|
@@ -3225,6 +3299,8 @@ interface Dict {
|
|
|
3225
3299
|
[k: string]: unknown
|
|
3226
3300
|
}
|
|
3227
3301
|
|
|
3302
|
+
export type DataAttrs = Record<\`data-\${string}\`, unknown>
|
|
3303
|
+
|
|
3228
3304
|
export interface UnstyledProps {
|
|
3229
3305
|
/**
|
|
3230
3306
|
* Whether to remove recipe styles
|
|
@@ -3249,7 +3325,7 @@ interface RecipeFn {
|
|
|
3249
3325
|
|
|
3250
3326
|
export interface JsxFactoryOptions<TProps extends Dict> {
|
|
3251
3327
|
dataAttr?: boolean
|
|
3252
|
-
defaultProps?: Partial<TProps>
|
|
3328
|
+
defaultProps?: Partial<TProps> & DataAttrs
|
|
3253
3329
|
shouldForwardProp?: (prop: string, variantKeys: string[]) => boolean
|
|
3254
3330
|
forwardProps?: string[]
|
|
3255
3331
|
}
|
|
@@ -3297,7 +3373,22 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3297
3373
|
export function createStyleContext(recipe) {
|
|
3298
3374
|
const StyleContext = Symbol('StyleContext')
|
|
3299
3375
|
const isConfigRecipe = '__recipe__' in recipe
|
|
3376
|
+
const recipeName = isConfigRecipe && recipe.__name__ ? recipe.__name__ : undefined
|
|
3377
|
+
const contextName = recipeName ? \`createStyleContext("\${recipeName}")\` : 'createStyleContext'
|
|
3300
3378
|
const svaFn = isConfigRecipe ? recipe : sva(recipe.config)
|
|
3379
|
+
|
|
3380
|
+
function useStyleContext(componentName, slot) {
|
|
3381
|
+
const context = inject(StyleContext)
|
|
3382
|
+
if (context === undefined) {
|
|
3383
|
+
const componentInfo = componentName ? \`Component "\${componentName}"\` : 'A component'
|
|
3384
|
+
const slotInfo = slot ? \` (slot: "\${slot}")\` : ''
|
|
3385
|
+
|
|
3386
|
+
throw new Error(
|
|
3387
|
+
\`\${componentInfo}\${slotInfo} cannot access \${contextName} because it's missing its Provider.\`
|
|
3388
|
+
)
|
|
3389
|
+
}
|
|
3390
|
+
return context
|
|
3391
|
+
}
|
|
3301
3392
|
|
|
3302
3393
|
const getResolvedProps = (props, slotStyles) => {
|
|
3303
3394
|
const { unstyled, ...restProps } = props
|
|
@@ -3380,6 +3471,7 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3380
3471
|
|
|
3381
3472
|
const withContext = (Component, slot, options) => {
|
|
3382
3473
|
const StyledComponent = ${factoryName}(Component, {}, options)
|
|
3474
|
+
const componentName = getDisplayName(Component)
|
|
3383
3475
|
|
|
3384
3476
|
const WithContext = defineComponent({
|
|
3385
3477
|
props: ["unstyled"],
|
|
@@ -3390,7 +3482,7 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3390
3482
|
propsWithClass.class = propsWithClass.class ?? options?.defaultProps?.class
|
|
3391
3483
|
return propsWithClass
|
|
3392
3484
|
})
|
|
3393
|
-
const slotStyles =
|
|
3485
|
+
const slotStyles = useStyleContext(componentName, slot)
|
|
3394
3486
|
|
|
3395
3487
|
return () => {
|
|
3396
3488
|
const resolvedProps = getResolvedProps(props.value, slotStyles.value[slot])
|
|
@@ -3400,7 +3492,6 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3400
3492
|
},
|
|
3401
3493
|
})
|
|
3402
3494
|
|
|
3403
|
-
const componentName = getDisplayName(Component)
|
|
3404
3495
|
WithContext.displayName = \`withContext(\${componentName})\`
|
|
3405
3496
|
|
|
3406
3497
|
return WithContext
|
|
@@ -3416,7 +3507,7 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3416
3507
|
dts: outdent40`
|
|
3417
3508
|
${ctx.file.importType("SlotRecipeRuntimeFn, RecipeVariantProps", "../types/recipe")}
|
|
3418
3509
|
${ctx.file.importType("JsxHTMLProps, JsxStyleProps, Assign", "../types/system-types")}
|
|
3419
|
-
${ctx.file.importType("JsxFactoryOptions", "../types/jsx")}
|
|
3510
|
+
${ctx.file.importType("JsxFactoryOptions, DataAttrs, AsProps", "../types/jsx")}
|
|
3420
3511
|
import type { Component, FunctionalComponent, NativeElements } from 'vue'
|
|
3421
3512
|
|
|
3422
3513
|
interface UnstyledProps {
|
|
@@ -3424,7 +3515,7 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3424
3515
|
}
|
|
3425
3516
|
|
|
3426
3517
|
interface WithProviderOptions<P = {}> {
|
|
3427
|
-
defaultProps?: Partial<P> | undefined
|
|
3518
|
+
defaultProps?: (Partial<P> & DataAttrs) | undefined
|
|
3428
3519
|
}
|
|
3429
3520
|
|
|
3430
3521
|
// Add v-model support types
|
|
@@ -3453,7 +3544,7 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3453
3544
|
: never
|
|
3454
3545
|
|
|
3455
3546
|
type StyleContextProvider<T extends ElementType, R extends SlotRecipe> = FunctionalComponent<
|
|
3456
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps & VModelProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
3547
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps & VModelProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
|
|
3457
3548
|
>
|
|
3458
3549
|
|
|
3459
3550
|
type StyleContextRootProvider<T extends ElementType, R extends SlotRecipe> = FunctionalComponent<
|
|
@@ -3461,7 +3552,7 @@ function generateVueCreateStyleContext(ctx) {
|
|
|
3461
3552
|
>
|
|
3462
3553
|
|
|
3463
3554
|
type StyleContextConsumer<T extends ElementType> = FunctionalComponent<
|
|
3464
|
-
JsxHTMLProps<ComponentProps<T> & UnstyledProps & VModelProps, JsxStyleProps>
|
|
3555
|
+
JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps & VModelProps, JsxStyleProps>
|
|
3465
3556
|
>
|
|
3466
3557
|
|
|
3467
3558
|
export interface StyleContext<R extends SlotRecipe> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pandacss/generator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "The css generator for css panda",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"outdent": " ^0.8.0",
|
|
38
38
|
"pluralize": "8.0.0",
|
|
39
39
|
"postcss": "8.5.6",
|
|
40
|
-
"ts-pattern": "5.
|
|
41
|
-
"@pandacss/core": "1.
|
|
42
|
-
"@pandacss/is-valid-prop": "^1.
|
|
43
|
-
"@pandacss/logger": "1.
|
|
44
|
-
"@pandacss/shared": "1.
|
|
45
|
-
"@pandacss/token-dictionary": "1.
|
|
46
|
-
"@pandacss/types": "1.
|
|
40
|
+
"ts-pattern": "5.9.0",
|
|
41
|
+
"@pandacss/core": "1.5.1",
|
|
42
|
+
"@pandacss/is-valid-prop": "^1.5.1",
|
|
43
|
+
"@pandacss/logger": "1.5.1",
|
|
44
|
+
"@pandacss/shared": "1.5.1",
|
|
45
|
+
"@pandacss/token-dictionary": "1.5.1",
|
|
46
|
+
"@pandacss/types": "1.5.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/pluralize": "0.0.33"
|