diff --git a/UNRELEASED.md b/UNRELEASED.md index e9b206e5ba2..ab6ee87ffaa 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -13,6 +13,18 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f - Set `Collapsible` to use `overflow: visible;` once fully open ([#951](https://github.com/Shopify/polaris-react/pull/951)) - Removes `TopBar` logo background ([#957](https://github.com/Shopify/polaris-react/pull/957)) +- Fixed vertical misalignment in `Banner.Header`([#870](https://github.com/Shopify/polaris-react/pull/870)) +- Removed a duplicate `activatorWrapper` in `Popover` when destructuring props ([#916](https://github.com/Shopify/polaris-react/pull/916)) +- Fixed `Banner` secondaryAction content wrapping in Firefox ([#719](https://github.com/Shopify/polaris-react/pull/719)) +- Added `onKeyPress`, `onKeyDown`, and `onKeyUp` to `Button` ([#860](https://github.com/Shopify/polaris-react/pull/860)) +- Added `monochrome` prop to `Button` and `Link` component ([#821](https://github.com/Shopify/polaris-react/pull/821)) +- Updated `Frame` layout and made `TopBar.UserMenu` visible on mobile ([#852](https://github.com/Shopify/polaris-react/pull/852)) +- Added a `forceRender` prop to `Page` to not delegate to the app bridge TitleBar action ([#695](https://github.com/Shopify/polaris-react/pull/695)) +- Changed `Tabs` example to contain children so the `Panel` renders for accessibility ([#893](https://github.com/Shopify/polaris-react/pull/893)) +- Fixed timezone not being accounted for in `ResourceList` date filter control ([#710](https://github.com/Shopify/polaris-react/pull/710)) +- Removed unnecessary tooltip text in the `TopBar` component ([#859](https://github.com/Shopify/polaris-react/pull/859)) +- Update `Card.Section` to accept `React.ReactNode` as `title` ([#781](https://github.com/Shopify/polaris-react/pull/781)) + ### Bug fixes ### Documentation diff --git a/src/components/Card/README.md b/src/components/Card/README.md index 27d98eaefcf..a792c0420ce 100644 --- a/src/components/Card/README.md +++ b/src/components/Card/README.md @@ -436,6 +436,30 @@ Use to be able to use custom React elements as header content. ``` +### Card section with custom React Node title + + + +Use to render custom content such as icons, links, or buttons in a card section's header. + +```jsx + + + + New Products + + } + > + + Socks + Super Shoes + + + +``` + --- ## Related components diff --git a/src/components/Card/components/Section/Section.tsx b/src/components/Card/components/Section/Section.tsx index 8a561cb48db..819999cb506 100644 --- a/src/components/Card/components/Section/Section.tsx +++ b/src/components/Card/components/Section/Section.tsx @@ -6,28 +6,29 @@ import Subheading from '../../../Subheading'; import styles from '../../Card.scss'; export interface Props { - title?: string; + title?: React.ReactNode; children?: React.ReactNode; subdued?: boolean; fullWidth?: boolean; } export default function Section({children, title, subdued, fullWidth}: Props) { - const headerContent = title ? ( -
- {title} -
- ) : null; - const className = classNames( styles.Section, subdued && styles['Section-subdued'], fullWidth && styles['Section-fullWidth'], ); + let headerMarkup = null; + if (title) { + const headerContent = + typeof title === 'string' ? {title} : title; + headerMarkup =
{headerContent}
; + } + return (
- {headerContent} + {headerMarkup} {children}
); diff --git a/src/components/Card/components/Section/tests/Section.test.tsx b/src/components/Card/components/Section/tests/Section.test.tsx new file mode 100644 index 00000000000..a487ff591db --- /dev/null +++ b/src/components/Card/components/Section/tests/Section.test.tsx @@ -0,0 +1,33 @@ +import * as React from 'react'; +import {mountWithAppProvider} from 'test-utilities'; +import {Badge, Subheading} from 'components'; +import Section from '../Section'; + +describe('', () => { + it('can have any valid react element as the card section title', () => { + const titleString = 'Online store'; + const badgeString = 'I am a badge'; + const titleMarkup = ( +

+ {titleString} + {badgeString} +

+ ); + + const card = mountWithAppProvider(
); + const headerMarkup = card.find('h2'); + + expect(headerMarkup.text().includes(titleString)).toBe(true); + expect(headerMarkup.find('Badge').text()).toBe(badgeString); + }); + + it('wraps plain string titles in a ', () => { + const titleString = 'Online store'; + + const card = mountWithAppProvider(
); + const headerMarkup = card.find(Subheading); + + expect(headerMarkup.exists()).toBeTruthy(); + expect(headerMarkup.text()).toEqual(titleString); + }); +});