@rbxts/uiblox 0.1.44 → 0.1.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,11 @@
1
1
  import React, { PropsWithChildren } from "@rbxts/react";
2
- import { ThemeDispatch, ThemeState } from "../types/index";
3
2
  import { Theme } from "../interfaces/index";
4
3
  export declare const ThemeContext: React.Context<{
5
- state: ThemeState;
6
- dispatch: ThemeDispatch | undefined;
4
+ theme: Theme;
5
+ setTheme?: React.Dispatch<React.SetStateAction<Theme>>;
7
6
  }>;
8
7
  export interface ThemeProviderProps {
9
- theme?: Theme;
8
+ initialTheme?: Theme;
10
9
  }
11
10
  export declare function ThemeProvider(props: PropsWithChildren<ThemeProviderProps>): JSX.Element;
12
- export default ThemeContext;
11
+ export default ThemeProvider;
@@ -0,0 +1,34 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ local TS = _G[script]
3
+ local _react = TS.import(script, TS.getModule(script, "@rbxts", "react"))
4
+ local React = _react
5
+ local useEffect = _react.useEffect
6
+ local useMemo = _react.useMemo
7
+ local useState = _react.useState
8
+ local DEFAULT_THEME = TS.import(script, script.Parent.Parent, "constants").DEFAULT_THEME
9
+ local ThemeContext = React.createContext({
10
+ theme = DEFAULT_THEME,
11
+ })
12
+ local function ThemeProvider(props)
13
+ local _binding = props
14
+ local initialTheme = _binding.initialTheme
15
+ local theme, setTheme = useState(initialTheme or DEFAULT_THEME)
16
+ useEffect(function()
17
+ setTheme(initialTheme or DEFAULT_THEME)
18
+ end, { initialTheme })
19
+ local memoizedValue = useMemo(function()
20
+ return {
21
+ theme = theme,
22
+ setTheme = setTheme,
23
+ }
24
+ end, { theme })
25
+ return React.createElement(ThemeContext.Provider, {
26
+ value = memoizedValue,
27
+ }, props.children)
28
+ end
29
+ local default = ThemeProvider
30
+ return {
31
+ ThemeProvider = ThemeProvider,
32
+ ThemeContext = ThemeContext,
33
+ default = default,
34
+ }
@@ -1,3 +1,2 @@
1
- export { default as ThemeContext } from "./provider";
2
- export * from "./provider";
3
- export { default as themeReducer } from "./reducer";
1
+ export { default as ThemeProvider } from "./ThemeProvider";
2
+ export * from "./ThemeProvider";
@@ -1,9 +1,8 @@
1
1
  -- Compiled with roblox-ts v3.0.0
2
2
  local TS = _G[script]
3
3
  local exports = {}
4
- exports.ThemeContext = TS.import(script, script, "provider").default
5
- for _k, _v in TS.import(script, script, "provider") or {} do
4
+ exports.ThemeProvider = TS.import(script, script, "ThemeProvider").default
5
+ for _k, _v in TS.import(script, script, "ThemeProvider") or {} do
6
6
  exports[_k] = _v
7
7
  end
8
- exports.themeReducer = TS.import(script, script, "reducer").default
9
8
  return exports
