mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 07:26:02 +01:00
feat(web): primary colour and shade convars
This commit is contained in:
32
web/src/providers/ConfigProvider.tsx
Normal file
32
web/src/providers/ConfigProvider.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Context, createContext, useContext, useEffect, useState } from 'react';
|
||||
import { MantineColor } from '@mantine/core';
|
||||
import { fetchNui } from '../utils/fetchNui';
|
||||
|
||||
interface Config {
|
||||
primaryColor: MantineColor;
|
||||
primaryShade: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
||||
}
|
||||
|
||||
interface ConfigCtxValue {
|
||||
config: Config;
|
||||
setConfig: (config: Config) => void;
|
||||
}
|
||||
|
||||
const ConfigCtx = createContext<{ config: Config; setConfig: (config: Config) => void } | null>(null);
|
||||
|
||||
const ConfigProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const [config, setConfig] = useState<Config>({
|
||||
primaryColor: 'blue',
|
||||
primaryShade: 6,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
fetchNui<Config>('getConfig').then((data) => setConfig(data));
|
||||
}, []);
|
||||
|
||||
return <ConfigCtx.Provider value={{ config, setConfig }}>{children}</ConfigCtx.Provider>;
|
||||
};
|
||||
|
||||
export default ConfigProvider;
|
||||
|
||||
export const useConfig = () => useContext<ConfigCtxValue>(ConfigCtx as Context<ConfigCtxValue>);
|
||||
Reference in New Issue
Block a user