-
Notifications
You must be signed in to change notification settings - Fork 70
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
chore: Refactor RedirectBox to StudioRedirectBox #13908
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import type { Meta, StoryFn } from '@storybook/react'; | ||
import { StudioRedirectBox } from './StudioRedirectBox'; | ||
import { StudioParagraph } from '../StudioParagraph'; | ||
|
||
type Story = StoryFn<typeof StudioRedirectBox>; | ||
|
||
const meta: Meta = { | ||
title: 'Components/StudioRedirectBox', | ||
component: StudioRedirectBox, | ||
argTypes: { | ||
title: { | ||
control: 'text', | ||
}, | ||
}, | ||
}; | ||
|
||
export const Preview: Story = (args): React.ReactElement => <StudioRedirectBox {...args} />; | ||
|
||
Preview.args = { | ||
title: 'title', | ||
children: <StudioParagraph size='sm'>Children text</StudioParagraph>, | ||
}; | ||
|
||
export default meta; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { StudioRedirectBox, type StudioRedirectBoxProps } from './StudioRedirectBox'; | ||
import { testRootClassNameAppending } from '../../test-utils/testRootClassNameAppending'; | ||
|
||
const mockTitle: string = 'title'; | ||
|
||
const defaultProps: StudioRedirectBoxProps = { | ||
title: mockTitle, | ||
children: <div />, | ||
}; | ||
|
||
describe('StudioRedirectBox', () => { | ||
it('should render the title and children', () => { | ||
const mockChildrenText: string = 'children'; | ||
renderStudioRedirectBox({ children: <p>{mockChildrenText}</p> }); | ||
|
||
expect(screen.getByText(mockTitle)).toBeInTheDocument(); | ||
expect(screen.getByText(mockChildrenText)).toBeInTheDocument(); | ||
}); | ||
|
||
it('Appends given classname to internal classname', () => { | ||
testRootClassNameAppending((className) => renderStudioRedirectBox({ className })); | ||
}); | ||
}); | ||
|
||
const renderStudioRedirectBox = (props: Partial<StudioRedirectBoxProps> = {}) => { | ||
return render(<StudioRedirectBox {...defaultProps} {...props} />); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
import React, { type ReactNode } from 'react'; | ||
import React, { type ReactElement, type HTMLAttributes } from 'react'; | ||
import cn from 'classnames'; | ||
import classes from './RedirectBox.module.css'; | ||
import classes from './StudioRedirectBox.module.css'; | ||
import { StudioLabelAsParagraph } from '@studio/components'; | ||
|
||
export type RedirectBoxProps = { | ||
export type StudioRedirectBoxProps = { | ||
title: string; | ||
children: ReactNode; | ||
className?: string; | ||
}; | ||
} & HTMLAttributes<HTMLDivElement>; | ||
|
||
export const RedirectBox = ({ | ||
export const StudioRedirectBox = ({ | ||
title, | ||
children, | ||
className: givenClassName, | ||
}: RedirectBoxProps): React.ReactElement => { | ||
}: StudioRedirectBoxProps): ReactElement => { | ||
const className = cn(classes.wrapper, givenClassName); | ||
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. Should we use HTMLAttributes here? To ensure we stay consistent? Then we can need our "className" prop. 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. I agree! 😄 |
||
return ( | ||
<div className={className}> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { StudioRedirectBox } from './StudioRedirectBox'; |
This file was deleted.
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.
Ref. previous comment, then we can check that className is applied to root by using the test-utils for that. 😊