-
Notifications
You must be signed in to change notification settings - Fork 350
feat(elements): Enable Blueprint animations #4718
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
Open
jfox-box
wants to merge
5
commits into
master
Choose a base branch
from
add-blueprint-animations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c03216c
feat(elements): Enable Blueprint animations
jfox-box 4ff5fa3
fix: Enable for Chromatic and remove wrapper from PresenceAvatarList
jfox-box 4fe8837
fix: chromatic test
jfox-box a248a37
fix: rename to enableBlueprintAnimations
jfox-box bae74cf
Merge branch 'master' into add-blueprint-animations
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
105 changes: 105 additions & 0 deletions
105
src/elements/common/__tests__/withBlueprintAnimations.test.tsx
This file contains hidden or 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,105 @@ | ||
| import * as React from 'react'; | ||
| import { render } from '../../../test-utils/testing-library'; | ||
| import { type BlueprintAnimationsProps, withBlueprintAnimations } from '../withBlueprintAnimations'; | ||
|
|
||
| jest.mock('@box/blueprint-web', () => { | ||
| const ReactMock = jest.requireActual('react'); | ||
|
|
||
| return { | ||
| BlueprintProvider: ({ children, configurationOverrides }) => | ||
| ReactMock.createElement( | ||
| 'div', | ||
| { | ||
| 'data-testid': 'blueprint-animations-provider', | ||
| 'data-animations-phase1': String(configurationOverrides?.animationsPhase1Enabled), | ||
| 'data-animations-phase2': String(configurationOverrides?.animationsPhase2Enabled), | ||
| }, | ||
| children, | ||
| ), | ||
| useNoopTreatment: () => 'control', | ||
| TooltipProvider: ({ children }) => | ||
| ReactMock.createElement('div', { 'data-testid': 'tooltip-provider' }, children), | ||
| }; | ||
| }); | ||
|
|
||
| type TestComponentProps = { | ||
| value?: string; | ||
| } & BlueprintAnimationsProps; | ||
|
|
||
| describe('src/elements/common/withBlueprintAnimations', () => { | ||
| const TestComponent = ({ value }: TestComponentProps) => ( | ||
| <div data-testid="test-component">{`Test ${value || 'default'}`}</div> | ||
| ); | ||
|
|
||
| const WrappedComponent = withBlueprintAnimations(TestComponent); | ||
|
|
||
| const renderComponent = (props?: TestComponentProps) => render(<WrappedComponent {...props} />); | ||
|
|
||
| test('should enable Blueprint animations by default', () => { | ||
| const { getByTestId } = renderComponent(); | ||
|
|
||
| expect(getByTestId('test-component')).toHaveTextContent('Test default'); | ||
| expect(getByTestId('blueprint-animations-provider')).toHaveAttribute('data-animations-phase1', 'true'); | ||
| expect(getByTestId('blueprint-animations-provider')).toHaveAttribute('data-animations-phase2', 'true'); | ||
| }); | ||
|
|
||
| test('should opt out when enableBlueprintAnimations is false', () => { | ||
| const { getByTestId } = renderComponent({ enableBlueprintAnimations: false }); | ||
|
|
||
| expect(getByTestId('blueprint-animations-provider')).toHaveAttribute('data-animations-phase1', 'false'); | ||
| expect(getByTestId('blueprint-animations-provider')).toHaveAttribute('data-animations-phase2', 'false'); | ||
| }); | ||
|
|
||
| test('should enable all phases when enableBlueprintAnimations is true', () => { | ||
| const { getByTestId } = renderComponent({ enableBlueprintAnimations: true }); | ||
|
|
||
| expect(getByTestId('blueprint-animations-provider')).toHaveAttribute('data-animations-phase1', 'true'); | ||
| expect(getByTestId('blueprint-animations-provider')).toHaveAttribute('data-animations-phase2', 'true'); | ||
| }); | ||
|
|
||
| test('should honor per-phase overrides matching Blueprint configurationOverrides keys', () => { | ||
| const { getByTestId } = renderComponent({ | ||
| enableBlueprintAnimations: { | ||
| animationsPhase1Enabled: true, | ||
| animationsPhase2Enabled: false, | ||
| }, | ||
| }); | ||
|
|
||
| expect(getByTestId('blueprint-animations-provider')).toHaveAttribute('data-animations-phase1', 'true'); | ||
| expect(getByTestId('blueprint-animations-provider')).toHaveAttribute('data-animations-phase2', 'false'); | ||
| }); | ||
|
|
||
| test('should default omitted phase keys to on when an object is passed', () => { | ||
| const { getByTestId } = renderComponent({ | ||
| enableBlueprintAnimations: { | ||
| animationsPhase2Enabled: false, | ||
| }, | ||
| }); | ||
|
|
||
| expect(getByTestId('blueprint-animations-provider')).toHaveAttribute('data-animations-phase1', 'true'); | ||
| expect(getByTestId('blueprint-animations-provider')).toHaveAttribute('data-animations-phase2', 'false'); | ||
| }); | ||
|
|
||
| test('should pass props to wrapped component', () => { | ||
| const { getByTestId } = renderComponent({ value: 'test-value' }); | ||
|
|
||
| expect(getByTestId('test-component')).toHaveTextContent('Test test-value'); | ||
| }); | ||
|
|
||
| test('should not forward enableBlueprintAnimations to the wrapped component', () => { | ||
| const DomFacingComponent = ({ value, ...rest }: TestComponentProps & Record<string, unknown>) => ( | ||
| <div data-testid="dom-facing" {...rest}> | ||
| {value} | ||
| </div> | ||
| ); | ||
| const WrappedDomFacing = withBlueprintAnimations(DomFacingComponent); | ||
|
|
||
| const { getByTestId } = render( | ||
| <WrappedDomFacing value="ok" enableBlueprintAnimations={false} data-extra="keep" />, | ||
| ); | ||
|
|
||
| expect(getByTestId('dom-facing')).not.toHaveAttribute('enableBlueprintAnimations'); | ||
| expect(getByTestId('dom-facing')).toHaveAttribute('data-extra', 'keep'); | ||
| expect(getByTestId('blueprint-animations-provider')).toHaveAttribute('data-animations-phase1', 'false'); | ||
| }); | ||
| }); |
This file contains hidden or 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,53 @@ | ||
| import React from 'react'; | ||
| import { BlueprintProvider, useNoopTreatment } from '@box/blueprint-web'; | ||
| import type { BlueprintConfigurationOverrides } from '@box/blueprint-web'; | ||
|
|
||
| export type BlueprintAnimationsProps = { | ||
| /** | ||
| * Blueprint component animations for this element. | ||
| * - omitted / `true`: all phases on (default) | ||
| * - `false`: all phases off | ||
| * - object: per-phase overrides from Blueprint `configurationOverrides` (omitted keys default on) | ||
| */ | ||
| enableBlueprintAnimations?: boolean | BlueprintConfigurationOverrides; | ||
| }; | ||
|
|
||
| export function getBlueprintAnimationOverrides( | ||
| value: boolean | BlueprintConfigurationOverrides | undefined, | ||
| ): Pick<BlueprintConfigurationOverrides, 'animationsPhase1Enabled' | 'animationsPhase2Enabled'> { | ||
| if (value === false) { | ||
| return { | ||
| animationsPhase1Enabled: false, | ||
| animationsPhase2Enabled: false, | ||
| }; | ||
| } | ||
|
|
||
| if (value === true || value == null) { | ||
| return { | ||
| animationsPhase1Enabled: true, | ||
| animationsPhase2Enabled: true, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| animationsPhase1Enabled: value.animationsPhase1Enabled !== false, | ||
| animationsPhase2Enabled: value.animationsPhase2Enabled !== false, | ||
| }; | ||
| } | ||
|
|
||
| export function withBlueprintAnimations<P>( | ||
| Component: React.ComponentType<P>, | ||
| ): React.FC<P & BlueprintAnimationsProps> { | ||
| return function WithBlueprintAnimations(props: P & BlueprintAnimationsProps) { | ||
| const { enableBlueprintAnimations, ...rest } = props; | ||
|
|
||
| return ( | ||
| <BlueprintProvider | ||
| useTreatment={useNoopTreatment} | ||
| configurationOverrides={getBlueprintAnimationOverrides(enableBlueprintAnimations)} | ||
| > | ||
| <Component {...(rest as P)} /> | ||
| </BlueprintProvider> | ||
| ); | ||
| }; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.