@@ -1,5 +1,4 @@
1
- declare function useTheme(): {
2
- state: import("../index").ThemeState;
3
- dispatch: import("../index").ThemeDispatch | undefined;
1
+ export default function useTheme(): {
2
+ theme: import("../index").Theme;
3
+ setTheme?: import("@rbxts/react").Dispatch<import("@rbxts/react").SetStateAction<import("..").Theme>>;
4
4
  };
5
- export default useTheme;
@@ -3,13 +3,8 @@ local TS = _G[script]
3
3
  local useContext = TS.import(script, TS.getModule(script, "@rbxts", "react")).useContext
4
4
  local ThemeContext = TS.import(script, script.Parent.Parent, "context").ThemeContext
5
5
  local function useTheme()
6
- local context = useContext(ThemeContext)
7
- if not context then
8
- error(error("Missing ThemeProvider"))
9
- end
10
- return context
6
+ return useContext(ThemeContext)
11
7
  end
12
- local default = useTheme
13
8
  return {
14
- default = default,
9
+ default = useTheme,
15
10
  }
@@ -1,10 +1,9 @@
1
1
  export { default as Theme } from "./interfaces/theme/Theme";
2
- export { useThemeCallbacks } from "./callbacks/index";
3
2
  export * from "./constants/index";
4
3
  export { DEFAULT_THEME } from "./constants/index";
5
4
  export * from "./context/index";
6
5
  export { ThemeProvider } from "./context/index";
7
- export { themeReducer } from "./context/index";
6
+ export { ThemeContext } from "./context/index";
8
7
  export * from "./enums/index";
9
8
  export { useTheme } from "./hooks/index";
10
9
  export * from "./interfaces/index";
@@ -1,7 +1,6 @@
1
1
  -- Compiled with roblox-ts v3.0.0
2
2
  local TS = _G[script]
3
3
  local exports = {}
4
- exports.useThemeCallbacks = TS.import(script, script, "callbacks").useThemeCallbacks
5
4
  for _k, _v in TS.import(script, script, "constants") or {} do
6
5
  exports[_k] = _v
7
6
  end
@@ -10,7 +9,7 @@ for _k, _v in TS.import(script, script, "context") or {} do
10
9
  exports[_k] = _v
11
10
  end
12
11
  exports.ThemeProvider = TS.import(script, script, "context").ThemeProvider
13
- exports.themeReducer = TS.import(script, script, "context").themeReducer
12
+ exports.ThemeContext = TS.import(script, script, "context").ThemeContext
14
13
  for _k, _v in TS.import(script, script, "enums") or {} do
15
14
  exports[_k] = _v
16
15
  end
@@ -6,9 +6,7 @@ local makeStyles = function(f)
6
6
  return function(props)
7
7
  local _exitType, _returns = TS.try(function()
8
8
  local _binding = useTheme()
9
- local state = _binding.state
10
- local _binding_1 = state
11
- local theme = _binding_1.theme
9
+ local theme = _binding.theme
12
10
  local _fn = f
13
11
  local _exp = theme or DefaultTheme
14
12
  local _condition = props
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/uiblox",
3
- "version": "0.1.44",
3
+ "version": "0.1.46",
4
4
  "description": "UI Library and theming for roblox-ts projects",
5
5
  "main": "out/init.lua",
6
6
  "scripts": {
@@ -1 +0,0 @@
1
- export { default as useThemeCallbacks } from "./useThemeCallbacks";
@@ -1,5 +0,0 @@
1
- -- Compiled with roblox-ts v3.0.0
2
- local TS = _G[script]
3
- local exports = {}
4
- exports.useThemeCallbacks = TS.import(script, script, "useThemeCallbacks").default
5
- return exports
@@ -1,7 +0,0 @@
1
- import { Theme } from "../interfaces/index";
2
- declare function useThemeCallbacks(): {
3
- onSetTheme: (theme: Theme) => void;
4
- } | {
5
- onSetTheme?: undefined;
6
- };
7
- export default useThemeCallbacks;
@@ -1,23 +0,0 @@
1
- -- Compiled with roblox-ts v3.0.0
2
- local TS = _G[script]
3
- local useMemo = TS.import(script, TS.getModule(script, "@rbxts", "react")).useMemo
4
- local ThemeActionTypes = TS.import(script, script.Parent.Parent, "enums").ThemeActionTypes
5
- local useTheme = TS.import(script, script.Parent.Parent, "hooks").useTheme
6
- local function useThemeCallbacks()
7
- local _binding = useTheme()
8
- local dispatch = _binding.dispatch
9
- return useMemo(function()
10
- return if dispatch then {
11
- onSetTheme = function(theme)
12
- return dispatch({
13
- type = ThemeActionTypes.SetTheme,
14
- theme = theme,
15
- })
16
- end,
17
- } else {}
18
- end, { dispatch })
19
- end
20
- local default = useThemeCallbacks
21
- return {
22
- default = default,
23
- }
@@ -1,38 +0,0 @@
1
- -- Compiled with roblox-ts v3.0.0
2
- local TS = _G[script]
3
- local _react = TS.import(script, TS.getModule(script, "@rbxts", "react"))
4
- local React = _react
5
- local useEffect = _react.useEffect
6
- local useReducer = _react.useReducer
7
- local themeReducer = TS.import(script, script.Parent, "reducer").default
8
- local INITIAL_THEME_STATE = TS.import(script, script.Parent.Parent, "constants").INITIAL_THEME_STATE
9
- local ThemeActionTypes = TS.import(script, script.Parent.Parent, "enums").ThemeActionTypes
10
- local ThemeContext = React.createContext({
11
- state = INITIAL_THEME_STATE,
12
- dispatch = nil,
13
- })
14
- local function ThemeProvider(props)
15
- local _binding = props
16
- local theme = _binding.theme
17
- local _object = table.clone(INITIAL_THEME_STATE)
18
- setmetatable(_object, nil)
19
- _object.theme = theme or INITIAL_THEME_STATE.theme
20
- local state, dispatch = useReducer(themeReducer, _object)
21
- useEffect(function()
22
- dispatch({
23
- type = ThemeActionTypes.Hydrate,
24
- })
25
- end, { dispatch })
26
- return React.createElement(ThemeContext.Provider, {
27
- value = {
28
- state = state,
29
- dispatch = dispatch,
30
- },
31
- }, props.children)
32
- end
33
- local default = ThemeContext
34
- return {
35
- ThemeProvider = ThemeProvider,
36
- ThemeContext = ThemeContext,
37
- default = default,
38
- }
@@ -1,3 +0,0 @@
1
- import { ThemeAction, ThemeState } from "../types/index";
2
- declare function themeReducer(state: ThemeState | undefined, action: ThemeAction): ThemeState;
3
- export default themeReducer;
@@ -1,26 +0,0 @@
1
- -- Compiled with roblox-ts v3.0.0
2
- local TS = _G[script]
3
- local INITIAL_THEME_STATE = TS.import(script, script.Parent.Parent, "constants").INITIAL_THEME_STATE
4
- local ThemeActionTypes = TS.import(script, script.Parent.Parent, "enums").ThemeActionTypes
5
- local function themeReducer(state, action)
6
- if action.type == ThemeActionTypes.Hydrate then
7
- local _object = table.clone(INITIAL_THEME_STATE)
8
- setmetatable(_object, nil)
9
- _object.theme = action.theme or INITIAL_THEME_STATE.theme
10
- return _object
11
- end
12
- if not state then
13
- error(error("State is undefined"))
14
- end
15
- if action.type == ThemeActionTypes.SetTheme then
16
- local _object = table.clone(state)
17
- setmetatable(_object, nil)
18
- _object.theme = action.theme
19
- return _object
20
- end
21
- error(error(`Unhandled action type: {action}`))
22
- end
23
- local default = themeReducer
24
- return {
25
- default = default,
26
- }