generated from cloudoperators/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ui): migrate AppShellProvider and CodeBlock to TypeScript (#547)
* chore(ui): migrate AppShellProvider to TypeScript * fix(ui): fix index and wrapper * fix(ui): fix index * fix(ui): fix test * fix(ui): use CodeBlock in AppShell stories * fix(ui): fix types * fix(ui): typings fix * fix(ui): fix types * fix(ui): hanful of improvements * fix(ui): fix format * fix(ui): few improvements * fix(ui): timer type fix * fix(ui): change default value * fix(ui): theme typing fix * fix(ui): inherited class fix * fix(ui): add comment to improve storybook --------- Co-authored-by: [email protected] <[email protected]> Co-authored-by: Andreas Pfau <[email protected]> Co-authored-by: hodanoori <[email protected]>
- Loading branch information
1 parent
d2957ff
commit a278544
Showing
18 changed files
with
165 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@cloudoperators/juno-ui-components": minor | ||
--- | ||
|
||
Migrate AppShellProvider and CodeBlock to TypeScript |
58 changes: 58 additions & 0 deletions
58
packages/ui-components/src/components/AppShellProvider/AppShellProvider.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from "react" | ||
|
||
import { StyleProvider } from "../StyleProvider" | ||
import { ShadowRoot } from "../ShadowRoot" | ||
import { PortalProvider } from "../PortalProvider" | ||
import { DEFAULT_THEME_NAME } from "../StyleProvider/StyleProvider.component" | ||
|
||
const Wrapper = ({ children, shadowRoot, shadowRootMode }: WrapperProps) => { | ||
return shadowRoot ? ( | ||
<ShadowRoot mode={shadowRootMode}> | ||
<>{children}</> | ||
</ShadowRoot> | ||
) : ( | ||
children | ||
) | ||
} | ||
|
||
/** | ||
* This provider acts as a wrapper for Juno apps. It renders a StyleProvider and PortalProvider | ||
*/ | ||
export const AppShellProvider = ({ | ||
shadowRoot = true, | ||
shadowRootMode = "open", | ||
stylesWrapper = "inline", | ||
theme = DEFAULT_THEME_NAME, | ||
children, | ||
}: AppShellProviderProps) => { | ||
return ( | ||
<Wrapper shadowRoot={shadowRoot} shadowRootMode={shadowRootMode}> | ||
<StyleProvider theme={theme} stylesWrapper={shadowRoot ? "inline" : stylesWrapper}> | ||
<PortalProvider>{children}</PortalProvider> | ||
</StyleProvider> | ||
</Wrapper> | ||
) | ||
} | ||
|
||
export type AppShellStyleWrapper = "head" | "inline" | ||
|
||
interface WrapperProps { | ||
/** React nodes or a collection of React nodes to be rendered as content. */ | ||
children?: React.ReactNode | ||
/** Whether the app is rendered inside a ShadowRoot. Only choose false if the app is meant to run as a stand-alone application. */ | ||
shadowRoot?: boolean | ||
/** Shadow root mode */ | ||
shadowRootMode?: ShadowRootMode | ||
} | ||
|
||
export interface AppShellProviderProps extends WrapperProps { | ||
/** Where app stylesheets are imported. This is only relevant if shadowRoot === false. If you use a ShadowRoot the styles must be inline. */ | ||
stylesWrapper?: AppShellStyleWrapper | ||
/** theme: theme-dark or theme-light */ | ||
theme?: "theme-dark" | "theme-light" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/ui-components/src/components/AppShellProvider/AppShellProvider.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import * as React from "react" | ||
import { render } from "@testing-library/react" | ||
import { AppShellProvider } from "./AppShellProvider.component" | ||
|
||
describe("AppShellProvider", () => { | ||
test("renders an AppShellProvider wrapper div with 'theme-dark' theme class by default", () => { | ||
render(<AppShellProvider shadowRoot={false} />) | ||
expect(document.querySelector(".juno-app-body")).toHaveClass("theme-dark") | ||
}) | ||
|
||
test("renders an AppShellProvider wrapper div with theme as passed", () => { | ||
render(<AppShellProvider shadowRoot={false} theme="theme-light" />) | ||
expect(document.querySelector("div.juno-app-body")).toHaveClass("theme-light") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.