User Dialog
User dialog is a menu that contains user profile-related actions.
const UserDialogExample = () => {const userDialogList = useUserDialogListState()const [selected, setSelected] = React.useState()const id1 = useUID();const id2 = useUID();const id3 = useUID();return (<UserDialogContainer name="User Name" icon={UserIcon} baseId="i-am-user-dialog"><UserDialog aria-label="user menu"><UserDialogUserInfo><UserDialogUserName>Name</UserDialogUserName><UserDialogUserEmail>email@email.com</UserDialogUserEmail></UserDialogUserInfo><UserDialogList {...userDialogList} aria-label="User menu actions"><UserDialogListItem{...userDialogList}key={id1}selected={selected === id1}onSelect={() => setSelected(id1)}><UserIcon decorative />Item</UserDialogListItem><UserDialogSeparator /><UserDialogListItem{...userDialogList}key={id2}selected={selected === id2}onSelect={() => setSelected(id2)}href="https://www.google.com"><UserIcon decorative />Item</UserDialogListItem><UserDialogSeparator /><UserDialogListItem{...userDialogList}key={id3}selected={selected === id3}onSelect={() => setSelected(id3)}><ThemeIcon decorative /><Box width="100%" display="flex" justifyContent="space-between">Theme<Badge variant="decorative10" as="span" size="small">Light</Badge></Box></UserDialogListItem><UserDialogSeparator /><UserDialogListItem {...userDialogList} key="4" selected={selected === '4'} onSelect={() => setSelected('4')}><TranslationIcon decorative /><Box width="100%" display="flex" justifyContent="space-between">Language<Badge variant="decorative10" as="span" size="small">EN</Badge></Box></UserDialogListItem></UserDialogList></UserDialog></UserDialogContainer>);}render(<UserDialogExample/>)
A User Dialog is a composition of Avatar, Button, the Non-Modal Dialog primitive, and the Listbox primitive that opens a dialog of profile-related actions. These actions can include visiting a user settings page, switching the language of a product, or logging out.
When the user is focused on the User Dialog Button, enter and space open the menu.
When the user is focused on a list item, the following keyboard interactions apply:
- Enter and space select the current menu item
- Up and down arrows move the user between the menu items
- Disabled menu items and separators are never focused
Use a User Dialog to display actions that a user can trigger related to their profile. Add separators to group menu items.
User Dialog works similarly to Avatar, in that you may use either initials, an image, or a Paste Icon to represent the user. Pass name
/src
/icon
to UserDialogContainer.
In order to use links as options for the UserDialogList items, provide the href
prop to the UserDialogListItem.
const UserDialogExample = () => {const userDialogList = useUserDialogListState()const [selected, setSelected] = React.useState()const id1 = useUID();const id2 = useUID();const id3 = useUID();return (<UserDialogContainer name="User Name" icon={UserIcon} baseId="i-am-user-dialog" src="/images/avatars/avatar3.png" ><UserDialog aria-label="user menu"><UserDialogUserInfo><UserDialogUserName>Name</UserDialogUserName><UserDialogUserEmail>email@email.com</UserDialogUserEmail></UserDialogUserInfo><UserDialogList {...userDialogList} aria-label="User menu actions"><UserDialogListItem{...userDialogList}key={id1}selected={selected === id1}onSelect={() => setSelected(id1)}><UserIcon decorative />Item</UserDialogListItem><UserDialogSeparator /><UserDialogListItem{...userDialogList}key={id2}selected={selected === id2}onSelect={() => setSelected(id2)}href="https://www.google.com"><UserIcon decorative />Item</UserDialogListItem><UserDialogSeparator /><UserDialogListItem{...userDialogList}key={id3}selected={selected === id3}onSelect={() => setSelected(id3)}><ThemeIcon decorative /><Box width="100%" display="flex" justifyContent="space-between">Theme<Badge variant="decorative10" as="span" size="small">Light</Badge></Box></UserDialogListItem><UserDialogSeparator /><UserDialogListItem {...userDialogList} key="4" selected={selected === '4'} onSelect={() => setSelected('4')}><TranslationIcon decorative /><Box width="100%" display="flex" justifyContent="space-between">Language<Badge variant="decorative10" as="span" size="small">EN</Badge></Box></UserDialogListItem></UserDialogList></UserDialog></UserDialogContainer>);}render(<UserDialogExample/>)
The User Dialog component is available in the Paste Components library as a Navigation component.
yarn add @twilio-paste/user-dialog - or - yarn add @twilio-paste/core
import {UserDialog} from '@twilio-paste/core/user-dialog';
const UserDialog = () => {
const userDialogList = useUserDialogListState();
return (
<UserDialogContainer name="Nora Krantz">
<UserDialog aria-label="my_user_menu">
<UserDialogUserInfo>
<UserDialogUserName>Name</UserDialogUserName>
<UserDialogUserEmail>email@email.com</UserDialogUserEmail>
</UserDialogUserInfo>
<UserDialogList {...userDialogList} aria-label="User menu actions">
<UserDialogListItem {...userDialogList} onSelect={() => {}}>One</UserDialogListItem>
<UserDialogListItem {...userDialogList} href="www.#.com"}>Two</UserDialogListItem>
</UserDialogList>
</UserDialog>
</UserDialogContainer>
);
};
Prop | Type | Description | Default |
---|---|---|---|
children | NonNullable<React.ReactNode> | ||
state? | NonModalDialogPrimitiveStateReturn | User Dialog state hook | |
name | string | Provides name for the Avatar initials | |
src? | string | Provides an image for the Avatar | |
icon? | React.FC<React.PropsWithChildren<GenericIconProps>> | Provides an icon for the Avatar |
Prop | Type | Description | Default |
---|---|---|---|
children | React.ReactNode | ||
aria-label | string | Accessible label for the User Dialog | |
element? | string | Overrides the default element name to apply unique styles with the Customization Provider | 'USER_DIALOG' |
Prop | Type | Description | Default |
---|---|---|---|
children | React.ReactNode | ||
element? | string | Overrides the default element name to apply unique styles with the Customization Provider | 'USER_DIALOG_USER_INFO' |
Prop | Type | Description | Default |
---|---|---|---|
children | React.ReactNode | ||
element? | string | Overrides the default element name to apply unique styles with the Customization Provider | 'USER_DIALOG_USER_NAME' |
Prop | Type | Description | Default |
---|---|---|---|
children | React.ReactNode | ||
element? | string | Overrides the default element name to apply unique styles with the Customization Provider | 'USER_DIALOG_USER_EMAIL' |
Prop | Type | Description | Default |
---|---|---|---|
children | React.ReactNode | ||
element? | string | Overrides the default element name to apply unique styles with the Customization Provider | 'USER_DIALOG_LIST' |
aria-label | string | Description of the list |
Prop | Type | Description | Default |
---|---|---|---|
children | React.ReactNode | ||
href? | string | Providing an href will make the list item an <a> tag | |
element? | string | Overrides the default element name to apply unique styles with the Customization Provider | 'USER_DIALOG_LIST_ITEM' |
Changelog
81b4c3f18
#3404 Thanks @SiTaggart! - [User Dialog] Fix the positioning of the user dialog by adding back the passing down of calculted styles to Box
733709127
#3395 Thanks @SiTaggart! - Modified the compile target of our JavaScript bundles fromnode
tobrowser
to minimize the risk of clashing with RequireJS. This is marked as a major out of an abundance of caution. You shouldn't need to do anything but we wanted you to be aware of the change on the off chance it has unintended consequences
- Updated dependencies [
733709127
]:- @twilio-paste/uid-library@2.0.0
- @twilio-paste/color-contrast-utils@5.0.0
- @twilio-paste/anchor@12.0.0
- @twilio-paste/avatar@9.0.0
- @twilio-paste/button@14.0.0
- @twilio-paste/separator@8.0.0
- @twilio-paste/spinner@14.0.0
- @twilio-paste/media-object@10.0.0
- @twilio-paste/stack@8.0.0
- @twilio-paste/box@10.0.0
- @twilio-paste/listbox-primitive@3.0.0
- @twilio-paste/non-modal-dialog-primitive@2.0.0
- @twilio-paste/text@10.0.0
- @twilio-paste/customization@8.0.0
- @twilio-paste/design-tokens@10.0.0
- @twilio-paste/icons@12.0.0
- @twilio-paste/animation-library@2.0.0
- @twilio-paste/reakit-library@2.0.0
- @twilio-paste/styling-library@3.0.0
- @twilio-paste/style-props@9.0.0
- @twilio-paste/theme@11.0.0
- @twilio-paste/types@6.0.0
4d1f7c65e
#3360 Thanks @SiTaggart! - Improved types where Paste extends the base HTML element that a component is based on, so that the existing blocked styling properties are not exposed as valid properties for the component via Typescript. This leads to less confusion around what is supported by a Paste component.Existing blocked component properties include:
className
style
color
e2f12ff7a
#3299 Thanks @nkrantz! - [User Dialog] adjust padding of list items to more clearly define item groups