Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ui): migrate AppShellProvider and CodeBlock to TypeScript #547

Merged
merged 24 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silent-maps-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudoperators/juno-ui-components": minor
---

Migrate AppShellProvider to TypeScript
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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/StyleProvider.component"
gjaskiewicz marked this conversation as resolved.
Show resolved Hide resolved
import { ShadowRoot } from "../ShadowRoot/ShadowRoot.component"
import { PortalProvider } from "../PortalProvider/PortalProvider.component"

/**
* 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 = null,
gjaskiewicz marked this conversation as resolved.
Show resolved Hide resolved
children,
}: AppShellProviderProps) => {
const Wrapper = React.useCallback(
gjaskiewicz marked this conversation as resolved.
Show resolved Hide resolved
({ children }: WrapperProps) => (shadowRoot ? <ShadowRoot mode={shadowRootMode}>{children}</ShadowRoot> : children),
[shadowRoot, shadowRootMode]
)
return (
<Wrapper>
<StyleProvider theme={theme} stylesWrapper={shadowRoot ? "inline" : stylesWrapper}>
<PortalProvider>{children}</PortalProvider>
</StyleProvider>
</Wrapper>
)
}

export type AppShellStyleWrapper = "head" | "inline"

interface WrapperProps {
gjaskiewicz marked this conversation as resolved.
Show resolved Hide resolved
children?: React.ReactNode
}

export interface AppShellProviderProps {
/** 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
/** 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?: string | null
gjaskiewicz marked this conversation as resolved.
Show resolved Hide resolved
children?: React.ReactNode
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
*/

import React from "react"
import { AppShellProvider } from "."
import { CodeBlock } from "../CodeBlock/index.js"
// import { CodeBlock } from "../CodeBlock/index.js"
gjaskiewicz marked this conversation as resolved.
Show resolved Hide resolved
import { Message } from "../Message/Message.component"
import { AppShellProvider, AppShellProviderProps } from "./AppShellProvider.component"

interface CodeBlockProps {
children: React.ReactNode
}
const CodeBlock = ({ children }: CodeBlockProps) => {
return <div>{children}</div>
}

export default {
title: "Layout/AppShellProvider",
Expand All @@ -18,7 +25,7 @@ export default {
},
}

const Template = (args) => <AppShellProvider {...args}>{args.children}</AppShellProvider>
const Template = (args: AppShellProviderProps) => <AppShellProvider {...args}>{args.children}</AppShellProvider>

export const Default = {
render: Template,
Expand Down
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 "./index"

describe("AppShellProvider", () => {
gjaskiewicz marked this conversation as resolved.
Show resolved Hide resolved
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 class as passed", () => {
render(<AppShellProvider shadowRoot={false} theme="my-theme" />)
expect(document.querySelector("div.juno-app-body")).toHaveClass("my-theme")
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as React from "react"
import { cleanup, render, screen, waitFor } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
import { ComboBox } from "./index"
import { AppShellProvider } from "../AppShellProvider/index"
import { AppShellProvider } from "../../deprecated_js/AppShellProvider/index"
import { ComboBoxOption } from "../ComboBoxOption/index"

const mockOnBlur = jest.fn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as React from "react"
import { cleanup, render, screen, waitFor } from "@testing-library/react"
import { AppShellProvider } from "../AppShellProvider"
import { AppShellProvider } from "../../deprecated_js/AppShellProvider"
import userEvent from "@testing-library/user-event"
import { ComboBox } from "../ComboBox/ComboBox.component"
import { ComboBoxOption } from "../ComboBoxOption/ComboBoxOption.component"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from "react"
import { cleanup, render, screen, waitFor } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
import { DateTimePicker } from "./index"
import { AppShellProvider } from "../AppShellProvider"
import { AppShellProvider } from "../../deprecated_js/AppShellProvider"

const mockOnOpen = jest.fn()
const mockOnClear = jest.fn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { cleanup, render, screen, waitFor } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
import { Select } from "./index"
import { SelectOption } from "../SelectOption/index"
import { AppShellProvider } from "../AppShellProvider/index"
import { AppShellProvider } from "../../deprecated_js/AppShellProvider/index"

const mockOnChange = jest.fn()
const mockOnValueChange = jest.fn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export interface StyleProviderProps {
/** What element to render as a wrapper, respectively where to render the StyleProvider. */
stylesWrapper?: StyleProviderStylesWrapper
/** The name of the theme to render. */
theme?: string
theme?: string | null
gjaskiewicz marked this conversation as resolved.
Show resolved Hide resolved
/** The mode of the shadowRoot. Only relevant when `stylesWrapper="shadowRoot"`. */
shadowRootMode?: ShadowRootMode
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from "react"
import PropTypes from "prop-types"

import { StyleProvider } from "../../deprecated_js/StyleProvider/StyleProvider.component"
import { StyleProvider } from "../StyleProvider/StyleProvider.component"
import { ShadowRoot } from "../../deprecated_js/ShadowRoot/ShadowRoot.component"
import { PortalProvider } from "../../deprecated_js/PortalProvider/PortalProvider.component"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors
* SPDX-License-Identifier: Apache-2.0
*/

export { AppShellProvider } from "./AppShellProvider.component"
2 changes: 1 addition & 1 deletion packages/ui-components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "./global.scss"
export { AppBody } from "./components/AppBody/index.js"
export { AppIntro } from "./components/AppIntro/index.js"
export { AppShell } from "./components/AppShell/index.js"
export { AppShellProvider } from "./components/AppShellProvider/index.js"
export { AppShellProvider } from "./deprecated_js//AppShellProvider/index.js"
gjaskiewicz marked this conversation as resolved.
Show resolved Hide resolved
export { Badge } from "./components/Badge/index.js"
export { Box } from "./components/Box/index.js"
export { Breadcrumb } from "./components/Breadcrumb/index.js"
Expand Down
Loading