Skip to content

Commit c450e60

Browse files
chore(ui): improve component and story types, move deprecated components (1st iteration) (#748)
* chore(ui): move deprecated components, add children type in story, improve types * chore(ui): fix import * chore(ui): fix import * chore(ui): improve types for more components * chore(ui): fix imports * chore(ui): changeset * chore(ui): improve types, fix errors and test * chore(ui): add missing childred prop * chore(ui): change default values for IntroBox * chore(ui): remove unnecessary null * chore(ui): remove unnecessary null * chore(ui): change Navigation components activeItem prop * chore(ui): change Navigation components activeItem prop * chore(ui): change Navigation components activeItem prop * chore(ui): export custom types * chore(ui): remove custom type ItemKeyType * chore(ui): improve types * chore(ui): ensure only children rendered as children in CodeBlock * chore(ui): ensure only children and content strins rendered as children in CodeBlock
1 parent e56b777 commit c450e60

File tree

66 files changed

+177
-152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+177
-152
lines changed

.changeset/strong-carrots-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudoperators/juno-ui-components": minor
3+
---
4+
5+
Improve TS types and documentation

packages/ui-components/src/components/AppShell/AppShell.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export interface AppShellProps extends React.HTMLAttributes<HTMLElement> {
7676
/** The main content of the app. */
7777
children?: React.ReactNode
7878
/** Pass either the `<PageHeader>` component or if you don't need to add any content to the page header pass a string to be used as the app name in the standard page header. */
79-
pageHeader?: string | React.ReactNode
79+
pageHeader?: React.ReactNode
8080
/** Optional. If specified pass a `<PageFooter>` component. If undefined will use default PageFooter */
8181
pageFooter?: React.ReactNode
8282
/** Optional. If specified expects a `<TopNavigation>` component. If undefined no top navigation is rendered. */

packages/ui-components/src/components/BreadcrumbItem/BreadcrumbItem.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface BreadcrumbItemProps extends React.HTMLAttributes<HTMLSpanElemen
2323
/**
2424
* The icon type to display in the breadcrumb item.
2525
*/
26-
icon?: KnownIcons | null
26+
icon?: KnownIcons
2727
/**
2828
* A URL the breadcrumb item points to for navigation.
2929
*/
@@ -70,10 +70,10 @@ export const BreadcrumbItem: React.FC<BreadcrumbItemProps> = ({
7070
disabled = false,
7171
onClick,
7272
className = "",
73+
icon,
7374
...props
7475
}) => {
7576
if (children) return <>{children}</>
76-
const { icon } = props
7777
const iconElement = icon ? (
7878
<Icon icon={icon} size="18" color="jn-text-theme-default" className={label ? "jn-mr-1" : ""} />
7979
) : null

packages/ui-components/src/components/Button/Button.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export const Button = React.forwardRef<HTMLButtonElement | HTMLAnchorElement, Bu
137137

138138
const buttonLabel = progress && progressLabel ? progressLabel : label || children
139139

140-
const handleClick = (event: React.MouseEvent<EventTarget, MouseEvent>) => {
140+
const handleClick = (event: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => {
141141
onClick && onClick(event)
142142
}
143143

@@ -218,7 +218,7 @@ export interface ButtonProps
218218
/** Pass a className */
219219
className?: string
220220
/** Click handler */
221-
onClick?: React.MouseEventHandler<EventTarget>
221+
onClick?: React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>
222222
/** Whether the button action is in progress */
223223
progress?: boolean
224224
/** Display an alternative label while the button action is in progress */

packages/ui-components/src/components/Button/Button.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export default {
1919
options: ["default", "primary", "primary-danger", "subdued"],
2020
control: { type: "select" },
2121
},
22+
children: {
23+
control: false,
24+
table: {
25+
type: { summary: "ReactNode" },
26+
},
27+
},
2228
},
2329
}
2430

packages/ui-components/src/components/ButtonRow/ButtonRow.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export const Default = {
3131
render: Template,
3232

3333
args: {
34-
name: "Default ButtonRow",
3534
children: [
3635
<Button key="1" label="Cancel" title="Cancel" />,
3736
<Button key="2" label="Save" title="Save" variant="primary" />,

packages/ui-components/src/components/CodeBlock/CodeBlock.component.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export const CodeBlock: React.FC<CodeBlockProps> = ({
161161
) : (
162162
<pre className={`juno-code-block-pre ${preStyles(wrap)} ${sizeStyles(size)}`}>
163163
<code className={`${codeStyles}`} ref={theCode}>
164-
{(content || children) as React.ReactNode}
164+
{children ?? (typeof content === "string" ? content : null)}
165165
</code>
166166
</pre>
167167
)}
@@ -181,10 +181,10 @@ export const CodeBlock: React.FC<CodeBlockProps> = ({
181181
type CodeBlockSize = "auto" | "small" | "medium" | "large"
182182

183183
export interface CodeBlockProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "content" | "children"> {
184-
/** The content to render. Will override children if passed. */
184+
/** The content to render. Used when `lang` is "json". Otherwise, if children are not provided. */
185185
content?: string | object
186-
/** The children to render. Will be overridden by content prop if passed as well. */
187-
children?: React.ReactNode | object
186+
/** The children to render. Used when `lang` is NOT "json", overriding `content`. */
187+
children?: React.ReactNode
188188
/** Pass at title to render. Will look like a single tab. */
189189
heading?: string
190190
/** Set whether the code should wrap or not. Default is true. */
@@ -193,7 +193,7 @@ export interface CodeBlockProps extends Omit<React.HTMLAttributes<HTMLDivElement
193193
size?: CodeBlockSize
194194
/** Render a button to copy the code to the clipboard. Defaults to true */
195195
copy?: boolean
196-
/** Pass a lang prop. Passing "json" will render a fully-featured JsonView. Will also add a data-lang-attribute to the codeblock */
196+
/** Pass a lang prop. Passing "json" will render a fully-featured JsonView. Will also add a data-lang attribute to the codeblock */
197197
lang?: string
198198
/** Add a custom className to the wrapper of the CodeBlock */
199199
className?: string

packages/ui-components/src/components/CodeBlock/CodeBlock.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export default {
2727
},
2828
children: {
2929
control: false,
30+
table: {
31+
type: { summary: "ReactNode" },
32+
},
3033
},
3134
},
3235
}

packages/ui-components/src/components/CodeBlock/CodeBlock.test.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,6 @@ describe("CodeBlock", () => {
9292
expect(document.querySelector("[data-json-viewer]")).toBeInTheDocument()
9393
})
9494

95-
test("renders a JSONView as passed with children", () => {
96-
const testObj = {
97-
someKey: "some value",
98-
someOtherKey: 12,
99-
}
100-
render(
101-
<CodeBlock data-testid="codeblock" lang="json">
102-
{testObj}
103-
</CodeBlock>
104-
)
105-
expect(screen.getByTestId("codeblock")).toBeInTheDocument()
106-
expect(screen.getByTestId("codeblock")).toHaveClass("juno-code-block")
107-
expect(screen.getByTestId("codeblock")).toHaveAttribute("data-lang", "json")
108-
expect(document.querySelector("[data-json-viewer]")).toBeInTheDocument()
109-
})
110-
11195
test("renders a CodeBlock with a Copy button by default", () => {
11296
render(<CodeBlock />)
11397
expect(screen.getByRole("button", { name: "contentCopy" })).toBeInTheDocument()

packages/ui-components/src/components/Container/Container.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export default {
1313
argTypes: {
1414
children: {
1515
control: false,
16+
table: {
17+
type: { summary: "ReactNode" },
18+
},
1619
},
1720
},
1821
parameters: {

0 commit comments

Comments
 (0)