Skip to content

Commit e09f8b9

Browse files
authored
Merge pull request #719 from SUI-Components/feat-button-topbar
feat(components/topbar/user): add navCTASecondary prop
2 parents 36ba051 + d9f874e commit e09f8b9

5 files changed

Lines changed: 28 additions & 1 deletion

File tree

components/topbar/user/demo/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,17 @@ const navCTA = {
125125
text: 'Check our code'
126126
}
127127

128+
const navCTASecondary = <a href="https://github.com/SUI-Components/sui-components/issues">Open an issue</a>
129+
128130
const Demo = () => {
129131
return (
130132
<>
131133
<h1>Topbar with CTA</h1>
132134
<Topbar />
133135

136+
<h1>Topbar with CTA and Secondary CTA</h1>
137+
<Topbar navCTASecondary={navCTASecondary} />
138+
134139
<h1>Topbar with Custom content</h1>
135140
<Topbar customContent={<div>custom content</div>} />
136141
</>

components/topbar/user/src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export default function TopbarUser({
8787
navButton,
8888
navCTA,
8989
navCTALogin,
90+
navCTASecondary,
9091
navMain,
9192
navUser,
9293
onToggle = () => {},
@@ -307,6 +308,7 @@ export default function TopbarUser({
307308
</AtomButton>
308309
</div>
309310
)}
311+
{navCTASecondary && !customContent && <div className="sui-TopbarUser-ctaSecondary">{navCTASecondary}</div>}
310312
</div>
311313
</div>
312314
)
@@ -483,6 +485,10 @@ TopbarUser.propTypes = {
483485
*/
484486
shape: PropTypes.string
485487
}),
488+
/**
489+
* Render custom node as secondary CTA, displayed after navCTA
490+
*/
491+
navCTASecondary: PropTypes.node,
486492
/**
487493
* CTALogin data.
488494
*/

components/topbar/user/src/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ $w-topbar-user-nav: 90% !default;
9393
}
9494

9595
&-cta {
96+
align-items: center;
9697
display: flex;
9798
gap: $m-m;
9899

components/topbar/user/test/fixtures.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,5 @@ export const navCTA = {
118118
icon: PencilIcon,
119119
text: 'Check our code'
120120
}
121+
122+
export const navCTASecondary = <a href="https://github.com/SUI-Components/sui-components/issues">Secondary action</a>

components/topbar/user/test/index.test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import chaiDOM from 'chai-dom'
99

1010
import {fireEvent, render, waitFor} from '@testing-library/react'
1111

12-
import {brand, navCTA, navMain, navUser} from './fixtures.js'
12+
import {brand, navCTA, navCTASecondary, navMain, navUser} from './fixtures.js'
1313

1414
chai.use(chaiDOM)
1515

@@ -40,6 +40,19 @@ describe('topbar/user', () => {
4040
expect(queryByTitle(navCTA.text)).not.exist
4141
})
4242

43+
it('The user can see the secondary CTA when declared', () => {
44+
const {getByText} = render(<Component navCTASecondary={navCTASecondary} />)
45+
46+
expect(getByText(/Secondary action/i)).to.exist
47+
})
48+
49+
it('The secondary CTA is not rendered when customContent is provided', () => {
50+
const customContent = <div>custom content</div>
51+
const {queryByText} = render(<Component customContent={customContent} navCTASecondary={navCTASecondary} />)
52+
53+
expect(queryByText(/Secondary action/i)).not.exist
54+
})
55+
4356
it('The user can open toggable menus and see clickable link items', async () => {
4457
const {queryByText} = render(<Component />)
4558

0 commit comments

Comments
 (0)