Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
tw15egan committed Apr 20, 2020
2 parents 597fc5f + f18dedd commit aec5231
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
Binary file not shown.
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"storybook-readme": "^5.0.8",
"string-replace-loader": "^2.1.0",
"terser-webpack-plugin": "^2.3.2",
"use-resize-observer": "^6.0.0",
"webpack": "^4.41.5",
"whatwg-fetch": "^2.0.3"
},
Expand Down
18 changes: 11 additions & 7 deletions packages/react/src/components/CodeSnippet/CodeSnippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
*/

import PropTypes from 'prop-types';
import React, { useState, useRef, useLayoutEffect } from 'react';
import React, { useState, useRef } from 'react';
import classNames from 'classnames';
import useResizeObserver from 'use-resize-observer/polyfilled';
import { ChevronDown16 } from '@carbon/icons-react';
import { settings } from 'carbon-components';
import Copy from '../Copy';
Expand Down Expand Up @@ -36,12 +37,15 @@ function CodeSnippet({
const { current: uid } = useRef(getUniqueId());
const codeContentRef = useRef();

useLayoutEffect(() => {
if (codeContentRef.current) {
const { height } = codeContentRef.current.getBoundingClientRect();
setShouldShowMoreLessBtn(type === 'multi' && height > 255);
}
}, [children, type]);
useResizeObserver({
ref: codeContentRef,
onResize: () => {
if (codeContentRef.current) {
const { height } = codeContentRef.current.getBoundingClientRect();
setShouldShowMoreLessBtn(type === 'multi' && height > 255);
}
},
});

const codeSnippetClasses = classNames(className, {
[`${prefix}--snippet`]: true,
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23866,6 +23866,13 @@ use-callback-ref@^1.2.1:
resolved "https://registry.yarnpkg.com/use-callback-ref/-/use-callback-ref-1.2.1.tgz#898759ccb9e14be6c7a860abafa3ffbd826c89bb"
integrity sha512-C3nvxh0ZpaOxs9RCnWwAJ+7bJPwQI8LHF71LzbQ3BvzH5XkdtlkMadqElGevg5bYBDFip4sAnD4m06zAKebg1w==

use-resize-observer@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/use-resize-observer/-/use-resize-observer-6.0.0.tgz#8450ade735c386e8d93cdf983c26d34a9f478a54"
integrity sha512-Zfe1qsZVhzfgECs+L/ZcSukyVPFGOmWtC7xZI5Lpn4PR2hNgVvD1NmQ/GYBoCSV2pJskxflJWcDzpTAt84nhvw==
dependencies:
resize-observer-polyfill "^1.5.1"

use-sidecar@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/use-sidecar/-/use-sidecar-1.0.2.tgz#e72f582a75842f7de4ef8becd6235a4720ad8af6"
Expand Down

0 comments on commit aec5231

Please sign in to comment.