@windrun-huaiin/base-ui 4.1.1 → 5.0.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,46 +1,38 @@
1
- 'use client';
2
-
3
1
  import { type LucideProps } from 'lucide-react';
4
2
  import { cn } from '@lib/utils';
5
- import { useIconConfigSafe } from '@base-ui/components/icon-context';
6
3
  import { globalLucideIcons } from '@base-ui/components/global-icon';
7
4
  import { themeIconColor } from '@base-ui/lib/theme-util';
8
5
 
9
6
  /**
10
- * site icon component - client component
11
- * based on React Context to get the config, solve the problem of cross-package module instance isolation
7
+ * Create a SiteIcon component with specific configuration
8
+ * This function helps avoid React multi-instance issues by creating the icon component
9
+ * at the application level with explicit configuration
12
10
  */
13
- export function SiteIcon({
14
- size = 24,
15
- className,
16
- ...props
17
- }: Omit<LucideProps, 'children'>) {
18
- const configuredIcon = useIconConfigSafe('siteIcon');
19
-
20
- if (configuredIcon === undefined) {
21
- throw new Error(
22
- '[SiteIcon] Site icon is not configured. Please use <IconConfigProvider config={{ siteIcon: YourCustomIcon }}> or <IconConfigProvider config={{ siteIcon: "IconKeyName" }}> to set a custom site icon to avoid legal risks.'
23
- );
24
- }
25
-
26
- // render the icon, pass in the config value and attributes
27
- if (typeof configuredIcon === 'string') {
28
- // string type: the key name of globalLucideIcons
29
- if (configuredIcon === '') {
30
- // empty string use default icon
31
- const DefaultIcon = globalLucideIcons['Download' as keyof typeof globalLucideIcons];
32
- return <DefaultIcon size={size} className={cn(themeIconColor, className)} {...props} />;
33
- }
34
- const IconComponent = globalLucideIcons[configuredIcon as keyof typeof globalLucideIcons];
35
- if (!IconComponent) {
36
- throw new Error(`[SiteIcon] Icon key "${configuredIcon}" not found in globalLucideIcons.`);
11
+ export function createSiteIcon(iconConfig: string | React.ComponentType<LucideProps>) {
12
+ return function CreatedSiteIcon({
13
+ size = 24,
14
+ className,
15
+ ...props
16
+ }: Omit<LucideProps, 'children'>) {
17
+ // render the icon, pass in the config value and attributes
18
+ if (typeof iconConfig === 'string') {
19
+ // string type: the key name of globalLucideIcons
20
+ if (iconConfig === '') {
21
+ // empty string use default icon
22
+ const DefaultIcon = globalLucideIcons['Download' as keyof typeof globalLucideIcons];
23
+ return <DefaultIcon size={size} className={cn(themeIconColor, className)} {...props} />;
24
+ }
25
+ const IconComponent = globalLucideIcons[iconConfig as keyof typeof globalLucideIcons];
26
+ if (!IconComponent) {
27
+ throw new Error(`[CreatedSiteIcon] Icon key "${iconConfig}" not found in globalLucideIcons.`);
28
+ }
29
+ return <IconComponent size={size} className={cn(themeIconColor, className)} {...props} />;
30
+ } else {
31
+ // React component type: custom icon component
32
+ const CustomIcon = iconConfig as React.ComponentType<LucideProps>;
33
+ const hasColorClass = className && /text-\w+/.test(className);
34
+ const finalClassName = hasColorClass ? className : cn(themeIconColor, className);
35
+ return <CustomIcon size={size} className={finalClassName} {...props} />;
37
36
  }
38
- return <IconComponent size={size} className={cn(themeIconColor, className)} {...props} />;
39
- } else {
40
- // React component type: custom icon component
41
- const CustomIcon = configuredIcon as React.ComponentType<LucideProps>;
42
- const hasColorClass = className && /text-\w+/.test(className);
43
- const finalClassName = hasColorClass ? className : cn(themeIconColor, className);
44
- return <CustomIcon size={size} className={finalClassName} {...props} />;
45
- }
37
+ };
46
38
  }
@@ -1,57 +0,0 @@
1
- 'use client';
2
-
3
- import { createContext, useContext, type ComponentType, type ReactNode } from 'react';
4
-
5
- export interface IconConfig {
6
- siteIcon?: ComponentType | string;
7
- }
8
-
9
- // icon config context, directly store the config value
10
- const IconConfigContext = createContext<IconConfig | null>(null);
11
-
12
- interface IconConfigProviderProps {
13
- config: IconConfig;
14
- children: ReactNode;
15
- }
16
-
17
- /**
18
- * IconConfigProvider - icon config provider based on React Context
19
- * directly store the config value, without depending on module state
20
- */
21
- export function IconConfigProvider({ config, children }: IconConfigProviderProps) {
22
- return (
23
- <IconConfigContext.Provider value={config}>
24
- {children}
25
- </IconConfigContext.Provider>
26
- );
27
- }
28
-
29
- /**
30
- * internal hook: get icon config
31
- * not exposed, only used by base-ui internal components
32
- */
33
- function useIconConfig(): IconConfig {
34
- const config = useContext(IconConfigContext);
35
-
36
- if (config === null) {
37
- throw new Error(
38
- '[SiteIcon] IconConfigProvider not found. Please wrap your app with <IconConfigProvider config={{ siteIcon: "YourIcon" }}>.'
39
- );
40
- }
41
-
42
- return config;
43
- }
44
-
45
- /**
46
- * internal hook: safe get specific icon config
47
- * not exposed, only used by base-ui internal components
48
- */
49
- export function useIconConfigSafe(iconKey: keyof IconConfig): ComponentType | string | undefined {
50
- try {
51
- const config = useIconConfig();
52
- return config[iconKey];
53
- } catch {
54
- // if there is no provider, return undefined, let the caller handle it
55
- return undefined;
56
- }
57
- }