feat(ui): improve code-block-footer api - #1859
Conversation
Signed-off-by: Vladislav Schur <u.shchur@sap.com>
🦋 Changeset detectedLatest commit: 0686a98 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
There was a problem hiding this comment.
Pull request overview
This PR refines the CodeBlock footer API in ui-components so custom footer content can be composed alongside (or instead of) the Copy button, and updates tests/stories accordingly.
Changes:
- Refactors
CodeBlockto always render a unifiedCodeBlockFooter, passingcodeBlockFooteras children. - Updates
CodeBlockFooterto support optional custom children and a “Copied!” tooltip on the Copy action. - Adjusts unit tests and Storybook stories to reflect the new footer composition behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/ui-components/src/components/CodeBlock/CodeBlockFooter.component.tsx | Makes footer composable (children + optional Copy) and adds tooltip feedback for copied state. |
| packages/ui-components/src/components/CodeBlock/CodeBlock.component.tsx | Switches to a single footer composition model (custom content rendered inside CodeBlockFooter). |
| packages/ui-components/src/components/CodeBlock/CodeBlock.test.tsx | Updates/extends tests for combined custom footer + Copy behavior and new footer API. |
| packages/ui-components/src/components/CodeBlock/CodeBlock.stories.tsx | Updates stories to demonstrate custom footer with/without Copy under the new API. |
Signed-off-by: Vladislav Schur <u.shchur@sap.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Suppressed comments (3)
packages/ui-components/src/components/CodeBlock/CodeBlock.component.tsx:163
codeBlockFooteris now typed asReactNode, so it can legally be values like0or an empty string. The current truthy check(copy || codeBlockFooter)would skip rendering the footer for those values; use a null/undefined check instead.
{(copy || codeBlockFooter) && (
<CodeBlockFooter onCopy={handleCopyClick} isCopied={isCopied} copy={copy}>
{codeBlockFooter}
</CodeBlockFooter>
)}
packages/ui-components/src/components/CodeBlockFooter/CodeBlockFooter.component.tsx:40
isCopiedandcopyare implemented with defaults (isCopied = false,copy = true), but the props interface currently requires callers to always pass them. This is a breaking API change and also mismatches runtime behavior; consider making them optional and documenting the defaults.
isCopied: boolean
/**
* Whether to show the Copy button. Defaults to true.
*/
copy: boolean
.changeset/hip-feet-divide.md:5
- The changeset note mentions
CodeBlockFooterchanges, but the PR also changesCodeBlock’s public API semantics:codeBlockFooterno longer replaces the footer/copy UI and its type widened toReactNode. It’d be helpful to capture that behavior change in the release note.
`CodeBlockFooter`: add `children`, `copy` props; replace inline "Copied!" span with a Tooltip on the Copy button
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Suppressed comments (2)
packages/ui-components/src/components/CodeBlockFooter/CodeBlockFooter.component.tsx:50
isCopiedandcopyare typed as required, but the component provides defaults (isCopied = false,copy = true). This forces consumers to pass values unnecessarily and makes the exported API inconsistent with runtime behavior.
export interface CodeBlockFooterProps extends Omit<HTMLAttributes<HTMLDivElement>, "onCopy"> {
/**
* Callback function to handle the copy action. Required when `copy` is true (the default).
*/
onCopy: () => void
/**
* Indicates whether the content has been copied. Drives the "Copied!" tooltip on the Copy button.
*/
isCopied: boolean
/**
* Whether to show the Copy button. Defaults to true.
*/
copy: boolean
.changeset/hip-feet-divide.md:5
- This changeset only mentions
CodeBlockFooter, but this PR also changesCodeBlock’s public API/behavior (codeBlockFooteris now rendered inside the unified footer and its type changed fromReactElementtoReactNode). The release note should mention that behavior change so consumers aren’t surprised.
`CodeBlockFooter`: add `children`, `copy` props; replace inline "Copied!" span with a Tooltip on the Copy button
|
Overall LGTM! Some notes I am not sure about:
|
franzheidl
left a comment
There was a problem hiding this comment.
LGTM, see my my other comment.
Signed-off-by: Vladislav Schur <u.shchur@sap.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Suppressed comments (5)
packages/ui-components/src/index.ts:27
CodeBlockFooteris no longer exported from the package entrypoint, even though a newcomponents/CodeBlockFootermodule was added andCodeBlocknow depends on it. This breaks consumers importingCodeBlockFooterfrom@cloudoperators/juno-ui-components.
export { Code } from "./components/Code/Code.component"
export { CodeBlock } from "./components/CodeBlock/CodeBlock.component"
export { ComboBox } from "./components/ComboBox/ComboBox.component"
packages/ui-components/src/index.ts:137
CodeBlockFooterPropsis no longer exported from the package types entrypoint. IfCodeBlockFooterremains part of the public API, its props type should be re-exported consistently with other components.
export type { CodeProps } from "./components/Code/Code.component"
export type { CodeBlockProps } from "./components/CodeBlock/CodeBlock.component"
export type { ComboBoxProps, ComboBoxWidth, ComboBoxContextType } from "./components/ComboBox/ComboBox.component"
packages/ui-components/src/components/CodeBlockFooter/index.ts:6
- Component barrel files in this package typically re-export both the component and its public prop types (e.g.
Button/index.ts). ExportingCodeBlockFooterPropshere enables clean re-exports from the package root.
export { CodeBlockFooter } from "./CodeBlockFooter.component"
packages/ui-components/src/components/CodeBlockFooter/CodeBlockFooter.component.tsx:40
CodeBlockFooterPropscurrently requiresonCopy,isCopied, andcopyeven though defaults exist andcopy={false}is a supported mode. This makes the public API harder to use (e.g. forcing a no-oponCopywhen hiding the Copy button). Consider making these props optional and relying on defaults / no-op behavior.
export interface CodeBlockFooterProps extends Omit<HTMLAttributes<HTMLDivElement>, "onCopy"> {
/**
* Callback function to handle the copy action. Required when `copy` is true (the default).
*/
onCopy: () => void
.changeset/hip-feet-divide.md:2
- This changeset describes a breaking change to
CodeBlock(and also removes/reworksCodeBlockFooterexports). With the package currently at version 9.x, the bump should bemajorto follow semver.
"@cloudoperators/juno-ui-components": minor
Summary
Changes Made
Related Issues
Testing Instructions
pnpm ipnpm TASKChecklist
PR Manifesto
Review the PR Manifesto for best practises.