@likec4/styles 1.44.0 → 1.46.0

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.
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable */
2
2
  import type { SlotRecipeRuntimeFn, RecipeVariantProps } from '../types/recipe';
3
3
  import type { JsxHTMLProps, JsxStyleProps, Assign } from '../types/system-types';
4
- import type { JsxFactoryOptions, ComponentProps } from '../types/jsx';
4
+ import type { JsxFactoryOptions, ComponentProps, DataAttrs, AsProps } from '../types/jsx';
5
5
  import type { ComponentType, ElementType } from 'react'
6
6
 
7
7
  interface UnstyledProps {
@@ -19,11 +19,11 @@ type SlotRecipe = SvaFn | SlotRecipeFn
19
19
  type InferSlot<R extends SlotRecipe> = R extends SlotRecipeFn ? R['__slot'] : R extends SvaFn<infer S> ? S : never
20
20
 
21
21
  interface WithProviderOptions<P = {}> {
22
- defaultProps?: Partial<P> | undefined
22
+ defaultProps?: (Partial<P> & DataAttrs) | undefined
23
23
  }
24
24
 
25
25
  type StyleContextProvider<T extends ElementType, R extends SlotRecipe> = ComponentType<
26
- JsxHTMLProps<ComponentProps<T> & UnstyledProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
26
+ JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, Assign<RecipeVariantProps<R>, JsxStyleProps>>
27
27
  >
28
28
 
29
29
  type StyleContextRootProvider<T extends ElementType, R extends SlotRecipe> = ComponentType<
@@ -31,7 +31,7 @@ type StyleContextRootProvider<T extends ElementType, R extends SlotRecipe> = Com
31
31
  >
32
32
 
33
33
  type StyleContextConsumer<T extends ElementType> = ComponentType<
34
- JsxHTMLProps<ComponentProps<T> & UnstyledProps, JsxStyleProps>
34
+ JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, JsxStyleProps>
35
35
  >
36
36
 
37
37
  export interface StyleContext<R extends SlotRecipe> {
@@ -5,9 +5,29 @@ import { styled } from './factory.mjs';
5
5
  import { getDisplayName } from './factory-helper.mjs';
6
6
  import { createContext, useContext, createElement, forwardRef } from 'react'
7
7
 
8
+ function createSafeContext(contextName) {
9
+ const Context = createContext(undefined)
10
+ const useStyleContext = (componentName, slot) => {
11
+ const context = useContext(Context)
12
+ if (context === undefined) {
13
+ const componentInfo = componentName ? `Component "${componentName}"` : 'A component'
14
+ const slotInfo = slot ? ` (slot: "${slot}")` : ''
15
+
16
+ throw new Error(
17
+ `${componentInfo}${slotInfo} cannot access ${contextName} because it's missing its Provider.`
18
+ )
19
+ }
20
+ return context
21
+ }
22
+ return [Context, useStyleContext]
23
+ }
24
+
8
25
  export function createStyleContext(recipe) {
9
- const StyleContext = createContext({})
10
26
  const isConfigRecipe = '__recipe__' in recipe
27
+ const recipeName = isConfigRecipe && recipe.__name__ ? recipe.__name__ : undefined
28
+ const contextName = recipeName ? `createStyleContext("${recipeName}")` : 'createStyleContext'
29
+
30
+ const [StyleContext, useStyleContext] = createSafeContext(contextName)
11
31
  const svaFn = isConfigRecipe ? recipe : sva(recipe.config)
12
32
 
13
33
  const getResolvedProps = (props, slotStyles) => {
@@ -71,9 +91,10 @@ export function createStyleContext(recipe) {
71
91
 
72
92
  const withContext = (Component, slot, options) => {
73
93
  const StyledComponent = styled(Component, {}, options)
94
+ const componentName = getDisplayName(Component)
74
95
 
75
96
  const WithContext = forwardRef((props, ref) => {
76
- const slotStyles = useContext(StyleContext)
97
+ const slotStyles = useStyleContext(componentName, slot)
77
98
 
78
99
  const propsWithClass = { ...props, className: props.className ?? options?.defaultProps?.className }
79
100
  const resolvedProps = getResolvedProps(propsWithClass, slotStyles[slot])
@@ -84,7 +105,6 @@ export function createStyleContext(recipe) {
84
105
  })
85
106
  })
86
107
 
87
- const componentName = getDisplayName(Component)
88
108
  WithContext.displayName = `withContext(${componentName})`
89
109
 
90
110
  return WithContext
package/dist/preset.d.mts CHANGED
@@ -7,6 +7,10 @@ declare const compoundNode: _pandacss_types.RecipeConfig<_pandacss_types.RecipeV
7
7
 
8
8
  declare const edgeActionBtn: _pandacss_types.RecipeConfig<_pandacss_types.RecipeVariantRecord>;
9
9
 
10
+ declare const edgeLabel: _pandacss_types.RecipeConfig<_pandacss_types.RecipeVariantRecord>;
11
+
12
+ declare const edgePath: _pandacss_types.SlotRecipeConfig;
13
+
10
14
  declare const elementNodeData: _pandacss_types.RecipeConfig<_pandacss_types.RecipeVariantRecord>;
11
15
 
12
16
  declare const elementShapeRecipe: _pandacss_types.RecipeConfig<_pandacss_types.RecipeVariantRecord>;
@@ -22,6 +26,8 @@ declare const overlay: _pandacss_types.RecipeConfig<_pandacss_types.RecipeVarian
22
26
  declare const recipes_actionBtn: typeof actionBtn;
23
27
  declare const recipes_compoundNode: typeof compoundNode;
24
28
  declare const recipes_edgeActionBtn: typeof edgeActionBtn;
29
+ declare const recipes_edgeLabel: typeof edgeLabel;
30
+ declare const recipes_edgePath: typeof edgePath;
25
31
  declare const recipes_elementNodeData: typeof elementNodeData;
26
32
  declare const recipes_elementShapeRecipe: typeof elementShapeRecipe;
27
33
  declare const recipes_likec4tag: typeof likec4tag;
@@ -29,17 +35,14 @@ declare const recipes_markdownBlock: typeof markdownBlock;
29
35
  declare const recipes_navigationPanelActionIcon: typeof navigationPanelActionIcon;
30
36
  declare const recipes_overlay: typeof overlay;
31
37
  declare namespace recipes {
32
- export { recipes_actionBtn as actionBtn, recipes_compoundNode as compoundNode, recipes_edgeActionBtn as edgeActionBtn, recipes_elementNodeData as elementNodeData, recipes_elementShapeRecipe as elementShapeRecipe, recipes_likec4tag as likec4tag, recipes_markdownBlock as markdownBlock, recipes_navigationPanelActionIcon as navigationPanelActionIcon, recipes_overlay as overlay };
38
+ export { recipes_actionBtn as actionBtn, recipes_compoundNode as compoundNode, recipes_edgeActionBtn as edgeActionBtn, recipes_edgeLabel as edgeLabel, recipes_edgePath as edgePath, recipes_elementNodeData as elementNodeData, recipes_elementShapeRecipe as elementShapeRecipe, recipes_likec4tag as likec4tag, recipes_markdownBlock as markdownBlock, recipes_navigationPanelActionIcon as navigationPanelActionIcon, recipes_overlay as overlay };
33
39
  }
34
40
 
35
- declare const edgeLabel: _pandacss_types.SlotRecipeConfig;
36
-
37
41
  declare const navigationLink: _pandacss_types.SlotRecipeConfig;
38
42
 
39
- declare const slotRecipes_edgeLabel: typeof edgeLabel;
40
43
  declare const slotRecipes_navigationLink: typeof navigationLink;
41
44
  declare namespace slotRecipes {
42
- export { slotRecipes_edgeLabel as edgeLabel, slotRecipes_navigationLink as navigationLink };
45
+ export { slotRecipes_navigationLink as navigationLink };
43
46
  }
44
47
 
45
48
  declare const theme: {
@@ -1009,6 +1012,16 @@ declare const theme: {
1009
1012
  };
1010
1013
  semanticTokens: {
1011
1014
  colors: {
1015
+ text: {
1016
+ DEFAULT: {
1017
+ description: string;
1018
+ value: "var(--mantine-color-text)";
1019
+ };
1020
+ dimmed: {
1021
+ description: string;
1022
+ value: "var(--mantine-color-dimmed)";
1023
+ };
1024
+ };
1012
1025
  likec4: {
1013
1026
  background: {
1014
1027
  DEFAULT: {
@@ -1060,7 +1073,7 @@ declare const theme: {
1060
1073
  description: string;
1061
1074
  value: {
1062
1075
  base: string;
1063
- _light: string;
1076
+ _light: "var(--mantine-color-gray-2)";
1064
1077
  };
1065
1078
  };
1066
1079
  text: {
@@ -1181,7 +1194,7 @@ declare const theme: {
1181
1194
  outline: {
1182
1195
  value: {
1183
1196
  _light: "var(--mantine-color-orange-8)";
1184
- _dark: "var(--mantine-color-orange-6)";
1197
+ _dark: string;
1185
1198
  };
1186
1199
  };
1187
1200
  };