@astral/ui 1.17.0 → 1.19.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/ConfigProvider/ConfigProvider.d.ts +3 -3
- package/ConfigProvider/ConfigProvider.js +4 -1
- package/DashboardLayout/Header/Header.d.ts +1 -1
- package/ErrorBoundary/ErrorBoundary.d.ts +1 -1
- package/ErrorBoundary/ErrorBoundary.js +1 -2
- package/ProductSwitcher/ProductSwitcher.d.ts +6 -0
- package/ProductSwitcher/ProductSwitcher.js +46 -0
- package/ProductSwitcher/ProductSwitcherContent/ProductSwitcherContent.d.ts +9 -0
- package/ProductSwitcher/ProductSwitcherContent/ProductSwitcherContent.js +17 -0
- package/ProductSwitcher/ProductSwitcherContent/index.d.ts +1 -0
- package/ProductSwitcher/ProductSwitcherContent/index.js +17 -0
- package/ProductSwitcher/ProductSwitcherContent/styles.d.ts +35 -0
- package/ProductSwitcher/ProductSwitcherContent/styles.js +18 -0
- package/ProductSwitcher/index.d.ts +2 -0
- package/ProductSwitcher/index.js +18 -0
- package/ProductSwitcher/styles.d.ts +8 -0
- package/ProductSwitcher/styles.js +20 -0
- package/ProductSwitcher/types.d.ts +6 -0
- package/ProductSwitcher/types.js +2 -0
- package/esm/ConfigProvider/ConfigProvider.d.ts +3 -3
- package/esm/ConfigProvider/ConfigProvider.js +4 -1
- package/esm/DashboardLayout/Header/Header.d.ts +1 -1
- package/esm/ErrorBoundary/ErrorBoundary.d.ts +1 -1
- package/esm/ErrorBoundary/ErrorBoundary.js +1 -2
- package/esm/ProductSwitcher/ProductSwitcher.d.ts +6 -0
- package/esm/ProductSwitcher/ProductSwitcher.js +42 -0
- package/esm/ProductSwitcher/ProductSwitcherContent/ProductSwitcherContent.d.ts +9 -0
- package/esm/ProductSwitcher/ProductSwitcherContent/ProductSwitcherContent.js +13 -0
- package/esm/ProductSwitcher/ProductSwitcherContent/index.d.ts +1 -0
- package/esm/ProductSwitcher/ProductSwitcherContent/index.js +1 -0
- package/esm/ProductSwitcher/ProductSwitcherContent/styles.d.ts +35 -0
- package/esm/ProductSwitcher/ProductSwitcherContent/styles.js +15 -0
- package/esm/ProductSwitcher/index.d.ts +2 -0
- package/esm/ProductSwitcher/index.js +2 -0
- package/esm/ProductSwitcher/styles.d.ts +8 -0
- package/esm/ProductSwitcher/styles.js +17 -0
- package/esm/ProductSwitcher/types.d.ts +6 -0
- package/esm/ProductSwitcher/types.js +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +2 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
export declare type ConfigContextProps = {
|
|
3
|
-
locale
|
|
4
|
-
captureException
|
|
3
|
+
locale: Locale;
|
|
4
|
+
captureException: (error: any) => void;
|
|
5
5
|
};
|
|
6
|
-
export declare type ConfigProviderProps = ConfigContextProps & {
|
|
6
|
+
export declare type ConfigProviderProps = Partial<ConfigContextProps> & {
|
|
7
7
|
children: ReactNode;
|
|
8
8
|
};
|
|
9
9
|
export declare const ConfigContext: import("react").Context<ConfigContextProps>;
|
|
@@ -18,6 +18,9 @@ const ConfigProvider = ({ children, locale = ru_1.default, captureException, })
|
|
|
18
18
|
'На данный момент все ошибки, отлавливаемые в ErrorBoundary будут выводиться только в консоль');
|
|
19
19
|
}
|
|
20
20
|
}, []);
|
|
21
|
-
return ((0, jsx_runtime_1.jsx)(exports.ConfigContext.Provider, Object.assign({ value: {
|
|
21
|
+
return ((0, jsx_runtime_1.jsx)(exports.ConfigContext.Provider, Object.assign({ value: {
|
|
22
|
+
locale,
|
|
23
|
+
captureException: captureException || ((error) => console.error(error)),
|
|
24
|
+
} }, { children: children })));
|
|
22
25
|
};
|
|
23
26
|
exports.ConfigProvider = ConfigProvider;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ProductProps } from '../../Product';
|
|
3
|
-
import { ProfileProps } from '../../Profile
|
|
3
|
+
import { ProfileProps } from '../../Profile';
|
|
4
4
|
export declare type HeaderProps = {
|
|
5
5
|
product: ProductProps;
|
|
6
6
|
productSwitcher?: React.FC;
|
|
@@ -19,8 +19,7 @@ class ErrorBoundary extends react_1.default.Component {
|
|
|
19
19
|
return { error: true };
|
|
20
20
|
}
|
|
21
21
|
componentDidCatch(error) {
|
|
22
|
-
|
|
23
|
-
(_b = (_a = this.props).captureException) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
22
|
+
this.props.captureException(error);
|
|
24
23
|
}
|
|
25
24
|
handleReloadPage() {
|
|
26
25
|
location.reload();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { WidgetProduct } from './types';
|
|
3
|
+
export declare type ProductSwitcherProps = {
|
|
4
|
+
getProducts: () => Promise<Array<WidgetProduct>>;
|
|
5
|
+
};
|
|
6
|
+
export declare const ProductSwitcher: ({ getProducts }: ProductSwitcherProps) => JSX.Element;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ProductSwitcher = void 0;
|
|
13
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
14
|
+
const icons_1 = require("@astral/icons");
|
|
15
|
+
const react_1 = require("react");
|
|
16
|
+
const ConfigProvider_1 = require("../ConfigProvider");
|
|
17
|
+
const IconButton_1 = require("../IconButton");
|
|
18
|
+
const hooks_1 = require("../hooks");
|
|
19
|
+
const ProductSwitcherContent_1 = require("./ProductSwitcherContent");
|
|
20
|
+
const styles_1 = require("./styles");
|
|
21
|
+
const ProductSwitcher = ({ getProducts }) => {
|
|
22
|
+
const [products, setProducts] = (0, react_1.useState)([]);
|
|
23
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
24
|
+
const [isError, setIsError] = (0, react_1.useState)(false);
|
|
25
|
+
const { captureException } = (0, react_1.useContext)(ConfigProvider_1.ConfigContext);
|
|
26
|
+
const { open, anchorRef, handleOpenMenu, handleCloseMenu } = (0, hooks_1.useMenu)();
|
|
27
|
+
const handleShowProducts = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
handleOpenMenu();
|
|
29
|
+
if (!products.length) {
|
|
30
|
+
setIsLoading(true);
|
|
31
|
+
try {
|
|
32
|
+
const productsList = yield getProducts();
|
|
33
|
+
setProducts(productsList);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
setIsError(true);
|
|
37
|
+
captureException(error);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
setIsLoading(false);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(IconButton_1.IconButton, Object.assign({ ref: anchorRef, selected: open, variant: "text", onClick: handleShowProducts }, { children: (0, jsx_runtime_1.jsx)(icons_1.ProductsFillMd, {}) })), (0, jsx_runtime_1.jsx)(styles_1.WidgetMenu, Object.assign({ open: open, anchorEl: anchorRef.current, onClose: handleCloseMenu }, { children: (0, jsx_runtime_1.jsx)(styles_1.ContentWrapper, { children: (0, jsx_runtime_1.jsx)(ProductSwitcherContent_1.ProductSwitcherContent, { isLoading: isLoading, isError: isError, products: products }) }) }))] }));
|
|
45
|
+
};
|
|
46
|
+
exports.ProductSwitcher = ProductSwitcher;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { WidgetProduct } from '../types';
|
|
3
|
+
declare type ProductSwitcherContentProps = {
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
products: Array<WidgetProduct>;
|
|
6
|
+
isError: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const ProductSwitcherContent: ({ isLoading, isError, products, }: ProductSwitcherContentProps) => JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductSwitcherContent = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const ContentState_1 = require("../../ContentState");
|
|
6
|
+
const styles_1 = require("./styles");
|
|
7
|
+
const ProductSwitcherContent = ({ isLoading, isError, products = [], }) => {
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(ContentState_1.ContentState, Object.assign({ isLoading: isLoading, isCustom: isError, customState: {
|
|
9
|
+
imgAlt: 'Что-то пошло не так',
|
|
10
|
+
title: 'Что-то пошло не так',
|
|
11
|
+
description: 'Произошла ошибка. Повторите попытку позже.',
|
|
12
|
+
// TODO: imgSrc обязательный параметр, а в title не засунуть текст с иконкой. Соответствующая доработка в задаче:
|
|
13
|
+
// https://astraltrack.atlassian.net/jira/software/c/projects/UIKIT/boards/142?modal=detail&selectedIssue=UIKIT-435
|
|
14
|
+
imgSrc: '',
|
|
15
|
+
} }, { children: products.map((product) => ((0, jsx_runtime_1.jsxs)(styles_1.ProductItem, Object.assign({}, product, { children: [(0, jsx_runtime_1.jsx)(styles_1.Logo, { src: product.logoUrl, color: product.color }), product.name] }), product.name))) })));
|
|
16
|
+
};
|
|
17
|
+
exports.ProductSwitcherContent = ProductSwitcherContent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ProductSwitcherContent';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ProductSwitcherContent"), exports);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const ProductItem: import("@emotion/styled").StyledComponent<{
|
|
3
|
+
autoFocus?: boolean | undefined;
|
|
4
|
+
classes?: Partial<import("@mui/material").MenuItemClasses> | undefined;
|
|
5
|
+
dense?: boolean | undefined;
|
|
6
|
+
disabled?: boolean | undefined;
|
|
7
|
+
disableGutters?: boolean | undefined;
|
|
8
|
+
divider?: boolean | undefined;
|
|
9
|
+
selected?: boolean | undefined;
|
|
10
|
+
sx?: import("@mui/system").SxProps<import("@mui/material").Theme> | undefined;
|
|
11
|
+
} & Omit<{
|
|
12
|
+
action?: import("react").Ref<import("@mui/material").ButtonBaseActions> | undefined;
|
|
13
|
+
centerRipple?: boolean | undefined;
|
|
14
|
+
children?: import("react").ReactNode;
|
|
15
|
+
classes?: Partial<import("@mui/material").ButtonBaseClasses> | undefined;
|
|
16
|
+
disabled?: boolean | undefined;
|
|
17
|
+
disableRipple?: boolean | undefined;
|
|
18
|
+
disableTouchRipple?: boolean | undefined;
|
|
19
|
+
focusRipple?: boolean | undefined;
|
|
20
|
+
focusVisibleClassName?: string | undefined;
|
|
21
|
+
LinkComponent?: import("react").ElementType<any> | undefined;
|
|
22
|
+
onFocusVisible?: import("react").FocusEventHandler<any> | undefined;
|
|
23
|
+
sx?: import("@mui/system").SxProps<import("@mui/material").Theme> | undefined;
|
|
24
|
+
tabIndex?: number | undefined;
|
|
25
|
+
TouchRippleProps?: Partial<import("@mui/material/ButtonBase/TouchRipple").TouchRippleProps> | undefined;
|
|
26
|
+
touchRippleRef?: import("react").Ref<import("@mui/material/ButtonBase/TouchRipple").TouchRippleActions> | undefined;
|
|
27
|
+
}, "classes"> & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, "key" | "css" | keyof import("react").LiHTMLAttributes<HTMLLIElement>> & {
|
|
28
|
+
ref?: ((instance: HTMLLIElement | null) => void) | import("react").RefObject<HTMLLIElement> | null | undefined;
|
|
29
|
+
}, "disabled" | "action" | "divider" | "onFocusVisible" | "tabIndex" | "children" | "autoFocus" | "selected" | keyof import("@mui/material/OverridableComponent").CommonProps | "centerRipple" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "sx" | "TouchRippleProps" | "touchRippleRef" | "dense" | "disableGutters"> & {
|
|
30
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
31
|
+
}, {}, {}>;
|
|
32
|
+
export declare const Logo: import("@emotion/styled").StyledComponent<{
|
|
33
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
34
|
+
as?: import("react").ElementType<any> | undefined;
|
|
35
|
+
}, import("react").DetailedHTMLProps<import("react").ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, {}>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logo = exports.ProductItem = void 0;
|
|
4
|
+
const styles_1 = require("../../styles");
|
|
5
|
+
const MenuItem_1 = require("../../MenuItem");
|
|
6
|
+
exports.ProductItem = (0, styles_1.styled)(MenuItem_1.MenuItem) `
|
|
7
|
+
width: 100%;
|
|
8
|
+
|
|
9
|
+
border-radius: ${({ theme }) => theme.shape.small};
|
|
10
|
+
`;
|
|
11
|
+
exports.Logo = styles_1.styled.img `
|
|
12
|
+
width: 40px;
|
|
13
|
+
height: 40px;
|
|
14
|
+
margin-right: ${({ theme }) => theme.spacing(2)};
|
|
15
|
+
|
|
16
|
+
background-color: ${({ color }) => color};
|
|
17
|
+
border-radius: ${({ theme }) => theme.shape.small};
|
|
18
|
+
`;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ProductSwitcher"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const ContentWrapper: import("@emotion/styled").StyledComponent<{
|
|
3
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
4
|
+
as?: import("react").ElementType<any> | undefined;
|
|
5
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
6
|
+
export declare const WidgetMenu: import("@emotion/styled").StyledComponent<import("@mui/material/Menu/Menu").MenuProps & {
|
|
7
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
8
|
+
}, {}, {}>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WidgetMenu = exports.ContentWrapper = void 0;
|
|
4
|
+
const styles_1 = require("../styles");
|
|
5
|
+
const Menu_1 = require("../Menu");
|
|
6
|
+
exports.ContentWrapper = styles_1.styled.div `
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
align-items: center;
|
|
10
|
+
justify-content: center;
|
|
11
|
+
min-width: 240px;
|
|
12
|
+
max-width: 280px;
|
|
13
|
+
min-height: 150px;
|
|
14
|
+
padding: ${({ theme }) => theme.spacing(2)};
|
|
15
|
+
`;
|
|
16
|
+
exports.WidgetMenu = (0, styles_1.styled)(Menu_1.Menu) `
|
|
17
|
+
.MuiList-root {
|
|
18
|
+
padding: 0;
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
export declare type ConfigContextProps = {
|
|
3
|
-
locale
|
|
4
|
-
captureException
|
|
3
|
+
locale: Locale;
|
|
4
|
+
captureException: (error: any) => void;
|
|
5
5
|
};
|
|
6
|
-
export declare type ConfigProviderProps = ConfigContextProps & {
|
|
6
|
+
export declare type ConfigProviderProps = Partial<ConfigContextProps> & {
|
|
7
7
|
children: ReactNode;
|
|
8
8
|
};
|
|
9
9
|
export declare const ConfigContext: import("react").Context<ConfigContextProps>;
|
|
@@ -12,5 +12,8 @@ export const ConfigProvider = ({ children, locale = ru, captureException, }) =>
|
|
|
12
12
|
'На данный момент все ошибки, отлавливаемые в ErrorBoundary будут выводиться только в консоль');
|
|
13
13
|
}
|
|
14
14
|
}, []);
|
|
15
|
-
return (_jsx(ConfigContext.Provider, Object.assign({ value: {
|
|
15
|
+
return (_jsx(ConfigContext.Provider, Object.assign({ value: {
|
|
16
|
+
locale,
|
|
17
|
+
captureException: captureException || ((error) => console.error(error)),
|
|
18
|
+
} }, { children: children })));
|
|
16
19
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ProductProps } from '../../Product';
|
|
3
|
-
import { ProfileProps } from '../../Profile
|
|
3
|
+
import { ProfileProps } from '../../Profile';
|
|
4
4
|
export declare type HeaderProps = {
|
|
5
5
|
product: ProductProps;
|
|
6
6
|
productSwitcher?: React.FC;
|
|
@@ -14,8 +14,7 @@ class ErrorBoundary extends React.Component {
|
|
|
14
14
|
return { error: true };
|
|
15
15
|
}
|
|
16
16
|
componentDidCatch(error) {
|
|
17
|
-
|
|
18
|
-
(_b = (_a = this.props).captureException) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
17
|
+
this.props.captureException(error);
|
|
19
18
|
}
|
|
20
19
|
handleReloadPage() {
|
|
21
20
|
location.reload();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { WidgetProduct } from './types';
|
|
3
|
+
export declare type ProductSwitcherProps = {
|
|
4
|
+
getProducts: () => Promise<Array<WidgetProduct>>;
|
|
5
|
+
};
|
|
6
|
+
export declare const ProductSwitcher: ({ getProducts }: ProductSwitcherProps) => JSX.Element;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { ProductsFillMd } from '@astral/icons';
|
|
12
|
+
import { useContext, useState } from 'react';
|
|
13
|
+
import { ConfigContext } from '../ConfigProvider';
|
|
14
|
+
import { IconButton } from '../IconButton';
|
|
15
|
+
import { useMenu } from '../hooks';
|
|
16
|
+
import { ProductSwitcherContent } from './ProductSwitcherContent';
|
|
17
|
+
import { ContentWrapper, WidgetMenu } from './styles';
|
|
18
|
+
export const ProductSwitcher = ({ getProducts }) => {
|
|
19
|
+
const [products, setProducts] = useState([]);
|
|
20
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
21
|
+
const [isError, setIsError] = useState(false);
|
|
22
|
+
const { captureException } = useContext(ConfigContext);
|
|
23
|
+
const { open, anchorRef, handleOpenMenu, handleCloseMenu } = useMenu();
|
|
24
|
+
const handleShowProducts = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
handleOpenMenu();
|
|
26
|
+
if (!products.length) {
|
|
27
|
+
setIsLoading(true);
|
|
28
|
+
try {
|
|
29
|
+
const productsList = yield getProducts();
|
|
30
|
+
setProducts(productsList);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
setIsError(true);
|
|
34
|
+
captureException(error);
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
setIsLoading(false);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return (_jsxs(_Fragment, { children: [_jsx(IconButton, Object.assign({ ref: anchorRef, selected: open, variant: "text", onClick: handleShowProducts }, { children: _jsx(ProductsFillMd, {}) })), _jsx(WidgetMenu, Object.assign({ open: open, anchorEl: anchorRef.current, onClose: handleCloseMenu }, { children: _jsx(ContentWrapper, { children: _jsx(ProductSwitcherContent, { isLoading: isLoading, isError: isError, products: products }) }) }))] }));
|
|
42
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { WidgetProduct } from '../types';
|
|
3
|
+
declare type ProductSwitcherContentProps = {
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
products: Array<WidgetProduct>;
|
|
6
|
+
isError: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const ProductSwitcherContent: ({ isLoading, isError, products, }: ProductSwitcherContentProps) => JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ContentState } from '../../ContentState';
|
|
3
|
+
import { Logo, ProductItem } from './styles';
|
|
4
|
+
export const ProductSwitcherContent = ({ isLoading, isError, products = [], }) => {
|
|
5
|
+
return (_jsx(ContentState, Object.assign({ isLoading: isLoading, isCustom: isError, customState: {
|
|
6
|
+
imgAlt: 'Что-то пошло не так',
|
|
7
|
+
title: 'Что-то пошло не так',
|
|
8
|
+
description: 'Произошла ошибка. Повторите попытку позже.',
|
|
9
|
+
// TODO: imgSrc обязательный параметр, а в title не засунуть текст с иконкой. Соответствующая доработка в задаче:
|
|
10
|
+
// https://astraltrack.atlassian.net/jira/software/c/projects/UIKIT/boards/142?modal=detail&selectedIssue=UIKIT-435
|
|
11
|
+
imgSrc: '',
|
|
12
|
+
} }, { children: products.map((product) => (_jsxs(ProductItem, Object.assign({}, product, { children: [_jsx(Logo, { src: product.logoUrl, color: product.color }), product.name] }), product.name))) })));
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ProductSwitcherContent';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ProductSwitcherContent';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const ProductItem: import("@emotion/styled").StyledComponent<{
|
|
3
|
+
autoFocus?: boolean | undefined;
|
|
4
|
+
classes?: Partial<import("@mui/material").MenuItemClasses> | undefined;
|
|
5
|
+
dense?: boolean | undefined;
|
|
6
|
+
disabled?: boolean | undefined;
|
|
7
|
+
disableGutters?: boolean | undefined;
|
|
8
|
+
divider?: boolean | undefined;
|
|
9
|
+
selected?: boolean | undefined;
|
|
10
|
+
sx?: import("@mui/system").SxProps<import("@mui/material").Theme> | undefined;
|
|
11
|
+
} & Omit<{
|
|
12
|
+
action?: import("react").Ref<import("@mui/material").ButtonBaseActions> | undefined;
|
|
13
|
+
centerRipple?: boolean | undefined;
|
|
14
|
+
children?: import("react").ReactNode;
|
|
15
|
+
classes?: Partial<import("@mui/material").ButtonBaseClasses> | undefined;
|
|
16
|
+
disabled?: boolean | undefined;
|
|
17
|
+
disableRipple?: boolean | undefined;
|
|
18
|
+
disableTouchRipple?: boolean | undefined;
|
|
19
|
+
focusRipple?: boolean | undefined;
|
|
20
|
+
focusVisibleClassName?: string | undefined;
|
|
21
|
+
LinkComponent?: import("react").ElementType<any> | undefined;
|
|
22
|
+
onFocusVisible?: import("react").FocusEventHandler<any> | undefined;
|
|
23
|
+
sx?: import("@mui/system").SxProps<import("@mui/material").Theme> | undefined;
|
|
24
|
+
tabIndex?: number | undefined;
|
|
25
|
+
TouchRippleProps?: Partial<import("@mui/material/ButtonBase/TouchRipple").TouchRippleProps> | undefined;
|
|
26
|
+
touchRippleRef?: import("react").Ref<import("@mui/material/ButtonBase/TouchRipple").TouchRippleActions> | undefined;
|
|
27
|
+
}, "classes"> & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, "key" | "css" | keyof import("react").LiHTMLAttributes<HTMLLIElement>> & {
|
|
28
|
+
ref?: ((instance: HTMLLIElement | null) => void) | import("react").RefObject<HTMLLIElement> | null | undefined;
|
|
29
|
+
}, "disabled" | "action" | "divider" | "onFocusVisible" | "tabIndex" | "children" | "autoFocus" | "selected" | keyof import("@mui/material/OverridableComponent").CommonProps | "centerRipple" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "sx" | "TouchRippleProps" | "touchRippleRef" | "dense" | "disableGutters"> & {
|
|
30
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
31
|
+
}, {}, {}>;
|
|
32
|
+
export declare const Logo: import("@emotion/styled").StyledComponent<{
|
|
33
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
34
|
+
as?: import("react").ElementType<any> | undefined;
|
|
35
|
+
}, import("react").DetailedHTMLProps<import("react").ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, {}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { styled } from '../../styles';
|
|
2
|
+
import { MenuItem } from '../../MenuItem';
|
|
3
|
+
export const ProductItem = styled(MenuItem) `
|
|
4
|
+
width: 100%;
|
|
5
|
+
|
|
6
|
+
border-radius: ${({ theme }) => theme.shape.small};
|
|
7
|
+
`;
|
|
8
|
+
export const Logo = styled.img `
|
|
9
|
+
width: 40px;
|
|
10
|
+
height: 40px;
|
|
11
|
+
margin-right: ${({ theme }) => theme.spacing(2)};
|
|
12
|
+
|
|
13
|
+
background-color: ${({ color }) => color};
|
|
14
|
+
border-radius: ${({ theme }) => theme.shape.small};
|
|
15
|
+
`;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const ContentWrapper: import("@emotion/styled").StyledComponent<{
|
|
3
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
4
|
+
as?: import("react").ElementType<any> | undefined;
|
|
5
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
6
|
+
export declare const WidgetMenu: import("@emotion/styled").StyledComponent<import("@mui/material/Menu/Menu").MenuProps & {
|
|
7
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
8
|
+
}, {}, {}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { styled } from '../styles';
|
|
2
|
+
import { Menu } from '../Menu';
|
|
3
|
+
export const ContentWrapper = styled.div `
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
align-items: center;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
min-width: 240px;
|
|
9
|
+
max-width: 280px;
|
|
10
|
+
min-height: 150px;
|
|
11
|
+
padding: ${({ theme }) => theme.spacing(2)};
|
|
12
|
+
`;
|
|
13
|
+
export const WidgetMenu = styled(Menu) `
|
|
14
|
+
.MuiList-root {
|
|
15
|
+
padding: 0;
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/index.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ export * from './MenuGroup';
|
|
|
47
47
|
export * from './OverflowTypography';
|
|
48
48
|
export * from './Placeholder';
|
|
49
49
|
export * from './Product';
|
|
50
|
+
export * from './ProductSwitcher';
|
|
50
51
|
export * from './Profile';
|
|
51
52
|
export * from './Radio';
|
|
52
53
|
export * from './RadioGroup';
|
package/esm/index.js
CHANGED
|
@@ -47,6 +47,7 @@ export * from './MenuGroup';
|
|
|
47
47
|
export * from './OverflowTypography';
|
|
48
48
|
export * from './Placeholder';
|
|
49
49
|
export * from './Product';
|
|
50
|
+
export * from './ProductSwitcher';
|
|
50
51
|
export * from './Profile';
|
|
51
52
|
export * from './Radio';
|
|
52
53
|
export * from './RadioGroup';
|
package/index.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ export * from './MenuGroup';
|
|
|
47
47
|
export * from './OverflowTypography';
|
|
48
48
|
export * from './Placeholder';
|
|
49
49
|
export * from './Product';
|
|
50
|
+
export * from './ProductSwitcher';
|
|
50
51
|
export * from './Profile';
|
|
51
52
|
export * from './Radio';
|
|
52
53
|
export * from './RadioGroup';
|
package/index.js
CHANGED
|
@@ -63,6 +63,7 @@ __exportStar(require("./MenuGroup"), exports);
|
|
|
63
63
|
__exportStar(require("./OverflowTypography"), exports);
|
|
64
64
|
__exportStar(require("./Placeholder"), exports);
|
|
65
65
|
__exportStar(require("./Product"), exports);
|
|
66
|
+
__exportStar(require("./ProductSwitcher"), exports);
|
|
66
67
|
__exportStar(require("./Profile"), exports);
|
|
67
68
|
__exportStar(require("./Radio"), exports);
|
|
68
69
|
__exportStar(require("./RadioGroup"), exports);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astral/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"browser": "./src/index.ts",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@astral/icons": "^1.
|
|
7
|
+
"@astral/icons": "^1.19.0",
|
|
8
8
|
"@emotion/cache": "11.7.1",
|
|
9
9
|
"@emotion/react": "11.9.0",
|
|
10
10
|
"@emotion/server": "11.4.0",
|