From da0cb344b4346638df6cd278f1fee98461530032 Mon Sep 17 00:00:00 2001 From: Zakaria Warsame Date: Wed, 12 Apr 2023 17:48:59 -0400 Subject: [PATCH 01/11] chore: update top bar menu to accept activatorcontent prop; title type to be string --- .../src/components/ActionList/ActionList.tsx | 2 +- .../ActionList/components/Section/Section.tsx | 33 ++++++++++++------- .../TopBar/components/UserMenu/UserMenu.tsx | 7 +++- polaris-react/src/types.ts | 2 +- 4 files changed, 29 insertions(+), 15 deletions(-) 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 ? (
- - {section.title} - - - ) : null; + let titleMarkup: string | React.ReactNode = null; + + if (section.title) { + titleMarkup = + typeof section.title === 'string' ? ( + + + {section.title} + + + ) : ( + + {section.title} + + ); + } let sectionRole: 'menu' | 'presentation' | undefined; switch (actionRole) { diff --git a/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx b/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx index 4b973ceff3e..3258af81930 100644 --- a/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx +++ b/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx @@ -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 */ + activatorContent?: React.ReactNode; } export function UserMenu({ @@ -41,10 +43,13 @@ export function UserMenu({ onToggle, open, accessibilityLabel, + activatorContent, }: UserMenuProps) { const showIndicator = Boolean(message); - const activatorContentMarkup = ( + const activatorContentMarkup = activatorContent ? ( + activatorContent + ) : ( <> Date: Wed, 12 Apr 2023 18:01:32 -0400 Subject: [PATCH 02/11] changeset --- .changeset/wicked-knives-begin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wicked-knives-begin.md diff --git a/.changeset/wicked-knives-begin.md b/.changeset/wicked-knives-begin.md new file mode 100644 index 00000000000..70f30dbd64b --- /dev/null +++ b/.changeset/wicked-knives-begin.md @@ -0,0 +1,5 @@ +--- +'@shopify/polaris': minor +--- + +updates user menu to accept activator content prop From 44dcfc05ecb1205a5faedd3a8c908683058db85f Mon Sep 17 00:00:00 2001 From: Zakaria Warsame Date: Wed, 12 Apr 2023 18:25:18 -0400 Subject: [PATCH 03/11] remove ul --- .../src/components/ActionList/components/Section/Section.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/polaris-react/src/components/ActionList/components/Section/Section.tsx b/polaris-react/src/components/ActionList/components/Section/Section.tsx index 1d264d8e6ed..b4b4e7703b4 100644 --- a/polaris-react/src/components/ActionList/components/Section/Section.tsx +++ b/polaris-react/src/components/ActionList/components/Section/Section.tsx @@ -73,9 +73,7 @@ export function Section({ ) : ( - - {section.title} - + {section.title} ); } From 9a068d2ee5f8d291044d5134c2e3e30044056a35 Mon Sep 17 00:00:00 2001 From: Zakaria Warsame Date: Thu, 13 Apr 2023 10:44:28 -0400 Subject: [PATCH 04/11] rename activator content to custom activator --- .../components/TopBar/components/UserMenu/UserMenu.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx b/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx index 3258af81930..03e0c8b994c 100644 --- a/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx +++ b/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx @@ -30,7 +30,7 @@ export interface UserMenuProps { /** 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 */ - activatorContent?: React.ReactNode; + customActivator?: React.ReactNode; } export function UserMenu({ @@ -43,12 +43,12 @@ export function UserMenu({ onToggle, open, accessibilityLabel, - activatorContent, + customActivator, }: UserMenuProps) { const showIndicator = Boolean(message); - const activatorContentMarkup = activatorContent ? ( - activatorContent + const activatorContentMarkup = customActivator ? ( + customActivator ) : ( <> From 6e771f64cab5f777d8b1f26775a867eca39ff89e Mon Sep 17 00:00:00 2001 From: Zakaria Warsame Date: Mon, 17 Apr 2023 09:58:19 -0400 Subject: [PATCH 05/11] add custom activator story to topbar --- .../src/components/TopBar/TopBar.stories.tsx | 93 ++++++++++++++++--- 1 file changed, 80 insertions(+), 13 deletions(-) diff --git a/polaris-react/src/components/TopBar/TopBar.stories.tsx b/polaris-react/src/components/TopBar/TopBar.stories.tsx index b79db4a50b9..b95a88ab2b5 100644 --- a/polaris-react/src/components/TopBar/TopBar.stories.tsx +++ b/polaris-react/src/components/TopBar/TopBar.stories.tsx @@ -1,13 +1,26 @@ import React, {useCallback, useState} from 'react'; import type {ComponentMeta} from '@storybook/react'; -import {ActionList, Frame, Icon, TopBar, Text} from '@shopify/polaris'; +import {ActionList, Frame, Icon, TopBar, Text, Avatar} from '@shopify/polaris'; import {ArrowLeftMinor, QuestionMarkMajor} from '@shopify/polaris-icons'; +import {UserMenuProps} from '../../../build/ts/latest/src/components/TopBar'; export default { component: TopBar, } as ComponentMeta; -export function Default() { +function TopBarWrapper({ + userActions, + name, + detail, + initials, + customActivator, +}: { + userActions?: UserMenuProps['actions']; + name?: UserMenuProps['name']; + detail?: UserMenuProps['detail']; + initials?: UserMenuProps['initials']; + customActivator?: UserMenuProps['customActivator']; +}) { const [isUserMenuOpen, setIsUserMenuOpen] = useState(false); const [isSecondaryMenuOpen, setIsSecondaryMenuOpen] = useState(false); const [isSearchActive, setIsSearchActive] = useState(false); @@ -47,17 +60,22 @@ export function Default() { const userMenuMarkup = ( @@ -118,3 +136,52 @@ export function Default() { ); } + +export function Default() { + const userActions: UserMenuProps['actions'] = [ + { + items: [{content: 'Back to Shopify', icon: ArrowLeftMinor}], + }, + { + items: [{content: 'Community forums'}], + }, + ]; + return ( + + ); +} + +export function WithCustomActivator() { + const userActions: UserMenuProps['actions'] = [ + { + items: [{content: 'Back to Shopify', icon: ArrowLeftMinor}], + }, + { + items: [{content: 'Community forums'}], + }, + ]; + + const customActivator = ( + <> + +

Dharma

+
+ + + ); + + return ( + + ); +} From 5b74e1c1046dbb1bbd6da06dcb2339fa70d2f1d9 Mon Sep 17 00:00:00 2001 From: Zakaria Warsame Date: Mon, 17 Apr 2023 10:03:36 -0400 Subject: [PATCH 06/11] make usermenu popover full height --- polaris-react/src/components/TopBar/components/Menu/Menu.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/polaris-react/src/components/TopBar/components/Menu/Menu.tsx b/polaris-react/src/components/TopBar/components/Menu/Menu.tsx index e35a9ed4ac3..47613683657 100644 --- a/polaris-react/src/components/TopBar/components/Menu/Menu.tsx +++ b/polaris-react/src/components/TopBar/components/Menu/Menu.tsx @@ -57,8 +57,6 @@ export function Menu(props: MenuProps) { /> ); - const isFullHeight = Boolean(message); - return ( From 4f90a0b5794eae45c236c7c1640abb3550a0893c Mon Sep 17 00:00:00 2001 From: Zakaria Warsame Date: Mon, 17 Apr 2023 10:51:16 -0400 Subject: [PATCH 07/11] make new activator internal --- .../src/components/TopBar/TopBar.stories.tsx | 38 +++++++++++++++++-- .../TopBar/components/UserMenu/UserMenu.scss | 2 +- .../TopBar/components/UserMenu/UserMenu.tsx | 15 ++++---- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/polaris-react/src/components/TopBar/TopBar.stories.tsx b/polaris-react/src/components/TopBar/TopBar.stories.tsx index b95a88ab2b5..f984350011b 100644 --- a/polaris-react/src/components/TopBar/TopBar.stories.tsx +++ b/polaris-react/src/components/TopBar/TopBar.stories.tsx @@ -2,6 +2,7 @@ import React, {useCallback, useState} from 'react'; import type {ComponentMeta} from '@storybook/react'; import {ActionList, Frame, Icon, TopBar, Text, Avatar} from '@shopify/polaris'; import {ArrowLeftMinor, QuestionMarkMajor} from '@shopify/polaris-icons'; + import {UserMenuProps} from '../../../build/ts/latest/src/components/TopBar'; export default { @@ -73,11 +74,17 @@ function TopBarWrapper({ ] } name={name ? name : 'Dharma'} - detail={detail ? detail : 'Jaded Pixel'} + detail={detail && detail} initials={initials ? initials : 'JD'} customActivator={customActivator} open={isUserMenuOpen} onToggle={toggleIsUserMenuOpen} + message={{ + title: 'Message title', + description: 'Message description', + link: {to: 'https://www.shopify.com', content: 'Link content'}, + action: {content: 'Action content', onAction: () => {}}, + }} /> ); @@ -146,17 +153,40 @@ export function Default() { items: [{content: 'Community forums'}], }, ]; + return ; +} + +export function WithCustomActivator() { + const userActions: UserMenuProps['actions'] = [ + { + items: [{content: 'Back to Shopify', icon: ArrowLeftMinor}], + }, + { + items: [{content: 'Community forums'}], + }, + ]; + + const customActivator = ( + <> + + +

Dharma

+
+ + ); + return ( ); } -export function WithCustomActivator() { +export function withMessage() { const userActions: UserMenuProps['actions'] = [ { items: [{content: 'Back to Shopify', icon: ArrowLeftMinor}], diff --git a/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.scss b/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.scss index 58294cf3e81..32f9f1a9f15 100644 --- a/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.scss +++ b/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.scss @@ -2,7 +2,7 @@ .Details { max-width: 160px; - margin-left: var(--p-space-2); + margin-right: var(--p-space-2); @media #{$p-breakpoints-md-down} { display: none; diff --git a/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx b/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx index 03e0c8b994c..c59e0ba58e0 100644 --- a/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx +++ b/polaris-react/src/components/TopBar/components/UserMenu/UserMenu.tsx @@ -51,13 +51,6 @@ export function UserMenu({ customActivator ) : ( <> - - - {name} @@ -72,6 +65,14 @@ export function UserMenu({ {detail} + + + ); From 1867425c79cd5fe8cb3aea4b8dde843c8278cf4f Mon Sep 17 00:00:00 2001 From: Zakaria Warsame Date: Mon, 17 Apr 2023 10:54:18 -0400 Subject: [PATCH 08/11] make new activator internal --- .../src/components/TopBar/TopBar.stories.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/polaris-react/src/components/TopBar/TopBar.stories.tsx b/polaris-react/src/components/TopBar/TopBar.stories.tsx index f984350011b..6d286dfcf7c 100644 --- a/polaris-react/src/components/TopBar/TopBar.stories.tsx +++ b/polaris-react/src/components/TopBar/TopBar.stories.tsx @@ -168,9 +168,20 @@ export function WithCustomActivator() { const customActivator = ( <> - + -

Dharma

+ + Dharma + + + Jaded Pixel +
); @@ -180,7 +191,6 @@ export function WithCustomActivator() { userActions={userActions} name="Dharma" detail="Jaded Pixel" - initials="JD" customActivator={customActivator} /> ); From c8b3a5ccdfa4aa7412b2dac4fe536221d3609a4e Mon Sep 17 00:00:00 2001 From: Zakaria Warsame Date: Mon, 17 Apr 2023 11:00:46 -0400 Subject: [PATCH 09/11] add new "with message" story --- .../src/components/TopBar/TopBar.stories.tsx | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/polaris-react/src/components/TopBar/TopBar.stories.tsx b/polaris-react/src/components/TopBar/TopBar.stories.tsx index 6d286dfcf7c..3e8157cf77c 100644 --- a/polaris-react/src/components/TopBar/TopBar.stories.tsx +++ b/polaris-react/src/components/TopBar/TopBar.stories.tsx @@ -15,12 +15,14 @@ function TopBarWrapper({ detail, initials, customActivator, + message, }: { userActions?: UserMenuProps['actions']; name?: UserMenuProps['name']; detail?: UserMenuProps['detail']; initials?: UserMenuProps['initials']; customActivator?: UserMenuProps['customActivator']; + message?: UserMenuProps['message']; }) { const [isUserMenuOpen, setIsUserMenuOpen] = useState(false); const [isSecondaryMenuOpen, setIsSecondaryMenuOpen] = useState(false); @@ -77,14 +79,9 @@ function TopBarWrapper({ detail={detail && detail} initials={initials ? initials : 'JD'} customActivator={customActivator} + message={message} open={isUserMenuOpen} onToggle={toggleIsUserMenuOpen} - message={{ - title: 'Message title', - description: 'Message description', - link: {to: 'https://www.shopify.com', content: 'Link content'}, - action: {content: 'Action content', onAction: () => {}}, - }} /> ); @@ -206,22 +203,18 @@ export function withMessage() { }, ]; - const customActivator = ( - <> - -

Dharma

-
- - - ); - return ( {}}, + }} /> ); } From cb653c37c8c3f85c7c83141cf814df3945352ab3 Mon Sep 17 00:00:00 2001 From: Zakaria Warsame Date: Mon, 17 Apr 2023 11:14:19 -0400 Subject: [PATCH 10/11] use import as type --- polaris-react/src/components/TopBar/TopBar.stories.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polaris-react/src/components/TopBar/TopBar.stories.tsx b/polaris-react/src/components/TopBar/TopBar.stories.tsx index 3e8157cf77c..b6b2e37be14 100644 --- a/polaris-react/src/components/TopBar/TopBar.stories.tsx +++ b/polaris-react/src/components/TopBar/TopBar.stories.tsx @@ -3,7 +3,7 @@ import type {ComponentMeta} from '@storybook/react'; import {ActionList, Frame, Icon, TopBar, Text, Avatar} from '@shopify/polaris'; import {ArrowLeftMinor, QuestionMarkMajor} from '@shopify/polaris-icons'; -import {UserMenuProps} from '../../../build/ts/latest/src/components/TopBar'; +import type {UserMenuProps} from '../../../build/ts/latest/src/components/TopBar'; export default { component: TopBar, From af3c8da0a7b124736f95bb5935c83b1c282fc191 Mon Sep 17 00:00:00 2001 From: zak warsame <42528878+zakwarsame@users.noreply.github.com> Date: Mon, 17 Apr 2023 11:16:28 -0400 Subject: [PATCH 11/11] update changeset content Co-authored-by: Kyle Durand --- .changeset/wicked-knives-begin.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.changeset/wicked-knives-begin.md b/.changeset/wicked-knives-begin.md index 70f30dbd64b..368d91ce20e 100644 --- a/.changeset/wicked-knives-begin.md +++ b/.changeset/wicked-knives-begin.md @@ -2,4 +2,5 @@ '@shopify/polaris': minor --- -updates user menu to accept activator content prop +- Added `customActivator` prop to `TopBar.UserMenu` +- Added support for setting a `ReactNode ` on `ActionList` `Section` `title`