-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
252 additions
and
164 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
66 changes: 66 additions & 0 deletions
66
...s/StudioPageHeader/StudioPageHeaderPopoverTrigger/StudioPageHeaderPopoverTrigger.test.tsx
This file contains 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,66 @@ | ||
import type { ForwardedRef } from 'react'; | ||
import React from 'react'; | ||
import type { RenderResult } from '@testing-library/react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { StudioPageHeader } from '../'; | ||
import { StudioPopover } from '../../'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { testRefForwarding } from '../../../test-utils/testRefForwarding'; | ||
import type { StudioPageHeaderPopoverTriggerProps } from './StudioPageHeaderPopoverTrigger'; | ||
import { testRootClassNameAppending } from '../../../test-utils/testRootClassNameAppending'; | ||
import { testCustomAttributes } from '../../../test-utils/testCustomAttributes'; | ||
|
||
// Test data: | ||
const triggerText = 'Trigger'; | ||
const contentText = 'Content'; | ||
const defaultProps: StudioPageHeaderPopoverTriggerProps = { | ||
children: triggerText, | ||
}; | ||
|
||
describe('StudioPageHeader.PopoverTrigger', () => { | ||
it('Renders the trigger button', () => { | ||
renderPopover(); | ||
expect(screen.getByRole('button', { name: triggerText })).toBeInTheDocument(); | ||
}); | ||
|
||
it('Does not display the popover by default', () => { | ||
renderPopover(); | ||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('Opens the popover when the user clicks the trigger', async () => { | ||
const user = userEvent.setup(); | ||
renderPopover(); | ||
await user.click(screen.getByRole('button', { name: triggerText })); | ||
expect(screen.getByRole('dialog')).toBeInTheDocument(); | ||
expect(screen.getByRole('dialog')).toHaveTextContent(contentText); | ||
}); | ||
|
||
it('Forwards the ref to the trigger button', () => { | ||
testRefForwarding<HTMLButtonElement>((ref) => renderPopoverTrigger({}, ref)); | ||
}); | ||
|
||
it('Appends the given className to the trigger button', () => { | ||
testRootClassNameAppending((className) => renderPopoverTrigger({ className })); | ||
}); | ||
|
||
it('Accepts custom attributes', () => { | ||
testCustomAttributes(renderPopoverTrigger); | ||
}); | ||
}); | ||
|
||
function renderPopover(): RenderResult { | ||
return render( | ||
<StudioPopover> | ||
<StudioPageHeader.PopoverTrigger {...defaultProps} /> | ||
<StudioPopover.Content>{contentText}</StudioPopover.Content> | ||
</StudioPopover>, | ||
); | ||
} | ||
|
||
function renderPopoverTrigger( | ||
props: StudioPageHeaderPopoverTriggerProps, | ||
ref?: ForwardedRef<HTMLButtonElement>, | ||
): RenderResult { | ||
return render(<StudioPageHeader.PopoverTrigger {...defaultProps} {...props} ref={ref} />); | ||
} |
23 changes: 23 additions & 0 deletions
23
...onents/StudioPageHeader/StudioPageHeaderPopoverTrigger/StudioPageHeaderPopoverTrigger.tsx
This file contains 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,23 @@ | ||
import React, { forwardRef } from 'react'; | ||
import type { StudioPopoverTriggerProps } from '../../StudioPopover'; | ||
import { StudioPopover } from '../../StudioPopover'; | ||
import cn from 'classnames'; | ||
import classes from '../common.module.css'; | ||
|
||
import type { StudioPageHeaderColor } from '../types/StudioPageHeaderColor'; | ||
import type { StudioPageHeaderVariant } from '../types/StudioPageHeaderVariant'; | ||
|
||
export type StudioPageHeaderPopoverTriggerProps = { | ||
color?: StudioPageHeaderColor; | ||
variant?: StudioPageHeaderVariant; | ||
} & Omit<StudioPopoverTriggerProps, 'color' | 'variant'>; | ||
|
||
export const StudioPageHeaderPopoverTrigger = forwardRef< | ||
HTMLButtonElement, | ||
StudioPageHeaderPopoverTriggerProps | ||
>(({ color = 'dark', variant = 'regular', className: givenClass, ...rest }, ref) => { | ||
const className = cn(classes.linkOrButton, classes[variant], classes[color], givenClass); | ||
return <StudioPopover.Trigger className={className} {...rest} ref={ref} />; | ||
}); | ||
|
||
StudioPageHeaderPopoverTrigger.displayName = 'StudioPageHeader.PopoverTrigger'; |
1 change: 1 addition & 0 deletions
1
...studio-components/src/components/StudioPageHeader/StudioPageHeaderPopoverTrigger/index.ts
This file contains 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 @@ | ||
export * from './StudioPageHeaderPopoverTrigger'; |
This file contains 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
46 changes: 28 additions & 18 deletions
46
frontend/libs/studio-components/src/components/StudioPopover/StudioPopover.tsx
This file contains 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
3 changes: 1 addition & 2 deletions
3
frontend/libs/studio-components/src/components/StudioPopover/index.ts
This file contains 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 |
---|---|---|
@@ -1,2 +1 @@ | ||
export { StudioPopover } from './StudioPopover'; | ||
export type { StudioPopoverProps } from './StudioPopover'; | ||
export * from './StudioPopover'; |
This file contains 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 @@ | ||
export type WithoutAsChild<Props> = Omit<Props, 'asChild'>; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.