-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: APP-2988 - Implement StatePingAnimation core component (#126)
- Loading branch information
1 parent
f50737f
commit 48deac0
Showing
7 changed files
with
95 additions
and
1 deletion.
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
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 +1,2 @@ | ||
export * from './emptyState'; | ||
export * from './statePingAnimation'; |
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,5 @@ | ||
export { | ||
StatePingAnimation, | ||
type IStatePingAnimationProps, | ||
type StatePingAnimationVariant, | ||
} from './statePingAnimation'; |
16 changes: 16 additions & 0 deletions
16
src/core/components/states/statePingAnimation/statePingAnimation.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,16 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { StatePingAnimation, type IStatePingAnimationProps } from './statePingAnimation'; | ||
|
||
describe('<StatePingAnimation/> component', () => { | ||
const createTestComponent = (props?: Partial<IStatePingAnimationProps>) => { | ||
const completeProps = { ...props }; | ||
|
||
return <StatePingAnimation {...completeProps} />; | ||
}; | ||
|
||
it('renders without crashing', () => { | ||
render(createTestComponent()); | ||
|
||
expect(screen.getByTestId('statePingAnimation')).toBeInTheDocument(); | ||
}); | ||
}); |
41 changes: 41 additions & 0 deletions
41
src/core/components/states/statePingAnimation/statePingAnimation.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,41 @@ | ||
import classNames from 'classnames'; | ||
import type React from 'react'; | ||
import { type ComponentPropsWithoutRef } from 'react'; | ||
|
||
export type StatePingAnimationVariant = 'primary' | 'info' | 'success' | 'warning' | 'critical'; | ||
|
||
export interface IStatePingAnimationProps extends ComponentPropsWithoutRef<'span'> { | ||
/** | ||
* Variant of the ping animation | ||
* @default primary | ||
*/ | ||
variant?: StatePingAnimationVariant; | ||
} | ||
|
||
const variantToBgClassName: Record<StatePingAnimationVariant, string> = { | ||
info: 'bg-info-500', | ||
primary: 'bg-primary-500', | ||
success: 'bg-success-500', | ||
warning: 'bg-warning-500', | ||
critical: 'bg-critical-500', | ||
}; | ||
|
||
export const StatePingAnimation: React.FC<IStatePingAnimationProps> = (props) => { | ||
const { className, variant = 'primary', ...otherProps } = props; | ||
|
||
return ( | ||
<span | ||
data-testid="statePingAnimation" | ||
className={classNames('relative flex size-3', className)} | ||
{...otherProps} | ||
> | ||
<span | ||
className={classNames( | ||
'absolute inline-flex size-full animate-ping rounded-full opacity-75', | ||
variantToBgClassName[variant], | ||
)} | ||
/> | ||
<span className={classNames('relative inline-flex size-3 rounded-full', variantToBgClassName[variant])} /> | ||
</span> | ||
); | ||
}; |
27 changes: 27 additions & 0 deletions
27
src/core/components/states/statePingAnimation/statePingAnimations.stories.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,27 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { StatePingAnimation } from './statePingAnimation'; | ||
|
||
const meta: Meta<typeof StatePingAnimation> = { | ||
title: 'Core/Components/States/StatePingAnimation', | ||
component: StatePingAnimation, | ||
tags: ['autodocs'], | ||
parameters: { | ||
design: { | ||
type: 'figma', | ||
url: 'https://www.figma.com/file/P0GeJKqILL7UXvaqu5Jj7V/v1.1.0?type=design&node-id=15073-29243&mode=design&t=FQrFXBU8bQ7ug6dM-4', | ||
}, | ||
}, | ||
}; | ||
|
||
type Story = StoryObj<typeof StatePingAnimation>; | ||
|
||
/** | ||
* Default usage of the `StatePingAnimation` | ||
*/ | ||
export const Default: Story = { | ||
args: { | ||
variant: 'info', | ||
}, | ||
}; | ||
|
||
export default meta; |