muffin-admin 9.4.5 → 9.5.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "9.4.5",
3
+ "version": "9.5.1",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
@@ -20,9 +20,14 @@ import { useEffect } from "react"
20
20
  import { ConfirmationProvider } from "./common"
21
21
  import { useMuffinAdminOpts } from "./hooks"
22
22
  import { buildProvider, muffinTranslations } from "./i18n"
23
+ import { muffinDarkTheme, muffinLightTheme } from "./themes"
23
24
  import { buildAdmin, deepMerge, findBuilder, findIcon, setupAdmin } from "./utils"
24
25
 
25
- export function MuffinAdmin(props: AdminProps) {
26
+ export function MuffinAdmin({
27
+ lightTheme = muffinLightTheme,
28
+ darkTheme = muffinDarkTheme,
29
+ ...props
30
+ }: AdminProps) {
26
31
  const opts = useMuffinAdminOpts()
27
32
  const { resources = [], auth, adminProps, apiUrl, locales: backendLocales } = opts
28
33
 
@@ -57,8 +62,6 @@ export function MuffinAdmin(props: AdminProps) {
57
62
  store = localStorageStore(),
58
63
  ready,
59
64
  theme,
60
- lightTheme,
61
- darkTheme,
62
65
  defaultTheme,
63
66
  title = "React Admin",
64
67
  } = props
@@ -4,8 +4,9 @@ import Collapse from "@mui/material/Collapse"
4
4
  import ListItemButton from "@mui/material/ListItemButton"
5
5
  import ListItemIcon from "@mui/material/ListItemIcon"
6
6
  import ListItemText from "@mui/material/ListItemText"
7
+ import { matchPath, useLocation } from "react-router-dom"
7
8
 
8
- import { Menu, MenuProps, useTranslate } from "react-admin"
9
+ import { Menu, MenuProps, useBasename, useTranslate } from "react-admin"
9
10
 
10
11
  import find from "lodash/find"
11
12
  import groupBy from "lodash/groupBy"
@@ -43,11 +44,19 @@ function MenuGroup({ name, resources }: { name: string; resources: AdminResource
43
44
  const iconRes = find(resources, "icon")
44
45
  const Icon = iconRes ? findIcon(iconRes.icon) : null
45
46
  const translate = useTranslate()
46
- const [groupOpen, setGroupOpen] = useState(false)
47
+ const basename = useBasename()
48
+ const { pathname } = useLocation()
49
+ const match = resources.some(
50
+ (resource) => !!matchPath({ path: `${basename}/${resource.name}/*` }, pathname)
51
+ )
52
+ const [groupOpen, setGroupOpen] = useState(match)
47
53
 
48
54
  return (
49
55
  <div>
50
- <ListItemButton onClick={() => setGroupOpen(!groupOpen)}>
56
+ <ListItemButton
57
+ onClick={() => setGroupOpen(!groupOpen)}
58
+ sx={{ color: match ? "rgba(0, 0, 0, 0.87)" : "rgba(0, 0, 0, 0.6)" }}
59
+ >
51
60
  {Icon && (
52
61
  <ListItemIcon sx={{ minWidth: 40 }}>
53
62
  <Icon />
package/src/index.tsx CHANGED
@@ -37,4 +37,4 @@ export async function initAdmin(prefix = "", containerId: string = "root") {
37
37
  )
38
38
  }
39
39
 
40
- export const VERSION = "9.4.5"
40
+ export const VERSION = "9.5.1"
package/src/themes.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { defaultDarkTheme, defaultLightTheme } from "react-admin"
2
+
3
+ export const muffinLightTheme: typeof defaultLightTheme = {
4
+ ...defaultLightTheme,
5
+ components: {
6
+ ...defaultLightTheme.components,
7
+ RaMenuItemLink: {
8
+ styleOverrides: {
9
+ root: {
10
+ "&.RaMenuItemLink-active": {
11
+ borderRadius: "4px",
12
+ backgroundColor: "#f0f0f0",
13
+ },
14
+ },
15
+ },
16
+ },
17
+ },
18
+ }
19
+
20
+ export const muffinDarkTheme: typeof defaultDarkTheme = {
21
+ ...defaultDarkTheme,
22
+ components: {
23
+ ...defaultDarkTheme.components,
24
+ RaMenuItemLink: {
25
+ styleOverrides: {
26
+ root: {
27
+ "&.RaMenuItemLink-active": {
28
+ borderRadius: "4px",
29
+ backgroundColor: "#424242",
30
+ },
31
+ },
32
+ },
33
+ },
34
+ },
35
+ }