UNPKG

1.46 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import { jsx as _jsx } from "react/jsx-runtime";
5const defaultContextValue = {
6 disableDefaultClasses: false
7};
8const ClassNameConfiguratorContext = /*#__PURE__*/React.createContext(defaultContextValue);
9if (process.env.NODE_ENV !== 'production') {
10 ClassNameConfiguratorContext.displayName = 'ClassNameConfiguratorContext';
11}
12/**
13 * @ignore - internal hook.
14 *
15 * Wraps the `generateUtilityClass` function and controls how the classes are generated.
16 * Currently it only affects whether the classes are applied or not.
17 *
18 * @returns Function to be called with the `generateUtilityClass` function specific to a component to generate the classes.
19 */
20export function useClassNamesOverride(generateUtilityClass) {
21 const {
22 disableDefaultClasses
23 } = React.useContext(ClassNameConfiguratorContext);
24 return slot => {
25 if (disableDefaultClasses) {
26 return '';
27 }
28 return generateUtilityClass(slot);
29 };
30}
31
32/**
33 * Allows to configure the components within to not apply any built-in classes.
34 */
35export function ClassNameConfigurator(props) {
36 const {
37 disableDefaultClasses,
38 children
39 } = props;
40 const contextValue = React.useMemo(() => ({
41 disableDefaultClasses: disableDefaultClasses != null ? disableDefaultClasses : false
42 }), [disableDefaultClasses]);
43 return /*#__PURE__*/_jsx(ClassNameConfiguratorContext.Provider, {
44 value: contextValue,
45 children: children
46 });
47}
\No newline at end of file