Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

[terra-clinical-header] Wrapped start and end content #936

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/terra-clinical-header/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Changed
* Changed styles to allow wrapping of start and end content.

## 3.30.0 - (March 1, 2024)

* Changed
Expand Down
4 changes: 4 additions & 0 deletions packages/terra-clinical-header/src/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,16 @@ const Header = ({
customProps.className,
]);

const renderTitle = !(!titleContent && startContent && endContent);

return (
<header {...customProps} className={headerClassNames}>
{startContent && <div className={cx('flex-end')}>{startContent}</div>}
{renderTitle && (
<div className={cx('flex-fill')}>
{titleElement}
</div>
)}
{content}
{endContent && <div className={cx('flex-end')}>{endContent}</div>}
</header>
Expand Down
6 changes: 4 additions & 2 deletions packages/terra-clinical-header/src/Header.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@

.flex-end {
display: flex;
flex: 0 0 auto;
position: relative;
flex-flow: column wrap;
justify-content: flex-start;
align-items: flex-start;
align-content: flex-start;
}

.title-container {
Expand Down
17 changes: 17 additions & 0 deletions packages/terra-clinical-header/tests/jest/Header.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ it('should render a header with all content', () => {
expect(header).toMatchSnapshot();
});

it('should render a header with start and end content and no title', () => {
const startContent = <div id="start-id">start content</div>;
const endContent = <div id="end-id">end content</div>;
const flexEndStart = <div className="flex-end">{startContent}</div>;
const flexEndEnd = <div className="flex-end">{endContent}</div>;
const header = shallow((
<Header
startContent={startContent}
endContent={endContent}
/>
));

expect(header.find('.flex-header').props().children[0]).toEqual(flexEndStart);
expect(header.find('.flex-header').props().children[3]).toEqual(flexEndEnd);
expect(header).toMatchSnapshot();
});

it('should render a subheader with title and heading level', () => {
const consoleSpy = jest.spyOn(global.console, 'warn');
const subheader = shallow(<Header title="title" isSubheader />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,31 @@ exports[`should render a header with id 1`] = `
</header>
`;

exports[`should render a header with start and end content and no title 1`] = `
<header
className="flex-header"
>
<div
className="flex-end"
>
<div
id="start-id"
>
start content
</div>
</div>
<div
className="flex-end"
>
<div
id="end-id"
>
end content
</div>
</div>
</header>
`;

exports[`should render a header with title 1`] = `
<header
className="flex-header"
Expand Down
Loading