Skip to content

Commit

Permalink
feat(CodeSnippet): support disabled single and multiline snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
emyarod committed Dec 17, 2020
1 parent b054005 commit 0c85063
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
29 changes: 24 additions & 5 deletions packages/components/src/components/code-snippet/_code-snippet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@
@include reset;
}

.#{$prefix}--snippet--disabled,
.#{$prefix}--snippet--disabled
.#{$prefix}--btn.#{$prefix}--snippet-btn--expand {
color: $disabled-02;
background-color: $disabled-01;
}

.#{$prefix}--snippet--disabled .#{$prefix}--snippet-btn--expand:hover,
.#{$prefix}--snippet--disabled .#{$prefix}--copy-btn:hover {
color: $disabled-02;
background-color: $disabled-01;
cursor: not-allowed;
}

.#{$prefix}--snippet--disabled .#{$prefix}--snippet__icon,
.#{$prefix}--snippet--disabled
.#{$prefix}--snippet-btn--expand
.#{$prefix}--icon-chevron--down {
fill: $disabled-02;
}

.#{$prefix}--snippet code {
@include type-style('code-01');
}
Expand Down Expand Up @@ -319,7 +340,7 @@
}

// Show more / less button
button.#{$prefix}--btn.#{$prefix}--snippet-btn--expand {
.#{$prefix}--snippet-btn--expand {
@include type-style('body-short-01');
@include carbon--font-family('sans');

Expand All @@ -335,8 +356,7 @@
border: 0;
}

button.#{$prefix}--btn.#{$prefix}--snippet-btn--expand
.#{$prefix}--snippet-btn--text {
.#{$prefix}--snippet-btn--expand .#{$prefix}--snippet-btn--text {
position: relative;
top: rem(-1px);
}
Expand All @@ -346,14 +366,13 @@
}

.#{$prefix}--snippet-btn--expand .#{$prefix}--icon-chevron--down {
margin-bottom: rem(1px);
margin-left: $spacing-03;
transform: rotate(0deg);
transition: $duration--moderate-01 motion(standard, productive);
fill: $text-01;
}

button.#{$prefix}--btn.#{$prefix}--snippet-btn--expand:hover {
.#{$prefix}--snippet-btn--expand:hover {
color: $text-01;
background: $hover-ui;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/react/src/components/CodeSnippet/CodeSnippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function CodeSnippet({
className,
type,
children,
disabled,
feedback,
onClick,
ariaLabel,
Expand Down Expand Up @@ -110,6 +111,7 @@ function CodeSnippet({

const codeSnippetClasses = classNames(className, `${prefix}--snippet`, {
[`${prefix}--snippet--${type}`]: type,
[`${prefix}--snippet--disabled`]: type !== 'inline' && disabled,
[`${prefix}--snippet--expand`]: expandedCode,
[`${prefix}--snippet--light`]: light,
[`${prefix}--snippet--no-copy`]: hideCopyButton,
Expand Down Expand Up @@ -169,6 +171,7 @@ function CodeSnippet({
)}
{!hideCopyButton && (
<CopyButton
disabled={disabled}
onClick={onClick}
feedback={feedback}
iconDescription={copyButtonDescription}
Expand All @@ -179,6 +182,7 @@ function CodeSnippet({
kind="ghost"
size="field"
className={`${prefix}--snippet-btn--expand`}
disabled={disabled}
onClick={() => setExpandedCode(!expandedCode)}>
<span className={`${prefix}--snippet-btn--text`}>
{expandCodeBtnText}
Expand Down Expand Up @@ -223,6 +227,11 @@ CodeSnippet.propTypes = {
*/
copyLabel: PropTypes.string,

/**
* Specify whether or not the CodeSnippet should be disabled
*/
disabled: PropTypes.bool,

/**
* Specify the string displayed when the snippet is copied
*/
Expand Down

0 comments on commit 0c85063

Please sign in to comment.