@otwdesign/admin-ui 1.10.0 → 1.12.0

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": "@otwdesign/admin-ui",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "description": "React components for OTW CMS admin screens: list tables, postboxes, forms, notices and buttons.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "OTW SRL",
@@ -34,7 +34,7 @@
34
34
  "node": ">=22.18"
35
35
  },
36
36
  "dependencies": {
37
- "@otwdesign/sdk": "1.10.0"
37
+ "@otwdesign/sdk": "1.12.0"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "react": "^19.0.0"
package/src/icon.tsx CHANGED
@@ -1,19 +1,27 @@
1
1
  import type { AdminIcon as AdminIconValue } from '@otwdesign/sdk'
2
+ import type { CSSProperties } from 'react'
3
+ import { cx } from './button'
2
4
  import { ICONS } from './icon-paths'
3
5
 
6
+ /** An icon by name, a base64 SVG data URI, or the address core serves a plugin's icon from. */
7
+ export type AdminIconSource = AdminIconValue | `/${string}`
8
+
9
+ // isAdminIcon() allows only base64 data URIs; an address may hold nothing that could close the
10
+ // CSS string or reach another site.
11
+ const DRAWN = /^(?:data:image\/svg\+xml;base64,[A-Za-z0-9+/]+={0,2}|\/(?!\/)[\w\-./?=&%]*)$/
12
+
4
13
  /**
5
- * A menu or screen icon in the current text colour. Data URIs are drawn as a mask over that
6
- * colour, so a plugin's SVG matches the menu around it, as WordPress tints them.
14
+ * A menu or screen icon in the current text colour. A data URI or an address is drawn as a mask
15
+ * over that colour, so a plugin's SVG matches the menu around it, as WordPress tints them. The
16
+ * stylesheet's `.cms-icon` holds the mask, so the page carries the image's address only once.
7
17
  */
8
- export function AdminIcon({ icon, className }: { icon: AdminIconValue; className?: string }) {
9
- if (icon.startsWith('data:')) {
10
- // isAdminIcon() allows only base64 data URIs, which cannot close the CSS string.
11
- const mask = `url("${icon}") center / contain no-repeat`
18
+ export function AdminIcon({ icon, className }: { icon: AdminIconSource; className?: string }) {
19
+ if (DRAWN.test(icon)) {
12
20
  return (
13
21
  <span
14
- className={className}
22
+ className={cx('cms-icon', className)}
15
23
  aria-hidden="true"
16
- style={{ display: 'inline-block', background: 'currentColor', mask, WebkitMask: mask }}
24
+ style={{ '--cms-icon': `url("${icon}")` } as CSSProperties}
17
25
  />
18
26
  )
19
27
  }
package/src/index.ts CHANGED
@@ -6,7 +6,8 @@
6
6
  export { Button, ButtonLink, FormButton, buttonClass, cx, type ButtonVariant } from './button'
7
7
  export { EditColumns, Notice, Postbox, type NoticeType } from './boxes'
8
8
  export { FormField, FormTable, SubmitButton } from './forms'
9
- export { AdminIcon } from './icon'
9
+ export { AdminIcon, type AdminIconSource } from './icon'
10
10
  export { ListTable, RowActions, TableNav, Views, type Column, type View } from './list-table'
11
11
  export { DismissButton } from './dismiss-button'
12
12
  export { RowToggle } from './row-toggle'
13
+ export { ADMIN_LINK, Tabs, type Tab } from './tabs'
package/src/tabs.tsx ADDED
@@ -0,0 +1,38 @@
1
+ import { cx } from './button'
2
+
3
+ /**
4
+ * The attribute that has the admin open a plain link as it opens its menu's: the next screen
5
+ * without loading the page again. For links between admin screens only; a link to anything
6
+ * else, or to a screen that runs a script of its own as it loads, stays plain.
7
+ */
8
+ export const ADMIN_LINK = 'data-admin-link'
9
+
10
+ /** One of a screen's tabs. */
11
+ export interface Tab {
12
+ label: string
13
+ href: string
14
+ current?: boolean
15
+ }
16
+
17
+ /**
18
+ * WordPress's tabs across the top of a screen (`.nav-tab-wrapper`), for one plugin's screens:
19
+ * a plugin keeps one link in the menu and its screens as tabs. A tab opens without loading the
20
+ * page again, as a menu link does.
21
+ */
22
+ export function Tabs({ label, tabs }: { label: string; tabs: readonly Tab[] }) {
23
+ return (
24
+ <nav className="nav-tab-wrapper" aria-label={label}>
25
+ {tabs.map((tab) => (
26
+ <a
27
+ key={tab.href}
28
+ href={tab.href}
29
+ className={cx('nav-tab', tab.current && 'nav-tab-active')}
30
+ aria-current={tab.current ? 'page' : undefined}
31
+ {...{ [ADMIN_LINK]: '' }}
32
+ >
33
+ {tab.label}
34
+ </a>
35
+ ))}
36
+ </nav>
37
+ )
38
+ }