@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.
- package/dist/components/client/index.d.mts +6 -23
- package/dist/components/client/index.d.ts +6 -23
- package/dist/components/client/index.js +7 -61
- package/dist/components/client/index.js.map +1 -1
- package/dist/components/client/index.mjs +9 -61
- package/dist/components/client/index.mjs.map +1 -1
- package/dist/components/index.d.mts +8 -1
- package/dist/components/index.d.ts +8 -1
- package/dist/components/index.js +33 -0
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +33 -1
- package/dist/components/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/components/404-page.tsx +7 -4
- package/src/components/client/index.ts +0 -3
- package/src/components/index.ts +2 -0
- package/src/components/site-icon.tsx +29 -37
- package/src/components/icon-context.tsx +0 -57
@@ -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
|
-
*
|
11
|
-
*
|
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
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
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
|
-
}
|