Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Play-528] Typescript Conversion Stat Change #2293

Merged
merged 3 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions playbook/app/pb_kits/playbook/pb_stat_change/_stat_change.jsx

This file was deleted.

66 changes: 66 additions & 0 deletions playbook/app/pb_kits/playbook/pb_stat_change/_stat_change.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react'
import classnames from 'classnames'

import { buildCss } from '../utilities/props'
import { globalProps } from '../utilities/globalProps'

import Body from '../pb_body/_body'
import Icon from '../pb_icon/_icon'

const statusMap: {neutral: 'neutral', decrease: 'negative' ,increase: 'positive'} = {
increase: 'positive',
decrease: 'negative',
neutral: 'neutral',
}

const iconMap = {
increase: 'arrow-up',
decrease: 'arrow-down',
}

type StatChangeProps = {
change?: 'increase' | 'decrease' | 'neutral',
className?: string,
icon?: string,
id?: string,
value?: string | number,
}

const StatChange = (props: StatChangeProps): React.ReactElement => {
const { change = 'neutral', className, icon, id, value } = props
const status = statusMap[change as keyof typeof statusMap]
let returnedIcon = iconMap[change as keyof typeof iconMap]
if (icon) {
returnedIcon = icon
}

return (
<>
{value &&
<div
className={classnames(
buildCss('pb_stat_change_kit', status),
globalProps(props),
className
)}
id={id}
>
<Body status={status}>
{returnedIcon &&
<>
<Icon
fixed_width
icon={returnedIcon}
/>
{' '}
</>
}
{`${value}%`}
</Body>
</div>
}
</>
)
}

export default StatChange
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react'
import { render, screen } from '../utilities/test-utils'

import StatChange from './_stat_change'

test('it renders each status', () => {
render(
<StatChange
change="increase"
value="28.4"
/>
)

const kit = screen.getByText('28.4%')
expect(kit).toHaveClass(`pb_body_kit_positive`)
})

test('it renders preset icon', () => {
render(
<StatChange
change="increase"
value="28.4"
/>
)

const kit = screen.getByLabelText('arrow-up icon')
expect(kit).toBeTruthy
})

test('it renders custom icon', () => {
render(
<StatChange
icon="chart-line-down"
value={6.1}
/>

)

const kit = screen.getByLabelText('chart-line-down icon')
expect(kit).toBeTruthy
})