@plasmicapp/react-web 0.2.396 → 0.2.398

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.
@@ -41,7 +41,7 @@ export type Flex<DefaultElementType extends React.ElementType> = (Omit<DefaultOv
41
41
  as?: never;
42
42
  render?: never;
43
43
  }) | ((props: React.ComponentProps<DefaultElementType>) => React.ReactNode);
44
- export declare function hasVariant<V extends Variants>(variants: V | undefined, groupName: keyof V, variant: string): any;
44
+ export declare function hasVariant<V extends Variants>(variants: V | undefined, groupName: keyof V, variant: string): boolean;
45
45
  export declare function wrapFlexContainerChildren(children: React.ReactNode, hasGap: boolean): React.DetailedReactHTMLElement<{
46
46
  className: string;
47
47
  }, HTMLElement> | null;
@@ -1 +1,49 @@
1
- export declare function ensureGlobalVariants<T extends Record<string, any>>(globalVariantValues: T): T;
1
+ export type GlobalVariants = {
2
+ [gv: string]: string | undefined;
3
+ };
4
+ export type UseGlobalVariants = () => GlobalVariants;
5
+ /**
6
+ * Usage:
7
+ * ```
8
+ * // plasmic.ts
9
+ * import { usePlatform } from "./PlasmicGlobalVariant__Platform";
10
+ * import { useTheme } from "./PlasmicGlobalVariant__Theme";
11
+ *
12
+ * export const useGlobalVariants = createUseGlobalVariants({
13
+ * platform: usePlatform,
14
+ * theme: useTheme,
15
+ * });
16
+ *
17
+ * // PlasmicComponent.tsx
18
+ * import { useGlobalVariants } from "./plasmic_project";
19
+ *
20
+ * export function PlasmicComponent() {
21
+ * // ...
22
+ * const globalVariants = useGlobalVariants();
23
+ * // ...
24
+ * }
25
+ * ```
26
+ */
27
+ export declare function createUseGlobalVariants<T extends {
28
+ [gv: string]: () => string | undefined;
29
+ }>(globalVariantHooks: T): UseGlobalVariants;
30
+ /**
31
+ * @deprecated - new generated code should use `useGlobalVariants` instead
32
+ *
33
+ * Usage:
34
+ * ```
35
+ * // PlasmicComponent.tsx
36
+ * import { useTheme } from "./PlasmicGlobalVariant__Theme";
37
+ * import { usePlatform } from "./PlasmicGlobalVariant__Platform";
38
+ *
39
+ * export function PlasmicComponent() {
40
+ * // ...
41
+ * const globalVariants = ensureGlobalVariants({
42
+ * platform: usePlatform(),
43
+ * theme: useTheme(),
44
+ * });
45
+ * // ...
46
+ * }
47
+ * ```
48
+ */
49
+ export declare function ensureGlobalVariants<T extends GlobalVariants>(globalVariants: T): GlobalVariants;
@@ -0,0 +1,114 @@
1
+ import React from "react";
2
+ import { UseGlobalVariants } from "./global-variants";
3
+ type ClassName = string;
4
+ /**
5
+ * All style token data for this project.
6
+ *
7
+ * Usage:
8
+ *
9
+ * ```
10
+ * // PlasmicStyleTokensProvider.ts
11
+ * import { usePlatform } from "./PlasmicGlobalVariant__Platform";
12
+ * import { useTheme } from "./PlasmicGlobalVariant__Theme";
13
+ * import projectcss from "./plasmic.module.css";
14
+ *
15
+ * const projectStyleTokenData: ProjectStyleTokenData = {
16
+ * base: projectcss.plasmic_tokens,
17
+ * varianted: [
18
+ * {
19
+ * className: projectcss.global_platform_windows,
20
+ * groupName: "platform",
21
+ * variant: "windows"
22
+ * },
23
+ * {
24
+ * className: projectcss.global_platform_osx,
25
+ * groupName: "platform",
26
+ * variant: "osx"
27
+ * },
28
+ * {
29
+ * className: projectcss.global_theme_light,
30
+ * groupName: "theme",
31
+ * variant: "light"
32
+ * },
33
+ * {
34
+ * className: projectcss.global_theme_dark,
35
+ * groupName: "theme",
36
+ * variant: "dark"
37
+ * },
38
+ * ],
39
+ * };
40
+ * ```
41
+ */
42
+ interface ProjectStyleTokenData {
43
+ base: ClassName;
44
+ varianted: {
45
+ className: ClassName;
46
+ groupName: string;
47
+ variant: string;
48
+ }[];
49
+ }
50
+ type UseStyleTokens = () => ClassName[];
51
+ /**
52
+ * Returns style tokens. If the context is not available, falls back to the
53
+ * current project's styles.
54
+ *
55
+ * Usage:
56
+ * ```
57
+ * // PlasmicStyleTokensProvider.ts
58
+ * export const useStyleTokens = createUseStyleTokens(
59
+ * projectStyleTokenData,
60
+ * useGlobalVariants,
61
+ * );
62
+ *
63
+ * // PlasmicPage.tsx
64
+ * import { useStyleTokens } from "./plasmic_project";
65
+ *
66
+ * export function PlasmicPage() {
67
+ * const styleTokensClassNames = useStyleTokens();
68
+ * return (
69
+ * <div className={classNames(
70
+ * projectcss.all,
71
+ * projectcss.root_reset,
72
+ * projectcss.plasmic_default_styles,
73
+ * projectcss.plasmic_mixins,
74
+ * styleTokensClassNames,
75
+ * )}>
76
+ * <h1 className={projectcss.all}>
77
+ * Hello, world!
78
+ * </h1>
79
+ * </div>
80
+ * );
81
+ * }
82
+ * ```
83
+ */
84
+ export declare function createUseStyleTokens(tokenData: ProjectStyleTokenData, useGlobalVariants: UseGlobalVariants): UseStyleTokens;
85
+ /**
86
+ * Creates a StyleTokens context provider for a given project, which includes
87
+ * its tokens, overrides, and all tokens from its dependencies.
88
+ *
89
+ * Usage:
90
+ * ```
91
+ * // PlasmicStyleTokensProvider.ts
92
+ * export const StyleTokensProvider = createStyleTokensProvider(
93
+ * projectStyleTokenData,
94
+ * useGlobalVariants,
95
+ * );
96
+ *
97
+ * // Page.tsx
98
+ * import { StyleTokensProvider } from "./plasmic_project";
99
+ *
100
+ * export default function Page() {
101
+ * return (
102
+ * <PlatformContext.Provider value="osx">
103
+ * <ThemeContext.Provider value="dark">
104
+ * <StyleTokensProvider>
105
+ * <PlasmicPage />
106
+ * </StyleTokensProvider>
107
+ * </ThemeContext.Provider>
108
+ * </PlatformContext.Provider>
109
+ * );
110
+ * }
111
+ * ```
112
+ */
113
+ export declare function createStyleTokensProvider(tokenData: ProjectStyleTokenData, useGlobalVariants: UseGlobalVariants): React.ComponentType<React.PropsWithChildren>;
114
+ export {};