Skip to content

Commit

Permalink
feat(Copy): add copy align prop to CodeSnippet, Copy (#14653)
Browse files Browse the repository at this point in the history
* feat(Copy): add align prop to Copy, CodeSnippet

* chore(test): update snapshots
  • Loading branch information
tw15egan authored Sep 18, 2023
1 parent c00b460 commit 1d12fb0
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
45 changes: 45 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,21 @@ Map {
"wrapText": false,
},
"propTypes": Object {
"align": Object {
"args": Array [
Array [
"top",
"top-left",
"top-right",
"bottom",
"bottom-left",
"bottom-right",
"left",
"right",
],
],
"type": "oneOf",
},
"aria-label": Object {
"type": "string",
},
Expand Down Expand Up @@ -1731,6 +1746,21 @@ Map {
"onClick": [Function],
},
"propTypes": Object {
"align": Object {
"args": Array [
Array [
"top",
"top-left",
"top-right",
"bottom",
"bottom-left",
"bottom-right",
"left",
"right",
],
],
"type": "oneOf",
},
"children": Object {
"type": "node",
},
Expand Down Expand Up @@ -1759,6 +1789,21 @@ Map {
"onClick": [Function],
},
"propTypes": Object {
"align": Object {
"args": Array [
Array [
"top",
"top-left",
"top-right",
"bottom",
"bottom-left",
"bottom-right",
"left",
"right",
],
],
"type": "oneOf",
},
"className": Object {
"type": "string",
},
Expand Down
17 changes: 17 additions & 0 deletions packages/react/src/components/CodeSnippet/CodeSnippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const defaultMinCollapsedNumberOfRows = 3;
const defaultMinExpandedNumberOfRows = 16;

function CodeSnippet({
align = 'bottom',
className,
type,
children,
Expand Down Expand Up @@ -185,6 +186,7 @@ function CodeSnippet({
return (
<Copy
{...rest}
align={align}
onClick={handleCopyClick}
aria-label={deprecatedAriaLabel || ariaLabel}
aria-describedby={uid}
Expand Down Expand Up @@ -255,6 +257,7 @@ function CodeSnippet({
)}
{!hideCopyButton && (
<CopyButton
align={align}
size={type === 'multi' ? 'sm' : 'md'}
disabled={disabled}
onClick={handleCopyClick}
Expand Down Expand Up @@ -285,6 +288,20 @@ function CodeSnippet({
}

CodeSnippet.propTypes = {
/**
* Specify how the trigger should align with the tooltip
*/
align: PropTypes.oneOf([
'top',
'top-left',
'top-right',
'bottom',
'bottom-left',
'bottom-right',
'left',
'right',
]),

/**
* Specify a label to be read by screen readers on the containing <textbox>
* node
Expand Down
17 changes: 16 additions & 1 deletion packages/react/src/components/Copy/Copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { usePrefix } from '../../internal/usePrefix';
import { IconButton } from '../IconButton';

export default function Copy({
align = 'bottom',
children,
className,
feedback,
Expand Down Expand Up @@ -59,7 +60,7 @@ export default function Copy({
return (
<IconButton
closeOnActivation={false}
align="bottom"
align={align}
className={classNames}
label={animation ? feedback : initialLabel}
onClick={composeEventHandlers([onClick, handleClick])}
Expand All @@ -77,6 +78,20 @@ export default function Copy({
}

Copy.propTypes = {
/**
* Specify how the trigger should align with the tooltip
*/
align: PropTypes.oneOf([
'top',
'top-left',
'top-right',
'bottom',
'bottom-left',
'bottom-right',
'left',
'right',
]),

/**
* Pass in content to be rendered in the underlying `<button>`
*/
Expand Down
22 changes: 21 additions & 1 deletion packages/react/src/components/CopyButton/CopyButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ import Copy from '../Copy';
import { LayoutConstraint } from '../Layout';
import { usePrefix } from '../../internal/usePrefix';

export default function CopyButton({ iconDescription, className, ...other }) {
export default function CopyButton({
align = 'bottom',
iconDescription,
className,
...other
}) {
const prefix = usePrefix();
return (
<LayoutConstraint size={{ default: 'md', max: 'lg' }}>
<Copy
align={align}
className={classnames(className, `${prefix}--copy-btn`)}
aria-label={iconDescription}
{...other}>
Expand All @@ -28,6 +34,20 @@ export default function CopyButton({ iconDescription, className, ...other }) {
}

CopyButton.propTypes = {
/**
* Specify how the trigger should align with the tooltip
*/
align: PropTypes.oneOf([
'top',
'top-left',
'top-right',
'bottom',
'bottom-left',
'bottom-right',
'left',
'right',
]),

/**
* Specify an optional className to be applied to the underlying `<button>`
*/
Expand Down

0 comments on commit 1d12fb0

Please sign in to comment.