Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/@adobe/spectrum-css-temp/components/dialog/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ governing permissions and limitations under the License.
/* The font-weight of the fullscreen dialog header */
--spectrum-dialog-fullscreen-header-text-font-weight: 100;

/* Distance between top and bottom of dialog and edge of window for fullscreen dialog */
--spectrum-dialog-fullscreen-margin: 40px;

--spectrum-dialog-small-width: 400px;
--spectrum-dialog-medium-width: 480px;
--spectrum-dialog-large-width: 640px;
Expand Down Expand Up @@ -199,8 +202,8 @@ governing permissions and limitations under the License.
}

.spectrum-Dialog--fullscreen {
width: calc(100vw - 32px);
height: calc(100vh - 32px);
width: calc(100vw - calc(2 * var(--spectrum-dialog-fullscreen-margin)));
height: calc(100vw - calc(2 * var(--spectrum-dialog-fullscreen-margin)));
}
.spectrum-Dialog--fullscreenTakeover {
width: 100vw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ governing permissions and limitations under the License.
--spectrum-dialog-exit-animation-delay: 0ms;

/* Distance between top and bottom of dialog and edge of window for fullscreen dialog */
--spectrum-dialog-fullscreen-margin: 32px;
--spectrum-dialog-fullscreen-margin: 40px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a common place for components/dialog/index.css and this file to share this variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I would've included it into the css var but Larry said that file was autogenerated and to put new vars at the top of the index.css file.

--spectrum-dialog-max-height: 90vh;
}

Expand Down
16 changes: 11 additions & 5 deletions packages/@react-spectrum/dialog/src/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ export function Dialog(props: SpectrumDialogProps) {
styleProps
),
{className: classNames(styles, {'spectrum-Dialog--dismissable': isDismissable})}
);
);
let size = type === 'popover' ? undefined : (otherProps.size || 'L');

