-
Notifications
You must be signed in to change notification settings - Fork 335
Add Sidebar and SidebarNotificationButton components #390
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 all commits
5a0be2c
01c7445
4c50796
2a75147
bf9dbff
60c9613
68cf1db
d41d22a
cd0e34d
fe6cf24
444b1a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import classNames from 'classnames'; | ||
| import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
| import { Icon } from '@edx/paragon'; | ||
| import { WatchOutline } from '@edx/paragon/icons'; | ||
|
|
||
| import messages from './messages'; | ||
|
|
||
| function NotificationIcon({ intl, status, notificationColor }) { | ||
| return ( | ||
| <> | ||
| <Icon src={WatchOutline} className="m-0 m-auto" alt={intl.formatMessage(messages.openSidebarButton)} /> | ||
| {status === 'active' | ||
| ? <span className={classNames(notificationColor, 'rounded-circle p-1 position-absolute')} style={{ top: '0.3rem', right: '0.55rem' }} /> | ||
| : null} | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| NotificationIcon.propTypes = { | ||
| intl: intlShape.isRequired, | ||
| status: PropTypes.string.isRequired, | ||
| notificationColor: PropTypes.string.isRequired, | ||
| }; | ||
|
|
||
| export default injectIntl(NotificationIcon); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
| import { Icon } from '@edx/paragon'; | ||
| import { ArrowBackIos, Close } from '@edx/paragon/icons'; | ||
| import './Sidebar.scss'; | ||
| import messages from './messages'; | ||
| import useWindowSize from '../../generic/tabs/useWindowSize'; | ||
|
|
||
| function Sidebar({ | ||
| intl, toggleSidebar, | ||
| }) { | ||
| const shouldDisplayFullScreen = useWindowSize().width < 992; | ||
| return ( | ||
| <section className="sidebar-container ml-0 ml-lg-4" aria-label={intl.formatMessage(messages.sidebarNotification)}> | ||
| {shouldDisplayFullScreen ? ( | ||
| <div className="mobile-close-container" onClick={() => { toggleSidebar(); }} onKeyDown={() => { toggleSidebar(); }} role="button" tabIndex="0" alt={intl.formatMessage(messages.responsiveCloseSidebar)}> | ||
| <Icon src={ArrowBackIos} /> | ||
| <span className="mobile-close">{intl.formatMessage(messages.responsiveCloseSidebar)}</span> | ||
| </div> | ||
| ) : null} | ||
| <div className="sidebar-header px-3"> | ||
| <span>{intl.formatMessage(messages.notificationTitle)}</span> | ||
| {shouldDisplayFullScreen | ||
| ? null | ||
| : <Icon src={Close} className="close-btn" onClick={() => { toggleSidebar(); }} onKeyDown={() => { toggleSidebar(); }} role="button" tabIndex="0" alt={intl.formatMessage(messages.closeSidebarButton)} />} | ||
| </div> | ||
| <div className="sidebar-divider" /> | ||
| <div className="sidebar-content"> | ||
| {/* REV-2130 TODO: add conditional here to display expiration box or display below message */} | ||
| <p>{intl.formatMessage(messages.noNotificationsMessage)}</p> | ||
| </div> | ||
| </section> | ||
| ); | ||
| } | ||
|
|
||
| Sidebar.propTypes = { | ||
| intl: intlShape.isRequired, | ||
| toggleSidebar: PropTypes.func, | ||
| }; | ||
|
|
||
| Sidebar.defaultProps = { | ||
| toggleSidebar: null, | ||
| }; | ||
|
|
||
| export default injectIntl(Sidebar); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| @import "~@edx/brand/paragon/fonts"; | ||
| @import "~@edx/brand/paragon/variables"; | ||
| @import "~@edx/paragon/scss/core/core"; | ||
| @import "~@edx/brand/paragon/overrides"; | ||
|
|
||
| .sidebar-container { | ||
| border: 1px solid $light-400; | ||
| border-radius: 4px; | ||
| width: 20rem; | ||
| vertical-align: top; | ||
|
|
||
| @media (max-width: map-get($grid-breakpoints, 'lg')) { | ||
| position: fixed; | ||
| top: 0; | ||
| bottom: 0; | ||
| left: 0; | ||
| right: 0; | ||
| width: 100%; | ||
| height: 100%; | ||
| background-color: white; | ||
| margin: 0; | ||
| border: none; | ||
|
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. If you use border: transparent instead of border: none, the border will show up as a white box on Windows High Contrast Mode. Sometimes this is useful. I'm not sure if it would help here. It would also change your box size calculation for the width of the borders.
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. @wittjeff Would it be useful to have the "transparent" border if it's on a full width screen (the sidebar takes up the entire screen)? |
||
| border-radius: 0; | ||
| } | ||
| } | ||
|
|
||
| .sidebar-header { | ||
| padding: 0.625rem 0; | ||
|
|
||
| span { | ||
| display: inline-block; | ||
| } | ||
| } | ||
|
|
||
| .close-btn { | ||
| float: right; | ||
| } | ||
|
|
||
| .sidebar-divider { | ||
| width: 100.5%; | ||
| height: 0.5rem; | ||
| background: $gray-100; | ||
| border: 1px solid $light-400; | ||
| border-left: 0; | ||
| } | ||
|
|
||
| .sidebar-content { | ||
| padding: 1rem; | ||
| font-size: 0.875rem; | ||
| } | ||
|
|
||
| .mobile-close-container { | ||
| padding-top: 0.5rem; | ||
| padding-bottom: 0.75rem; | ||
| border-bottom: 1px solid $light-400; | ||
|
|
||
| span { | ||
| display: inline-block; | ||
| } | ||
| svg { | ||
| top: 0.4rem; | ||
| left: 0.8rem; | ||
| } | ||
| } | ||
|
|
||
| .mobile-close { | ||
| font-weight: 500; | ||
|
Contributor
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. Could you use the
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. Because I have a separate SCSS file, I'm generally choosing not to add utility classes inline but add all CSS to the file to keep it contained. Except for responsive padding/margin, which are simpler to do than adding media queries. |
||
| margin-left: 1.2rem; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import React from 'react'; | ||
| import { Factory } from 'rosie'; | ||
| import { | ||
| render, initializeTestStore, screen, fireEvent, waitFor, | ||
| } from '../../setupTest'; | ||
| import Sidebar from './Sidebar'; | ||
| import useWindowSize from '../../generic/tabs/useWindowSize'; | ||
|
|
||
| jest.mock('../../generic/tabs/useWindowSize'); | ||
|
|
||
| describe('Sidebar', () => { | ||
| let mockData; | ||
| const courseMetadata = Factory.build('courseMetadata'); | ||
|
|
||
| beforeEach(async () => { | ||
| mockData = { | ||
| toggleSidebar: () => {}, | ||
| }; | ||
| }); | ||
|
|
||
| beforeAll(async () => { | ||
| await initializeTestStore({ courseMetadata, excludeFetchCourse: true, excludeFetchSequence: true }); | ||
| }); | ||
|
|
||
| it('renders sidebar', async () => { | ||
| useWindowSize.mockReturnValue({ width: 1200, height: 422 }); | ||
| const { container } = render(<Sidebar {...mockData} />); | ||
|
|
||
| expect(container).toBeInTheDocument(); | ||
| expect(container).toHaveTextContent('Notifications'); | ||
| expect(container).not.toHaveTextContent('Back to course'); | ||
| }); | ||
|
|
||
| it('renders no notifications message', async () => { | ||
| // REV-2130 TODO: add conditional if no expiration box/upgradeable | ||
| const testData = { ...mockData }; | ||
| const { container } = render(<Sidebar {...testData} />); | ||
|
|
||
| expect(container).toBeInTheDocument(); | ||
| expect(container).toHaveTextContent('You have no new notifications at this time.'); | ||
| }); | ||
|
|
||
| it('renders sidebar with full screen "Back to course" at response width', async () => { | ||
| useWindowSize.mockReturnValue({ width: 991, height: 422 }); | ||
| const toggleSidebar = jest.fn(); | ||
| const testData = { | ||
| ...mockData, | ||
| toggleSidebar, | ||
| }; | ||
| render(<Sidebar {...testData} />); | ||
|
|
||
| const responsiveCloseButton = screen.getByRole('button', { name: 'Back to course' }); | ||
| await waitFor(() => expect(responsiveCloseButton).toBeInTheDocument()); | ||
|
|
||
| fireEvent.click(responsiveCloseButton); | ||
| expect(toggleSidebar).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
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.
Is there a reusable variable that can be used here (and other places where the sizes are hardcoded) so you don't have to hardcode the pixel size? Something like
media-breakpoint-down(xs)in edx-platform?Uh oh!
There was an error while loading. Please reload this page.
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.
Good question, there is a way to add to a SCSS file (ie.
$grid-breakpoints), but not sure about here, will take a look how to do it in JSX.