Skip to content

Commit

Permalink
WIP(ui-top-nav-bar): add breadcrumb to topnavbar
Browse files Browse the repository at this point in the history
  • Loading branch information
joyenjoyer committed Nov 10, 2023
1 parent 73a3001 commit e340ae9
Show file tree
Hide file tree
Showing 16 changed files with 600 additions and 14 deletions.
11 changes: 8 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion packages/ui-top-nav-bar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@instructure/shared-types": "8.47.1",
"@instructure/ui-a11y-content": "8.47.1",
"@instructure/ui-avatar": "8.47.1",
"@instructure/ui-breadcrumb": "8.47.1",
"@instructure/ui-buttons": "8.47.1",
"@instructure/ui-dialog": "8.47.1",
"@instructure/ui-dom-utils": "8.47.1",
Expand All @@ -48,11 +49,14 @@
"prop-types": "^15.8.1"
},
"devDependencies": {
"@instructure/ui-axe-check": "^8.47.1",
"@instructure/ui-babel-preset": "8.47.1",
"@instructure/ui-color-utils": "8.47.1",
"@instructure/ui-test-locator": "8.47.1",
"@instructure/ui-test-utils": "8.47.1",
"@instructure/ui-themes": "8.47.1"
"@instructure/ui-themes": "8.47.1",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.1.0"
},
"peerDependencies": {
"react": ">=16.8 <=18"
Expand Down
41 changes: 41 additions & 0 deletions packages/ui-top-nav-bar/src/TopNavBar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,47 @@ example: true
</div>
```

##### TopNavBar.Breadcrumb

`<TopNavBar.Breadcrumb>` contains a Breadcrumb component with multiple links/pages.

You can't use `<TopNavBar.Breadcrumb>` along with the brand logo or menu items.

```js
---
example: true
---
<div>
<View as="div" margin="medium 0">
<TopNavBar inverseColor>
{() => (
<TopNavBar.Layout
navLabel="Example navigation bar"
desktopConfig={{
hideActionsUserSeparator: false
}}
smallViewportConfig={{
dropdownMenuToggleButtonLabel: 'Toggle Menu',
dropdownMenuLabel: 'Main Menu',
}}
renderBreadcrumb={(
<TopNavBar.Breadcrumb>
<Breadcrumb label="You are here:">
<Breadcrumb.Link>Course page 1</Breadcrumb.Link>
<Breadcrumb.Link>Course page 2</Breadcrumb.Link>
<Breadcrumb.Link>Course page 3</Breadcrumb.Link>
<Breadcrumb.Link>Course page 4</Breadcrumb.Link>
<Breadcrumb.Link>Course page 5</Breadcrumb.Link>
</Breadcrumb>
</TopNavBar.Breadcrumb>
)}
/>
)}
</TopNavBar>
</View>
</div>
```

##### TopNavBar.MenuItems

`<TopNavBar.MenuItems>` contains the main menu items, subpage links.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
/** @jsx jsx */
import React, { Component } from 'react'

import { getElementType, omitProps } from '@instructure/ui-react-utils'
import {
deprecated,
getElementType,
omitProps
} from '@instructure/ui-react-utils'
import { testable } from '@instructure/ui-testable'

import { withStyle, jsx } from '@instructure/emotion'
Expand All @@ -50,6 +54,7 @@ id: TopNavBar.Brand
**/
@withStyle(generateStyle, generateComponentTheme)
@testable()
@deprecated('9', null, 'Please use the updated TopNavBar design.')
class TopNavBarBrand extends Component<TopNavBarBrandProps> {
static readonly componentId = 'TopNavBar.Brand'
// TODO: add to the docs: making it static on parent and jsdocs parent/module settings, dont export child on its own
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 - present Instructure, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import React from 'react'
import { render } from '@testing-library/react'
import '@testing-library/jest-dom'

// eslint-disable-next-line no-restricted-imports
import { runAxeCheck } from '@instructure/ui-axe-check'
import { TopNavBarBreadcrumb } from '../index'
import { Breadcrumb } from '@instructure/ui-breadcrumb'
import TopNavBarContext from '../../TopNavBarContext'

let originalResizeObserver: typeof ResizeObserver
let originalMatchMedia: typeof window.matchMedia

beforeAll(() => {
originalResizeObserver = global.ResizeObserver
originalMatchMedia = window.matchMedia

class MockResizeObserver {
observe = jest.fn()
unobserve = jest.fn()
disconnect = jest.fn()
}
global.ResizeObserver = MockResizeObserver

window.matchMedia = jest.fn().mockImplementation((query) => {
return {
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn()
}
})
})

afterAll(() => {
global.ResizeObserver = originalResizeObserver
window.matchMedia = originalMatchMedia
})

const TEST_BREADCRUMB_LABEL = 'You are here:'

const BaseExample = (props: {
inverseColor: boolean
layout: 'desktop' | 'smallViewport'
}) => {
return (
<TopNavBarContext.Provider
value={{
layout: props.layout,
inverseColor: props.inverseColor
}}
>
<TopNavBarBreadcrumb>
<Breadcrumb label={TEST_BREADCRUMB_LABEL}>
<Breadcrumb.Link>Course page 1</Breadcrumb.Link>
<Breadcrumb.Link>Course page 2</Breadcrumb.Link>
<Breadcrumb.Link>Course page 3</Breadcrumb.Link>
<Breadcrumb.Link>Course page 4</Breadcrumb.Link>
<Breadcrumb.Link>Course page 5</Breadcrumb.Link>
</Breadcrumb>
</TopNavBarBreadcrumb>
</TopNavBarContext.Provider>
)
}

describe('<TopNavBarBreadcrumb />', () => {
it('should render', () => {
const { getByLabelText } = render(
<BaseExample inverseColor={true} layout="desktop" />
)

const element = getByLabelText(TEST_BREADCRUMB_LABEL)

expect(element).toBeInTheDocument()
})

it('should warn if inverseColor is false', () => {
const consoleMock = jest.spyOn(console, 'error').mockImplementation()

const { queryByLabelText } = render(
<BaseExample inverseColor={false} layout="desktop" />
)

const element = queryByLabelText(TEST_BREADCRUMB_LABEL)

expect(element).not.toBeInTheDocument()
expect(consoleMock.mock.calls[0][0]).toEqual(
'Warning: [TopNavBarBreadcrumb] If the inverseColor prop is not set to true, TopNavBarBreadcrumb fails to render.'
)
})

describe('should be accessible', () => {
it('a11y', async () => {
const { container } = render(
<BaseExample inverseColor={true} layout="desktop" />
)
const axeCheck = await runAxeCheck(container)

expect(axeCheck).toBe(true)
})
})
})
Loading

0 comments on commit e340ae9

Please sign in to comment.