Skip to content

Commit 91a5c68

Browse files
author
k.golikov
committed
DataUrlViewerPage
1 parent c0369e9 commit 91a5c68

File tree

18 files changed

+268
-34
lines changed

18 files changed

+268
-34
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"react-color": "^2.19.3",
3535
"react-css-theme-switcher": "^0.3.0",
3636
"react-dom": "^18.0.0",
37+
"react-json-view": "^1.21.3",
3738
"react-konva": "^18.0.0-0",
3839
"react-redux": "^7.2.6",
3940
"react-router-dom": "^6.2.2",

src/App.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@
1919
}
2020
}
2121
}
22+
23+
.view-iframe {
24+
flex: 1;
25+
border: none;
26+
max-width: 100%;
27+
overflow: auto;
28+
}

src/components/code/Code.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { FunctionComponent, HTMLProps } from 'react';
22
import classNames from 'classnames';
33

4-
/** @deprecated Use code tag instead */
4+
/** @deprecated Use <Text code/> instead */
55
const Code: FunctionComponent<HTMLProps<HTMLSpanElement>> = ({ className, children, ...props }) => {
66
return (
77
<code className={classNames('code', className)} {...props}>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.container {
2+
display: flex;
3+
flex-direction: column;
4+
gap: 6px;
5+
}

src/components/pageCol/PageCol.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, { FunctionComponent, useMemo } from 'react';
2+
import { Col, ColProps } from 'antd';
3+
import styles from './PageCol.module.scss';
4+
import classNames from 'classnames';
5+
import TupleToUnion from '../../types/common/TupleToUnion';
6+
import { defaults, pick } from 'lodash';
7+
8+
type Props = ColProps;
9+
10+
const sizePropNames = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'] as const;
11+
12+
type SizeProps = Pick<ColProps, TupleToUnion<typeof sizePropNames>>;
13+
14+
const sizePropsDefaults: Record<'default', SizeProps> = {
15+
default: {
16+
xs: 24,
17+
md: 18,
18+
lg: 14,
19+
xl: 10,
20+
xxl: 8
21+
}
22+
};
23+
24+
const PageCol: FunctionComponent<Props> = ({ className, children, ...props }) => {
25+
const restProps = useMemo(() => {
26+
const overriddenSizeProps = pick(props, sizePropNames);
27+
28+
return {
29+
...props,
30+
...defaults(overriddenSizeProps, sizePropsDefaults.default)
31+
};
32+
}, [props]);
33+
34+
return (
35+
<Col className={classNames(styles.container)} {...restProps}>
36+
{children}
37+
</Col>
38+
);
39+
};
40+
41+
export default PageCol;

src/constants/router/menuItems.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ const menuItems: MenuItem[] = [
6868
{
6969
route: routes.dataUrl
7070
},
71+
{
72+
route: routes.dataUrlViewer
73+
},
7174
{
7275
route: routes.dateUtils
7376
},

src/constants/router/routes.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import CounterPage from '../../pages/counterPage/CounterPage';
3434
import RooksDemoPage from '../../pages/rooksDemoPage/RooksDemoPage';
3535
import MarkdownCheatSheetPage from '../../pages/markdownCheatSheetPage/MarkdownCheatSheetPage';
3636
import JsEventTesterPage from '../../pages/jsEventTesterPage/JsEventTesterPage';
37+
import DataUrlViewerPage from '../../pages/dataUrlViewerPage/DataUrlViewerPage';
3738

3839
export interface AppRoute extends Omit<RouteProps, 'element'> {
3940
path: string;
@@ -68,6 +69,7 @@ type AppRoutesMap = Readonly<{
6869
base64: AppRoute;
6970
dataUrl: AppRoute;
7071
dataUrlView: AppRoute;
72+
dataUrlViewer: AppRoute;
7173
counter: AppRoute;
7274
rooksDemo: AppRoute;
7375
jsEventTester: AppRoute;
@@ -203,6 +205,11 @@ export const routes: AppRoutesMap = {
203205
title: 'Content View',
204206
isLayoutHidden: true
205207
},
208+
dataUrlViewer: {
209+
path: '/tools/data-url-viewer',
210+
component: DataUrlViewerPage,
211+
title: 'Data URL Viewer'
212+
},
206213
counter: {
207214
path: '/tools/counter',
208215
component: CounterPage,

src/hooks/useInputState.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Dispatch, SetStateAction, useState } from 'react';
1+
import React, { Dispatch, SetStateAction, useCallback, useState } from 'react';
22

33
const handleEventTargetValueChange =
44
<S>(callback: (value: S) => void) =>
@@ -17,8 +17,9 @@ function useInputState<S = undefined>(): [
1717
];
1818
function useInputState<S>(initialState?: S | (() => S)) {
1919
const [value, setValue] = useState<PossiblyUndefined<S, typeof initialState>>(initialState);
20+
const setValueByEvent = useCallback(handleEventTargetValueChange(setValue), [setValue]);
2021

21-
return [value, setValue, handleEventTargetValueChange(setValue)];
22+
return [value, setValue, setValueByEvent];
2223
}
2324

2425
export default useInputState;

src/layouts/appLayout/components/appHeader/components/appHeaderSearch/AppHeaderSearch.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FunctionComponent, useCallback, useRef, useState } from 'react';
1+
import React, { FunctionComponent, useCallback, useMemo, useRef, useState } from 'react';
22
import Search from 'antd/lib/input/Search';
33
import styles from './AppHeaderSearch.module.scss';
44
import { AutoComplete, InputRef } from 'antd';
@@ -12,21 +12,12 @@ import { AutoCompleteProps } from 'antd/lib/auto-complete';
1212
import classNames from 'classnames';
1313
import { useKey } from 'rooks';
1414
import { isEmpty } from 'lodash';
15+
import useAppSettings from '../../../../../../hooks/useAppSettings';
1516

1617
interface OptionType extends DefaultOptionType {
1718
data: MenuRouteItem;
1819
}
1920

20-
const allSearchOptions: OptionType[] = menuRouteItems.map((item) => {
21-
const title = item.title ?? item.route.title;
22-
23-
return {
24-
label: title,
25-
value: title,
26-
data: item
27-
};
28-
});
29-
3021
const filterOption: FilterFunc<OptionType> = (inputValue, option) => {
3122
const query = inputValue.trim().toLocaleLowerCase();
3223

@@ -49,11 +40,26 @@ interface Props extends Omit<AutoCompleteProps, 'options' | 'filterOption' | 'on
4940

5041
const AppHeaderSearch: FunctionComponent<Props> = ({ className, inputClassName, ...props }) => {
5142
const navigate = useNavigate();
52-
53-
const searchInputRef = useRef<InputRef>(null);
43+
const { doShowHiddenMenuItems } = useAppSettings();
5444

5545
const [query, setQuery] = useState<string>('');
5646

47+
const allSearchOptions = useMemo<OptionType[]>(() => {
48+
return menuRouteItems
49+
.filter((item) => doShowHiddenMenuItems || !item.isHidden)
50+
.map((item) => {
51+
const title = item.title ?? item.route.title;
52+
53+
return {
54+
label: title,
55+
value: title,
56+
data: item
57+
};
58+
});
59+
}, [doShowHiddenMenuItems]);
60+
61+
const searchInputRef = useRef<InputRef>(null);
62+
5763
const autoCompleteRef = useRef<BaseSelectRef>(null);
5864

5965
const selectOption = useCallback((option: MenuRouteItem) => {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.iframe {
2+
background: white;
3+
}

0 commit comments

Comments
 (0)