1 | "use client";
|
2 |
|
3 | import * as React from 'react';
|
4 | import { useContext, useMemo } from 'react';
|
5 | import { jsx as _jsx } from "react/jsx-runtime";
|
6 | export const DEFAULT_BREAKPOINTS = ['xxl', 'xl', 'lg', 'md', 'sm', 'xs'];
|
7 | export const DEFAULT_MIN_BREAKPOINT = 'xs';
|
8 | const ThemeContext = React.createContext({
|
9 | prefixes: {},
|
10 | breakpoints: DEFAULT_BREAKPOINTS,
|
11 | minBreakpoint: DEFAULT_MIN_BREAKPOINT
|
12 | });
|
13 | const {
|
14 | Consumer,
|
15 | Provider
|
16 | } = ThemeContext;
|
17 | function ThemeProvider({
|
18 | prefixes = {},
|
19 | breakpoints = DEFAULT_BREAKPOINTS,
|
20 | minBreakpoint = DEFAULT_MIN_BREAKPOINT,
|
21 | dir,
|
22 | children
|
23 | }) {
|
24 | const contextValue = useMemo(() => ({
|
25 | prefixes: {
|
26 | ...prefixes
|
27 | },
|
28 | breakpoints,
|
29 | minBreakpoint,
|
30 | dir
|
31 | }), [prefixes, breakpoints, minBreakpoint, dir]);
|
32 | return _jsx(Provider, {
|
33 | value: contextValue,
|
34 | children: children
|
35 | });
|
36 | }
|
37 | export function useBootstrapPrefix(prefix, defaultPrefix) {
|
38 | const {
|
39 | prefixes
|
40 | } = useContext(ThemeContext);
|
41 | return prefix || prefixes[defaultPrefix] || defaultPrefix;
|
42 | }
|
43 | export function useBootstrapBreakpoints() {
|
44 | const {
|
45 | breakpoints
|
46 | } = useContext(ThemeContext);
|
47 | return breakpoints;
|
48 | }
|
49 | export function useBootstrapMinBreakpoint() {
|
50 | const {
|
51 | minBreakpoint
|
52 | } = useContext(ThemeContext);
|
53 | return minBreakpoint;
|
54 | }
|
55 | export function useIsRTL() {
|
56 | const {
|
57 | dir
|
58 | } = useContext(ThemeContext);
|
59 | return dir === 'rtl';
|
60 | }
|
61 | function createBootstrapComponent(Component, opts) {
|
62 | if (typeof opts === 'string') opts = {
|
63 | prefix: opts
|
64 | };
|
65 | const isClassy = Component.prototype && Component.prototype.isReactComponent;
|
66 |
|
67 | const {
|
68 | prefix,
|
69 | forwardRefAs = isClassy ? 'ref' : 'innerRef'
|
70 | } = opts;
|
71 | const Wrapped = React.forwardRef(({
|
72 | ...props
|
73 | }, ref) => {
|
74 | props[forwardRefAs] = ref;
|
75 | const bsPrefix = useBootstrapPrefix(props.bsPrefix, prefix);
|
76 | return _jsx(Component, {
|
77 | ...props,
|
78 | bsPrefix: bsPrefix
|
79 | });
|
80 | });
|
81 | Wrapped.displayName = `Bootstrap(${Component.displayName || Component.name})`;
|
82 | return Wrapped;
|
83 | }
|
84 | export { createBootstrapComponent, Consumer as ThemeConsumer };
|
85 | export default ThemeProvider; |
\ | No newline at end of file |