Skip to content

Commit

Permalink
replace getWindow() util
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswhong committed Sep 18, 2023
1 parent 6950b90 commit dc641ee
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
7 changes: 4 additions & 3 deletions src/components/control-text/control-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ControlLabel from '../control-label';
import ControlWrapper from '../control-wrapper';
import Popover from '../popover';
import Icon from '../icon';
import getWindow from '../utils/get-window';
import {InputProps, PopoverProps} from '../typings';

interface Props extends Omit<InputProps, 'onChange'> {
Expand Down Expand Up @@ -71,9 +70,11 @@ export default function ControlText({
};

const isActive = () => {
if (typeof window === 'undefined') return false

return (
getWindow().document.activeElement === inputElement.current ||
getWindow().document.activeElement === errorElement.current
window.document.activeElement === inputElement.current ||
window.document.activeElement === errorElement.current
);
};

Expand Down
24 changes: 14 additions & 10 deletions src/components/copiable/copiable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import CopyButton from '../copy-button';
import Popover from '../popover';
import OSKey from 'os-key';
import select from 'select';
import getWindow from '../utils/get-window';

const DISABLE_CLICK_TO_SELECT_THRESHOLD = 640;
const FEEDBACK_TIME = 2000;
Expand Down Expand Up @@ -59,7 +58,8 @@ export default function Copiable({
}, [copyTooltipActive]);

const handleTextFocus = () => {
if (getWindow().innerWidth < DISABLE_CLICK_TO_SELECT_THRESHOLD) return;
if (typeof window === 'undefined') return
if (window.innerWidth < DISABLE_CLICK_TO_SELECT_THRESHOLD) return;
select(() => textEl.current);
setCopyTooltipActive(true);
};
Expand All @@ -80,14 +80,18 @@ export default function Copiable({
</div>
);

const renderCopyHintText = (
<span>
<span className="txt-kbd">
{getCopyKeys(getWindow().navigator.userAgent)}
</span>{' '}
to copy
</span>
);
const renderCopyHintText = () => {
if (typeof window === 'undefined') return

return (
<span>
<span className="txt-kbd">
{getCopyKeys(window.navigator.userAgent)}
</span>{' '}
to copy
</span>
)
}

const textClasses = classnames('my3 txt-mono txt-s mr24', {
'txt-truncate': truncated
Expand Down
5 changes: 2 additions & 3 deletions src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { ReactElement, useRef, useEffect, SVGProps, DetailedHTMLProps } from 'react';
import PropTypes from 'prop-types';
import getWindow from '../utils/get-window';
import * as AccessibleIcon from '@radix-ui/react-accessible-icon';

interface Props {
Expand Down Expand Up @@ -28,8 +27,8 @@ export default function Icon({
const el = useRef(null);

useEffect(() => {
if (inline && el.current) {
const lineHeight = getWindow().getComputedStyle(el.current)[
if (inline && el.current && typeof window !== 'undefined') {
const lineHeight = window.getComputedStyle(el.current)[
'line-height'
];
el.current.style.height = lineHeight;
Expand Down
8 changes: 0 additions & 8 deletions src/components/utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

All utils can be imported from `@mapbox/mr-ui/utils/{name}`.

## getWindow

```js
import getWindow from '@mapbox/mr-ui/utils/get-window';
```

Wraps `window` to make it easy to mock aspects of the browser environment while testing.

## shallowEqualObjects

```js
Expand Down
9 changes: 0 additions & 9 deletions src/components/utils/get-window.ts

This file was deleted.

0 comments on commit dc641ee

Please sign in to comment.