@stack-spot/citric-react 0.10.2 → 0.11.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.d.ts","sourceRoot":"","sources":["../../../src/components/MenuOverlay/Menu.tsx"],"names":[],"mappings":"AASA,OAAO,
|
|
1
|
+
{"version":3,"file":"Menu.d.ts","sourceRoot":"","sources":["../../../src/components/MenuOverlay/Menu.tsx"],"names":[],"mappings":"AASA,OAAO,EAAyC,SAAS,EAA0B,MAAM,SAAS,CAAA;AAiFlG;;GAEG;AACH,wBAAgB,IAAI,CAClB,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,SAAS,2CAqDlI"}
|
|
@@ -55,7 +55,7 @@ interface ItemWithIcon {
|
|
|
55
55
|
*/
|
|
56
56
|
iconRight?: React.ReactElement;
|
|
57
57
|
}
|
|
58
|
-
export interface
|
|
58
|
+
export interface MenuAction extends ItemWithIcon, Action {
|
|
59
59
|
/**
|
|
60
60
|
* Whether or not this option is currently active.
|
|
61
61
|
*/
|
|
@@ -65,7 +65,7 @@ export interface ListAction extends ItemWithIcon, Action {
|
|
|
65
65
|
*/
|
|
66
66
|
className?: string;
|
|
67
67
|
}
|
|
68
|
-
interface
|
|
68
|
+
interface MenuGroup {
|
|
69
69
|
/**
|
|
70
70
|
* If this group is rendered as a section with its items right below it or a collapsible, which requires a click to open a submenu.
|
|
71
71
|
*/
|
|
@@ -73,37 +73,37 @@ interface ListGroup {
|
|
|
73
73
|
/**
|
|
74
74
|
* The items of this group.
|
|
75
75
|
*/
|
|
76
|
-
children:
|
|
76
|
+
children: MenuItem[];
|
|
77
77
|
/**
|
|
78
78
|
* A class to be added to this item.
|
|
79
79
|
*/
|
|
80
80
|
className?: string;
|
|
81
81
|
}
|
|
82
|
-
export interface
|
|
82
|
+
export interface MenuSection extends MenuGroup {
|
|
83
83
|
type: 'section';
|
|
84
84
|
/**
|
|
85
85
|
* The section's title.
|
|
86
86
|
*/
|
|
87
87
|
label?: string;
|
|
88
88
|
}
|
|
89
|
-
export interface
|
|
89
|
+
export interface MenuCollapsible extends MenuGroup, ItemWithIcon {
|
|
90
90
|
type?: 'collapsible';
|
|
91
91
|
/**
|
|
92
92
|
* The title of the collapsible menu.
|
|
93
93
|
*/
|
|
94
94
|
label: string;
|
|
95
95
|
}
|
|
96
|
-
export type
|
|
96
|
+
export type MenuItem = MenuSection | MenuCollapsible | MenuAction;
|
|
97
97
|
export interface MenuState {
|
|
98
|
-
items:
|
|
98
|
+
items: MenuItem[];
|
|
99
99
|
parent?: MenuState;
|
|
100
100
|
label?: string;
|
|
101
101
|
}
|
|
102
102
|
export interface BaseMenuProps {
|
|
103
103
|
/**
|
|
104
|
-
* The options in the
|
|
104
|
+
* The options in the menu.
|
|
105
105
|
*/
|
|
106
|
-
items:
|
|
106
|
+
items: MenuItem[];
|
|
107
107
|
/**
|
|
108
108
|
* A header for the menu.
|
|
109
109
|
*/
|
package/package.json
CHANGED
|
@@ -7,12 +7,12 @@ import { IconButton } from '../IconBox'
|
|
|
7
7
|
import { useOverlayController } from '../Overlay/context'
|
|
8
8
|
import { MenuProvider, useMenuController, useMenuState } from './context'
|
|
9
9
|
import { keyboardNavigation } from './keyboard'
|
|
10
|
-
import {
|
|
10
|
+
import { MenuAction, MenuCollapsible, MenuItem, MenuProps, MenuSection, MenuState } from './types'
|
|
11
11
|
|
|
12
12
|
// Arbitrary time (ms) to wait before running a function that needs the view to be updated with the next state value.
|
|
13
13
|
const RENDER_DELAY = 20
|
|
14
14
|
|
|
15
|
-
function Submenu({ children, label, className, icon, iconRight }:
|
|
15
|
+
function Submenu({ children, label, className, icon, iconRight }: MenuCollapsible) {
|
|
16
16
|
const controller = useMenuController()
|
|
17
17
|
return (
|
|
18
18
|
<button
|
|
@@ -37,7 +37,7 @@ function Submenu({ children, label, className, icon, iconRight }: ListCollapsibl
|
|
|
37
37
|
)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
function MenuSection({ children, label, className }:
|
|
40
|
+
function MenuSection({ children, label, className }: MenuSection) {
|
|
41
41
|
return (
|
|
42
42
|
<section className={className}>
|
|
43
43
|
{label && <h6>{label}</h6>}
|
|
@@ -49,7 +49,7 @@ function MenuSection({ children, label, className }: ListSection) {
|
|
|
49
49
|
)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function MenuAction({ label, active, href, icon, iconRight, className, onClick, ...props }:
|
|
52
|
+
function MenuAction({ label, active, href, icon, iconRight, className, onClick, ...props }: MenuAction) {
|
|
53
53
|
const overlayController = useOverlayController()
|
|
54
54
|
const children = <>
|
|
55
55
|
{icon}
|
|
@@ -72,15 +72,15 @@ function MenuAction({ label, active, href, icon, iconRight, className, onClick,
|
|
|
72
72
|
)
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
function hasSections(items:
|
|
75
|
+
function hasSections(items: MenuItem[]) {
|
|
76
76
|
return items.some(i => 'children' in i && i.children.length && i.type === 'section')
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
function hasSubmenus(items:
|
|
79
|
+
function hasSubmenus(items: MenuItem[]) {
|
|
80
80
|
return items.some(i => 'children' in i && i.children.length && i.type === 'collapsible')
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
function MenuItems({ items }: { items:
|
|
83
|
+
function MenuItems({ items }: { items: MenuItem[] }) {
|
|
84
84
|
return useMemo(() => items.map((item, index) => {
|
|
85
85
|
if ('children' in item && item.type === 'section') return <MenuSection key={item.label || index} {...item} />
|
|
86
86
|
if ('children' in item && item.type === 'collapsible') return <Submenu key={item.label || index} {...item} />
|
|
@@ -59,7 +59,7 @@ interface ItemWithIcon {
|
|
|
59
59
|
iconRight?: React.ReactElement,
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
export interface
|
|
62
|
+
export interface MenuAction extends ItemWithIcon, Action {
|
|
63
63
|
/**
|
|
64
64
|
* Whether or not this option is currently active.
|
|
65
65
|
*/
|
|
@@ -70,7 +70,7 @@ export interface ListAction extends ItemWithIcon, Action {
|
|
|
70
70
|
className?: string,
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
interface
|
|
73
|
+
interface MenuGroup {
|
|
74
74
|
/**
|
|
75
75
|
* If this group is rendered as a section with its items right below it or a collapsible, which requires a click to open a submenu.
|
|
76
76
|
*/
|
|
@@ -78,14 +78,14 @@ interface ListGroup {
|
|
|
78
78
|
/**
|
|
79
79
|
* The items of this group.
|
|
80
80
|
*/
|
|
81
|
-
children:
|
|
81
|
+
children: MenuItem[],
|
|
82
82
|
/**
|
|
83
83
|
* A class to be added to this item.
|
|
84
84
|
*/
|
|
85
85
|
className?: string,
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
export interface
|
|
88
|
+
export interface MenuSection extends MenuGroup {
|
|
89
89
|
type: 'section',
|
|
90
90
|
/**
|
|
91
91
|
* The section's title.
|
|
@@ -93,7 +93,7 @@ export interface ListSection extends ListGroup {
|
|
|
93
93
|
label?: string,
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
export interface
|
|
96
|
+
export interface MenuCollapsible extends MenuGroup, ItemWithIcon {
|
|
97
97
|
type?: 'collapsible',
|
|
98
98
|
/**
|
|
99
99
|
* The title of the collapsible menu.
|
|
@@ -101,19 +101,19 @@ export interface ListCollapsible extends ListGroup, ItemWithIcon {
|
|
|
101
101
|
label: string,
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
export type
|
|
104
|
+
export type MenuItem = MenuSection | MenuCollapsible | MenuAction
|
|
105
105
|
|
|
106
106
|
export interface MenuState {
|
|
107
|
-
items:
|
|
107
|
+
items: MenuItem[],
|
|
108
108
|
parent?: MenuState,
|
|
109
109
|
label?: string,
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
export interface BaseMenuProps {
|
|
113
113
|
/**
|
|
114
|
-
* The options in the
|
|
114
|
+
* The options in the menu.
|
|
115
115
|
*/
|
|
116
|
-
items:
|
|
116
|
+
items: MenuItem[],
|
|
117
117
|
/**
|
|
118
118
|
* A header for the menu.
|
|
119
119
|
*/
|