-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Banner] Rebuild with layout components #7365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
4e614dc
a8e2143
1b385ce
a5af2a3
08de3f6
72cdd60
72dcd5d
bbbd721
88856f7
7ee1f68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@shopify/polaris': minor | ||
| --- | ||
|
|
||
| Updated `Banner` component to use new layout primitives |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,17 +15,18 @@ import { | |||||||
|
|
||||||||
| import {classNames, variationName} from '../../utilities/css'; | ||||||||
| import {BannerContext} from '../../utilities/banner-context'; | ||||||||
| import {useUniqueId} from '../../utilities/unique-id'; | ||||||||
| import {useI18n} from '../../utilities/i18n'; | ||||||||
| import type {Action, DisableableAction, LoadableAction} from '../../types'; | ||||||||
| import {Button} from '../Button'; | ||||||||
| import {Heading} from '../Heading'; | ||||||||
| import {ButtonGroup} from '../ButtonGroup'; | ||||||||
| import {UnstyledButton, unstyledButtonFrom} from '../UnstyledButton'; | ||||||||
| import {UnstyledLink} from '../UnstyledLink'; | ||||||||
| import {Spinner} from '../Spinner'; | ||||||||
| import {Icon, IconProps} from '../Icon'; | ||||||||
| import {WithinContentContext} from '../../utilities/within-content-context'; | ||||||||
| import {Text} from '../Text'; | ||||||||
| import {Box} from '../Box'; | ||||||||
| import {Bleed} from '../Bleed'; | ||||||||
|
|
||||||||
| import styles from './Banner.scss'; | ||||||||
|
|
||||||||
|
|
@@ -64,7 +65,6 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner( | |||||||
| bannerRef, | ||||||||
| ) { | ||||||||
| const withinContentContainer = useContext(WithinContentContext); | ||||||||
| const id = useUniqueId('Banner'); | ||||||||
| const i18n = useI18n(); | ||||||||
| const {wrapperRef, handleKeyUp, handleBlur, handleMouseUp, shouldShowFocus} = | ||||||||
| useBannerFocus(bannerRef); | ||||||||
|
|
@@ -79,14 +79,12 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner( | |||||||
| ); | ||||||||
|
|
||||||||
| let headingMarkup: React.ReactNode = null; | ||||||||
| let headingID: string | undefined; | ||||||||
|
|
||||||||
| if (title) { | ||||||||
| headingID = `${id}Heading`; | ||||||||
| headingMarkup = ( | ||||||||
| <div className={styles.Heading} id={headingID}> | ||||||||
| <Heading element="p">{title}</Heading> | ||||||||
| </div> | ||||||||
| <Text as="h2" variant="headingMd"> | ||||||||
| {title} | ||||||||
| </Text> | ||||||||
| ); | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -109,13 +107,13 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner( | |||||||
| ) : null; | ||||||||
|
|
||||||||
| const primaryActionMarkup = action ? ( | ||||||||
| <div className={styles.PrimaryAction}> | ||||||||
| <Box paddingRight="2"> | ||||||||
| {action.loading | ||||||||
| ? spinnerMarkup | ||||||||
| : unstyledButtonFrom(action, { | ||||||||
| className: styles.Button, | ||||||||
| className: `${styles.Button} ${styles.PrimaryAction}`, | ||||||||
| })} | ||||||||
| </div> | ||||||||
| </Box> | ||||||||
| ) : null; | ||||||||
|
|
||||||||
| const secondaryActionMarkup = secondaryAction ? ( | ||||||||
|
|
@@ -124,24 +122,25 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner( | |||||||
|
|
||||||||
| const actionMarkup = | ||||||||
| action || secondaryAction ? ( | ||||||||
| <div className={styles.Actions}> | ||||||||
| <Box | ||||||||
| paddingTop={withinContentContainer ? '3' : '4'} | ||||||||
| paddingBottom={withinContentContainer ? '1' : undefined} | ||||||||
| > | ||||||||
| <ButtonGroup> | ||||||||
| {primaryActionMarkup} | ||||||||
| {secondaryActionMarkup} | ||||||||
| </ButtonGroup> | ||||||||
| </div> | ||||||||
| </Box> | ||||||||
| ) : null; | ||||||||
|
|
||||||||
| let contentMarkup: React.ReactNode = null; | ||||||||
| let contentID: string | undefined; | ||||||||
|
|
||||||||
| if (children || actionMarkup) { | ||||||||
| contentID = `${id}Content`; | ||||||||
| contentMarkup = ( | ||||||||
| <div className={styles.Content} id={contentID}> | ||||||||
| <Box paddingTop="05" paddingBottom="05"> | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if we could do something like this until we can remove id:
Suggested change
We'd have to ping the person who contributed the id prop to the component to see if this would be sufficient
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be some context here #3199 |
||||||||
| {children} | ||||||||
| {actionMarkup} | ||||||||
| </div> | ||||||||
| </Box> | ||||||||
| ); | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -168,19 +167,17 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner( | |||||||
| onMouseUp={handleMouseUp} | ||||||||
| onKeyUp={handleKeyUp} | ||||||||
| onBlur={handleBlur} | ||||||||
| aria-labelledby={headingID} | ||||||||
| aria-describedby={contentID} | ||||||||
| > | ||||||||
| {dismissButton} | ||||||||
|
|
||||||||
| <div className={styles.Ribbon}> | ||||||||
| <Box paddingRight="4"> | ||||||||
| <Icon source={iconName} color={iconColor} /> | ||||||||
| </div> | ||||||||
| </Box> | ||||||||
|
|
||||||||
| <div className={styles.ContentWrapper}> | ||||||||
| <Bleed top="05"> | ||||||||
| {headingMarkup} | ||||||||
| {contentMarkup} | ||||||||
| </div> | ||||||||
| </Bleed> | ||||||||
| </div> | ||||||||
| </BannerContext.Provider> | ||||||||
| ); | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing id is likely a breaking change. I imagine this was added for analytics or tracking of some kind. Makes me a bit uncomfortable to remove it but I want to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's a good call about analytics tracking. The thinking in this case was the
idwas maybe used for semantics and aria labelling. I do have another PR to addidand could refactor this if we are game to merge that in #7363There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no way for teams to know the ID as it's generated with
useUniqueId. I think this should be safe to remove. Other ID's though this could be the case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BPScott do you remember why banners needed unique ids?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is because they don't use semantic heading elements so they get
ariaroles to link the ID. This should be fixed with HTML.