diff --git a/.changeset/famous-hairs-jam.md b/.changeset/famous-hairs-jam.md new file mode 100644 index 00000000000..9c3cd6919fd --- /dev/null +++ b/.changeset/famous-hairs-jam.md @@ -0,0 +1,5 @@ +--- +'@shopify/polaris': minor +--- + +Updated top bar menu active state diff --git a/polaris-react/src/components/ActionList/ActionList.scss b/polaris-react/src/components/ActionList/ActionList.scss index 1d28b1196af..b83c07699db 100644 --- a/polaris-react/src/components/ActionList/ActionList.scss +++ b/polaris-react/src/components/ActionList/ActionList.scss @@ -58,11 +58,6 @@ svg { fill: var(--p-color-icon-interactive); } - - &::before { - // stylelint-disable-next-line -- alignment for left tab style https://github.com/Shopify/polaris/pull/3619 - @include list-selected-indicator; - } } &.destructive { diff --git a/polaris-react/src/components/ActionList/ActionList.tsx b/polaris-react/src/components/ActionList/ActionList.tsx index 9d384861588..92ec54bdafc 100644 --- a/polaris-react/src/components/ActionList/ActionList.tsx +++ b/polaris-react/src/components/ActionList/ActionList.tsx @@ -49,7 +49,7 @@ export function ActionList({ const sectionMarkup = finalSections.map((section, index) => { return section.items.length > 0 ? (
@@ -80,16 +92,28 @@ export function Item({ ); - const suffixMarkup = suffix && ( - - {suffix} - - ); + let suffixMarkup: React.ReactNode | null = null; + + if (active) { + suffixMarkup = ( + + + + + + ); + } else if (suffix) { + suffixMarkup = suffix && ( + + {suffix} + + ); + } const textMarkup = {contentMarkup}; const contentElement = ( - + {prefixMarkup} {textMarkup} {badgeMarkup} @@ -134,3 +158,19 @@ export function Item({ ); } + +const truncateText = (text: string) => { + const trimmedText = text.trim(); + return ( + + + {trimmedText} + + + ); +}; diff --git a/polaris-react/src/components/ActionList/components/Item/tests/Item.test.tsx b/polaris-react/src/components/ActionList/components/Item/tests/Item.test.tsx index 5494718b75d..174bb9f913f 100644 --- a/polaris-react/src/components/ActionList/components/Item/tests/Item.test.tsx +++ b/polaris-react/src/components/ActionList/components/Item/tests/Item.test.tsx @@ -102,6 +102,16 @@ describe('', () => { onClick: null, }); }); + + it('truncates content when truncate is true', () => { + const item = mountWithApp( + , + ); + expect(item).toContainReactComponent(Text, {truncate: true}); + }); }); function noop() {} diff --git a/polaris-react/src/components/TopBar/TopBar.stories.tsx b/polaris-react/src/components/TopBar/TopBar.stories.tsx index b79db4a50b9..4f79f1320e4 100644 --- a/polaris-react/src/components/TopBar/TopBar.stories.tsx +++ b/polaris-react/src/components/TopBar/TopBar.stories.tsx @@ -1,7 +1,13 @@ import React, {useCallback, useState} from 'react'; import type {ComponentMeta} from '@storybook/react'; -import {ActionList, Frame, Icon, TopBar, Text} from '@shopify/polaris'; -import {ArrowLeftMinor, QuestionMarkMajor} from '@shopify/polaris-icons'; +import {ActionList, Frame, Icon, TopBar, Text, Avatar} from '@shopify/polaris'; +import { + ArrowLeftMinor, + QuestionMarkMajor, + EditMinor, + TickSmallMinor, + SearchMinor, +} from '@shopify/polaris-icons'; export default { component: TopBar, @@ -49,15 +55,42 @@ export function Default() { , + suffix: , + truncate: true, + }, + { + content: 'Jaded Pixel 2.0', + prefix: , + truncate: true, + }, + { + content: 'View all 3 stores', + prefix: , + }, + ], }, { items: [{content: 'Community forums'}], }, + { + items: [{content: 'Help Center'}], + }, + { + items: [{content: 'Keyboard shortcuts'}], + }, + { + title: 'Dharma Johnson', + items: [{content: 'Manage account'}, {content: 'Log out'}], + }, ]} name="Dharma" detail="Jaded Pixel" - initials="D" + initials="JP" open={isUserMenuOpen} onToggle={toggleIsUserMenuOpen} /> diff --git a/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx b/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx index 4b973ceff3e..33100a79c4b 100644 --- a/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx +++ b/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx @@ -1,18 +1,18 @@ import React from 'react'; -import type {IconableAction} from '../../../../types'; import {Avatar} from '../../../Avatar'; import type {AvatarProps} from '../../../Avatar'; import {MessageIndicator} from '../../../MessageIndicator'; import {Menu} from '../Menu'; import type {MenuProps} from '../Menu'; import {Text} from '../../../Text'; +import type {ActionListProps} from '../../../ActionList'; import styles from './UserMenu.scss'; export interface UserMenuProps { /** An array of action objects that are rendered inside of a popover triggered by this menu */ - actions: {items: IconableAction[]}[]; + actions: ActionListProps['sections']; /** Accepts a message that facilitates direct, urgent communication with the merchant through the user menu */ message?: MenuProps['message']; /** A string detailing the merchant’s full name to be displayed in the user menu */ @@ -29,6 +29,8 @@ export interface UserMenuProps { open: boolean; /** A callback function to handle opening and closing the user menu */ onToggle(): void; + /** A custom activator that can be used when the default activator is not desired */ + customActivator?: React.ReactNode; } export function UserMenu({ @@ -41,10 +43,13 @@ export function UserMenu({ onToggle, open, accessibilityLabel, + customActivator, }: UserMenuProps) { const showIndicator = Boolean(message); - const activatorContentMarkup = ( + const activatorContentMarkup = customActivator ? ( + customActivator + ) : ( <>