Skip to content

Commit

Permalink
Adjust icon-button props and prepare 2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tristen committed Feb 13, 2023
1 parent 692025e commit f4c8a1d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Changelog


## 2.4.0

- [feature] add `tooltipTextSize` option to copy-button.
- [fix] rename `themeTooltip` option to `tooltipColoring` to match convention.

## 2.3.1

- [bug] Fix layout bug introduced in copy-button changes where wrapper was given `inline-block`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mapbox/mr-ui",
"version": "2.3.1",
"version": "2.4.0",
"description": "UI components for Mapbox projects",
"main": "index.js",
"homepage": "./",
Expand Down
5 changes: 3 additions & 2 deletions src/components/copy-button/copy-button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ describe('CopyButton', () => {
className: 'px6 py6 btn btn--purple btn--stroke',
focusTrapPaused: true,
block: true,
tooltipTheme: 'dark',
tooltipColoring: 'dark',
tooltipTextSize: 'none',
children: (
<span>A custom child in place of the visual button</span>
),
passthroughProps: {
'data-testid': 'foo'
}
};
} as const;

test('renders as expected', () => {
const { baseElement } = render(<CopyButton {...props} />)
Expand Down
26 changes: 20 additions & 6 deletions src/components/copy-button/copy-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ interface Props {
block?: boolean;
focusTrapPaused?: boolean;
className?: string;
themeTooltip?: 'light' | 'dark';
tooltipColoring?: 'light' | 'dark';
tooltipTextSize?: 'xs' | 's' | 'none';
children?: ReactNode;
passthroughProps?: HTMLAttributes<HTMLButtonElement>;
}
Expand All @@ -34,7 +35,8 @@ export default function CopyButton({
focusTrapPaused,
className = 'btn btn--xs py3 px3 round',
children,
themeTooltip = 'light',
tooltipColoring = 'light',
tooltipTextSize = 's',
passthroughProps
}: Props): ReactElement {
const [clipboard, setClipboard] = useState(null);
Expand Down Expand Up @@ -110,6 +112,13 @@ export default function CopyButton({
<Icon name={iconName} />
</button>

let popoverContent: ReactNode = 'Copied!';
if (tooltipTextSize !== 'none') {
popoverContent = (
<div className={`txt-${tooltipTextSize}`}>{popoverContent}</div>
);
}

// data-clipboard-text and the container ref are used by clipboard.js
// to copy text. Note that this wont have as nice a failure mode.
return (
Expand All @@ -122,9 +131,9 @@ export default function CopyButton({
onClick={handleCopyButtonClick}
>
<Popover
content={<div className="txt-s">Copied!</div>}
content={popoverContent}
active={showingFeedback}
coloring={themeTooltip}
coloring={tooltipColoring}
placement="top"
alignment="center"
hideWhenAnchorIsOffscreen={true}
Expand All @@ -133,7 +142,8 @@ export default function CopyButton({
<div>
<Tooltip
disabled={showingFeedback}
coloring={themeTooltip}
coloring={tooltipColoring}
textSize={tooltipTextSize}
content="Copy"
>
{body}
Expand Down Expand Up @@ -181,7 +191,11 @@ CopyButton.propTypes = {
/**
* Either `'light'` or `'dark'`. This value is passed as the `coloring` prop found in Tooltip and Popover.
*/
themeTooltip: PropTypes.oneOf(['light', 'dark']),
tooltipColoring: PropTypes.oneOf(['light', 'dark']),
/**
* `'xs'` (extra small), `'s'` (small), or `'none'` (no size class).
*/
tooltipTextSize: PropTypes.oneOf(['xs', 's', 'none']),
/** Optional content to represent the button. */
children: PropTypes.node
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/copy-button/examples/copy-button-c.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import CopyButton from '../copy-button';
export default function Example() {
return (
<div className="inline-block">
<CopyButton themeTooltip="dark" text="Some copy from the custom element">
<CopyButton tooltipColoring="dark" tooltipTextSize="xs" text="Some copy from the custom element">
<button className="w240 btn">Just a custom element</button>
</CopyButton>
</div>
Expand Down

0 comments on commit f4c8a1d

Please sign in to comment.