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(FloatingPanel): new component #1611

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

feat(FloatingPanel): new component #1611

wants to merge 8 commits into from

Conversation

marcinsawicki
Copy link
Contributor

@marcinsawicki marcinsawicki commented Feb 27, 2025

Resolves: #1205

Description

New component

Storybook

https://feature-1205--613a8e945a5665003a05113b.chromatic.com

Checklist

Obligatory:

  • Self review (use this as your final check for proposed changes before requesting the review)
  • Add correct label
  • Assign pull request with the correct issue

Summary by CodeRabbit

  • New Features
    • Introduced a floating panel component offering dynamic visibility, multiple placement options, and smooth transitions.
    • Added new CSS classes for improved layout and design of floating panels.
  • Documentation
    • Added comprehensive, interactive documentation showcasing the floating panel’s functionality and usage.
  • Style
    • Refined visual styling with improved transitions, opacity effects, and layout adjustments for a polished user interface.
  • Chores
    • Enabled customizable animation durations for a more fluid user experience.
  • Bug Fixes
    • Updated shadow styling for enhanced visual depth and consistency across themes.

Copy link
Contributor

coderabbitai bot commented Feb 27, 2025

Walkthrough

This update introduces a new FloatingPanel component along with its comprehensive support suite, including documentation, Storybook stories, styles, tests, and helper functions for dynamic styles and animation management. Additionally, a minor update in the AppFrame styling establishes relative positioning for improved layout behavior.

Changes

File(s) Change Summary
packages/react-components/.../AppFrame/AppFrame.module.scss Added position: relative; to .app-frame__content.
packages/react-components/.../FloatingPanel.mdx Created new documentation file for the FloatingPanel component.
packages/react-components/.../FloatingPanel.module.scss Introduced new SCSS file with styles for the FloatingPanel component.
packages/react-components/.../FloatingPanel.spec.tsx Added unit tests for the FloatingPanel component.
packages/react-components/.../FloatingPanel.stories.tsx Created Storybook file with stories for the FloatingPanel component.
packages/react-components/.../FloatingPanel.tsx Added new FloatingPanel component with props and functionality.
packages/react-components/.../FloatingPanelStories.css Introduced new CSS file with styles for floating panels.
packages/react-components/.../FloatingPanel/helpers.ts Added getFloatingStyles function for dynamic positioning of the FloatingPanel.
packages/react-components/.../FloatingPanel/types.ts Introduced IFloatingPanelProps interface for the FloatingPanel component.
packages/react-components/.../stories-helpers.tsx Added ExampleAppContent component for demonstrating FloatingPanel usage.
packages/react-components/.../hooks/useAnimations.ts Updated useAnimations hook to support an optional animationDuration property.
packages/react-components/.../foundations/shadow.css Updated shadow-related CSS variables for improved styling.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant FP as FloatingPanel Component
    participant Anim as useAnimations Hook
    participant HS as getFloatingStyles Helper

    U->>FP: Toggle visibility (isVisible)
    FP->>Anim: Initiate animation with given duration
    FP->>HS: Compute styles based on placement and size
    HS-->>FP: Return calculated CSS styles
    FP->>U: Render FloatingPanel with updated styling and ARIA attributes
Loading

Suggested reviewers

  • JoannaSikora
  • vladko-uxds

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0cbb935 and 5e06cd9.

📒 Files selected for processing (1)
  • packages/react-components/src/components/AppFrame/AppFrame.module.scss (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-components/src/components/AppFrame/AppFrame.module.scss
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: chromatic-deployment
  • GitHub Check: build

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@marcinsawicki marcinsawicki self-assigned this Feb 28, 2025
@marcinsawicki marcinsawicki added the feature New feature or request label Feb 28, 2025
@marcinsawicki marcinsawicki added this to the Future plans milestone Feb 28, 2025
@marcinsawicki marcinsawicki marked this pull request as ready for review February 28, 2025 10:22
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (18)
packages/react-components/src/components/FloatingPanel/FloatingPanel.module.scss (1)

1-29: Clean BEM-structured styles with potential improvements.

The stylesheet effectively handles placement variations and animations. Consider:

  1. The hardcoded min-height (100px) might be too restrictive
  2. Missing max-width/max-height constraints could cause layout issues with large content
  3. Consider adding transform transitions for smoother animations
 .#{$base-class} {
   position: absolute;
-  transition: all var(--transition-duration-moderate-2) ease-in-out;
+  transition: opacity var(--transition-duration-moderate-2) ease-in-out, transform var(--transition-duration-moderate-2) ease-in-out;
   opacity: 0;
   z-index: $stacking-context-level-popover;
   box-shadow: var(--shadow-fixed-bottom);
   background-color: var(--surface-primary-default);
   min-height: 100px;
+  max-height: 80%;
+  overflow: auto;

   &--bottom,
   &--top {
     right: 0;
     left: 0;
+    max-width: 100%;
   }

   &--left,
   &--right {
     top: 0;
     bottom: 0;
+    max-width: 80%;
   }

   &--visible {
     opacity: 1;
   }
 }
