-
Notifications
You must be signed in to change notification settings - Fork 247
feat: Added new accordion with updated styles CLOUDP-314036 #6902
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
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
.../compass-indexes/src/components/create-index-form/create-index-options-accordion.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import React from 'react'; | ||
| import { render, screen, userEvent } from '@mongodb-js/testing-library-compass'; | ||
| import { expect } from 'chai'; | ||
| import CreateIndexOptionsAccordion from './create-index-options-accordion'; | ||
|
|
||
| describe('CreateIndexOptionsAccordion', () => { | ||
| it('renders the button with "Options" text', () => { | ||
| render( | ||
| <CreateIndexOptionsAccordion>Test Content</CreateIndexOptionsAccordion> | ||
| ); | ||
| expect(screen.getByText('Options')).to.exist; | ||
| }); | ||
|
|
||
| it('toggles the accordion content when the button is clicked', () => { | ||
| render( | ||
| <CreateIndexOptionsAccordion>Test Content</CreateIndexOptionsAccordion> | ||
| ); | ||
|
|
||
| const button = screen.getByRole('button', { name: /options/i }); | ||
| expect(screen.queryByText('Test Content')).to.not.exist; | ||
|
|
||
| userEvent.click(button); | ||
| expect(screen.getByText('Test Content')).to.exist; | ||
|
|
||
| userEvent.click(button); | ||
| expect(screen.queryByText('Test Content')).to.not.exist; | ||
| }); | ||
|
|
||
| it('renders the correct icon based on the open state', () => { | ||
| render( | ||
| <CreateIndexOptionsAccordion>Test Content</CreateIndexOptionsAccordion> | ||
| ); | ||
|
|
||
| const button = screen.getByRole('button', { name: /options/i }); | ||
| expect( | ||
| screen.getByTestId('create-index-options-accordion-icon') | ||
| ).to.have.attribute('aria-label', 'Chevron Right Icon'); | ||
|
|
||
| userEvent.click(button); | ||
| expect( | ||
| screen.getByTestId('create-index-options-accordion-icon') | ||
| ).to.have.attribute('aria-label', 'Chevron Down Icon'); | ||
| }); | ||
| }); |
64 changes: 64 additions & 0 deletions
64
packages/compass-indexes/src/components/create-index-form/create-index-options-accordion.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { | ||
| Body, | ||
| css, | ||
| Icon, | ||
| palette, | ||
| useDarkMode, | ||
| } from '@mongodb-js/compass-components'; | ||
| import React, { useState } from 'react'; | ||
|
|
||
| const buttonStyles = css({ | ||
| fontWeight: 'bold', | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| paddingLeft: 0, | ||
| paddingRight: 0, | ||
| border: 'none', | ||
| background: 'none', | ||
| boxShadow: 'none', | ||
| '&:hover': { | ||
| cursor: 'pointer', | ||
| }, | ||
| }); | ||
|
|
||
| const iconStyles = css({ | ||
| marginLeft: '4px', | ||
| }); | ||
|
|
||
| const CreateIndexOptionsAccordion = ({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode; | ||
| }) => { | ||
| const [open, setOpen] = useState(false); | ||
| const darkMode = useDarkMode(); | ||
|
|
||
| const onOpenChange = () => { | ||
| setOpen(!open); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <button | ||
| className={buttonStyles} | ||
| type="button" | ||
| aria-expanded={open ? 'true' : 'false'} | ||
| onClick={onOpenChange} | ||
| > | ||
| <Body baseFontSize={16} weight="medium"> | ||
| Options | ||
| </Body> | ||
| <Icon | ||
| color={darkMode ? palette.gray.base : palette.gray.dark1} | ||
| className={iconStyles} | ||
| glyph={open ? 'ChevronDown' : 'ChevronRight'} | ||
| data-testid="create-index-options-accordion-icon" | ||
| /> | ||
| </button> | ||
|
|
||
| {open && <>{children}</>} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default CreateIndexOptionsAccordion; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why can't we use the existing accordion here? It would be nice to keep things standard in Compass where we can. If it's design changes here, maybe we should update the existing accordion?
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.
left a question here https://mongodb.slack.com/archives/C06SXC3BUUQ/p1746637912608249
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.
removed all these changes and we ended up only having to change the copy