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(SideNavigationGroup): extend component, make it controllable #1513

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

Conversation

pastepi
Copy link
Collaborator

@pastepi pastepi commented Jan 31, 2025

Resolves: #1498

Description

This PR adds missing customization options to SideNavigationGroup component, as well as prepares it for the future changes visible in the figma designs attached to the issue.

Extended the SideNavigationGroup component:

  • with multiple ...className props to make targeting elements with CSS more manageable,
  • with onClick prop, allowing for custom (and default) behavior when handling label click,
  • with support for rightNode for non-collapsible case,
  • with isLinkLabel, isActive props - using them allows re-using visual styles already available in current component (and/or SideNavigationItem that's being used as label)
  • made the component controllable by exposing isOpen, isMounted, setShouldBeVisible and listWrapperRef props,
  • exported useAnimations hook to be used with above-mentioned props, to keep the animation style aligned,
  • adjusted types accordingly
  • fixed listElements selecting from children nodes (when single child element was present it wasn't an array, causing listElements?.some to throw an error)
  • added tests and updated docs

Storybook

https://feature-1498--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

Summary by CodeRabbit

  • New Features
    • Enhanced side navigation with new properties for controlling visibility, mounting state, and interaction behavior.
    • Integration with an animations hook to support dynamic transitions.
  • Documentation
    • Updated guidance detailing recommended usage patterns for optimal side navigation configuration.
  • Styling
    • Introduced new layout options for flexible label wrappers and fixed-size right nodes.
  • Tests
    • Expanded test coverage to validate new functionality and ensure consistent behavior.
  • Exports
    • Made the animations hook accessible for broader usage across the package.

@pastepi pastepi added the feature New feature or request label Jan 31, 2025
@pastepi pastepi self-assigned this Jan 31, 2025
Copy link
Contributor

coderabbitai bot commented Jan 31, 2025

Walkthrough

The pull request enhances the SideNavigationGroup component by introducing new props for better control over visibility and behavior. Documentation is updated to clarify these changes and their integration with the useAnimations hook. New SCSS classes improve layout options, while test coverage is expanded to validate the updated functionality. Additionally, supporting interfaces, constants, and hook exports are revised to align with the new features.

Changes

File(s) Summary
packages/react-components/src/components/AppFrame/AppFrame.mdx Updated documentation for new props and usage patterns related to SideNavigationGroup.
packages/react-components/src/components/AppFrame/components/SideNavigationGroup/SideNavigationGroup.module.scss Added new classes (&__simple-label-wrapper, &__right-node) for enhanced layout styling.
.../SideNavigationGroup.spec.tsx Expanded test cases for new props and adjusted existing tests for rightNode rendering.
.../SideNavigationGroup.tsx Introduced new props (e.g., labelClassName, isOpen, isMounted, setShouldBeVisible) and updated internal state management.
.../constants.ts, .../types.ts Added a new test ID constant and updated interfaces with additional properties for event handling and state management.
packages/react-components/src/hooks/useAnimations.ts, packages/react-components/src/index.ts Exported IUseAnimations interface and the useAnimations hook from the main index.

Sequence Diagram(s)

sequenceDiagram
    participant Parent as Parent Component
    participant SNG as SideNavigationGroup
    participant UA as useAnimations Hook

    Parent->>SNG: Render with new props (isOpen, isMounted, etc.)
    SNG->>UA: Initialize animations using listWrapperRef
    UA-->>SNG: Return animation state (localIsOpen, localIsMounted, etc.)
    SNG->>SNG: Render label, right-node based on props
    SNG->>Parent: Trigger onClick handler on interaction
Loading

Assessment against linked issues

Objective Addressed Explanation
Extend props with class names for easier sub-element targeting and customization (#1498)
Add right-node support for non-collapsible label case (#1498)
Add left-node support for label (e.g. an icon, with or without a separate chevron) (#1498) No changes implementing left-node support were observed.

Suggested labels

design

Suggested reviewers

  • marcinsawicki
  • vladko-uxds
  • JoannaSikora

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

🪧 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. (Beta)
  • @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.

@pastepi pastepi marked this pull request as ready for review February 3, 2025 13:41
@pastepi pastepi requested a review from Copilot February 3, 2025 13:43

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 8 changed files in this pull request and generated no comments.

Files not reviewed (3)
  • packages/react-components/src/components/AppFrame/AppFrame.mdx: Language not supported
  • packages/react-components/src/components/AppFrame/components/SideNavigationGroup/SideNavigationGroup.module.scss: Language not supported
  • packages/react-components/src/components/AppFrame/components/SideNavigationGroup/SideNavigationGroup.tsx: Evaluated as low risk
@pastepi pastepi requested a review from a team February 3, 2025 13:44
@pastepi pastepi added the documentation Documentation of any kind label Feb 3, 2025
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 (6)
packages/react-components/src/components/AppFrame/components/SideNavigationGroup/types.ts (1)

27-51: Consider grouping related props into a sub-interface.

The visibility control props (isOpen, isMounted, setShouldBeVisible) could be grouped into a single interface for better organization and reusability.

+interface IVisibilityControl {
+  isOpen?: IUseAnimations['isOpen'];
+  isMounted?: IUseAnimations['isMounted'];
+  setShouldBeVisible?: IUseAnimations['setShouldBeVisible'];
+}

-export interface ISideNavigationGroupProps extends ComponentCoreProps {
+export interface ISideNavigationGroupProps extends ComponentCoreProps, IVisibilityControl {
   // ... other props
-  isOpen?: IUseAnimations['isOpen'];
-  isMounted?: IUseAnimations['isMounted'];
-  setShouldBeVisible?: IUseAnimations['setShouldBeVisible'];
packages/react-components/src/index.ts (1)

3-3: Consider grouping hook exports.

For better organization, consider grouping all hook exports together, similar to how component exports are grouped.

-export { useAnimations } from './hooks';
 export * from './foundations';
+export * from './hooks';  // Export all hooks together
 export * from './providers';
packages/react-components/src/components/AppFrame/components/SideNavigationGroup/SideNavigationGroup.tsx (3)

50-56: Consider memoizing derived values.

The local state derivations could benefit from memoization to prevent unnecessary recalculations.

+const localValues = React.useMemo(() => ({
+  isOpen: externalIsOpen ?? isOpen,
+  isMounted: externalIsMounted ?? isMounted,
+  rightNode: typeof rightNode === 'function' ? rightNode(localIsOpen) : rightNode,
+  label: typeof label === 'function' ? label(localIsOpen) : label
+}), [externalIsOpen, isOpen, externalIsMounted, isMounted, rightNode, label, localIsOpen]);

71-73: Add safety check for non-element children.

The current implementation assumes all children are React elements. Add a filter to handle potential non-element children.

-const listElements = React.Children.toArray(children) as React.ReactElement[];
+const listElements = React.Children.toArray(children)
+  .filter(React.isValidElement) as React.ReactElement[];

94-145: Consider extracting render methods.

The conditional rendering logic could be simplified by extracting the label rendering into separate methods.

+const renderCollapsibleLabel = () => (
+  <SideNavigationItem
+    leftNode={/* ... */}
+    label={/* ... */}
+    /* ... other props ... */
+  />
+);

+const renderSimpleLabel = () => (
+  <span className={/* ... */}>
+    {/* ... label content ... */}
+  </span>
+);

-{isCollapsible || isLinkLabel ? (
-  <SideNavigationItem /* ... */ />
-) : (
-  <span /* ... */ />
-)}
+{(isCollapsible || isLinkLabel) ? renderCollapsibleLabel() : renderSimpleLabel()}
packages/react-components/src/components/AppFrame/AppFrame.mdx (1)

129-129: Add missing commas for better readability.

The sentence structure needs improvement.

Apply this diff:

-Additionally, SideNavigationGroup exposes isOpen, isMounted and setShouldBeVisible props, allowing external control of the list visibility state. To maintain consistency with the default behavior of the component, when using these props it is recommended to do so with the useAnimations hook. For that purpose a ref can be created and passed as listWrapperRef prop to SideNavigationGroup - the same ref should also be passed to the external useAnimations hook. All of the aforementioned props should be used together to ensure SideNavigationGroup behaves as expected.
+Additionally, SideNavigationGroup exposes isOpen, isMounted, and setShouldBeVisible props, allowing external control of the list visibility state. To maintain consistency with the default behavior of the component, when using these props, it is recommended to do so with the useAnimations hook. For that purpose, a ref can be created and passed as listWrapperRef prop to SideNavigationGroup - the same ref should also be passed to the external useAnimations hook. All the aforementioned props should be used together to ensure SideNavigationGroup behaves as expected.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~129-~129: Possible missing comma found.
Context: ...vior of the component, when using these props it is recommended to do so with the `us...

(AI_HYDRA_LEO_MISSING_COMMA)


[typographical] ~129-~129: Use a comma after an introductory phrase.
Context: ...to do so with the useAnimations hook. For that purpose a ref can be created and passed as `lis...

(COMMA_INTRODUCTORY_WORDS_PHRASES)


[style] ~129-~129: Consider removing “of” to be more concise
Context: ...d to the external useAnimations hook. All of the aforementioned props should be used tog...

(ALL_OF_THE)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 69030e0 and 7ef44f8.

📒 Files selected for processing (8)
  • packages/react-components/src/components/AppFrame/AppFrame.mdx (1 hunks)
  • packages/react-components/src/components/AppFrame/components/SideNavigationGroup/SideNavigationGroup.module.scss (2 hunks)
  • packages/react-components/src/components/AppFrame/components/SideNavigationGroup/SideNavigationGroup.spec.tsx (5 hunks)
  • packages/react-components/src/components/AppFrame/components/SideNavigationGroup/SideNavigationGroup.tsx (3 hunks)
  • packages/react-components/src/components/AppFrame/components/SideNavigationGroup/constants.ts (1 hunks)
  • packages/react-components/src/components/AppFrame/components/SideNavigationGroup/types.ts (2 hunks)
  • packages/react-components/src/hooks/useAnimations.ts (1 hunks)
  • packages/react-components/src/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/react-components/src/components/AppFrame/components/SideNavigationGroup/constants.ts
🧰 Additional context used
🪛 LanguageTool
packages/react-components/src/components/AppFrame/AppFrame.mdx

[uncategorized] ~129-~129: Possible missing comma found.
Context: ...vior of the component, when using these props it is recommended to do so with the `us...

(AI_HYDRA_LEO_MISSING_COMMA)


[typographical] ~129-~129: Use a comma after an introductory phrase.
Context: ...to do so with the useAnimations hook. For that purpose a ref can be created and passed as `lis...

(COMMA_INTRODUCTORY_WORDS_PHRASES)


[style] ~129-~129: Consider removing “of” to be more concise
Context: ...d to the external useAnimations hook. All of the aforementioned props should be used tog...

(ALL_OF_THE)

🔇 Additional comments (5)
packages/react-components/src/components/AppFrame/components/SideNavigationGroup/types.ts (2)

6-8: LGTM! Well-defined interface for onClick handler.


63-74: LGTM! Well-structured className props.

The className props follow a consistent naming pattern and provide granular styling control.

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

11-15: LGTM! Appropriate export of the interface.

The export enables type reuse and maintains a single source of truth for animation-related types.

packages/react-components/src/components/AppFrame/components/SideNavigationGroup/SideNavigationGroup.spec.tsx (1)

29-222: LGTM! Comprehensive test coverage.

The test suite thoroughly covers all new functionality including custom styling, link labels, right node rendering, click handlers, and visibility states.

packages/react-components/src/components/AppFrame/components/SideNavigationGroup/SideNavigationGroup.module.scss (1)

24-44: LGTM! Well-structured styling.

The new classes follow BEM naming convention and implement proper flex layout patterns.

@@ -126,6 +126,8 @@ import { SideNavigationGroup } from '@livechat/design-system-react-components';
...
```

Additionally, `SideNavigationGroup` exposes `isOpen`, `isMounted` and `setShouldBeVisible` props, allowing external control of the list visibility state. To maintain consistency with the default behavior of the component, when using these props it is recommended to do so with the `useAnimations` hook. For that purpose a ref can be created and passed as `listWrapperRef` prop to `SideNavigationGroup` - the same ref should also be passed to the external `useAnimations` hook. All of the aforementioned props should be used together to ensure `SideNavigationGroup` behaves as expected.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we make this a little bit clearer? I found it a bit difficult to grasp at first. Maybe we could add something like: 'It allows parent components to have full control over the navigation group's state if needed' or something similar to help clarify its purpose

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point (turns out Cursor isn't exactly the best at helping with docs 🙄).
Would you say adding code example could be helpful here?

Copy link
Contributor

Choose a reason for hiding this comment

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

That would be great 👍🏼

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 (2)
packages/react-components/src/components/AppFrame/AppFrame.mdx (2)

106-106: Enhance clarity in collapsible behavior description.
Add a comma after "Alternatively," and insert "the" before "shouldOpenOnInit prop" to improve readability.

🧰 Tools
🪛 LanguageTool

[misspelling] ~106-~106: Did you mean “site”?
Context: ...dren is the assumed pattern of building side navigation, however if you need to wrap...

(SIDE_SITE)


[typographical] ~106-~106: Consider adding a comma after ‘Alternatively’ for more clarity.
Context: ...ctiveto the child component yourself. Alternatively you can useshouldOpenOnInit` prop whi...

(RB_LY_COMMA)


[uncategorized] ~106-~106: You might be missing the article “the” here.
Context: ...ent yourself. Alternatively you can use shouldOpenOnInit prop which will automa...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


129-131: Refine punctuation for control props explanation.
Place a comma after the introductory phrase for better clarity (e.g., "To maintain consistency with the default behavior of SideNavigationGroup, when using these props, it is recommended to do so with the useAnimations hook.").

🧰 Tools
🪛 LanguageTool

[uncategorized] ~129-~129: Possible missing comma found.
Context: ...SideNavigationGroup, when using these props it is recommended to do so with the `us...

(AI_HYDRA_LEO_MISSING_COMMA)


[typographical] ~129-~129: Use a comma after an introductory phrase.
Context: ...to do so with the useAnimations hook. For that purpose a ref can be created and passed as `lis...

(COMMA_INTRODUCTORY_WORDS_PHRASES)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7ef44f8 and 1d8bf6e.

📒 Files selected for processing (1)
  • packages/react-components/src/components/AppFrame/AppFrame.mdx (2 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/react-components/src/components/AppFrame/AppFrame.mdx

[misspelling] ~106-~106: Did you mean “site”?
Context: ...dren is the assumed pattern of building side navigation, however if you need to wrap...

(SIDE_SITE)


[typographical] ~106-~106: Consider adding a comma after ‘Alternatively’ for more clarity.
Context: ...ctiveto the child component yourself. Alternatively you can useshouldOpenOnInit` prop whi...

(RB_LY_COMMA)


[uncategorized] ~106-~106: You might be missing the article “the” here.
Context: ...ent yourself. Alternatively you can use shouldOpenOnInit prop which will automa...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~129-~129: Possible missing comma found.
Context: ...SideNavigationGroup, when using these props it is recommended to do so with the `us...

(AI_HYDRA_LEO_MISSING_COMMA)


[typographical] ~129-~129: Use a comma after an introductory phrase.
Context: ...to do so with the useAnimations hook. For that purpose a ref can be created and passed as `lis...

(COMMA_INTRODUCTORY_WORDS_PHRASES)

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

Successfully merging this pull request may close these issues.

[SideNavigationGroup] - Extend component to allow for better customization
2 participants