packages/react-components/src/components/FloatingPanel/helpers.ts (2)

3-34: Consider using switch statement for better readability

The function logic is sound, but using separate if statements for each placement makes the code slightly less readable. A switch statement would be more appropriate here.

export const getFloatingStyles = (
  placement: IFloatingPanelProps['placement'],
  isOpen: boolean,
  panelHeight: number,
  panelWidth: number
) => {
-  if (placement === 'bottom') {
-    return {
-      top: !isOpen ? '100%' : `calc(100% - ${panelHeight}px)`,
-    };
-  }
-
-  if (placement === 'top') {
-    return {
-      bottom: !isOpen ? '100%' : `calc(100% - ${panelHeight}px)`,
-    };
-  }
-
-  if (placement === 'right') {
-    return {
-      left: !isOpen ? '100%' : `calc(100% - ${panelWidth}px)`,
-    };
-  }
-
-  if (placement === 'left') {
-    return {
-      right: !isOpen ? '100%' : `calc(100% - ${panelWidth}px)`,
-    };
-  }
+  switch(placement) {
+    case 'bottom':
+      return {
+        top: !isOpen ? '100%' : `calc(100% - ${panelHeight}px)`,
+      };
+    case 'top':
+      return {
+        bottom: !isOpen ? '100%' : `calc(100% - ${panelHeight}px)`,
+      };
+    case 'right':
+      return {
+        left: !isOpen ? '100%' : `calc(100% - ${panelWidth}px)`,
+      };
+    case 'left':
+      return {
+        right: !isOpen ? '100%' : `calc(100% - ${panelWidth}px)`,
+      };
+    default:
+      return {};
+  }
-
-  return {};
}

3-8: Consider adding return type

Adding TypeScript return type would improve type safety and documentation.

