Skip to content

Commit

Permalink
chore(content-explorer): Migrate shareDialog (#3735)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-in-a-box authored Nov 12, 2024
1 parent b64fefa commit c76176e
Show file tree
Hide file tree
Showing 10 changed files with 363 additions and 173 deletions.
1 change: 1 addition & 0 deletions src/elements/common/modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
background-color: $darker-black;
}

.be-modal-share .be-modal-dialog-content,
.be-modal-delete .be-modal-dialog-content {
padding: 0;
border-radius: tokens.$radius-4;
Expand Down
103 changes: 0 additions & 103 deletions src/elements/content-explorer/ShareDialog.js

This file was deleted.

102 changes: 102 additions & 0 deletions src/elements/content-explorer/ShareDialog.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import * as React from 'react';
import Modal from 'react-modal';
import noop from 'lodash/noop';
import { FormattedMessage, useIntl } from 'react-intl';
import { Button, Modal as BlueprintModal, Text } from '@box/blueprint-web';

import ShareAccessSelect from '../common/share-access-select';
import { CLASS_MODAL_CONTENT, CLASS_MODAL_OVERLAY, CLASS_MODAL } from '../../constants';
import type { BoxItem } from '../../common/types/core';

import messages from '../common/messages';

import './ShareDialog.scss';

type Props = {
appElement: HTMLElement,
canSetShareAccess: boolean,
isLoading: boolean,
isOpen: boolean,
item: BoxItem,
onCancel: any,
onShareAccessChange: any,
parentElement: HTMLElement
};

const ShareDialog = ({
appElement,
canSetShareAccess,
isLoading,
isOpen,
item,
onCancel,
onShareAccessChange,
parentElement,
}: Props) => {
const { formatMessage } = useIntl();
let textInput = null;

const copy = () => {
if (textInput instanceof HTMLInputElement) {
textInput.select();
document.execCommand('copy');
}
};

const { shared_link: sharedLink }: BoxItem = item;
const { url } = sharedLink || {
url: formatMessage(messages.shareDialogNone),
};

return (
<Modal
appElement={appElement}
className={CLASS_MODAL_CONTENT}
contentLabel={formatMessage(messages.shareDialogLabel)}
isOpen={isOpen}
onRequestClose={onCancel}
overlayClassName={CLASS_MODAL_OVERLAY}
parentSelector={() => parentElement}
portalClassName={`${CLASS_MODAL} be-modal-share`}
>
<BlueprintModal.Body>
<Text as="label">
<FormattedMessage {...messages.shareDialogText} />
</Text>
<div className="be-modal-input-group">
<input
ref={input => {
textInput = input;
}}
onChange={noop}
type="text"
value={url}
/>
<Button autoFocus className="be-modal-button-copy" onClick={copy} variant="primary">
{formatMessage(messages.copy)}
</Button>
</div>

<BlueprintModal.Footer className="be-modal-btns">
<ShareAccessSelect
canSetShareAccess={canSetShareAccess}
className="bce-shared-access-select"
item={item}
onChange={onShareAccessChange}
/>
<Button
loading={isLoading}
loadingAriaLabel={formatMessage(messages.loading)}
onClick={onCancel}
size="large"
variant="secondary"
>
{formatMessage(messages.close)}
</Button>
</BlueprintModal.Footer>
</BlueprintModal.Body>
</Modal>
);
};

export default ShareDialog;
20 changes: 6 additions & 14 deletions src/elements/content-explorer/ShareDialog.scss
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
@import '../common/variables';
@use '@box/blueprint-web-assets/tokens/tokens.scss';

.be-modal.be-modal-share {
.bce-shared-access-select {
height: 27px;
line-height: 15px;
border-radius: tokens.$radius-2;
}

.be-modal-content {
position: relative;
.be-modal-input-group {
display: flex;

input[type='text'] {
flex-grow: 1;
max-width: 296px;
text-overflow: ellipsis;
border-right: 0 none;
border-radius: $bdl-border-radius-size 0 0 $bdl-border-radius-size;
border-radius: tokens.$radius-2 0 0 tokens.$radius-2;

.be-is-small & {
width: 237px;
}
}
}

.be-modal-input-group {
display: flex;
justify-content: space-between;
}

.be-modal-button-copy {
min-width: 70px;
height: 36px;
Expand All @@ -37,15 +33,11 @@
line-height: 34px;
letter-spacing: 1px;
text-transform: uppercase;
border-radius: 0 $bdl-border-radius-size $bdl-border-radius-size 0;
border-radius: 0 tokens.$radius-2 tokens.$radius-2 0;
}

.be-modal-btns {
align-items: center;
justify-content: space-between;

.btn {
margin: 0;
}
}
}
102 changes: 102 additions & 0 deletions src/elements/content-explorer/ShareDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import * as React from 'react';
import Modal from 'react-modal';
import noop from 'lodash/noop';
import { FormattedMessage, useIntl } from 'react-intl';
import { Button, Modal as BlueprintModal, Text } from '@box/blueprint-web';

import ShareAccessSelect from '../common/share-access-select';
import { CLASS_MODAL_CONTENT, CLASS_MODAL_OVERLAY, CLASS_MODAL } from '../../constants';
import type { BoxItem } from '../../common/types/core';

import messages from '../common/messages';

import './ShareDialog.scss';

export interface ShareDialogProps {
appElement: HTMLElement;
canSetShareAccess: boolean;
isLoading: boolean;
isOpen: boolean;
item: BoxItem;
onCancel: () => void;
onShareAccessChange: () => void;
parentElement: HTMLElement;
}

const ShareDialog = ({
appElement,
canSetShareAccess,
isLoading,
isOpen,
item,
onCancel,
onShareAccessChange,
parentElement,
}: ShareDialogProps) => {
const { formatMessage } = useIntl();
let textInput = null;

const copy = () => {
if (textInput instanceof HTMLInputElement) {
textInput.select();
document.execCommand('copy');
}
};

const { shared_link: sharedLink }: BoxItem = item;
const { url } = sharedLink || {
url: formatMessage(messages.shareDialogNone),
};

return (
<Modal
appElement={appElement}
className={CLASS_MODAL_CONTENT}
contentLabel={formatMessage(messages.shareDialogLabel)}
isOpen={isOpen}
onRequestClose={onCancel}
overlayClassName={CLASS_MODAL_OVERLAY}
parentSelector={() => parentElement}
portalClassName={`${CLASS_MODAL} be-modal-share`}
>
<BlueprintModal.Body>
<Text as="label">
<FormattedMessage {...messages.shareDialogText} />
</Text>
<div className="be-modal-input-group">
<input
ref={input => {
textInput = input;
}}
onChange={noop}
type="text"
value={url}
/>
<Button autoFocus className="be-modal-button-copy" onClick={copy} variant="primary">
{formatMessage(messages.copy)}
</Button>
</div>

<BlueprintModal.Footer className="be-modal-btns">
<ShareAccessSelect
canSetShareAccess={canSetShareAccess}
className="bce-shared-access-select"
item={item}
onChange={onShareAccessChange}
/>
<Button
loading={isLoading}
loadingAriaLabel={formatMessage(messages.loading)}
onClick={onCancel}
size="large"
variant="secondary"
>
{formatMessage(messages.close)}
</Button>
</BlueprintModal.Footer>
</BlueprintModal.Body>
</Modal>
);
};

export default ShareDialog;

This file was deleted.

Loading

0 comments on commit c76176e

Please sign in to comment.