@camunda/camunda-composite-components 0.1.4-rc.1 → 0.1.4
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/lib/esm/api/api.d.ts +2 -4
- package/lib/esm/api/api.js +2 -9
- package/lib/esm/api/endpoints.const.d.ts +0 -2
- package/lib/esm/api/endpoints.const.js +0 -14
- package/lib/esm/components/c3-navigation/c3-navigation-appbar.js +3 -3
- package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-user-sidebar.js +4 -10
- package/lib/esm/components/c3-navigation/c3-navigation.js +8 -9
- package/lib/esm/components/c3-navigation/c3-navigation.types.d.ts +0 -1
- package/lib/esm/components/c3-navigation/c3-notification-provider/c3-notification-provider.js +1 -1
- package/lib/esm/components/c3-navigation/story-helpers.d.ts +0 -1
- package/lib/esm/components/c3-navigation/story-helpers.js +4 -6
- package/lib/esm/components/c3-user-configuration/c3-user-configuration-provider.d.ts +1 -4
- package/lib/esm/components/c3-user-configuration/c3-user-configuration-provider.js +3 -11
- package/lib/esm/index.d.ts +0 -1
- package/lib/esm/index.js +0 -1
- package/package.json +5 -9
- package/lib/esm/api/profile.d.ts +0 -16
- package/lib/esm/api/profile.js +0 -29
- package/lib/esm/components/c3-user-configuration/c3-profile-provider/c3-profile-provider.d.ts +0 -10
- package/lib/esm/components/c3-user-configuration/c3-profile-provider/c3-profile-provider.js +0 -34
- package/lib/esm/components/c3-user-configuration/c3-profile-provider/c3-theme-provider.d.ts +0 -3
- package/lib/esm/components/c3-user-configuration/c3-profile-provider/c3-theme-provider.js +0 -23
package/lib/esm/api/api.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare class HttpError extends Error {
|
|
|
4
4
|
constructor(message: string, status: number);
|
|
5
5
|
}
|
|
6
6
|
export interface RequestPayload {
|
|
7
|
-
base?: "notifications"
|
|
7
|
+
base?: "notifications";
|
|
8
8
|
stage?: Stage;
|
|
9
9
|
endpoints?: Endpoints;
|
|
10
10
|
url: string;
|
|
@@ -18,8 +18,6 @@ export interface RequestPayload {
|
|
|
18
18
|
token: string;
|
|
19
19
|
refreshTokenMethod: () => Promise<string>;
|
|
20
20
|
};
|
|
21
|
-
body?:
|
|
22
|
-
[key: string]: unknown;
|
|
23
|
-
};
|
|
21
|
+
body?: any;
|
|
24
22
|
}
|
|
25
23
|
export declare function request(payload: RequestPayload): Promise<any>;
|
package/lib/esm/api/api.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getEndpoint, NOTIFICATIONS
|
|
1
|
+
import { getEndpoint, NOTIFICATIONS } from "./endpoints.const";
|
|
2
2
|
import { JWTUtils } from "./jwt.utils";
|
|
3
3
|
export class HttpError extends Error {
|
|
4
4
|
status;
|
|
@@ -41,13 +41,6 @@ export async function request(payload) {
|
|
|
41
41
|
base = getEndpoint(payload.stage, NOTIFICATIONS);
|
|
42
42
|
}
|
|
43
43
|
break;
|
|
44
|
-
case "theme":
|
|
45
|
-
if (payload.endpoints?.theme) {
|
|
46
|
-
base = payload.endpoints.theme;
|
|
47
|
-
}
|
|
48
|
-
else if (payload.stage) {
|
|
49
|
-
base = getEndpoint(payload.stage, THEME);
|
|
50
|
-
}
|
|
51
44
|
}
|
|
52
45
|
}
|
|
53
46
|
const url = base ? `${base}/${payload.url}` : payload.url;
|
|
@@ -69,7 +62,7 @@ export async function request(payload) {
|
|
|
69
62
|
const responseType = payload.responseType ?? type;
|
|
70
63
|
switch (responseType) {
|
|
71
64
|
case "json":
|
|
72
|
-
return response.
|
|
65
|
+
return response.json();
|
|
73
66
|
case "text":
|
|
74
67
|
return response.text();
|
|
75
68
|
default:
|
|
@@ -6,10 +6,8 @@ export interface Endpoint {
|
|
|
6
6
|
}
|
|
7
7
|
export interface Endpoints {
|
|
8
8
|
notifications?: string;
|
|
9
|
-
theme?: string;
|
|
10
9
|
}
|
|
11
10
|
export declare const NOTIFICATIONS: Endpoint;
|
|
12
|
-
export declare const THEME: Endpoint;
|
|
13
11
|
export type Stage = "dev" | "int" | "prod";
|
|
14
12
|
export declare function getEndpoint(stage: Stage, endpoint: Endpoint): string;
|
|
15
13
|
export declare function getEndpointByOptions(options: {
|
|
@@ -4,12 +4,6 @@ export const NOTIFICATIONS = {
|
|
|
4
4
|
int: "https://notifications.cloud.ultrawombat.com",
|
|
5
5
|
prod: "https://notifications.cloud.camunda.io",
|
|
6
6
|
};
|
|
7
|
-
export const THEME = {
|
|
8
|
-
id: "theme",
|
|
9
|
-
dev: "https://accounts.cloud.dev.ultrawombat.com",
|
|
10
|
-
int: "https://accounts.cloud.ultrawombat.com",
|
|
11
|
-
prod: "https://accounts.cloud.camunda.io",
|
|
12
|
-
};
|
|
13
7
|
export function getEndpoint(stage, endpoint) {
|
|
14
8
|
switch (stage) {
|
|
15
9
|
case "dev":
|
|
@@ -31,14 +25,6 @@ export function getEndpointByOptions(options) {
|
|
|
31
25
|
else if (options.stage) {
|
|
32
26
|
return getEndpoint(options.stage, options.endpoint);
|
|
33
27
|
}
|
|
34
|
-
break;
|
|
35
|
-
case "theme":
|
|
36
|
-
if (options.endpoints?.theme) {
|
|
37
|
-
return options.endpoints.theme;
|
|
38
|
-
}
|
|
39
|
-
else if (options.stage) {
|
|
40
|
-
return getEndpoint(options.stage, options.endpoint);
|
|
41
|
-
}
|
|
42
28
|
}
|
|
43
29
|
throw new Error(`Missing stage or notifications endpoint`);
|
|
44
30
|
}
|
|
@@ -30,7 +30,7 @@ export const C3NavigationAppBar = ({ appBar, forwardRef, navbar, }) => {
|
|
|
30
30
|
React.createElement(NavWrapper, null,
|
|
31
31
|
React.createElement(SideNav, { ref: panelRef, "aria-label": appBar.ariaLabel || "Side Navigation", expanded: appBarOpen, isPersistent: false },
|
|
32
32
|
React.createElement(SideNavItems, null,
|
|
33
|
-
React.createElement("li", null, navbar.elements.length > 0 && (React.createElement(HeaderSideNavItems, { hasDivider: true }, navbar.elements.map((element) => (React.createElement(HeaderMenuItem, { key: element.key,
|
|
33
|
+
React.createElement("li", null, navbar.elements.length > 0 && (React.createElement(HeaderSideNavItems, { hasDivider: true }, navbar.elements.map((element) => (React.createElement(HeaderMenuItem, { key: element.key, as: element.routeProps && forwardRef, isActive: element.isCurrentPage, ...element.routeProps, onClick: () => {
|
|
34
34
|
if (element.routeProps.onClick) {
|
|
35
35
|
element.routeProps.onClick();
|
|
36
36
|
}
|
|
@@ -41,7 +41,7 @@ export const C3NavigationAppBar = ({ appBar, forwardRef, navbar, }) => {
|
|
|
41
41
|
appBar.elements &&
|
|
42
42
|
appBar.elements.map((element) => {
|
|
43
43
|
if (element.subElements && element.subElements.length > 0) {
|
|
44
|
-
return (React.createElement(SideNavMenu, { large: true, title: element.label, key: element.key }, element.subElements.map((subElement) => (React.createElement(SideNavMenuItem, {
|
|
44
|
+
return (React.createElement(SideNavMenu, { large: true, title: element.label, key: element.key }, element.subElements.map((subElement) => (React.createElement(SideNavMenuItem, { as: subElement.routeProps && forwardRef, key: subElement.key, href: subElement.href, target: subElement.href ? subElement.target : undefined, ...subElement.routeProps, onClick: () => {
|
|
45
45
|
if (subElement.onClick) {
|
|
46
46
|
subElement.onClick();
|
|
47
47
|
}
|
|
@@ -57,7 +57,7 @@ export const C3NavigationAppBar = ({ appBar, forwardRef, navbar, }) => {
|
|
|
57
57
|
} }, subElement.label)))));
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
|
-
return (React.createElement(SideNavLink, {
|
|
60
|
+
return (React.createElement(SideNavLink, { as: element.routeProps && forwardRef, key: element.key, large: true, isActive: element.active, ...element.routeProps, onClick: () => {
|
|
61
61
|
if (element.onClick) {
|
|
62
62
|
element.onClick();
|
|
63
63
|
}
|
|
@@ -4,8 +4,6 @@ import { FormLabel, RadioButton, RadioButtonGroup, Stack, SwitcherDivider, Toggl
|
|
|
4
4
|
import { UserAvatar } from "@carbon/react/icons";
|
|
5
5
|
import styled from "styled-components";
|
|
6
6
|
import { useUserSidebarState } from "./c3-sidebar-state-provider";
|
|
7
|
-
import { useC3Profile, } from "../../c3-user-configuration/c3-profile-provider/c3-profile-provider";
|
|
8
|
-
import { useC3UserConfiguration } from "../../c3-user-configuration/c3-user-configuration-provider";
|
|
9
7
|
const VersionWrapper = styled.div `
|
|
10
8
|
align-self: end;
|
|
11
9
|
padding: 0.5rem 1rem;
|
|
@@ -30,8 +28,6 @@ const C3UserSidebar = ({ sideBar }) => {
|
|
|
30
28
|
const themeSelector = customElements?.themeSelector;
|
|
31
29
|
const stageToggle = customElements?.stageToggle;
|
|
32
30
|
const customSection = customElements?.customSection;
|
|
33
|
-
const { handleTheme } = useC3UserConfiguration();
|
|
34
|
-
const { theme, onThemeChange } = useC3Profile();
|
|
35
31
|
const { isOpen } = useUserSidebarState();
|
|
36
32
|
const itemTabIndex = isOpen ? undefined : -1;
|
|
37
33
|
return (React.createElement(C3NavigationSideBar, { sideBar: {
|
|
@@ -55,16 +51,14 @@ const C3UserSidebar = ({ sideBar }) => {
|
|
|
55
51
|
React.createElement(Stack, null,
|
|
56
52
|
React.createElement("div", { className: "textPrimary", style: { fontSize: "14px" } }, profile.user.name),
|
|
57
53
|
React.createElement("div", { className: "textPrimary", style: { fontSize: "12px" } }, profile.user.email))))),
|
|
58
|
-
|
|
54
|
+
themeSelector && (React.createElement(React.Fragment, null,
|
|
59
55
|
React.createElement(SwitcherDivider, null),
|
|
60
56
|
React.createElement("div", { style: {
|
|
61
57
|
padding: ".5rem 1rem",
|
|
62
58
|
} },
|
|
63
|
-
React.createElement(RadioButtonGroup, { name: "theme-radio-group", legendText: "Theme", orientation: "vertical", onChange: (newValue) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
: themeSelector?.onChange(newValue);
|
|
67
|
-
}, valueSelected: handleTheme ? theme : themeSelector?.currentTheme },
|
|
59
|
+
React.createElement(RadioButtonGroup, { name: "theme-radio-group", defaultSelected: themeSelector.currentTheme, legendText: "Theme", orientation: "vertical", onChange: (newValue) => {
|
|
60
|
+
themeSelector.onChange(newValue);
|
|
61
|
+
} },
|
|
68
62
|
React.createElement(RadioButton, { id: "light", labelText: "Light", value: "light", tabIndex: itemTabIndex }),
|
|
69
63
|
React.createElement(RadioButton, { id: "system", labelText: "System", value: "system", tabIndex: itemTabIndex }),
|
|
70
64
|
React.createElement(RadioButton, { id: "dark", labelText: "Dark", value: "dark", tabIndex: itemTabIndex }))))),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Header, HeaderContainer, HeaderGlobalBar, HeaderMenuItem, HeaderName
|
|
1
|
+
import { Header, HeaderContainer, HeaderGlobalBar, HeaderMenuItem, HeaderName, HeaderNavigation, SkipToContent, Tag, Toggletip, ToggletipButton, ToggletipContent, Stack as CarbonStack, } from "@carbon/react";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import C3InfoSidebar from "./c3-navigation-sidebar/c3-info-sidebar";
|
|
4
4
|
import { C3NotificationSidebar } from "./c3-navigation-sidebar/c3-notification-sidebar";
|
|
@@ -16,10 +16,8 @@ import { C3SidebarStateProvider } from "./c3-navigation-sidebar/c3-sidebar-state
|
|
|
16
16
|
* Docs: https://react.carbondesignsystem.com/?path=/story/components-ui-shell--fixed-side-nav
|
|
17
17
|
*/
|
|
18
18
|
const BREAKPOINT_LG_WIDTH = "66rem"; // This is Carbon's breakpoint (lg) width https://github.com/carbon-design-system/carbon/blob/main/packages/layout/src/index.js#L56
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
grid-auto-flow: column;
|
|
22
|
-
gap: 0.5rem;
|
|
19
|
+
const Stack = styled(CarbonStack) `
|
|
20
|
+
align-items: center;
|
|
23
21
|
`;
|
|
24
22
|
const StyledToggletipContent = styled(ToggletipContent) `
|
|
25
23
|
.cds--link:visited {
|
|
@@ -41,10 +39,11 @@ export const C3Navigation = ({ app, appBar, forwardRef, navbar, orgSideBar, info
|
|
|
41
39
|
return (React.createElement(Header, { "aria-label": app.ariaLabel },
|
|
42
40
|
React.createElement(SkipToContent, null),
|
|
43
41
|
displayAppBar && (React.createElement(C3NavigationAppBar, { app: app, appBar: appBar, forwardRef: forwardRef, navbar: navbar })),
|
|
44
|
-
React.createElement(HeaderName, {
|
|
45
|
-
React.createElement(
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
React.createElement(HeaderName, { as: forwardRef, prefix: "", ...app.routeProps },
|
|
43
|
+
React.createElement(Stack, { gap: 3, orientation: "horizontal" },
|
|
44
|
+
React.createElement(CamundaLogo, { "aria-label": "Camunda" }),
|
|
45
|
+
React.createElement("span", null, app.name))),
|
|
46
|
+
React.createElement(HeaderNavigation, { "aria-label": app.ariaLabel }, navbar.elements.map((element) => (React.createElement(HeaderMenuItem, { key: element.key, as: element.routeProps && forwardRef, isActive: element.isCurrentPage, ...element.routeProps },
|
|
48
47
|
React.createElement("span", null, element.label))))),
|
|
49
48
|
React.createElement(HeaderGlobalBar, null,
|
|
50
49
|
React.createElement("div", { style: {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { Tag } from "@carbon/react";
|
|
3
2
|
import { Endpoints, Stage } from "../../api/endpoints.const";
|
|
4
3
|
import { C3NavigationAppBarProps, C3NavigationInfoSideBarProps, C3NavigationNotificationsSideBarProps, C3NavigationOrgSideBarProps, C3NavigationUserSideBarProps } from "./c3-navigation-sidebar/c3-navigation-sidebar.types";
|
package/lib/esm/components/c3-navigation/c3-notification-provider/c3-notification-provider.js
CHANGED
|
@@ -16,7 +16,7 @@ const C3NotificationProvider = ({ children, }) => {
|
|
|
16
16
|
const [activeOrganizationId, setActiveOrganizationId] = useState("");
|
|
17
17
|
const [isEventStreamAvailable, setEventStreamAvailable] = useState(false);
|
|
18
18
|
const config = useContext(C3UserConfigurationContext);
|
|
19
|
-
const enabled = !!config
|
|
19
|
+
const enabled = !!config;
|
|
20
20
|
// if the organization changes, we need to reset the state
|
|
21
21
|
if (enabled && config.activeOrganizationId !== activeOrganizationId) {
|
|
22
22
|
setActiveOrganizationId(config.activeOrganizationId);
|
|
@@ -19,7 +19,6 @@ export declare function createOrgSideBarProps(options: {
|
|
|
19
19
|
export declare function createUserSideBarProps(options: {
|
|
20
20
|
isOpen: boolean;
|
|
21
21
|
customSection?: React.JSX.Element;
|
|
22
|
-
hideThemeSelector?: boolean;
|
|
23
22
|
}): C3NavigationProps["userSideBar"];
|
|
24
23
|
export declare function createNotificationSideBarProps(options: {
|
|
25
24
|
isOpen: boolean;
|
|
@@ -169,12 +169,10 @@ export function createUserSideBarProps(options) {
|
|
|
169
169
|
name: "Team Cloud",
|
|
170
170
|
},
|
|
171
171
|
},
|
|
172
|
-
themeSelector:
|
|
173
|
-
|
|
174
|
-
:
|
|
175
|
-
|
|
176
|
-
onChange: (newTheme) => console.log(`Selected ${newTheme} theme`),
|
|
177
|
-
},
|
|
172
|
+
themeSelector: {
|
|
173
|
+
currentTheme: "dark",
|
|
174
|
+
onChange: () => console.log("Selected dark theme"),
|
|
175
|
+
},
|
|
178
176
|
stageToggle: {
|
|
179
177
|
prodFeaturesEnabled: true,
|
|
180
178
|
toggle: () => console.log("Toggle stage"),
|
|
@@ -7,16 +7,13 @@ type C3UserConfigurationBase = {
|
|
|
7
7
|
};
|
|
8
8
|
type C3UserConfigurationWithEndpoints = C3UserConfigurationBase & {
|
|
9
9
|
endpoints: Endpoints;
|
|
10
|
-
handleTheme?: never;
|
|
11
10
|
};
|
|
12
11
|
type C3UserConfigurationWithStage = C3UserConfigurationBase & {
|
|
13
12
|
stage: Stage;
|
|
14
|
-
handleTheme?: boolean;
|
|
15
13
|
};
|
|
16
14
|
export type C3UserConfiguration = C3UserConfigurationWithEndpoints | C3UserConfigurationWithStage;
|
|
17
|
-
export declare const C3UserConfigurationContext: React.Context<C3UserConfiguration>;
|
|
15
|
+
export declare const C3UserConfigurationContext: React.Context<C3UserConfiguration | null>;
|
|
18
16
|
declare const C3UserConfigurationProvider: FC<C3UserConfiguration & {
|
|
19
17
|
children?: ReactNode;
|
|
20
18
|
}>;
|
|
21
|
-
export declare const useC3UserConfiguration: () => C3UserConfiguration;
|
|
22
19
|
export default C3UserConfigurationProvider;
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import React
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
stage: "dev",
|
|
5
|
-
activeOrganizationId: "",
|
|
6
|
-
userToken: "",
|
|
7
|
-
getNewUserToken: () => Promise.resolve(""),
|
|
8
|
-
});
|
|
9
|
-
const C3UserConfigurationProvider = ({ children, ...config }) => (React.createElement(C3UserConfigurationContext.Provider, { value: config },
|
|
10
|
-
React.createElement(C3ProfileProvider, null, children)));
|
|
11
|
-
export const useC3UserConfiguration = () => useContext(C3UserConfigurationContext);
|
|
1
|
+
import React from "react";
|
|
2
|
+
export const C3UserConfigurationContext = React.createContext(null);
|
|
3
|
+
const C3UserConfigurationProvider = ({ children, ...config }) => (React.createElement(C3UserConfigurationContext.Provider, { value: config }, children));
|
|
12
4
|
export default C3UserConfigurationProvider;
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -7,4 +7,3 @@ export { C3AppMenuIcon } from "./icons/c3-icons";
|
|
|
7
7
|
export { C3IconProps } from "./icons/c3-icons.types";
|
|
8
8
|
export { default as C3UserConfigurationProvider } from "./components/c3-user-configuration/c3-user-configuration-provider";
|
|
9
9
|
export { C3UserConfiguration } from "./components/c3-user-configuration/c3-user-configuration-provider";
|
|
10
|
-
export { useC3Profile } from "./components/c3-user-configuration/c3-profile-provider/c3-profile-provider";
|
package/lib/esm/index.js
CHANGED
|
@@ -2,4 +2,3 @@ export { C3EmptyState } from "./components/c3-empty-state/c3-empty-state";
|
|
|
2
2
|
export { default as C3Navigation } from "./components/c3-navigation";
|
|
3
3
|
export { C3AppMenuIcon } from "./icons/c3-icons";
|
|
4
4
|
export { default as C3UserConfigurationProvider } from "./components/c3-user-configuration/c3-user-configuration-provider";
|
|
5
|
-
export { useC3Profile } from "./components/c3-user-configuration/c3-profile-provider/c3-profile-provider";
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camunda/camunda-composite-components",
|
|
3
|
-
"version": "0.1.4
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"clean": "rimraf lib/",
|
|
6
6
|
"build": "yarn clean && tsc",
|
|
7
7
|
"storybook": "storybook dev -p 6006",
|
|
8
8
|
"start": "yarn storybook",
|
|
9
9
|
"build:storybook": "storybook build",
|
|
10
|
-
"build:all": "yarn build && yarn build:storybook",
|
|
11
10
|
"serve:storybook": "serve ./storybook-static -p 8081 -n -L",
|
|
12
11
|
"prepare": "husky install",
|
|
13
12
|
"format": "prettier --write .",
|
|
@@ -47,8 +46,8 @@
|
|
|
47
46
|
"@storybook/testing-library": "0.2.0",
|
|
48
47
|
"@types/carbon-components-react": "7.55.2",
|
|
49
48
|
"@types/event-source-polyfill": "1.0.1",
|
|
50
|
-
"@types/node": "18.17.
|
|
51
|
-
"@types/react": "18.2.
|
|
49
|
+
"@types/node": "18.17.12",
|
|
50
|
+
"@types/react": "18.2.21",
|
|
52
51
|
"@types/react-dom": "18.2.7",
|
|
53
52
|
"@types/styled-components": "5.1.26",
|
|
54
53
|
"@typescript-eslint/eslint-plugin": "5.62.0",
|
|
@@ -73,17 +72,14 @@
|
|
|
73
72
|
"rimraf": "3.0.2",
|
|
74
73
|
"sass": "1.66.1",
|
|
75
74
|
"sass-loader": "13.3.2",
|
|
76
|
-
"serve": "14.2.
|
|
75
|
+
"serve": "14.2.1",
|
|
77
76
|
"storybook": "7.3.2",
|
|
78
77
|
"style-loader": "3.3.3",
|
|
79
78
|
"styled-components": "6.0.7",
|
|
80
|
-
"typescript": "5.
|
|
79
|
+
"typescript": "5.2.2",
|
|
81
80
|
"wait-on": "7.0.1",
|
|
82
81
|
"webpack": "5.88.2"
|
|
83
82
|
},
|
|
84
|
-
"dependencies": {
|
|
85
|
-
"jwt-decode": "3.1.2"
|
|
86
|
-
},
|
|
87
83
|
"peerDependencies": {
|
|
88
84
|
"@carbon/react": "1.x",
|
|
89
85
|
"event-source-polyfill": "1.0.x",
|
package/lib/esm/api/profile.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { C3NotificationsProps } from "../components/c3-navigation/c3-navigation.types";
|
|
2
|
-
import { Theme } from "../components/c3-user-configuration/c3-profile-provider/c3-profile-provider";
|
|
3
|
-
export type Profile = {
|
|
4
|
-
theme: Theme;
|
|
5
|
-
};
|
|
6
|
-
export type Token = {
|
|
7
|
-
sub?: string;
|
|
8
|
-
"https://camunda.com/settings"?: {
|
|
9
|
-
theme?: Theme;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
export declare const getUserTheme: (userToken: string) => Theme | null;
|
|
13
|
-
export type UpdateThemeOptions = C3NotificationsProps & {
|
|
14
|
-
theme: Profile["theme"];
|
|
15
|
-
};
|
|
16
|
-
export declare const updateTheme: ({ endpoints, stage, userToken, getNewUserToken, theme, }: UpdateThemeOptions) => Promise<void>;
|
package/lib/esm/api/profile.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import jwt from "jwt-decode";
|
|
2
|
-
import { request } from "./api";
|
|
3
|
-
const decodeJWT = (userToken) => {
|
|
4
|
-
let decodedToken = {};
|
|
5
|
-
try {
|
|
6
|
-
decodedToken = jwt(userToken);
|
|
7
|
-
}
|
|
8
|
-
catch (error) {
|
|
9
|
-
console.error("User token invalid");
|
|
10
|
-
}
|
|
11
|
-
return decodedToken;
|
|
12
|
-
};
|
|
13
|
-
export const getUserTheme = (userToken) => decodeJWT(userToken)["https://camunda.com/settings"]?.theme || null;
|
|
14
|
-
export const updateTheme = async ({ endpoints, stage, userToken, getNewUserToken, theme, }) => {
|
|
15
|
-
try {
|
|
16
|
-
await request({
|
|
17
|
-
method: "patch",
|
|
18
|
-
base: "theme",
|
|
19
|
-
stage,
|
|
20
|
-
endpoints,
|
|
21
|
-
camundaAuth: { token: userToken, refreshTokenMethod: getNewUserToken },
|
|
22
|
-
url: `external/user/theme`,
|
|
23
|
-
body: { theme },
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
console.error(error);
|
|
28
|
-
}
|
|
29
|
-
};
|
package/lib/esm/components/c3-user-configuration/c3-profile-provider/c3-profile-provider.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React, { FC, PropsWithChildren } from "react";
|
|
2
|
-
export type Theme = "light" | "dark" | "system";
|
|
3
|
-
export type C3ProfileContextValue = {
|
|
4
|
-
isEnabled: boolean;
|
|
5
|
-
theme: Theme;
|
|
6
|
-
onThemeChange: (newTheme: Theme) => void;
|
|
7
|
-
};
|
|
8
|
-
export declare const C3ProfileContext: React.Context<C3ProfileContextValue>;
|
|
9
|
-
export declare const C3ProfileProvider: FC<PropsWithChildren>;
|
|
10
|
-
export declare const useC3Profile: () => C3ProfileContextValue;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import React, { createContext, useContext, useEffect, useState, } from "react";
|
|
2
|
-
import { C3UserConfigurationContext } from "../c3-user-configuration-provider";
|
|
3
|
-
import { getUserTheme, updateTheme } from "../../../api/profile";
|
|
4
|
-
import { ThemeProvider } from "./c3-theme-provider";
|
|
5
|
-
const defaultTheme = "light";
|
|
6
|
-
export const C3ProfileContext = createContext({
|
|
7
|
-
isEnabled: false,
|
|
8
|
-
theme: defaultTheme,
|
|
9
|
-
onThemeChange: () => undefined,
|
|
10
|
-
});
|
|
11
|
-
export const C3ProfileProvider = ({ children }) => {
|
|
12
|
-
const config = useContext(C3UserConfigurationContext);
|
|
13
|
-
const isEnabled = !!config;
|
|
14
|
-
const [theme, setTheme] = useState(getUserTheme(config.userToken) || defaultTheme);
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (isEnabled && config?.userToken) {
|
|
17
|
-
const currentTheme = getUserTheme(config.userToken);
|
|
18
|
-
if (currentTheme)
|
|
19
|
-
setTheme(currentTheme);
|
|
20
|
-
}
|
|
21
|
-
}, [config?.userToken]);
|
|
22
|
-
const onThemeChange = (newTheme) => {
|
|
23
|
-
if (isEnabled) {
|
|
24
|
-
setTheme(newTheme);
|
|
25
|
-
updateTheme({ ...config, theme: newTheme });
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
if (!isEnabled)
|
|
29
|
-
return children;
|
|
30
|
-
return ("stage" in config && config.handleTheme) ||
|
|
31
|
-
("endpoints" in config && config.endpoints.theme) ? (React.createElement(C3ProfileContext.Provider, { value: { isEnabled, theme, onThemeChange } },
|
|
32
|
-
React.createElement(ThemeProvider, null, children))) : (children);
|
|
33
|
-
};
|
|
34
|
-
export const useC3Profile = () => useContext(C3ProfileContext);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { useC3Profile } from "./c3-profile-provider";
|
|
3
|
-
import { GlobalTheme } from "@carbon/react";
|
|
4
|
-
const THEMES = { light: "g10", dark: "g100" };
|
|
5
|
-
const getCarbonTheme = (theme) => theme === "light" ||
|
|
6
|
-
window.matchMedia("(prefers-color-scheme: light)").matches
|
|
7
|
-
? THEMES.light
|
|
8
|
-
: THEMES.dark;
|
|
9
|
-
const setThemeClass = (newTheme, currentTheme) => {
|
|
10
|
-
if (currentTheme) {
|
|
11
|
-
document.documentElement.classList.remove(`cds--${getCarbonTheme(currentTheme)}`);
|
|
12
|
-
}
|
|
13
|
-
document.documentElement.classList.add(`cds--${getCarbonTheme(newTheme)}`);
|
|
14
|
-
};
|
|
15
|
-
export const ThemeProvider = ({ children }) => {
|
|
16
|
-
const { theme } = useC3Profile();
|
|
17
|
-
const [previousTheme, setPreviousTheme] = useState(theme);
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
setThemeClass(theme, previousTheme);
|
|
20
|
-
setPreviousTheme(theme);
|
|
21
|
-
}, [theme]);
|
|
22
|
-
return React.createElement(GlobalTheme, { theme: getCarbonTheme(theme) }, children);
|
|
23
|
-
};
|