Skip to content
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

feat(opentrons-ai-client): Header component with progressbar #16543

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ describe('Header', () => {

it('should render log out button', () => {
render()
screen.getByText('Log out')
screen.getByText('Logout')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Meta, StoryObj } from '@storybook/react'
import { HeaderWithMeter as HeaderWithMeterComponent } from '.'
import { COLORS, Flex, SPACING } from '@opentrons/components'

const meta: Meta<typeof HeaderWithMeterComponent> = {
title: 'AI/Molecules/HeaderWithMeter',
component: HeaderWithMeterComponent,
decorators: [
Story => (
<Flex backgroundColor={COLORS.grey10} padding={SPACING.spacing40}>
<Story />
</Flex>
),
],
}
export default meta

type Story = StoryObj<typeof HeaderWithMeterComponent>

export const HeaderWithMeterExample: Story = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { renderWithProviders } from '../../../__testing-utils__'
import { i18n } from '../../../i18n'
import { HeaderWithMeter } from '../index'
import { describe, expect, it } from 'vitest'
import { screen, render as rtlRender } from '@testing-library/react'

const render = (): ReturnType<typeof renderWithProviders> => {
return renderWithProviders(<HeaderWithMeter progressPercentage={0.3} />, {
i18nInstance: i18n,
})
}

describe('HeaderWithMeter', () => {
it('should render Header component', () => {
render()
screen.getByText('Opentrons')
})

it('should render progress bar', () => {
render()
screen.getByRole('progressbar')
})

it('should render progress bar with correct value', () => {
render()
const progressBar = screen.getByRole('progressbar')
expect(progressBar).toHaveAttribute('value', '0.3')
})

it('should update when progressPercentage prop changes', () => {
const { rerender } = rtlRender(
<HeaderWithMeter progressPercentage={0.3} />,
{}
)

const progressBar = screen.getByRole('progressbar')
expect(progressBar).toHaveAttribute('value', '0.3')

rerender(<HeaderWithMeter progressPercentage={0.6} />)
expect(progressBar).toHaveAttribute('value', '0.6')

rerender(<HeaderWithMeter progressPercentage={1} />)
expect(progressBar).toHaveAttribute('value', '1')

rerender(<HeaderWithMeter progressPercentage={0} />)
expect(progressBar).toHaveAttribute('value', '0')

rerender(<HeaderWithMeter progressPercentage={0.2} />)
expect(progressBar).toHaveAttribute('value', '0.2')
})
})
50 changes: 50 additions & 0 deletions opentrons-ai-client/src/molecules/HeaderWithMeter/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
Flex,
DIRECTION_COLUMN,
JUSTIFY_SPACE_BETWEEN,
COLORS,
} from '@opentrons/components'
import { Header } from '../Header'
import styled from 'styled-components'

const SquareProgressBar = styled.progress`
width: 100%;
height: 4px;
border-radius: 0;
appearance: none;

&::-webkit-progress-bar {
background-color: ${COLORS.grey30}; /* Background color of the progress bar */
border-radius: 0;
}

&::-webkit-progress-value {
background-color: ${COLORS.blue50}; /* Color of the progress value */
border-radius: 0;
transition: width 1s;
}

&::-moz-progress-bar {
background-color: ${COLORS.blue50}; /* Color of the progress value for Firefox */
border-radius: 0;
}
`

export interface ChatHeaderProps {
progressPercentage: number
}

export function HeaderWithMeter({
progressPercentage = 0.5,
}: ChatHeaderProps): JSX.Element {
return (
<Flex
flexDirection={DIRECTION_COLUMN}
justifyContent={JUSTIFY_SPACE_BETWEEN}
width="100%"
>
<Header />
<SquareProgressBar value={progressPercentage}></SquareProgressBar>
</Flex>
)
}
Loading