@goplusvn/core 0.1.17 → 0.1.18

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.18 — SettingsProvider nhận `defaults` (đổi màu/theme mặc định theo app)
4
+
5
+ Customizer khóa cứng `defaultSettings.theme = "blue"` trong core → app không đặt
6
+ được màu mặc định riêng (vd wu-vpbank muốn "green"). Thêm prop tùy chọn `defaults?:
7
+ Partial<SettingsType>` cho `SettingsProvider` — merge lên core defaults (áp cho state
8
+ đầu, khi không có cookie, và resetSettings). Additive/backward-compatible. App dùng:
9
+ `<SettingsProvider locale={locale} defaults={{ theme: "green" }}>`.
10
+
11
+
3
12
  ## 0.1.17 — Fix: khôi phục nền màu tab (page-tabs) theo golden vinhhoa
4
13
 
5
14
  Bản "neutral single-style" trước đó bỏ gradient nền tab NHƯNG vẫn để icon/chữ
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@goplusvn/core",
3
3
  "description": "GoPlusVN Platform Kit - ERP kernel: layout, RBAC, CRUD, multi-tenant, system pages",
4
- "version": "0.1.17",
4
+ "version": "0.1.18",
5
5
  "private": false,
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org",
@@ -39,14 +39,20 @@ export const SettingsContext = createContext<
39
39
  export function SettingsProvider({
40
40
  locale,
41
41
  children,
42
+ defaults,
42
43
  }: {
43
44
  locale: LocaleType;
44
45
  children: ReactNode;
46
+ /** App-level overrides của defaultSettings (vd theme, radius). Truyền object
47
+ * ỔN ĐỊNH (module-level const) để tránh re-render. Mặc định = defaultSettings core. */
48
+ defaults?: Partial<SettingsType>;
45
49
  }) {
50
+ // Mặc định của app = core defaults + override từ app (vd theme:"green").
51
+ const base = { ...defaultSettings, ...defaults };
46
52
  const [storedSettings, setStoredSettings, deleteStoredSettings] =
47
53
  useCookie("settings");
48
54
  const [settings, setSettings] = useState<SettingsType>(() => ({
49
- ...defaultSettings,
55
+ ...base,
50
56
  locale,
51
57
  }));
52
58
 
@@ -54,14 +60,15 @@ export function SettingsProvider({
54
60
  if (storedSettings) {
55
61
  try {
56
62
  const parsedSettings = JSON.parse(storedSettings);
57
- setSettings({ ...defaultSettings, ...parsedSettings });
63
+ setSettings({ ...base, ...parsedSettings });
58
64
  } catch {
59
- setSettings({ ...defaultSettings, locale });
65
+ setSettings({ ...base, locale });
60
66
  }
61
67
  } else {
62
- setSettings({ ...defaultSettings, locale });
68
+ setSettings({ ...base, locale });
63
69
  }
64
- }, [storedSettings, locale]);
70
+ // eslint-disable-next-line react-hooks/exhaustive-deps
71
+ }, [storedSettings, locale, defaults]);
65
72
 
66
73
  const updateSettings = useCallback(
67
74
  (newSettings: SettingsType) => {
@@ -73,8 +80,8 @@ export function SettingsProvider({
73
80
 
74
81
  const resetSettings = useCallback(() => {
75
82
  deleteStoredSettings();
76
- setSettings(defaultSettings);
77
- }, [deleteStoredSettings]);
83
+ setSettings({ ...defaultSettings, ...defaults });
84
+ }, [deleteStoredSettings, defaults]);
78
85
 
79
86
  // Apply the appearance choices the Customizer exposes but that nothing else
80
87
  // wires up. Without this, the "Radius" and "Density" controls store a value