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(PPDSC-2119): floating element motion #245

Merged
merged 7 commits into from
Jul 4, 2022
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
92 changes: 56 additions & 36 deletions src/base-floating-element/base-floating-element.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import {CSSTransition} from 'react-transition-group';
import {useEffect, useRef} from 'react';
import {
arrow,
Expand All @@ -15,6 +16,8 @@ import {StyledFloatingElement, StyledPanel, StyledPointer} from './styled';
import {useControlled} from '../utils/hooks';
import {useTheme} from '../theme';
import {showOverridePxWarnings, getOverridePxValue} from './utils';
import {getTransitionDuration} from '../utils';
import {getTransitionClassName} from '../utils/get-transition-class-name';

export const BaseFloatingElement: React.FC<BaseFloatingElementProps> = ({
children,
Expand Down Expand Up @@ -143,6 +146,8 @@ export const BaseFloatingElement: React.FC<BaseFloatingElementProps> = ({
// handler).
const referenceProps = getReferenceProps();

const baseTransitionClassname = `nk-${path}`;

return (
<>
{React.cloneElement(children, {
Expand All @@ -154,46 +159,61 @@ export const BaseFloatingElement: React.FC<BaseFloatingElementProps> = ({
: undefined,
...referenceProps,
})}
{open && (
<StyledFloatingElement
{...getFloatingProps({
ref: floating,
id: floatingId,
className,
})}
strategy={strategy}
$x={x}
$y={y}
placement={statefulPlacement}
overrides={overrides}
hidePointer={hidePointer}
role={role}
{...floatingElAriaAttributes}
path={path}
>
<StyledPanel
tabIndex={-1}
data-testid="floating-element-panel"
as={contentIsString ? 'p' : 'div'}
<CSSTransition
in={open}
timeout={getTransitionDuration(path, '')({theme, overrides})}
classNames={baseTransitionClassname}
mountOnEnter
unmountOnExit
appear
>
{state => (
<StyledFloatingElement
{...getFloatingProps({
ref: floating,
id: floatingId,
})}
className={`${className || ''} ${getTransitionClassName(
baseTransitionClassname,
state,
)}`}
baseTransitionClassname={baseTransitionClassname}
strategy={strategy}
$x={x}
$y={y}
placement={statefulPlacement}
overrides={overrides}
hidePointer={hidePointer}
role={role}
{...floatingElAriaAttributes}
path={path}
ref={panelRef}
>
{typeof content === 'function' ? content(referenceProps) : content}
</StyledPanel>
{!hidePointer && (
<StyledPointer
path={path}
id={`${floatingId}-pointer`}
ref={pointerRef}
placement={statefulPlacement}
$x={pointerX}
$y={pointerY}
<StyledPanel
tabIndex={-1}
data-testid="floating-element-panel"
as={contentIsString ? 'p' : 'div'}
overrides={overrides}
/>
)}
</StyledFloatingElement>
)}
path={path}
ref={panelRef}
>
{typeof content === 'function'
? content(referenceProps)
: content}
</StyledPanel>
{!hidePointer && (
<StyledPointer
path={path}
id={`${floatingId}-pointer`}
ref={pointerRef}
placement={statefulPlacement}
$x={pointerX}
$y={pointerY}
overrides={overrides}
/>
)}
</StyledFloatingElement>
)}
</CSSTransition>
</>
);
};
4 changes: 4 additions & 0 deletions src/base-floating-element/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getResponsiveSize,
getResponsiveSpace,
getStylePreset,
getTransitionPreset,
getTypographyPreset,
styled,
} from '../utils/style';
Expand All @@ -17,6 +18,7 @@ export const StyledFloatingElement = styled.div<
$x?: number;
$y?: number;
hidePointer: boolean;
baseTransitionClassname: string;
} & Pick<BaseFloatingElementProps, 'overrides' | 'path'>
>`
${({path}) => getStylePreset(`${path}`, '')};
Expand All @@ -28,6 +30,8 @@ export const StyledFloatingElement = styled.div<
left: $x != null ? `${$x}px` : '',
top: $y != null ? `${$y}px` : '',
})}
${({path, baseTransitionClassname}) =>
getTransitionPreset(`${path}`, '', baseTransitionClassname)};
`;

export const StyledPanel = styled(TextBlock)<
Expand Down
2 changes: 2 additions & 0 deletions src/base-floating-element/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@floating-ui/react-dom-interactions';
import {MQ} from '../utils';
import {LogicalPaddingProps} from '../utils/logical-properties';
import {TransitionToken} from '../theme';

export type TriggerType = 'click' | 'hover' | 'focus';
export type FallbackBehaviourType = 'flip' | 'shift';
Expand Down Expand Up @@ -51,6 +52,7 @@ export interface FloatingElementProps
size?: MQ<string>;
edgeOffset?: string;
};
transitionPreset?: TransitionToken | TransitionToken[];
};
className?: string;
onDismiss?: () => void;
Expand Down
Loading