avent-ui
Version:
The best UI library for Typescript and React
28 lines (25 loc) • 997 B
JavaScript
import { jsx } from 'react/jsx-runtime';
import { useState, createContext, useContext } from 'react';
const ButtonContext = createContext(undefined);
const ButtonProvider = ({ children }) => {
const [isActive, setIsActive] = useState(false);
const [backgroundColor, setBackgroundColor] = useState('rgb(29,29,29)');
const toggleActive = () => setIsActive((prev) => !prev);
const toggleBackgroundColor = (backgroundColor) => setBackgroundColor(backgroundColor);
const value = {
isActive,
toggleActive,
backgroundColor,
toggleBackgroundColor
};
return (jsx(ButtonContext.Provider, { value: value, children: children }));
};
const useButtonContext = () => {
const context = useContext(ButtonContext);
if (context === undefined) {
throw new Error('useButtonContext must be used within a ButtonProvider');
}
return context;
};
export { ButtonProvider, useButtonContext };
//# sourceMappingURL=hammenu-provider.js.map