lupine.components 1.0.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/LICENSE +21 -0
- package/README.md +3 -0
- package/package.json +40 -0
- package/src/components/button-push-animation.tsx +138 -0
- package/src/components/button.tsx +55 -0
- package/src/components/drag-refresh.tsx +110 -0
- package/src/components/editable-label.tsx +83 -0
- package/src/components/float-window.tsx +225 -0
- package/src/components/grid.tsx +18 -0
- package/src/components/html-var.tsx +40 -0
- package/src/components/index.ts +35 -0
- package/src/components/input-with-title.tsx +24 -0
- package/src/components/link-item.tsx +13 -0
- package/src/components/link-list.tsx +62 -0
- package/src/components/menu-bar.tsx +219 -0
- package/src/components/menu-item-props.tsx +10 -0
- package/src/components/menu-sidebar.tsx +288 -0
- package/src/components/message-box.tsx +44 -0
- package/src/components/meta-data.tsx +36 -0
- package/src/components/meta-description.tsx +12 -0
- package/src/components/modal.tsx +29 -0
- package/src/components/notice-message.tsx +118 -0
- package/src/components/page-title.tsx +6 -0
- package/src/components/paging-link.tsx +99 -0
- package/src/components/panel.tsx +21 -0
- package/src/components/popup-menu.tsx +219 -0
- package/src/components/progress.tsx +91 -0
- package/src/components/redirect.tsx +19 -0
- package/src/components/resizable-splitter.tsx +128 -0
- package/src/components/select-with-title.tsx +37 -0
- package/src/components/spinner.tsx +100 -0
- package/src/components/svg.tsx +24 -0
- package/src/components/tabs.tsx +251 -0
- package/src/components/text-glow.tsx +36 -0
- package/src/components/text-wave.tsx +54 -0
- package/src/components/theme-selector.tsx +31 -0
- package/src/components/toggle-base.tsx +260 -0
- package/src/components/toggle-switch.tsx +156 -0
- package/src/index.ts +4 -0
- package/src/lib/date-utils.ts +317 -0
- package/src/lib/deep-merge.ts +37 -0
- package/src/lib/document-ready.ts +36 -0
- package/src/lib/dom/calculate-text-width.ts +13 -0
- package/src/lib/dom/download-stream.ts +17 -0
- package/src/lib/dom/download.ts +12 -0
- package/src/lib/dom/index.ts +71 -0
- package/src/lib/dynamical-load.ts +138 -0
- package/src/lib/format-bytes.ts +11 -0
- package/src/lib/index.ts +13 -0
- package/src/lib/lite-dom.ts +227 -0
- package/src/lib/message-hub.ts +105 -0
- package/src/lib/observable.ts +188 -0
- package/src/lib/promise-timeout.ts +1 -0
- package/src/lib/simple-storage.ts +40 -0
- package/src/lib/stop-propagation.ts +7 -0
- package/src/lib/upload-file.ts +68 -0
- package/src/styles/base-themes.ts +17 -0
- package/src/styles/dark-themes.ts +86 -0
- package/src/styles/index.ts +5 -0
- package/src/styles/light-themes.ts +93 -0
- package/src/styles/media-query.ts +93 -0
- package/src/styles/shared-themes.ts +52 -0
- package/tsconfig.json +113 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { RefProps, VNode, mountComponents } from 'lupine.web';
|
|
2
|
+
|
|
3
|
+
export const HtmlVar = (initial?: string | VNode<any>) => {
|
|
4
|
+
let _value: string | VNode<any> = initial || '';
|
|
5
|
+
let _dirty = false;
|
|
6
|
+
const waitUpdate = async (value: string | VNode<any>) => {
|
|
7
|
+
if (!ref.current) return;
|
|
8
|
+
if (typeof value === 'object' && value.type && value.props) {
|
|
9
|
+
await mountComponents(ref.current, value);
|
|
10
|
+
} else {
|
|
11
|
+
ref.current.innerHTML = value;
|
|
12
|
+
}
|
|
13
|
+
_dirty = false;
|
|
14
|
+
}
|
|
15
|
+
const ref: RefProps = { onLoad: async (el: Element) => {
|
|
16
|
+
_dirty && waitUpdate(_value);
|
|
17
|
+
} };
|
|
18
|
+
const FragmentRef = (props: any) => {
|
|
19
|
+
return <>{props.children}</>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
set value(value: string | VNode<any>) {
|
|
24
|
+
_value = value;
|
|
25
|
+
_dirty = true;
|
|
26
|
+
waitUpdate(value);
|
|
27
|
+
},
|
|
28
|
+
get value() {
|
|
29
|
+
return ref.current ? ref.current.innerHTML : _value;
|
|
30
|
+
},
|
|
31
|
+
get ref() {
|
|
32
|
+
return ref;
|
|
33
|
+
},
|
|
34
|
+
// _fragment_ref is a special id to add ref to a fragment and it is processed in mount-components
|
|
35
|
+
get node() {
|
|
36
|
+
_dirty = false;
|
|
37
|
+
return <FragmentRef _fragment_ref={ref}>{_value}</FragmentRef>;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
export * from './button-push-animation';
|
|
3
|
+
export * from './button';
|
|
4
|
+
export * from './drag-refresh';
|
|
5
|
+
export * from './editable-label';
|
|
6
|
+
export * from './float-window';
|
|
7
|
+
export * from './grid';
|
|
8
|
+
export * from './html-var';
|
|
9
|
+
export * from './input-with-title';
|
|
10
|
+
export * from './link-item';
|
|
11
|
+
export * from './link-list';
|
|
12
|
+
export * from './menu-bar';
|
|
13
|
+
export * from './menu-item-props';
|
|
14
|
+
export * from './menu-sidebar';
|
|
15
|
+
export * from './message-box';
|
|
16
|
+
export * from './meta-data';
|
|
17
|
+
export * from './meta-description';
|
|
18
|
+
export * from './modal';
|
|
19
|
+
export * from './notice-message';
|
|
20
|
+
export * from './page-title';
|
|
21
|
+
export * from './paging-link';
|
|
22
|
+
export * from './panel';
|
|
23
|
+
export * from './popup-menu';
|
|
24
|
+
export * from './progress';
|
|
25
|
+
export * from './redirect';
|
|
26
|
+
export * from './resizable-splitter';
|
|
27
|
+
export * from './select-with-title';
|
|
28
|
+
export * from './spinner';
|
|
29
|
+
export * from './svg';
|
|
30
|
+
export * from './tabs';
|
|
31
|
+
export * from './text-glow';
|
|
32
|
+
export * from './text-wave';
|
|
33
|
+
export * from './theme-selector';
|
|
34
|
+
export * from './toggle-base';
|
|
35
|
+
export * from './toggle-switch';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// used in MessageBox.show
|
|
2
|
+
export const InputWithTitle = (
|
|
3
|
+
title: string,
|
|
4
|
+
defaultValue: string,
|
|
5
|
+
onInputChanged?: (option: string) => void,
|
|
6
|
+
onInputInputed?: (option: string) => void,
|
|
7
|
+
className = 'input-base',
|
|
8
|
+
width = '100%',
|
|
9
|
+
) => {
|
|
10
|
+
return (
|
|
11
|
+
<div>
|
|
12
|
+
<div>{title}</div>
|
|
13
|
+
<div>
|
|
14
|
+
<input
|
|
15
|
+
class={className}
|
|
16
|
+
style={{ width }}
|
|
17
|
+
onChange={(e: any) => onInputChanged?.(e?.target?.value)}
|
|
18
|
+
onInput={(e: any) => onInputInputed?.(e?.target?.value)}
|
|
19
|
+
value={defaultValue}
|
|
20
|
+
/>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type LinkItemProps = {
|
|
2
|
+
className?: string;
|
|
3
|
+
text: string;
|
|
4
|
+
url: string;
|
|
5
|
+
alt?: string;
|
|
6
|
+
};
|
|
7
|
+
export const LinkItem = (props: LinkItemProps) => {
|
|
8
|
+
return (
|
|
9
|
+
<a class={['link-item', props.className].join(' ')} href={props.url} alt={props.alt || props.text}>
|
|
10
|
+
{props.text}
|
|
11
|
+
</a>
|
|
12
|
+
);
|
|
13
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LinkItem } from './link-item';
|
|
2
|
+
import { NestMenuItemProps } from './menu-item-props';
|
|
3
|
+
|
|
4
|
+
export type LinkListProps = {
|
|
5
|
+
title: string;
|
|
6
|
+
items: NestMenuItemProps[];
|
|
7
|
+
className?: string;
|
|
8
|
+
textColor?: string;
|
|
9
|
+
backgroundColor?: string;
|
|
10
|
+
titleBackgroundColor?: string;
|
|
11
|
+
};
|
|
12
|
+
export const LinkList = ({
|
|
13
|
+
title,
|
|
14
|
+
items,
|
|
15
|
+
className,
|
|
16
|
+
textColor = 'black',
|
|
17
|
+
backgroundColor = '#d3d3d3',
|
|
18
|
+
titleBackgroundColor = '#b6b6b6',
|
|
19
|
+
}: LinkListProps) => {
|
|
20
|
+
const css: any = {
|
|
21
|
+
width: '100%',
|
|
22
|
+
margin: 'auto',
|
|
23
|
+
height: 'auto',
|
|
24
|
+
backgroundColor,
|
|
25
|
+
'.link-list-title, .link-list-top': {
|
|
26
|
+
display: 'flex',
|
|
27
|
+
width: '100%',
|
|
28
|
+
flexWrap: 'wrap',
|
|
29
|
+
padding: '0 16px',
|
|
30
|
+
},
|
|
31
|
+
'.link-list-title': {
|
|
32
|
+
backgroundColor: titleBackgroundColor,
|
|
33
|
+
},
|
|
34
|
+
'.link-list-item': {
|
|
35
|
+
display: 'inline-block',
|
|
36
|
+
color: textColor,
|
|
37
|
+
padding: '8px 16px 8px 0',
|
|
38
|
+
textDecoration: 'none',
|
|
39
|
+
},
|
|
40
|
+
'.link-list-item:last-child': {
|
|
41
|
+
paddingRight: 'unset',
|
|
42
|
+
},
|
|
43
|
+
'.link-list-title .link-list-item': {
|
|
44
|
+
fontSize: '18px',
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div css={css} class={['link-list-box', className].join(' ')}>
|
|
50
|
+
{title && (
|
|
51
|
+
<div class='link-list-title'>
|
|
52
|
+
<div class='link-list-item'>{title}</div>
|
|
53
|
+
</div>
|
|
54
|
+
)}
|
|
55
|
+
<div class='link-list-top'>
|
|
56
|
+
{items.map((item) => {
|
|
57
|
+
return <LinkItem className='link-list-item' url={item.url} alt={item.alt} text={item.text} />;
|
|
58
|
+
})}
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { getRenderPageProps, RefProps } from 'lupine.web';
|
|
2
|
+
import { MediaQueryMaxWidth } from '../styles';
|
|
3
|
+
import { LinkItem } from './link-item';
|
|
4
|
+
import { NestMenuItemProps } from './menu-item-props';
|
|
5
|
+
|
|
6
|
+
const fetchMenu = async (menuId: string) => {
|
|
7
|
+
const data = await getRenderPageProps().renderPageFunctions.fetchData(`/api/menu/get/${menuId}`);
|
|
8
|
+
return data.json;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type MenuBarProps = {
|
|
12
|
+
menuId?: string;
|
|
13
|
+
items: NestMenuItemProps[];
|
|
14
|
+
className?: string;
|
|
15
|
+
textColor?: string;
|
|
16
|
+
hoverColor?: string;
|
|
17
|
+
hoverBgColor?: string;
|
|
18
|
+
maxWidthMobileMenu?: string;
|
|
19
|
+
maxWidth?: string;
|
|
20
|
+
backgroundColor?: string;
|
|
21
|
+
};
|
|
22
|
+
export const MenuBar = ({
|
|
23
|
+
menuId,
|
|
24
|
+
items,
|
|
25
|
+
className,
|
|
26
|
+
textColor = 'var(--menubar-color)',
|
|
27
|
+
backgroundColor = 'var(--menubar-bg-color)', //'black',
|
|
28
|
+
hoverColor = 'var(--activatable-color-hover)', //'#ffffff',
|
|
29
|
+
hoverBgColor = 'var(--activatable-bg-color-hover)', //'#d12121',
|
|
30
|
+
maxWidth = '100%',
|
|
31
|
+
maxWidthMobileMenu = MediaQueryMaxWidth.TabletMax,
|
|
32
|
+
}: MenuBarProps) => {
|
|
33
|
+
const css: any = {
|
|
34
|
+
width: '100%',
|
|
35
|
+
maxWidth: maxWidth,
|
|
36
|
+
margin: 'auto',
|
|
37
|
+
// height: 'auto',
|
|
38
|
+
backgroundColor,
|
|
39
|
+
position: 'relative',
|
|
40
|
+
'.menu-bar-top': {
|
|
41
|
+
display: 'flex',
|
|
42
|
+
width: '100%',
|
|
43
|
+
justifyContent: 'center',
|
|
44
|
+
},
|
|
45
|
+
'.menu-bar-item': {
|
|
46
|
+
display: 'inline-block',
|
|
47
|
+
color: textColor,
|
|
48
|
+
padding: '14px 16px',
|
|
49
|
+
textDecoration: 'none',
|
|
50
|
+
position: 'relative',
|
|
51
|
+
},
|
|
52
|
+
'.menu-bar-item:hover, .menu-bar-sub-box:hover > .menu-bar-item': {
|
|
53
|
+
// for desktop, make parent menu hover when sub menu is hover
|
|
54
|
+
color: hoverColor,
|
|
55
|
+
backgroundColor: hoverBgColor,
|
|
56
|
+
},
|
|
57
|
+
'.menu-bar-sub-box .menu-bar-sub': {
|
|
58
|
+
display: 'none',
|
|
59
|
+
position: 'absolute',
|
|
60
|
+
backgroundColor: 'var(--menubar-sub-bg-color)', //'#f9f9f9',
|
|
61
|
+
minWidth: '160px',
|
|
62
|
+
boxShadow: '0px 8px 16px 0px rgba(0,0,0,0.2)',
|
|
63
|
+
zIndex: 'var(--layer-menu-sub)',
|
|
64
|
+
flexDirection: 'column',
|
|
65
|
+
},
|
|
66
|
+
'.menu-bar-sub-box > .menu-bar-item': {
|
|
67
|
+
padding: '14px 26px 14px 16px',
|
|
68
|
+
width: '100%',
|
|
69
|
+
},
|
|
70
|
+
'.menu-bar-sub-box > .menu-bar-item::after': {
|
|
71
|
+
content: '""',
|
|
72
|
+
position: 'absolute',
|
|
73
|
+
top: '50%',
|
|
74
|
+
transform: 'translateY(-50%)',
|
|
75
|
+
marginLeft: '6px',
|
|
76
|
+
width: 0,
|
|
77
|
+
height: 0,
|
|
78
|
+
borderLeft: '5px solid transparent',
|
|
79
|
+
borderRight: '5px solid transparent',
|
|
80
|
+
borderTop: '5px solid ' + textColor,
|
|
81
|
+
},
|
|
82
|
+
'.menu-bar-sub-box .menu-bar-sub > .menu-bar-item': {
|
|
83
|
+
color: 'black',
|
|
84
|
+
},
|
|
85
|
+
'.menu-bar-sub-box:hover > .menu-bar-sub': {
|
|
86
|
+
display: 'flex',
|
|
87
|
+
},
|
|
88
|
+
'.menu-bar-sub-box .menu-bar-sub .menu-bar-item:hover': {
|
|
89
|
+
// backgroundColor: '#ddd',
|
|
90
|
+
color: hoverColor,
|
|
91
|
+
backgroundColor: hoverBgColor,
|
|
92
|
+
},
|
|
93
|
+
'.menu-bar-mobile': {
|
|
94
|
+
display: 'none',
|
|
95
|
+
position: 'relative',
|
|
96
|
+
backgroundColor,
|
|
97
|
+
padding: '5px 18px 6px',
|
|
98
|
+
'.menu-bar-toggle': {
|
|
99
|
+
cursor: 'pointer',
|
|
100
|
+
padding: '14px 0 19px 0',
|
|
101
|
+
'span, span::before, span::after': {
|
|
102
|
+
cursor: 'pointer',
|
|
103
|
+
height: '3px',
|
|
104
|
+
width: '25px',
|
|
105
|
+
borderRadius: '1px',
|
|
106
|
+
background: '#ffffff',
|
|
107
|
+
position: 'absolute',
|
|
108
|
+
display: 'block',
|
|
109
|
+
transition: 'all 300ms ease-in-out',
|
|
110
|
+
},
|
|
111
|
+
'span::before, span::after': {
|
|
112
|
+
content: '""',
|
|
113
|
+
},
|
|
114
|
+
'span::before': {
|
|
115
|
+
top: '-10px',
|
|
116
|
+
},
|
|
117
|
+
'span::after': {
|
|
118
|
+
bottom: '-10px',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
'.menu-bar-toggle.active span': {
|
|
122
|
+
backgroundColor: 'transparent',
|
|
123
|
+
},
|
|
124
|
+
'.menu-bar-toggle.active span::before': {
|
|
125
|
+
transform: 'rotate(45deg)',
|
|
126
|
+
top: 0,
|
|
127
|
+
},
|
|
128
|
+
'.menu-bar-toggle.active span::after': {
|
|
129
|
+
transform: 'rotate(-45deg)',
|
|
130
|
+
top: 0,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
['@media only screen and (max-width: ' + maxWidthMobileMenu + ')']: {
|
|
134
|
+
'.menu-bar-mobile': {
|
|
135
|
+
display: 'block',
|
|
136
|
+
},
|
|
137
|
+
'.menu-bar-top': {
|
|
138
|
+
display: 'none',
|
|
139
|
+
},
|
|
140
|
+
'.menu-bar-top.open': {
|
|
141
|
+
display: 'flex',
|
|
142
|
+
flexDirection: 'column',
|
|
143
|
+
},
|
|
144
|
+
'.menu-bar-top.open .menu-bar-sub-box > .menu-bar-sub': {
|
|
145
|
+
display: 'flex',
|
|
146
|
+
position: 'unset',
|
|
147
|
+
'.menu-bar-item': {
|
|
148
|
+
paddingLeft: '32px',
|
|
149
|
+
color: textColor,
|
|
150
|
+
backgroundColor,
|
|
151
|
+
},
|
|
152
|
+
'.menu-bar-item:hover': {
|
|
153
|
+
color: hoverColor,
|
|
154
|
+
backgroundColor: hoverBgColor,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
'.menu-bar-sub-box:hover > .menu-bar-item': {
|
|
158
|
+
// for mobile, no parent menu hover when sub menu is hover
|
|
159
|
+
color: textColor,
|
|
160
|
+
backgroundColor: backgroundColor,
|
|
161
|
+
},
|
|
162
|
+
'.menu-bar-sub-box:hover > .menu-bar-item:hover': {
|
|
163
|
+
color: hoverColor,
|
|
164
|
+
backgroundColor: hoverBgColor,
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const renderItems = (items: NestMenuItemProps[], className: string) => {
|
|
170
|
+
return (
|
|
171
|
+
<div class={className}>
|
|
172
|
+
{items.map((item) => {
|
|
173
|
+
return item.items ? (
|
|
174
|
+
<div class='menu-bar-sub-box'>
|
|
175
|
+
<div class='menu-bar-item'>{item.text}</div>
|
|
176
|
+
{renderItems(item.items, 'menu-bar-sub')}
|
|
177
|
+
</div>
|
|
178
|
+
) : (
|
|
179
|
+
<LinkItem className='menu-bar-item' url={item.url} alt={item.alt} text={item.text} />
|
|
180
|
+
);
|
|
181
|
+
})}
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const ref: RefProps = {
|
|
187
|
+
onLoad: async () => {
|
|
188
|
+
if (menuId) {
|
|
189
|
+
const menu = await fetchMenu(menuId);
|
|
190
|
+
if (menu.result && menu.result.items.length > 0) {
|
|
191
|
+
const items = menu.result.items.map((i: any) => {
|
|
192
|
+
const l = i.split('\t');
|
|
193
|
+
return { text: l[5], url: l[4] };
|
|
194
|
+
});
|
|
195
|
+
const newDom = renderItems(items, 'menu-bar-top');
|
|
196
|
+
//mountComponents('.menu-bar-top', newDom);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
const onToggleClick = () => {
|
|
202
|
+
const menu = ref.$('.menu-bar-mobile .menu-bar-toggle');
|
|
203
|
+
menu.classList.toggle('active');
|
|
204
|
+
const topMenu = ref.$('.menu-bar-top');
|
|
205
|
+
topMenu.classList.toggle('open');
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
<div ref={ref} css={css} class={['menu-bar-box', className].join(' ')}>
|
|
210
|
+
<div class='menu-bar-mobile'>
|
|
211
|
+
<div class='menu-bar-toggle' onClick={onToggleClick}>
|
|
212
|
+
<span></span>
|
|
213
|
+
</div>
|
|
214
|
+
</div>
|
|
215
|
+
|
|
216
|
+
{renderItems(items, 'menu-bar-top')}
|
|
217
|
+
</div>
|
|
218
|
+
);
|
|
219
|
+
};
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { bindGlobalStyles, CssProps, getRenderPageProps, RefProps } from 'lupine.web';
|
|
2
|
+
import { stopPropagation } from '../lib';
|
|
3
|
+
import { MediaQueryMaxWidth } from '../styles';
|
|
4
|
+
import { NestMenuItemProps } from './menu-item-props';
|
|
5
|
+
|
|
6
|
+
const fetchMenu = async (menuId: string) => {
|
|
7
|
+
const data = await getRenderPageProps().renderPageFunctions.fetchData(`/api/menu/get/${menuId}`);
|
|
8
|
+
return data.json;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type MenuSidebarProps = {
|
|
12
|
+
mobileMenu?: boolean;
|
|
13
|
+
desktopMenu?: boolean;
|
|
14
|
+
menuId?: string;
|
|
15
|
+
items: NestMenuItemProps[];
|
|
16
|
+
className?: string;
|
|
17
|
+
maxWidthMobileMenu?: string;
|
|
18
|
+
maxWidth?: string;
|
|
19
|
+
color?: string;
|
|
20
|
+
backgroundColor?: string;
|
|
21
|
+
};
|
|
22
|
+
export const MenuSidebar = ({
|
|
23
|
+
mobileMenu,
|
|
24
|
+
desktopMenu,
|
|
25
|
+
menuId,
|
|
26
|
+
items,
|
|
27
|
+
className,
|
|
28
|
+
color = 'white',
|
|
29
|
+
backgroundColor = 'dark',
|
|
30
|
+
maxWidth = '100%',
|
|
31
|
+
maxWidthMobileMenu = MediaQueryMaxWidth.TabletMax,
|
|
32
|
+
}: MenuSidebarProps) => {
|
|
33
|
+
const css: CssProps = {
|
|
34
|
+
backgroundColor,
|
|
35
|
+
'.menu-sidebar-top': {
|
|
36
|
+
width: '100%',
|
|
37
|
+
backgroundColor: 'var(--sidebar-bg-color)',
|
|
38
|
+
maxWidth: maxWidth,
|
|
39
|
+
margin: 'auto',
|
|
40
|
+
// height: 'auto',
|
|
41
|
+
position: 'relative',
|
|
42
|
+
|
|
43
|
+
display: 'flex',
|
|
44
|
+
// width: '100%',
|
|
45
|
+
justifyContent: 'center',
|
|
46
|
+
flexDirection: 'column',
|
|
47
|
+
},
|
|
48
|
+
'&.mobile .menu-sidebar-top': {
|
|
49
|
+
position: 'absolute',
|
|
50
|
+
},
|
|
51
|
+
'.menu-sidebar-item': {
|
|
52
|
+
display: 'inline-block',
|
|
53
|
+
color,
|
|
54
|
+
cursor: 'pointer',
|
|
55
|
+
padding: '14px 16px',
|
|
56
|
+
textDecoration: 'none',
|
|
57
|
+
position: 'relative',
|
|
58
|
+
borderBottom: 'var(--sidebar-border)',
|
|
59
|
+
},
|
|
60
|
+
// select parent when hover on a child, .menu-sidebar-sub-box:hover > .menu-sidebar-item
|
|
61
|
+
'.menu-sidebar-item:hover': {
|
|
62
|
+
color: 'var(--activatable-color-hover)',
|
|
63
|
+
backgroundColor: 'var(--activatable-bg-color-hover)',
|
|
64
|
+
},
|
|
65
|
+
'.menu-sidebar-sub-box .menu-sidebar-sub': {
|
|
66
|
+
display: 'none',
|
|
67
|
+
// position: 'absolute',
|
|
68
|
+
// color: 'var(--sidebar-sub-color)',
|
|
69
|
+
// backgroundColor: 'var(--sidebar-sub-bg-color)',
|
|
70
|
+
minWidth: '160px',
|
|
71
|
+
// boxShadow: '0px 8px 16px 0px rgba(0,0,0,0.2)',
|
|
72
|
+
zIndex: 'var(--layer-sidebar-sub)',
|
|
73
|
+
flexDirection: 'column',
|
|
74
|
+
},
|
|
75
|
+
'.menu-sidebar-sub-box > .menu-sidebar-item': {
|
|
76
|
+
padding: '14px 26px 14px 16px',
|
|
77
|
+
width: '100%',
|
|
78
|
+
},
|
|
79
|
+
'.menu-sidebar-sub-box > .menu-sidebar-sub > .menu-sidebar-item': {
|
|
80
|
+
paddingLeft: '32px',
|
|
81
|
+
},
|
|
82
|
+
'.menu-sidebar-sub-box > .menu-sidebar-item::after': {
|
|
83
|
+
content: '""',
|
|
84
|
+
position: 'absolute',
|
|
85
|
+
top: '50%',
|
|
86
|
+
transform: 'translateY(-50%) rotate(-90deg)',
|
|
87
|
+
marginLeft: '6px',
|
|
88
|
+
width: 0,
|
|
89
|
+
height: 0,
|
|
90
|
+
borderLeft: '5px solid transparent',
|
|
91
|
+
borderRight: '5px solid transparent',
|
|
92
|
+
borderTop: '5px solid ' + color,
|
|
93
|
+
right: '10px',
|
|
94
|
+
transition: 'all 300ms ease-in-out',
|
|
95
|
+
},
|
|
96
|
+
'.menu-sidebar-sub-box.open > .menu-sidebar-item::after': {
|
|
97
|
+
transform: 'rotate(0deg)',
|
|
98
|
+
},
|
|
99
|
+
'&.mobile .menu-sidebar-sub-box > .menu-sidebar-item::after': {
|
|
100
|
+
transform: 'rotate(0deg)',
|
|
101
|
+
},
|
|
102
|
+
// '.menu-sidebar-sub-box .menu-sidebar-sub > .menu-sidebar-item': {
|
|
103
|
+
// color: 'black',
|
|
104
|
+
// },
|
|
105
|
+
'.menu-sidebar-sub-box.open > .menu-sidebar-sub': {
|
|
106
|
+
display: 'flex',
|
|
107
|
+
},
|
|
108
|
+
'.menu-sidebar-sub-box .menu-sidebar-sub .menu-sidebar-item:hover': {
|
|
109
|
+
color: 'var(--activatable-color-hover)',
|
|
110
|
+
backgroundColor: 'var(--activatable-bg-color-hover)',
|
|
111
|
+
},
|
|
112
|
+
'.menu-sidebar-mobile': {
|
|
113
|
+
display: 'none',
|
|
114
|
+
position: 'relative',
|
|
115
|
+
backgroundColor: 'var(--primary-bg-color)',
|
|
116
|
+
padding: '5px 4px 6px',
|
|
117
|
+
'.menu-sidebar-toggle': {
|
|
118
|
+
cursor: 'pointer',
|
|
119
|
+
padding: '6px 0 8px 0',
|
|
120
|
+
'span, span::before, span::after': {
|
|
121
|
+
cursor: 'pointer',
|
|
122
|
+
height: '3px',
|
|
123
|
+
width: '25px',
|
|
124
|
+
borderRadius: '1px',
|
|
125
|
+
background: 'var(--primary-color)',
|
|
126
|
+
position: 'absolute',
|
|
127
|
+
display: 'block',
|
|
128
|
+
transition: 'all 300ms ease-in-out',
|
|
129
|
+
},
|
|
130
|
+
'span::before, span::after': {
|
|
131
|
+
content: '""',
|
|
132
|
+
},
|
|
133
|
+
'span::before': {
|
|
134
|
+
top: '-7px',
|
|
135
|
+
},
|
|
136
|
+
'span::after': {
|
|
137
|
+
bottom: '-7px',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
'.menu-sidebar-toggle.active span': {
|
|
141
|
+
backgroundColor: 'transparent',
|
|
142
|
+
},
|
|
143
|
+
'.menu-sidebar-toggle.active span::before': {
|
|
144
|
+
transform: 'rotate(45deg)',
|
|
145
|
+
top: 0,
|
|
146
|
+
},
|
|
147
|
+
'.menu-sidebar-toggle.active span::after': {
|
|
148
|
+
transform: 'rotate(-45deg)',
|
|
149
|
+
top: 0,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
// hide menu for mobile place
|
|
153
|
+
'&.mobile': {
|
|
154
|
+
display: 'none',
|
|
155
|
+
// width: '33px',
|
|
156
|
+
},
|
|
157
|
+
'&.mobile .menu-sidebar-mobile': {
|
|
158
|
+
display: 'block',
|
|
159
|
+
width: '33px',
|
|
160
|
+
},
|
|
161
|
+
['@media only screen and (max-width: ' + maxWidthMobileMenu + ')']: {
|
|
162
|
+
// hide menu for not mobile place
|
|
163
|
+
display: 'none',
|
|
164
|
+
// show menu for mobile place
|
|
165
|
+
'&.mobile': {
|
|
166
|
+
display: 'block',
|
|
167
|
+
},
|
|
168
|
+
'.menu-sidebar-top': {
|
|
169
|
+
display: 'none',
|
|
170
|
+
},
|
|
171
|
+
'.menu-sidebar-top.open': {
|
|
172
|
+
display: 'flex',
|
|
173
|
+
flexDirection: 'column',
|
|
174
|
+
zIndex: 'var(--layer-sidebar)',
|
|
175
|
+
},
|
|
176
|
+
'.menu-sidebar-top.open .menu-sidebar-sub-box > .menu-sidebar-sub': {
|
|
177
|
+
display: 'flex',
|
|
178
|
+
position: 'unset',
|
|
179
|
+
'.menu-sidebar-item': {
|
|
180
|
+
paddingLeft: '32px',
|
|
181
|
+
color,
|
|
182
|
+
backgroundColor,
|
|
183
|
+
},
|
|
184
|
+
'.menu-sidebar-item:hover': {
|
|
185
|
+
color: 'var(--activatable-color-hover)',
|
|
186
|
+
backgroundColor: 'var(--activatable-bg-color-hover)',
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
'.menu-sidebar-sub-box:hover > .menu-sidebar-item': {
|
|
190
|
+
backgroundColor: 'unset',
|
|
191
|
+
},
|
|
192
|
+
'.menu-sidebar-sub-box:hover > .menu-sidebar-item:hover': {
|
|
193
|
+
color: 'var(--activatable-color-hover)',
|
|
194
|
+
backgroundColor: 'var(--activatable-bg-color-hover)',
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// first level is grouped
|
|
200
|
+
const renderItems = (items: NestMenuItemProps[], className: string) => {
|
|
201
|
+
return (
|
|
202
|
+
<div class={className}>
|
|
203
|
+
{items.map((item) => {
|
|
204
|
+
let ref: RefProps = {};
|
|
205
|
+
return item.items ? (
|
|
206
|
+
<div ref={ref} class='menu-sidebar-sub-box' onClick={() => onItemToggleClick(ref)}>
|
|
207
|
+
<div class='menu-sidebar-item'>{item.text}</div>
|
|
208
|
+
{renderItems(item.items, 'menu-sidebar-sub')}
|
|
209
|
+
</div>
|
|
210
|
+
) : item.js ? (
|
|
211
|
+
<a
|
|
212
|
+
class='menu-sidebar-item'
|
|
213
|
+
href='javascript:void(0)'
|
|
214
|
+
alt={item.alt || item.text}
|
|
215
|
+
onClick={(event) => {
|
|
216
|
+
stopPropagation(event);
|
|
217
|
+
// hide menu
|
|
218
|
+
onToggleClick();
|
|
219
|
+
item.js && item.js();
|
|
220
|
+
}}
|
|
221
|
+
>
|
|
222
|
+
{item.text}
|
|
223
|
+
</a>
|
|
224
|
+
) : (
|
|
225
|
+
<a class='menu-sidebar-item' href={item.url} alt={item.alt || item.text}>
|
|
226
|
+
{item.text}
|
|
227
|
+
</a>
|
|
228
|
+
);
|
|
229
|
+
})}
|
|
230
|
+
</div>
|
|
231
|
+
);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const ref: RefProps = {
|
|
235
|
+
onLoad: async () => {
|
|
236
|
+
if (menuId) {
|
|
237
|
+
const menu = await fetchMenu(menuId);
|
|
238
|
+
if (menu.result.items.length > 0) {
|
|
239
|
+
const items = menu.result.items.map((i: any) => {
|
|
240
|
+
const l = i.split('\t');
|
|
241
|
+
return { text: l[5], url: l[4] };
|
|
242
|
+
});
|
|
243
|
+
const newDom = renderItems(items, 'menu-sidebar-top');
|
|
244
|
+
//mountComponents('.menu-sidebar-top', newDom);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
const onToggleClick = () => {
|
|
250
|
+
const menu = ref.$('.menu-sidebar-mobile .menu-sidebar-toggle');
|
|
251
|
+
menu.classList.toggle('active');
|
|
252
|
+
const topMenu = ref.$('.menu-sidebar-top');
|
|
253
|
+
topMenu.classList.toggle('open');
|
|
254
|
+
};
|
|
255
|
+
const onItemToggleClick = (ref: RefProps) => {
|
|
256
|
+
// if (event.target != ref.current && (event.target as any).parentNode != ref.current) {
|
|
257
|
+
// return;
|
|
258
|
+
// }
|
|
259
|
+
ref.current.classList.toggle('open');
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// if this component is used twice, then the Global styles is only set at the first time
|
|
263
|
+
bindGlobalStyles('menu-sidebar-box', '.menu-sidebar-box', css);
|
|
264
|
+
|
|
265
|
+
// show the menu on both mobile and desktop
|
|
266
|
+
const newCss: CssProps =
|
|
267
|
+
(!desktopMenu && !mobileMenu) || (desktopMenu && mobileMenu)
|
|
268
|
+
? {
|
|
269
|
+
['@media only screen and (max-width: ' + maxWidthMobileMenu + ')']: {
|
|
270
|
+
display: 'block',
|
|
271
|
+
'.menu-sidebar-top': {
|
|
272
|
+
display: 'block',
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
}
|
|
276
|
+
: {};
|
|
277
|
+
return (
|
|
278
|
+
<div css={newCss} ref={ref} class={['menu-sidebar-box', className, mobileMenu ? 'mobile' : ''].join(' ')}>
|
|
279
|
+
<div class='menu-sidebar-mobile'>
|
|
280
|
+
<div class='menu-sidebar-toggle' onClick={onToggleClick}>
|
|
281
|
+
<span></span>
|
|
282
|
+
</div>
|
|
283
|
+
</div>
|
|
284
|
+
|
|
285
|
+
{renderItems(items, 'menu-sidebar-top')}
|
|
286
|
+
</div>
|
|
287
|
+
);
|
|
288
|
+
};
|