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

fix(CodeSnippet): adjust calculation when show more button is clicked #15839

Merged
merged 4 commits into from Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/react/src/components/CodeSnippet/CodeSnippet.js
Expand Up @@ -22,7 +22,7 @@ const rowHeightInPixels = 16;
const defaultMaxCollapsedNumberOfRows = 15;
const defaultMaxExpandedNumberOfRows = 0;
const defaultMinCollapsedNumberOfRows = 3;
const defaultMinExpandedNumberOfRows = 16;
const defaultMinExpandedNumberOfRows = 0;

function CodeSnippet({
align = 'bottom',
Expand Down Expand Up @@ -108,8 +108,7 @@ function CodeSnippet({
ref: getCodeRef(),
onResize: () => {
if (codeContentRef?.current && type === 'multi') {
const { height } = codeContentRef.current.getBoundingClientRect();

const { height } = innerCodeRef.current.getBoundingClientRect();
if (
maxCollapsedNumberOfRows > 0 &&
(maxExpandedNumberOfRows <= 0 ||
Expand Down
Expand Up @@ -69,6 +69,25 @@ export const Multiline = () => (
</CodeSnippet>
);

export const Test = () => (
<CodeSnippet type="multi" feedback="Copied to clipboard">
{` "scripts": {
"build": "lerna run build --stream --prefix --npm-client yarn",
"ci-check": "carbon-cli ci-check",
"clean": "lerna run clean && lerna clean --yes && rimraf node_modules",
"doctoc": "doctoc --title '## Table of Contents'",
"format": "prettier --write '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**'",
"format:diff": "prettier --list-different '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**' '!packages/components/**'",
"lint": "eslint actions config codemods packages",
"lint:styles": "stylelint '**/*.{css,scss}' --report-needless-disables --report-invalid-scope-disables",
"sync": "carbon-cli sync",
"test:e2e": "cross-env BABEL_ENV=test jest --testPathPattern=e2e",
"sync": "carbon-cli sync",
},
`}
</CodeSnippet>
);

export const Singleline = () => (
<CodeSnippet type="single" feedback="Copied to clipboard">
yarn add carbon-components@latest carbon-components-react@latest
Expand Down
Expand Up @@ -225,7 +225,6 @@ $copy-btn-feedback: $background-inverse !default;

// collapsed pre
.#{$prefix}--snippet--multi .#{$prefix}--snippet-container pre {
padding-block-end: convert.to-rem(24px);
padding-inline-end: $spacing-08;
}

Expand Down