export const getFloatingStyles = (
  placement: IFloatingPanelProps['placement'],
  isOpen: boolean,
  panelHeight: number,
  panelWidth: number
-) => {
+): Record<string, string> => {
packages/react-components/src/components/FloatingPanel/FloatingPanel.spec.tsx (2)

10-15: Consider testing screen readers can access the component

The tests cover basic visibility, but not accessibility for screen readers.

  it('should not be visible by default', () => {
    const { container } = renderComponent({});

    expect(container.firstChild).not.toBeInTheDocument();
+   // Also verify it's not announced to screen readers
  });

26-33: Test is good but consider adding additional placement tests

The test correctly verifies children rendering, but lacks tests for different placement scenarios.

Consider adding tests for each placement option (top, bottom, left, right) to verify the component's positioning behavior works correctly.

packages/react-components/src/components/FloatingPanel/FloatingPanel.mdx (1)

18-26: Add more examples for different placements

The documentation clearly explains the positioning requirement but would benefit from examples for each placement option.

Consider adding examples for top, bottom, left, and right placements to demonstrate the full capabilities of the component.

packages/react-components/src/components/FloatingPanel/stories-helpers.tsx (6)

10-16: Fix typo in props interface

The interface contains a typo in property names.

interface IExampleAppContentProps {
-  isBottomBarVisisble: boolean;
-  isTopBarVisisble: boolean;
-  isLeftBarVisisble: boolean;
-  isRightBarVisisble: boolean;
+  isBottomBarVisible: boolean;
+  isTopBarVisible: boolean;
+  isLeftBarVisible: boolean;
+  isRightBarVisible: boolean;
  handleBarVisibilityChange: (kind: string) => void;
}

18-24: Fix property names in component declaration

Property names contain typos and should be fixed for consistency.

export const ExampleAppContent: FC<IExampleAppContentProps> = ({
-  isBottomBarVisisble,
-  isTopBarVisisble,
-  isLeftBarVisisble,
-  isRightBarVisisble,
+  isBottomBarVisible,
+  isTopBarVisible,
+  isLeftBarVisible,
+  isRightBarVisible,
  handleBarVisibilityChange,
}) => {

42-44: Update property names in component usage

Update the variable names to match the corrected property names.

            <Switch
              size="compact"
-              on={isBottomBarVisisble}
+              on={isBottomBarVisible}
              onChange={() => handleBarVisibilityChange('bottom')}
            />

50-52: Update property names in component usage

Update the variable names to match the corrected property names.

            <Switch
              size="compact"
-              on={isTopBarVisisble}
+              on={isTopBarVisible}
              onChange={() => handleBarVisibilityChange('top')}
            />

58-60: Update property names in component usage

Update the variable names to match the corrected property names.

            <Switch
              size="compact"
-              on={isLeftBarVisisble}
+              on={isLeftBarVisible}
              onChange={() => handleBarVisibilityChange('left')}
            />

66-68: Update property names in component usage

Update the variable names to match the corrected property names.

            <Switch
              size="compact"
-              on={isRightBarVisisble}
+              on={isRightBarVisible}
              onChange={() => handleBarVisibilityChange('right')}
            />
packages/react-components/src/components/FloatingPanel/FloatingPanel.tsx (3)

21-28: Consider using ResizeObserver for responsive dimensions

The component tracks panel dimensions only on mount, but might not update if content changes dynamically.

- const { isOpen, isMounted } = useAnimations({
-   isVisible: isVisible,
-   elementRef: floatingElementWrapperRef,
-   animationDuration: 500,
- });
+ const { isOpen, isMounted } = useAnimations({
+   isVisible,
+   elementRef: floatingElementWrapperRef,
+   animationDuration: 500,
+ });

Consider implementing a ResizeObserver to dynamically update dimensions when content changes:

useEffect(() => {
  if (!isMounted) return;
  
  const updateDimensions = () => {
    if (floatingElementWrapperRef?.current) {
      setPanelHeight(floatingElementWrapperRef.current.getBoundingClientRect().height || 0);
      setPanelWidth(floatingElementWrapperRef.current.getBoundingClientRect().width || 0);
    }
  };
  
  updateDimensions();
  
  const resizeObserver = new ResizeObserver(updateDimensions);
  if (floatingElementWrapperRef.current) {
    resizeObserver.observe(floatingElementWrapperRef.current);
  }
  
  return () => {
    resizeObserver.disconnect();
  };
}, [isMounted]);

38-47: Potential performance improvement for dimension calculations

The component recalculates dimensions whenever isMounted changes, but it could be more efficient.

- useEffect(() => {
-   if (isMounted) {
-     setPanelHeight(
-       floatingElementWrapperRef?.current?.getBoundingClientRect().height || 0
-     );
-     setPanelWidth(
-       floatingElementWrapperRef?.current?.getBoundingClientRect().width || 0
-     );
-   }
- }, [isMounted]);
+ useEffect(() => {
+   if (isMounted && floatingElementWrapperRef.current) {
+     const { height, width } = floatingElementWrapperRef.current.getBoundingClientRect();
+     setPanelHeight(height || 0);
+     setPanelWidth(width || 0);
+   }
+ }, [isMounted]);

53-64: Consider using more semantic ARIA attributes

The component uses a custom role, but standard ARIA roles might be more appropriate.

- <div
-   role="floating-panel"
-   aria-visible={isOpen}
+ <div
+   role="dialog"
+   aria-hidden={!isOpen}

The standard "dialog" role would be more semantic than a custom "floating-panel" role, and "aria-hidden" is more standard than "aria-visible".

packages/react-components/src/components/FloatingPanel/FloatingPanel.stories.tsx (3)

98-101: Fix typo in variable names

Variable names contain a typo that should be corrected for consistency.

- const [isBottomBarVisisble, setIsBottomBarVisisble] = useState(true);
- const [isTopBarVisisble, setIsTopBarVisisble] = useState(false);
- const [isLeftBarVisisble, setIsLeftBarVisisble] = useState(false);
- const [isRightBarVisisble, setIsRightBarVisisble] = useState(false);
+ const [isBottomBarVisible, setIsBottomBarVisible] = useState(true);
+ const [isTopBarVisible, setIsTopBarVisible] = useState(false);
+ const [isLeftBarVisible, setIsLeftBarVisible] = useState(false);
+ const [isRightBarVisible, setIsRightBarVisible] = useState(false);

Remember to update all references to these variables throughout the file.


103-131: Consider simplifying panel visibility management

The current implementation closes all panels before opening a new one, but this could be made more maintainable.

- const closePanels = () => {
-   setIsBottomBarVisisble(false);
-   setIsTopBarVisisble(false);
-   setIsLeftBarVisisble(false);
-   setIsRightBarVisisble(false);
- };
- 
- const handleBarVisibilityChange = (kind: string) => {
-   switch (kind) {
-     case 'bottom':
-       closePanels();
-       setIsBottomBarVisisble(!isBottomBarVisisble);
-       break;
-     case 'top':
-       closePanels();
-       setIsTopBarVisisble(!isTopBarVisisble);
-       break;
-     case 'left':
-       closePanels();
-       setIsLeftBarVisisble(!isLeftBarVisisble);
-       break;
-     case 'right':
-       closePanels();
-       setIsRightBarVisisble(!isRightBarVisisble);
-       break;
-     default:
-       break;
-   }
- };
+ const handleBarVisibilityChange = (kind: string) => {
+   const stateUpdates = {
+     bottom: false,
+     top: false,
+     left: false,
+     right: false,
+   };
+   
+   if (kind in stateUpdates) {
+     const currentState = 
+       kind === 'bottom' ? isBottomBarVisible :
+       kind === 'top' ? isTopBarVisible :
+       kind === 'left' ? isLeftBarVisible :
+       isRightBarVisible;
+     
+     stateUpdates[kind as keyof typeof stateUpdates] = !currentState;
+     
+     setIsBottomBarVisible(stateUpdates.bottom);
+     setIsTopBarVisible(stateUpdates.top);
+     setIsLeftBarVisible(stateUpdates.left);
+     setIsRightBarVisible(stateUpdates.right);
+   }
+ };

This approach is more scalable and less prone to errors as it uses a declarative pattern.


293-318: Consider consolidating panel examples

The examples for different panel placements contain duplicated structure.

Consider creating a reusable panel content component to reduce duplication:

type PanelContentProps = {
  placement: 'top' | 'bottom' | 'left' | 'right';
};

const PanelContent = ({ placement }: PanelContentProps) => {
  const isHorizontal = placement === 'top' || placement === 'bottom';
  
  return isHorizontal ? (
    <div className="horizontal-panel">
      <Button kind="primary" onClick={() => {}}>Save</Button>
      <Button onClick={() => {}}>Cancel</Button>
    </div>
  ) : (
    <div className="vertical-panel">
      {Array.from({ length: 5 }).map((_, i) => (
        <Checkbox key={i}>Option {i + 1}</Checkbox>
      ))}
    </div>
  );
};

Then use it in your panels:

<FloatingPanel isVisible={isBottomBarVisible} placement="bottom">
  <PanelContent placement="bottom" />
</FloatingPanel>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 422ca80 and 2235c4f.

📒 Files selected for processing (11)
  • packages/react-components/src/components/AppFrame/AppFrame.module.scss (1 hunks)
  • packages/react-components/src/components/FloatingPanel/FloatingPanel.mdx (1 hunks)
  • packages/react-components/src/components/FloatingPanel/FloatingPanel.module.scss (1 hunks)
  • packages/react-components/src/components/FloatingPanel/FloatingPanel.spec.tsx (1 hunks)
  • packages/react-components/src/components/FloatingPanel/FloatingPanel.stories.tsx (1 hunks)
  • packages/react-components/src/components/FloatingPanel/FloatingPanel.tsx (1 hunks)
  • packages/react-components/src/components/FloatingPanel/FloatingPanelStories.css (1 hunks)
  • packages/react-components/src/components/FloatingPanel/helpers.ts (1 hunks)
  • packages/react-components/src/components/FloatingPanel/stories-helpers.tsx (1 hunks)
  • packages/react-components/src/components/FloatingPanel/types.ts (1 hunks)
  • packages/react-components/src/hooks/useAnimations.ts (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/react-components/src/components/FloatingPanel/FloatingPanelStories.css
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: chromatic-deployment
🔇 Additional comments (11)
packages/react-components/src/components/AppFrame/AppFrame.module.scss (1)

67-67: Excellent positioning addition for FloatingPanel support.

Setting position: relative creates the proper positioning context for absolute elements like the new FloatingPanel component.

packages/react-components/src/components/FloatingPanel/types.ts (1)

1-12: Well-structured interface with clear documentation.

The interface follows TypeScript best practices with meaningful property names and clear JSDoc comments.

packages/react-components/src/hooks/useAnimations.ts (3)

9-9: Good extensibility with animation duration parameter.

Adding configurable animation duration improves the hook's flexibility.


22-22: Sensible default animation duration.

300ms is a good default that balances perceived speed with smooth transitions.


47-50: Fallback timeout now properly uses the configured duration.

This ensures consistency between CSS transitions and the JavaScript fallback.

packages/react-components/src/components/FloatingPanel/FloatingPanel.mdx (1)

28-30: The Component API section looks good

Clear and well-structured documentation of the component's API.

packages/react-components/src/components/FloatingPanel/FloatingPanel.tsx (2)

1-11: Clean imports with good organization

Imports are well-structured with proper grouping of React, third-party, and internal dependencies.


14-20: Well-defined props with sensible defaults

The component props are clearly defined with appropriate default values for isVisible and placement.

packages/react-components/src/components/FloatingPanel/FloatingPanel.stories.tsx (3)

33-40: Well-configured Storybook metadata

The Storybook configuration includes appropriate parameters for chromatic testing and fullscreen layout.


74-91: Simple and effective default story

The Default story demonstrates basic functionality clearly with toggle behavior.


285-292: Good usage example of bottom-positioned panel

The bottom-positioned FloatingPanel is well-implemented with clear action buttons.

Copy link

@vladko-uxds vladko-uxds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FloatingPanel] - new component
2 participants