Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a54d6b7
rough draft toast container
ktabors Oct 31, 2019
9cdee2d
positive via context working
ktabors Nov 1, 2019
b684d4e
refactor to use toast container and toast provider
ktabors Nov 5, 2019
d5fa497
adding the toast container styles
ktabors Nov 5, 2019
7f98e8d
support multiple toasts
ktabors Nov 7, 2019
5e3367f
different approach on removing toasts from the container
ktabors Nov 20, 2019
dcdf21f
post cherrypick new branch cleanup
ktabors Dec 18, 2019
850dec9
toast add/remove refactor mess
ktabors Dec 21, 2019
abcac35
fixed refactor so stately add works
ktabors Jan 13, 2020
aa58a1c
lint and toast stately tests
ktabors Jan 13, 2020
31331df
adding toast container tests
ktabors Jan 15, 2020
95c501a
errant code removal audit
ktabors Jan 15, 2020
c467bf7
missed a console.log
ktabors Jan 15, 2020
c23a599
Merge branch 'master' into toast_container
ktabors Jan 15, 2020
7c638f7
seperating toast and toast provider
ktabors Jan 16, 2020
4c438ca
seperating toast and toast provider
ktabors Jan 16, 2020
e6ef8b9
fixing the dependancy circles
ktabors Jan 17, 2020
a23ce9c
removing v2 copyright headers
ktabors Jan 17, 2020
f09cce4
refactoring a toast container test to be more sematically corret
ktabors Jan 21, 2020
930a70b
Merge branch 'master' into toast_container
ktabors Jan 21, 2020
5a26d3b
Merge branch 'master' into toast_container
ktabors Jan 21, 2020
78d951e
improving types and moving toast container to bottom
ktabors Feb 4, 2020
e2b6636
refactoring toast state test inputs
ktabors Feb 4, 2020
d535caf
Merge branch 'master' into toast_container
ktabors Feb 4, 2020
0bfc8f6
undoing a bad merge of a conflict of provider in button
ktabors Feb 4, 2020
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
5 changes: 3 additions & 2 deletions packages/@react-aria/toast/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-aria/toast",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.1",
"private": true,
"description": "Spectrum UI components in React",
"main": "dist/main.js",
Expand All @@ -19,8 +19,9 @@
"@babel/runtime": "^7.6.2",
"@react-aria/i18n": "^3.0.0-alpha.2",
"@react-aria/interactions": "^3.0.0-alpha.2",
"@react-aria/utils": "^3.0.0-alpha.2",
"@react-types/shared": "^3.0.0-alpha.2",
"@react-types/toast": "^3.0.0-alpha.2"
"@react-types/toast": "^3.0.0-alpha.1"
},
"peerDependencies": {
"react": "^16.8.0"
Expand Down
9 changes: 8 additions & 1 deletion packages/@react-aria/toast/src/useToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@ import {HTMLAttributes, ImgHTMLAttributes} from 'react';
import intlMessages from '../intl/*.json';
import {PressProps} from '@react-aria/interactions';
import {ToastProps} from '@react-types/toast';
import {useId} from '@react-aria/utils';
import {useMessageFormatter} from '@react-aria/i18n';

interface AriaToastProps extends ToastProps {
id?: string
}

interface ToastAria {
toastProps: HTMLAttributes<HTMLElement>,
iconProps: ImgHTMLAttributes<HTMLElement>,
actionButtonProps: PressProps,
closeButtonProps: DOMProps & PressProps
}

export function useToast(props: ToastProps): ToastAria {
export function useToast(props: AriaToastProps): ToastAria {
let {
id,
onAction,
onClose,
shouldCloseOnAction,
Expand All @@ -35,6 +41,7 @@ export function useToast(props: ToastProps): ToastAria {

return {
toastProps: {
id: useId(id),
role: 'alert'
},
iconProps,
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-spectrum/button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@react-aria/interactions": "^3.0.0-rc.1",
"@react-aria/utils": "^3.0.0-rc.1",
"@react-aria/selection": "^3.0.0-alpha.2",
"@react-spectrum/provider": "^3.0.0-rc.1",
"@react-spectrum/utils": "^3.0.0-rc.1",
"@react-stately/button": "^3.0.0-alpha.2",
"@react-types/button": "^3.0.0-rc.1",
Expand All @@ -46,7 +45,8 @@
},
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
"react-dom": "^16.8.0",
"@react-spectrum/provider": "^3.0.0-rc.1"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-spectrum/icon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
},
"dependencies": {
"@babel/runtime": "^7.6.2",
"@react-spectrum/provider": "^3.0.0-rc.1",
"@react-spectrum/utils": "^3.0.0-rc.1",
"@react-types/shared": "^3.0.0-rc.1"
},
"devDependencies": {
"@adobe/spectrum-css-temp": "^3.0.0-alpha.2"
},
"peerDependencies": {
"react": "^16.8.0"
"react": "^16.8.0",
"@react-spectrum/provider": "^3.0.0-rc.1"
},
"publishConfig": {
"access": "public"
Expand Down
1 change: 1 addition & 0 deletions packages/@react-spectrum/provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@babel/runtime": "^7.6.2",
"@react-aria/dialog": "^3.0.0-alpha.2",
"@react-aria/i18n": "^3.0.0-rc.1",
"@react-spectrum/toast": "^3.0.0-alpha.1",
"@react-spectrum/utils": "^3.0.0-rc.1",
"@react-types/provider": "^3.0.0-rc.1",
"@react-types/shared": "^3.0.0-rc.1",
Expand Down
5 changes: 4 additions & 1 deletion packages/@react-spectrum/provider/src/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {ModalProvider, useModalProvider} from '@react-aria/dialog';
import {ProviderContext, ProviderProps} from '@react-types/provider';
import React, {useContext, useEffect} from 'react';
import styles from '@adobe/spectrum-css-temp/components/page/vars.css';
import {ToastProvider} from '@react-spectrum/toast';
import typographyStyles from '@adobe/spectrum-css-temp/components/typography/index.css';
import {useColorScheme, useScale} from './mediaQueries';
// @ts-ignore
Expand Down Expand Up @@ -67,7 +68,9 @@ function Provider(props: ProviderProps, ref: DOMRef<HTMLDivElement>) {
if (!prevContext || theme !== prevContext.theme || colorScheme !== prevContext.colorScheme || scale !== prevContext.scale || Object.keys(domProps).length > 0 || otherProps.UNSAFE_className || Object.keys(styleProps.style).length > 0) {
contents = (
<ProviderWrapper {...props} ref={ref}>
{contents}
<ToastProvider>
Copy link
Member

Choose a reason for hiding this comment

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

given that a ToastProvider renders its own ToastContainer, will this be a problem if someone launches a toast from inside a form that has a Provider wrapping it for setting isQuiet?
There'd then be two ToastContainers on the page I think?

Copy link
Member Author

@ktabors ktabors Jan 15, 2020

Choose a reason for hiding this comment

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

@devongovett Can you remind me what the desired functionality is? Is it that toasts only render into the topmost provider or that a toast renders into whichever provider it is in? I can't recall, I think v2 was more like the first, but you wanted v3 to do the second option.

Copy link
Member Author

@ktabors ktabors Jan 24, 2020

Choose a reason for hiding this comment

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

I'm going to add a followup to create a story and test for this. The goal will be all toasts show up in the top provider. https://jira.corp.adobe.com/browse/RSP-1491

{contents}
</ToastProvider>
</ProviderWrapper>
);
}
Expand Down
13 changes: 7 additions & 6 deletions packages/@react-spectrum/toast/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-spectrum/toast",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.1",
"private": true,
"description": "Spectrum UI components in React",
"main": "dist/main.js",
Expand Down Expand Up @@ -29,12 +29,12 @@
},
"dependencies": {
"@babel/runtime": "^7.6.2",
"@react-aria/toast": "^3.0.0-alpha.2",
"@react-spectrum/button": "^3.0.0-alpha.2",
"@react-spectrum/provider": "^3.0.0-alpha.2",
"@react-aria/toast": "^3.0.0-alpha.1",
"@react-spectrum/button": "^3.0.0-rc.1",
"@react-spectrum/utils": "^3.0.0-alpha.2",
"@react-stately/toast": "^3.0.0-alpha.1",
"@react-types/shared": "^3.0.0-rc.1",
"@react-types/toast": "^3.0.0-alpha.2",
"@react-types/toast": "^3.0.0-alpha.1",
"@spectrum-icons/ui": "^3.0.0-alpha.2"
},
"devDependencies": {
Expand All @@ -43,7 +43,8 @@
},
"peerDependencies": {
"react": "^16.8.0",
"react-dom": "^16.8.0"
"react-dom": "^16.8.0",
"@react-spectrum/provider": "^3.0.0-rc.1"
},
"publishConfig": {
"access": "public"
Expand Down
24 changes: 6 additions & 18 deletions packages/@react-spectrum/toast/src/Toast.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
/*************************************************************************
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2019 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers, if any. The intellectual
* and technical concepts contained herein are proprietary to Adobe
* and its suppliers and are protected by all applicable intellectual
* property laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe.
**************************************************************************/

import AlertMedium from '@spectrum-icons/ui/AlertMedium';
import {Button, ClearButton} from '@react-spectrum/button';
import {classNames, filterDOMProps, useDOMRef, useStyleProps} from '@react-spectrum/utils';
Expand All @@ -25,6 +8,7 @@ import React from 'react';
import {SpectrumToastProps} from '@react-types/toast';
import styles from '@adobe/spectrum-css-temp/components/toast/vars.css';
import SuccessMedium from '@spectrum-icons/ui/SuccessMedium';
import toastContainerStyles from './toastContainer.css';
import {useToast} from '@react-aria/toast';

export const ICONS = {
Expand Down Expand Up @@ -59,7 +43,11 @@ function Toast(props: SpectrumToastProps, ref: DOMRef<HTMLDivElement>) {
className={classNames(styles,
'spectrum-Toast',
{['spectrum-Toast--' + variant]: variant},
styleProps.className
styleProps.className,
classNames(
toastContainerStyles,
'spectrum-Toast'
)
)}>
{Icon &&
<Icon
Expand Down
21 changes: 21 additions & 0 deletions packages/@react-spectrum/toast/src/ToastContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {classNames} from '@react-spectrum/utils';
import React, {ReactElement} from 'react';
import {Toast} from './';
import toastContainerStyles from './toastContainer.css';
import {ToastStateBase} from '@react-types/toast';

interface ToastProviderProps {
toasts?: ToastStateBase[],
}

export function ToastContainer(props: ToastProviderProps): ReactElement {
let renderToasts = () => props.toasts.map((toast) =>
(<Toast {...toast.props}>{toast.content}</Toast>)
);

return (
<div className={classNames(toastContainerStyles, 'react-spectrum-ToastContainer')}>
{renderToasts()}
</div>
);
}
53 changes: 53 additions & 0 deletions packages/@react-spectrum/toast/src/ToastProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, {ReactElement, ReactNode, useContext} from 'react';
import {ToastContainer} from './';
import {ToastOptions, ToastStateBase} from '@react-types/toast';
import {useProviderProps} from '@react-spectrum/provider';
import {useToastState} from '@react-stately/toast';

interface ToastContextProps {
setToasts?: (any) => void,
toasts?: ToastStateBase[],
positive?: (content: ReactNode, options: ToastOptions) => void,
negative?: (content: ReactNode, options: ToastOptions) => void,
neutral?: (content: ReactNode, options: ToastOptions) => void,
info?: (content: ReactNode, options: ToastOptions) => void
}

interface ToastProviderProps {
children: ReactNode
}

export const ToastContext = React.createContext<ToastContextProps | null>(null);
Copy link
Member Author

Choose a reason for hiding this comment

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

@snowystinger do you want this context to be it's own file?

Copy link
Member

Choose a reason for hiding this comment

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

I don't particularly care, I had hoped originally that it would help with the circular dep, but since it doesn't affect it, you can leave it in here much like the Provider does


export function useToastProvider() {
return useContext(ToastContext);
}

export function ToastProvider(props: ToastProviderProps): ReactElement {
let {onAdd, toasts} = useToastState();
let {
children
} = useProviderProps(props);

let contextValue = {
Copy link
Member

Choose a reason for hiding this comment

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

how does someone add their own toast completely? is that not something we're going to support?

Copy link
Member Author

Choose a reason for hiding this comment

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

Now sure what you mean? I believe we are only allowing them to use the functions from the context.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

No, the Toast component is no longer public.

neutral: (content: ReactNode, options: ToastOptions = {}) => {
onAdd(content, options);
},
positive: (content: ReactNode, options: ToastOptions = {}) => {
onAdd(content, {...options, variant: 'positive'});
},
negative: (content: ReactNode, options: ToastOptions = {}) => {
onAdd(content, {...options, variant: 'negative'});
},
info: (content: ReactNode, options: ToastOptions = {}) => {
onAdd(content, {...options, variant: 'info'});
}
};

return (
<ToastContext.Provider value={contextValue}>
<ToastContainer toasts={toasts} />
{children}
</ToastContext.Provider>
);
}
2 changes: 2 additions & 0 deletions packages/@react-spectrum/toast/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './Toast';
export * from './ToastContainer';
export * from './ToastProvider';
35 changes: 35 additions & 0 deletions packages/@react-spectrum/toast/src/toastContainer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.react-spectrum-ToastContainer {
position: fixed;
top: unset;
bottom: 0;
inset-inline-start: 0;
inset-inline-end: 0;
z-index: 100050; /* above modals */
display: flex;
flex-direction: column-reverse;
align-items: center;
pointer-events: none;

.spectrum-Toast {
margin: 8px;
pointer-events: all;
}
}
.react-spectrum-ToastContainer--top {
top: 0;
flex-direction: column;
bottom: unset;
}
.react-spectrum-ToastContainer--bottom {
flex-direction: column-reverse;
bottom: 0;
}
.react-spectrum-ToastContainer--left {
align-items: flex-start;
}
.react-spectrum-ToastContainer--center {
align-items: center;
}
.react-spectrum-ToastContainer--right {
align-items: flex-end;
}
34 changes: 34 additions & 0 deletions packages/@react-spectrum/toast/stories/Toast.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {action} from '@storybook/addon-actions';
import {Button} from '@react-spectrum/button';
import React from 'react';
import {storiesOf} from '@storybook/react';
import {Toast} from '../';
import {ToastProps} from '@react-types/toast';
import {useToastProvider} from '../';

storiesOf('Toast', module)
.add(
Expand All @@ -28,6 +30,9 @@ storiesOf('Toast', module)
.add(
'action triggers close',
() => render({actionLabel: 'Undo', onAction: action('onAction'), shouldCloseOnAction: true, onClose: action('onClose')}, 'Close on untoasting of the toast')
).add(
'add via provider',
() => <RenderProvider />
);

function render(props:ToastProps = {}, message:String) {
Expand All @@ -37,3 +42,32 @@ function render(props:ToastProps = {}, message:String) {
</Toast>
);
}

function RenderProvider() {
let toastContext = useToastProvider();

return (
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't' feel we needed a story for each type of toast since we have one of each type in the non-provider example stories.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds fine to me, curious on what chomatic would look like though

Copy link
Member Author

Choose a reason for hiding this comment

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

chromatic would need a non-button triggered toast to the toast container story. I'm not sure that is useful beyond chromatic?????

Copy link
Member

Choose a reason for hiding this comment

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

Ah true... unless there is a way to have the button be triggered by default? Not super adamant on this though, the other Toast stories probably suffice

<div>
<Button
onPress={() => toastContext.neutral('Toast is default', {onClose: action('onClose')})}
variant="secondary">
Show Default Toast
</Button>
<Button
onPress={() => toastContext.positive('Toast is positive', {onClose: action('onClose')})}
variant="primary">
Show Primary Toast
</Button>
<Button
onPress={() => toastContext.negative('Toast is negative', {onClose: action('onClose')})}
variant="negative">
Show Negative Toast
</Button>
<Button
onPress={() => toastContext.info('Toast is info', {onClose: action('onClose')})}
variant="cta">
Show info Toast
</Button>
</div>
);
}
Loading