96 lines
3.5 KiB
JavaScript
Executable File
96 lines
3.5 KiB
JavaScript
Executable File
"use strict";
|
|
"use client";
|
|
|
|
exports.__esModule = true;
|
|
exports.ThemeConsumer = exports.DEFAULT_MIN_BREAKPOINT = exports.DEFAULT_BREAKPOINTS = void 0;
|
|
exports.createBootstrapComponent = createBootstrapComponent;
|
|
exports.default = void 0;
|
|
exports.useBootstrapBreakpoints = useBootstrapBreakpoints;
|
|
exports.useBootstrapMinBreakpoint = useBootstrapMinBreakpoint;
|
|
exports.useBootstrapPrefix = useBootstrapPrefix;
|
|
exports.useIsRTL = useIsRTL;
|
|
var _react = _interopRequireWildcard(require("react"));
|
|
var React = _react;
|
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
const DEFAULT_BREAKPOINTS = exports.DEFAULT_BREAKPOINTS = ['xxl', 'xl', 'lg', 'md', 'sm', 'xs'];
|
|
const DEFAULT_MIN_BREAKPOINT = exports.DEFAULT_MIN_BREAKPOINT = 'xs';
|
|
const ThemeContext = /*#__PURE__*/React.createContext({
|
|
prefixes: {},
|
|
breakpoints: DEFAULT_BREAKPOINTS,
|
|
minBreakpoint: DEFAULT_MIN_BREAKPOINT
|
|
});
|
|
const {
|
|
Consumer,
|
|
Provider
|
|
} = ThemeContext;
|
|
exports.ThemeConsumer = Consumer;
|
|
function ThemeProvider({
|
|
prefixes = {},
|
|
breakpoints = DEFAULT_BREAKPOINTS,
|
|
minBreakpoint = DEFAULT_MIN_BREAKPOINT,
|
|
dir,
|
|
children
|
|
}) {
|
|
const contextValue = (0, _react.useMemo)(() => ({
|
|
prefixes: {
|
|
...prefixes
|
|
},
|
|
breakpoints,
|
|
minBreakpoint,
|
|
dir
|
|
}), [prefixes, breakpoints, minBreakpoint, dir]);
|
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Provider, {
|
|
value: contextValue,
|
|
children: children
|
|
});
|
|
}
|
|
function useBootstrapPrefix(prefix, defaultPrefix) {
|
|
const {
|
|
prefixes
|
|
} = (0, _react.useContext)(ThemeContext);
|
|
return prefix || prefixes[defaultPrefix] || defaultPrefix;
|
|
}
|
|
function useBootstrapBreakpoints() {
|
|
const {
|
|
breakpoints
|
|
} = (0, _react.useContext)(ThemeContext);
|
|
return breakpoints;
|
|
}
|
|
function useBootstrapMinBreakpoint() {
|
|
const {
|
|
minBreakpoint
|
|
} = (0, _react.useContext)(ThemeContext);
|
|
return minBreakpoint;
|
|
}
|
|
function useIsRTL() {
|
|
const {
|
|
dir
|
|
} = (0, _react.useContext)(ThemeContext);
|
|
return dir === 'rtl';
|
|
}
|
|
function createBootstrapComponent(Component, opts) {
|
|
if (typeof opts === 'string') opts = {
|
|
prefix: opts
|
|
};
|
|
const isClassy = Component.prototype && Component.prototype.isReactComponent;
|
|
// If it's a functional component make sure we don't break it with a ref
|
|
const {
|
|
prefix,
|
|
forwardRefAs = isClassy ? 'ref' : 'innerRef'
|
|
} = opts;
|
|
const Wrapped = /*#__PURE__*/React.forwardRef(({
|
|
...props
|
|
}, ref) => {
|
|
props[forwardRefAs] = ref;
|
|
const bsPrefix = useBootstrapPrefix(props.bsPrefix, prefix);
|
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
...props,
|
|
bsPrefix: bsPrefix
|
|
});
|
|
});
|
|
Wrapped.displayName = `Bootstrap(${Component.displayName || Component.name})`;
|
|
return Wrapped;
|
|
}
|
|
var _default = exports.default = ThemeProvider; |