if (type === 'popover') {
return <BaseDialog {...allProps} size={otherProps.size}>{children}</BaseDialog>;
return <BaseDialog {...allProps} size={size}>{children}</BaseDialog>;
} else {
if (type === 'fullscreen' || type === 'fullscreenTakeover') {
size = type;
}

return (
<ModalDialog {...allProps} size={otherProps.size}>
<ModalDialog {...allProps} size={size}>
{children}
{isDismissable && <ActionButton slot="closeButton" isQuiet icon={<CrossLarge size="L" />} onPress={onDismiss} />}
</ModalDialog>
Expand All @@ -70,8 +75,9 @@ let sizeMap = {
fullscreenTakeover: 'fullscreenTakeover'
};

function BaseDialog({children, slots, size = 'L', role, ...otherProps}: SpectrumBaseDialogProps) {
function BaseDialog({children, slots, size, role, ...otherProps}: SpectrumBaseDialogProps) {
let ref = useRef();
let sizeVariant = sizeMap[size];
let {dialogProps} = useDialog({ref, role});
if (!slots) {
slots = {
Expand All @@ -94,7 +100,7 @@ function BaseDialog({children, slots, size = 'L', role, ...otherProps}: Spectrum
className={classNames(
styles,
'spectrum-Dialog',
{[`spectrum-Dialog--${sizeMap[size]}`]: size},
{[`spectrum-Dialog--${sizeVariant}`]: sizeVariant},
otherProps.className
)}
ref={ref}>
Expand Down
9 changes: 8 additions & 1 deletion packages/@react-spectrum/dialog/src/DialogTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ export function DialogTrigger(props: SpectrumDialogTriggerProps) {

let renderOverlay = () => {
switch (type) {
case 'fullscreen':
case 'fullscreenTakeover':
return (
<Modal isOpen={isOpen} onClose={onClose} type={type}>
{content}
</Modal>
);
case 'modal':
return (
<Modal isOpen={isOpen} onClose={onClose}>
Expand Down Expand Up @@ -150,7 +157,7 @@ function DialogTriggerBase({type, isOpen, onPress, onClose, dialogProps = {}, tr
<PressResponder
{...triggerProps}
onPress={onPress}
isPressed={isOpen && type !== 'modal'}>
isPressed={isOpen && type !== 'modal' && type !== 'fullscreen' && type !== 'fullscreenTakeover'}>
{trigger}
</PressResponder>
<DialogContext.Provider value={context}>
Expand Down
12 changes: 2 additions & 10 deletions packages/@react-spectrum/dialog/stories/Dialog.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,13 @@ storiesOf('Dialog', module)
'large',
() => render({size: 'L'})
)
.add(
'fullscreen',
() => render({size: 'fullscreen'})
)
.add(
'fullscreenTakeover',
() => render({size: 'fullscreenTakeover'})
)
.add(
'form',
() => renderWithForm({})
)
.add(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be added somewhere, it's a good story to demonstrate tabbing order

'fullscreenTakeover form',
() => renderWithForm({size: 'fullscreenTakeover'})
() => renderWithForm({type: 'fullscreenTakeover'})
)
.add(
'three buttons',
Expand Down Expand Up @@ -261,7 +253,7 @@ function renderAlert({width = 'auto', ...props}: SpectrumAlertDialogProps) {
function renderWithForm({width = 'auto', ...props}) {
return (
<div style={{display: 'flex', width, margin: '100px 0'}}>
<DialogTrigger isOpen>
<DialogTrigger isOpen type={props.type}>
<ActionButton>Trigger</ActionButton>
<Dialog {...props}>
<Header><Text slot="title">The Title</Text></Header>
Expand Down
16 changes: 16 additions & 0 deletions packages/@react-spectrum/dialog/stories/DialogTrigger.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,27 @@ storiesOf('DialogTrigger', module)
() => render({type: 'modal'}),
{chromaticProvider: {scales: ['medium'], height: 1000}}
)
.add(
'type: fullscreen',
() => render({type: 'fullscreen'})
)
.add(
'type: fullscreenTakeover',
() => render({type: 'fullscreenTakeover'})
)
.add(
'type: tray',
() => renderPopover({type: 'tray'}),
{chromaticProvider: {scales: ['medium'], height: 1000}}
)
.add(
'mobileType: fullscreen',
() => render({type: 'modal', mobileType: 'fullscreen'})
)
.add(
'mobileType: fullscreenTakeover',
() => render({type: 'modal', mobileType: 'fullscreenTakeover'})
)
.add(
'popover with mobileType: modal',
() => renderPopover({type: 'popover', mobileType: 'modal'}),
Expand Down
20 changes: 15 additions & 5 deletions packages/@react-spectrum/overlays/src/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,37 @@ import {useModal, useOverlay} from '@react-aria/overlays';
interface ModalProps {
children: ReactElement,
isOpen?: boolean,
onClose?: () => void
onClose?: () => void,
type?: 'fullscreen' | 'fullscreenTakeover'
}

interface ModalWrapperProps extends ModalProps {
isOpen?: boolean
}

export function Modal(props: ModalProps) {
let {children, onClose, ...otherProps} = props;
let {children, onClose, type, ...otherProps} = props;

return (
<Overlay {...otherProps}>
<Underlay />
<ModalWrapper onClose={onClose}>
<ModalWrapper
onClose={onClose}
type={type}>
{children}
</ModalWrapper>
</Overlay>
);
}

let typeMap = {
fullscreen: 'fullscreen',
fullscreenTakeover: 'fullscreenTakeover'
};

function ModalWrapper(props: ModalWrapperProps) {
let {children, onClose, isOpen} = props;
let {children, onClose, isOpen, type} = props;
let typeVariant = typeMap[type];
let ref = useRef(null);
let {overlayProps} = useOverlay({ref, onClose, isOpen});
useModal();
Expand All @@ -67,7 +76,8 @@ function ModalWrapper(props: ModalWrapperProps) {
overrideStyles,
'spectrum-Modal',
'react-spectrum-Modal'
)
),
{[`spectrum-Modal--${typeVariant}`]: typeVariant}
);

return (
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-types/dialog/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {Slots} from '@react-types/layout';

export interface SpectrumDialogTriggerProps extends PositionProps {
children: ReactElement[],
type?: 'modal' | 'popover' | 'tray',
mobileType?: 'modal' | 'tray',
type?: 'modal' | 'popover' | 'tray' | 'fullscreen' | 'fullscreenTakeover',
mobileType?: 'modal' | 'tray' | 'fullscreen' | 'fullscreenTakeover',
hideArrow?: boolean,
targetRef?: RefObject<HTMLElement>,
isOpen?: boolean,
Expand Down