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

+5
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

+1-1
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

+2-2
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

+2-2
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

+6
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

-1
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

+5-5
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

+3
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

-16
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

+3
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: {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export interface DataGridProps extends React.HTMLAttributes<HTMLDivElement> {
103103
* which means that all child elements of the cell will be stacked vertically. To avoid this, wrap the elements in their own div */
104104
cellVerticalAlignment?: CellVerticalAlignmentType
105105
/** Children to render in the DataGrid */
106-
children?: JSX.Element | (JSX.Element[] | JSX.Element | null)[] | null
106+
children?: React.ReactNode
107107
/** Add a class name */
108108
className?: string
109109
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export default {
1515
argTypes: {
1616
children: {
1717
control: false,
18+
table: {
19+
type: { summary: "ReactNode" },
20+
},
1821
},
1922
},
2023
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export interface DataGridCellProps extends React.HTMLAttributes<HTMLDivElement>
6262
/** Set nowrap to true if the cell content shouldn't wrap (this is achieved by adding white-space: nowrap;) */
6363
nowrap?: boolean
6464
/** Children to render in the DataGridCell */
65-
children?: (JSX.Element[] | JSX.Element | null)[] | JSX.Element | string | null
65+
children?: React.ReactNode
6666
/** Add a classname */
6767
className?: string
6868
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export default {
1616
argTypes: {
1717
children: {
1818
control: false,
19+
table: {
20+
type: { summary: "ReactNode" },
21+
},
1922
},
2023
},
2124
decorators: [

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

-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ type StoryFunction = () => JSX.Element
1313
export default {
1414
title: "WiP/DataGrid/DataGridCheckboxCell",
1515
component: DataGridCheckboxCell,
16-
argTypes: {
17-
children: {
18-
control: false,
19-
},
20-
},
2116
decorators: [
2217
(story: StoryFunction) => (
2318
<DataGrid columns={3}>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const DataGridFoot: React.FC<DataGridFootProps> = ({ className = "", chil
1515

1616
export interface DataGridFootProps extends React.HTMLAttributes<HTMLTableSectionElement> {
1717
/** Children to render in the DataGridFoot */
18-
children?: JSX.Element | null
18+
children?: React.ReactNode
1919
/** Add a classname */
2020
className?: string
2121
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export default {
1414
argTypes: {
1515
children: {
1616
control: false,
17+
table: {
18+
type: { summary: "ReactNode" },
19+
},
1720
},
1821
},
1922
decorators: [(story: StoryFunction) => <table>{story()}</table>],

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export interface DataGridHeadCellProps extends React.HTMLAttributes<HTMLElement>
5757
/** Set nowrap to true if the cell content shouldn't wrap (this is achieved by adding white-space: nowrap;) */
5858
nowrap?: boolean
5959
/** Children to render in the DataGridHeadCell */
60-
children?: JSX.Element | string | null
60+
children?: React.ReactNode
6161
/** Add a classname */
6262
className?: string
6363
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export default {
1616
argTypes: {
1717
children: {
1818
control: false,
19+
table: {
20+
type: { summary: "ReactNode" },
21+
},
1922
},
2023
},
2124
decorators: [

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface DataGridRowProps extends React.HTMLAttributes<HTMLDivElement> {
4444
// /** Whether the row/item is disabled (only relevant in a `selectable` DataGrid */
4545
// disabled: PropTypes.bool,
4646
/** Children to render in the DataGridRow */
47-
children?: JSX.Element | (JSX.Element | null)[] | null
47+
children?: React.ReactNode
4848
/** Add a classname */
4949
className?: string
5050
// /** Pass a handler to be executed when selected state changes */

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

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export default {
2424
},
2525
children: {
2626
control: false,
27+
table: {
28+
type: { summary: "ReactNode" },
29+
},
2730
},
2831
},
2932
decorators: [(story: StoryFunction) => <DataGrid columns={columns}>{story()}</DataGrid>],

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface DataGridToolbarProps extends React.HTMLAttributes<HTMLDivElemen
3232
/** Pass an optional SearchInput component */
3333
search?: JSX.Element
3434
/** Children to render in the DataGridToolbar */
35-
children?: JSX.Element | null
35+
children?: React.ReactNode
3636
/** Add a classname */
3737
className?: string
3838
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export default {
1111
component: DataGridToolbar,
1212
argTypes: {
1313
children: {
14-
control: { type: "text" },
14+
control: false,
15+
table: {
16+
type: { summary: "ReactNode" },
17+
},
1518
},
1619
search: {
1720
control: { type: "text" },

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

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export default {
1414
argTypes: {
1515
children: {
1616
control: false,
17+
table: {
18+
type: { summary: "ReactNode" },
19+
},
1720
},
1821
},
1922
parameters: {

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

+9-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import React from "react"
77

8-
const introbox = (variant: string, heroImage: string | null) => {
8+
const introbox = (variant: string, heroImage: string) => {
99
return `
1010
jn-bg-theme-introbox
1111
jn-text-theme-default
@@ -30,7 +30,7 @@ const introboxBorder = `
3030
jn-border-theme-introbox
3131
`
3232

33-
const introboxContent = (variant: string, heroImage: string | null) => {
33+
const introboxContent = (variant: string, heroImage: string) => {
3434
return `
3535
${heroImage ? `jn-pl-4 jn-pr-56` : `jn-px-4`}
3636
@@ -57,30 +57,28 @@ const introboxHeading = `
5757

5858
export interface IntroBoxProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "title"> {
5959
/** Pass an optional title */
60-
title?: string | null
60+
title?: string
6161
/** Pass a string of text to be rendered as contents. Alternatively, contents can be passed as children (see below) */
62-
text?: string | null
62+
text?: string
6363
/** Pass a custom class */
6464
variant?: "default" | "hero"
6565
/** optional "hero" flavor image for hero variant. Specify as css bg image string pointing to an image in your app (see template app for an example). Will always be positioned top and right */
66-
heroImage?: string | null
66+
heroImage?: string
6767
/** Pass a custom class */
6868
className?: string
69-
/** Pass child nodes to be rendered as contents */
69+
/** Pass child nodes to be rendered as content */
7070
children?: React.ReactNode
71-
/** For additional props*/
72-
[key: string]: any
7371
}
7472

7573
/**
7674
* An Introbox holds generally important information to help understand the contents, purpose, or state of a whole page or view, or individual sections on longer pages.
7775
Use sparingly, there should never be any two or more subsequent instances of Introbox as direct siblings/neighbors on an individual view.
7876
*/
7977
export const IntroBox: React.FC<IntroBoxProps> = ({
80-
title = null,
81-
text = null,
78+
title = "",
79+
text = "",
8280
variant = "default",
83-
heroImage = null,
81+
heroImage = "",
8482
className = "",
8583
children,
8684
...props

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe("IntroBox", () => {
6565
})
6666

6767
test("renders other props as passed", () => {
68-
render(<IntroBox data-testid="my-introbox" name="My shiny little IntroBox" />)
69-
expect(screen.getByTestId("my-introbox")).toHaveAttribute("name", "My shiny little IntroBox")
68+
render(<IntroBox data-testid="my-introbox" id="unique-id" />)
69+
expect(screen.getByTestId("my-introbox")).toHaveAttribute("id", "unique-id")
7070
})
7171
})

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ const NameLabel: React.FC<NameLabelProps> = ({ name }) => {
137137
}
138138

139139
interface NameLabelProps {
140-
name?: string | number | boolean | null
140+
name?: string | number | boolean
141141
}
142142

143143
// this component show the right side of the json, type + value
@@ -354,7 +354,7 @@ export const JsonViewer: React.FC<JsonViewerProps> = ({
354354
data = {},
355355
showRoot = false,
356356
toolbar = false,
357-
theme = null,
357+
theme,
358358
expanded = DEFAULT_EXPANDED,
359359
indentWidth = DEFAULT_INDENT_WIDTH,
360360
style,
@@ -436,7 +436,7 @@ export interface JsonViewerProps extends Omit<React.HTMLProps<HTMLDivElement>, "
436436
* @param base0E collapsed icon, types: "boolean"
437437
* @param base0F copy icon, type "integer"
438438
*/
439-
theme?: themes.JsonViewerTheme | ThemeType | null
439+
theme?: themes.JsonViewerTheme | ThemeType
440440
/** expanded can be true|false or a number. The number denotes the hierarchy level to which the object is expanded. */
441441
expanded?: boolean | number
442442
// cut strings after max length is reached, default length is 100 characters, if set to true. Or specifcy a different character length. */

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

+3
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
}

0 commit comments

Comments
 (0)