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

14063 add map breadcrumbs component to fe library #97

Draft
wants to merge 4 commits into
base: v5
Choose a base branch
from

Conversation

Natallia-Harshunova
Copy link
Contributor

@Natallia-Harshunova Natallia-Harshunova commented Aug 12, 2024

https://kontur.fibery.io/Tasks/Task/Add-map-breadcrumbs-component-to-FE-library-14063

Summary by CodeRabbit

  • New Features

    • Introduced a new Breadcrumbs component for improved navigation within applications.
    • Added the BreadcrumbItem for reusable breadcrumb elements.
    • Implemented the Ellipsis component for managing overflow in breadcrumb navigation.
  • Styling Enhancements

    • New CSS styles for breadcrumb components to enhance visual clarity and interactivity.
    • Added responsive design features to accommodate varying screen sizes.
  • Bug Fixes

    • Improved rendering behavior and accessibility for breadcrumb navigation.

Copy link

coderabbitai bot commented Aug 12, 2024

Walkthrough

The recent changes introduce a new Breadcrumbs component to enhance navigation within the UI Kit. This includes restructuring imports and exports, adding new styling, and implementing state management for breadcrumb items. The updates improve code clarity and maintainability while offering users a more interactive and visually appealing way to navigate through applications.

Changes

Files Change Summary
cosmos/cosmos.userdeps.js Restructured imports; added Breadcrumbs fixture; updated export structure for clarity.
packages/ui-kit/src/Breadcrumbs/BreadcrumbItem.module.css, packages/ui-kit/src/Breadcrumbs/style.module.css Introduced CSS styles for breadcrumb items; improved visual structure and interactive behavior.
packages/ui-kit/src/Breadcrumbs/BreadcrumbItem.tsx, packages/ui-kit/src/Breadcrumbs/index.tsx Created BreadcrumbItem and Breadcrumbs components with state management and responsive design.
packages/ui-kit/src/Breadcrumbs/Breadcrumbs.fixture.tsx Added BreadcrumbsContainer component to manage state and render a navigation interface.
packages/ui-kit/src/Breadcrumbs/components/Ellipsis/Ellipsis.tsx, packages/ui-kit/src/Breadcrumbs/hooks/useModelHook.tsx Introduced Ellipsis for hidden items in breadcrumbs and useModel hook for dynamic item display.
packages/ui-kit/src/Breadcrumbs/components/commonStyles.module.css, packages/ui-kit/src/Breadcrumbs/components/index.ts Added a centralized export hub and common styling for breadcrumbs, enhancing modularity.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Breadcrumbs
    participant BreadcrumbItem
    participant Ellipsis

    User->>Breadcrumbs: Click on breadcrumb item
    Breadcrumbs->>BreadcrumbItem: Trigger onClick
    BreadcrumbItem-->>Breadcrumbs: Update active state
    Breadcrumbs-->>User: Reflect active breadcrumb visually
    Note over Breadcrumbs: If items exceed width, show Ellipsis
    Breadcrumbs->>Ellipsis: Render hidden items
    User->>Ellipsis: Click on hidden item
    Ellipsis-->>Breadcrumbs: Update visible items
Loading

Poem

🐰 In the warren of code, changes abound,
New breadcrumbs sprout from the ground.
With style and grace, they lead the way,
Guiding us gently, come what may.
A hop, a skip, through UI delight,
Navigating paths, both clear and bright! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Copy link

github-actions bot commented Aug 12, 2024

🎊 PR Preview c5d96fd has been successfully built and deployed to https://konturio-ui-preview-pr-97.surge.sh

🕐 Build time: 47.952s

🤖 By surge-preview

Copy link

@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: 6

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 5c7c909 and 44f5517.

Files selected for processing (6)
  • cosmos/cosmos.userdeps.js (2 hunks)
  • packages/ui-kit/src/Breadcrumbs/BreadcrumbItem.module.css (1 hunks)
  • packages/ui-kit/src/Breadcrumbs/BreadcrumbItem.tsx (1 hunks)
  • packages/ui-kit/src/Breadcrumbs/Breadcrumbs.fixture.tsx (1 hunks)
  • packages/ui-kit/src/Breadcrumbs/index.tsx (1 hunks)
  • packages/ui-kit/src/Breadcrumbs/style.module.css (1 hunks)
Additional context used
Biome
packages/ui-kit/src/Breadcrumbs/BreadcrumbItem.tsx

[error] 28-28: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

packages/ui-kit/src/Breadcrumbs/index.tsx

[error] 101-101: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 42-42: Use Number.parseFloat instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseFloat instead.

(lint/style/useNumberNamespace)


[error] 43-43: Use Number.parseFloat instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseFloat instead.

(lint/style/useNumberNamespace)

Additional comments not posted (9)
packages/ui-kit/src/Breadcrumbs/style.module.css (1)

1-18: CSS Styles Look Good!

The styles for the breadcrumbs container and breadcrumbs are well-defined and use CSS variables for consistency.

packages/ui-kit/src/Breadcrumbs/BreadcrumbItem.module.css (1)

1-34: CSS Styles Look Good!

The styles for breadcrumb items, buttons, labels, and separators are well-structured and make good use of CSS variables.

packages/ui-kit/src/Breadcrumbs/BreadcrumbItem.tsx (1)

1-41: Component Structure Looks Good!

The BreadcrumbItem component is well-structured and uses React.memo for performance optimization. The use of props and CSS modules is appropriate.

Tools
Biome

[error] 28-28: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

packages/ui-kit/src/Breadcrumbs/Breadcrumbs.fixture.tsx (2)

32-39: LGTM! Fixture setup is clear and functional.

The fixture correctly sets up the Breadcrumbs component with state management and styling for demonstration purposes.


1-2: Ensure correct import paths.

The import paths for useState and Breadcrumbs appear correct, assuming the Breadcrumbs component is located in the same directory. Verify the paths if there are issues during integration.

Verification successful

Import paths are correct.

The import path for the Breadcrumbs component is correct, as the index.tsx file is present in the expected directory. No issues with the import statement in Breadcrumbs.fixture.tsx.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the Breadcrumbs component.

# Test: Check if the Breadcrumbs component exists in the expected directory.
fd 'index.tsx' packages/ui-kit/src/Breadcrumbs

Length of output: 88

packages/ui-kit/src/Breadcrumbs/index.tsx (2)

107-123: Ensure accessibility with ARIA labels.

The component uses aria-label for navigation, which is good for accessibility. Ensure all interactive elements are keyboard navigable and screen reader friendly.


1-1: Review unused imports.

The useState and useCallback hooks are used, but ensure all other hooks are necessary for the component's functionality.

Verification successful

All imported hooks are used in the component.

The useState, useRef, useEffect, and useCallback hooks are all utilized in the Breadcrumbs component, confirming there are no unused imports.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of imported hooks in the Breadcrumbs component.

# Test: Search for the usage of useRef, useEffect, and useCallback in the file.
rg 'useRef|useEffect|useCallback' packages/ui-kit/src/Breadcrumbs/index.tsx

Length of output: 270

cosmos/cosmos.userdeps.js (2)

70-70: Ensure correct export mapping for Breadcrumbs.

The export mapping for the Breadcrumbs fixture seems correct. Verify that the fixture is correctly loaded and used in the application.


18-18: Verify the new fixture import path.

Ensure that the path for the new Breadcrumbs fixture is correct and that the file exists.

Verification successful

Import path verified successfully.

The import path for the Breadcrumbs fixture is correct, and the file exists at the specified location. No issues found with the import statement.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the Breadcrumbs fixture file.

# Test: Check if the Breadcrumbs fixture file exists in the expected directory.
fd 'Breadcrumbs.fixture.tsx' packages/ui-kit/src/Breadcrumbs

Length of output: 116

}: BreadcrumbItemProps) => {
return (
<li className={cn(styles.breadcrumbItem)}>
<button className={cn(styles.button, { [styles.active]: active })} onClick={() => onClick(value)}>
Copy link

Choose a reason for hiding this comment

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

Specify Button Type to Prevent Unintended Behavior

Add an explicit type="button" to the button element to prevent unintended form submissions if this component is used within a form.

-        <button className={cn(styles.button, { [styles.active]: active })} onClick={() => onClick(value)}>
+        <button type="button" className={cn(styles.button, { [styles.active]: active })} onClick={() => onClick(value)}>
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<button className={cn(styles.button, { [styles.active]: active })} onClick={() => onClick(value)}>
<button type="button" className={cn(styles.button, { [styles.active]: active })} onClick={() => onClick(value)}>
Tools
Biome

[error] 28-28: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

Comment on lines 25 to 30
const BreadcrumbsContainer = () => {
const [activeCrumb, setActiveCrumb] = useState<string | null>(null);

const handleClick = (value: string) => {
setActiveCrumb(value);
};
Copy link

Choose a reason for hiding this comment

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

Consider initializing activeCrumb with a default value.

Initializing activeCrumb with a default value could improve the initial state handling, especially if a default breadcrumb is intended to be active.

-  const [activeCrumb, setActiveCrumb] = useState<string | null>(null);
+  const [activeCrumb, setActiveCrumb] = useState<string | null>('product1_0');
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const BreadcrumbsContainer = () => {
const [activeCrumb, setActiveCrumb] = useState<string | null>(null);
const handleClick = (value: string) => {
setActiveCrumb(value);
};
const BreadcrumbsContainer = () => {
const [activeCrumb, setActiveCrumb] = useState<string | null>('product1_0');
const handleClick = (value: string) => {
setActiveCrumb(value);
};

Comment on lines 22 to 23
const ellipsis = '...';
const ellipsisWidth = 35; // Approximate width of the `... >` element
Copy link

Choose a reason for hiding this comment

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

Consider dynamic ellipsis width calculation.

The ellipsisWidth is hardcoded. Consider dynamically calculating it based on the actual rendered width for better accuracy.

- const ellipsisWidth = 35; // Approximate width of the `... >` element
+ const ellipsisWidth = measureEllipsisWidth(); // Function to measure actual width

Committable suggestion was skipped due to low confidence.

Comment on lines 98 to 105
const handleItemClick = useCallback(
(value: string) => {
if (value !== ellipsis) {
onClick && onClick(value);
}
},
[onClick],
);
Copy link

Choose a reason for hiding this comment

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

Use optional chaining for safety.

Refactor to use optional chaining for the onClick callback to prevent potential runtime errors.

- onClick && onClick(value);
+ onClick?.(value);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleItemClick = useCallback(
(value: string) => {
if (value !== ellipsis) {
onClick && onClick(value);
}
},
[onClick],
);
const handleItemClick = useCallback(
(value: string) => {
if (value !== ellipsis) {
onClick?.(value);
}
},
[onClick],
);
Tools
Biome

[error] 101-101: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/ui-kit/src/Breadcrumbs/index.tsx Outdated Show resolved Hide resolved
Comment on lines 31 to 35
useEffect(() => {
if (!olRef.current) return;
const widths = Array.from(olRef.current.children).map((child) => (child as HTMLElement).offsetWidth);
setItemWidths(widths);
}, [items]);
Copy link

Choose a reason for hiding this comment

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

Optimize width calculation with useLayoutEffect.

Consider using useLayoutEffect instead of useEffect for DOM measurement to avoid layout thrashing.

- useEffect(() => {
+ useLayoutEffect(() => {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
if (!olRef.current) return;
const widths = Array.from(olRef.current.children).map((child) => (child as HTMLElement).offsetWidth);
setItemWidths(widths);
}, [items]);
useLayoutEffect(() => {
if (!olRef.current) return;
const widths = Array.from(olRef.current.children).map((child) => (child as HTMLElement).offsetWidth);
setItemWidths(widths);
}, [items]);

border-radius: var(--border-radius);
color: var(--text-faint-strong-up);

&:focus {
Copy link
Contributor

@dqunbp dqunbp Aug 19, 2024

Choose a reason for hiding this comment

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

It's important to show focus outlines from keyboard focus event only, as described in the task.
Here is an example of how to achieve such behavior: https://css-tricks.com/keyboard-only-focus-styles/

Copy link

@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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 44f5517 and c5d96fd.

Files selected for processing (9)
  • packages/ui-kit/src/Breadcrumbs/Breadcrumbs.fixture.tsx (1 hunks)
  • packages/ui-kit/src/Breadcrumbs/components/BreadcrumbItem/BreadcrumbItem.module.css (1 hunks)
  • packages/ui-kit/src/Breadcrumbs/components/BreadcrumbItem/BreadcrumbItem.tsx (1 hunks)
  • packages/ui-kit/src/Breadcrumbs/components/Ellipsis/Ellipsis.tsx (1 hunks)
  • packages/ui-kit/src/Breadcrumbs/components/commonStyles.module.css (1 hunks)
  • packages/ui-kit/src/Breadcrumbs/components/index.ts (1 hunks)
  • packages/ui-kit/src/Breadcrumbs/hooks/useModelHook.tsx (1 hunks)
  • packages/ui-kit/src/Breadcrumbs/index.tsx (1 hunks)
  • packages/ui-kit/src/Breadcrumbs/style.module.css (1 hunks)
Additional context used
Biome
packages/ui-kit/src/Breadcrumbs/components/BreadcrumbItem/BreadcrumbItem.tsx

[error] 24-24: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

packages/ui-kit/src/Breadcrumbs/hooks/useModelHook.tsx

[error] 27-27: Use Number.parseFloat instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseFloat instead.

(lint/style/useNumberNamespace)


[error] 28-28: Use Number.parseFloat instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseFloat instead.

(lint/style/useNumberNamespace)

Additional comments not posted (13)
packages/ui-kit/src/Breadcrumbs/components/index.ts (1)

1-2: Exports are correctly set up.

The export statements are straightforward and correctly set up for the BreadcrumbItem and Ellipsis components.

packages/ui-kit/src/Breadcrumbs/components/commonStyles.module.css (1)

1-5: Styles for .separator look good.

The styles are appropriately set for the .separator class, ensuring proper margin and color.

packages/ui-kit/src/Breadcrumbs/style.module.css (1)

1-10: Styles for .breadcrumbs are well-defined.

The styles ensure a consistent and visually appealing layout for the breadcrumbs component, including background color, shadow, and padding.

packages/ui-kit/src/Breadcrumbs/components/BreadcrumbItem/BreadcrumbItem.module.css (3)

1-6: Styles for .breadcrumbItem are appropriate.

The styles define a flexible layout for breadcrumb items, ensuring proper alignment and size.


8-24: Button styles are comprehensive and accessible.

The styles for the .button class include focus-visible and hover states, enhancing accessibility and user interaction.


26-28: Styles for .breadcrumbLabel are concise.

The text-wrap: nowrap; ensures that the label text does not wrap, maintaining a clean appearance.

packages/ui-kit/src/Breadcrumbs/components/BreadcrumbItem/BreadcrumbItem.tsx (3)

1-6: Imports are well-organized.

The imports include necessary modules and styles, ensuring the component is properly set up.


8-18: Interface definitions are clear.

The BreadcrumbBase and BreadcrumbItemProps interfaces are well-defined, providing clarity on the expected props.


35-35: Display name is correctly set.

Setting the displayName for the BreadcrumbItem component aids in debugging and improves readability.

packages/ui-kit/src/Breadcrumbs/Breadcrumbs.fixture.tsx (1)

1-43: LGTM!

The code is well-structured and demonstrates a clear example of using the Breadcrumbs component.

packages/ui-kit/src/Breadcrumbs/components/Ellipsis/Ellipsis.tsx (1)

1-48: LGTM!

The Ellipsis component is well-implemented and efficiently handles hidden breadcrumb items.

packages/ui-kit/src/Breadcrumbs/index.tsx (1)

1-71: LGTM!

The Breadcrumbs component is well-structured, with clear handling of overflow and item rendering.

packages/ui-kit/src/Breadcrumbs/hooks/useModelHook.tsx (1)

1-82: LGTM!

The useModel hook is well-implemented and efficiently manages breadcrumb overflow logic. The use of parseFloat aligns with the codebase's preferences.

Tools
Biome

[error] 27-27: Use Number.parseFloat instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseFloat instead.

(lint/style/useNumberNamespace)


[error] 28-28: Use Number.parseFloat instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseFloat instead.

(lint/style/useNumberNamespace)

Comment on lines +20 to +33
export const BreadcrumbItem = React.memo(
({ label, value, active = false, onClick, separator, isLastItem = false }: BreadcrumbItemProps) => {
return (
<li className={cn(styles.breadcrumbItem)}>
<button className={cn(styles.button, { [styles.active]: active })} onClick={() => onClick(value)}>
<Text type="caption" className={styles.breadcrumbLabel}>
{label}
</Text>
</button>
{!isLastItem && <div className={commonStyles.separator}>{separator}</div>}
</li>
);
},
);
Copy link

Choose a reason for hiding this comment

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

Add explicit button type to prevent form submission.

The button should have an explicit type to avoid unintended form submissions within forms.

<button className={cn(styles.button, { [styles.active]: active })} onClick={() => onClick(value)}>
+  type="button"
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const BreadcrumbItem = React.memo(
({ label, value, active = false, onClick, separator, isLastItem = false }: BreadcrumbItemProps) => {
return (
<li className={cn(styles.breadcrumbItem)}>
<button className={cn(styles.button, { [styles.active]: active })} onClick={() => onClick(value)}>
<Text type="caption" className={styles.breadcrumbLabel}>
{label}
</Text>
</button>
{!isLastItem && <div className={commonStyles.separator}>{separator}</div>}
</li>
);
},
);
export const BreadcrumbItem = React.memo(
({ label, value, active = false, onClick, separator, isLastItem = false }: BreadcrumbItemProps) => {
return (
<li className={cn(styles.breadcrumbItem)}>
<button type="button" className={cn(styles.button, { [styles.active]: active })} onClick={() => onClick(value)}>
<Text type="caption" className={styles.breadcrumbLabel}>
{label}
</Text>
</button>
{!isLastItem && <div className={commonStyles.separator}>{separator}</div>}
</li>
);
},
);
Tools
Biome

[error] 24-24: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

};

const BreadcrumbsContainer = () => {
const [activeCrumb, setActiveCrumb] = useState<string | null>(null);
Copy link

Choose a reason for hiding this comment

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

Consider initializing activeCrumb with a default value.

Initializing activeCrumb with a default value could improve the initial state handling, especially if a default breadcrumb is intended to be active.

-  const [activeCrumb, setActiveCrumb] = useState<string | null>(null);
+  const [activeCrumb, setActiveCrumb] = useState<string | null>('product1_0');
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const [activeCrumb, setActiveCrumb] = useState<string | null>(null);
const [activeCrumb, setActiveCrumb] = useState<string | null>('product1_0');


// TODO: get rid of this hardcode and add ability to dynamically count width
export const ellipsis = '...';
export const ellipsisWidth = 35; // Approximate width of the `... >` element
Copy link

Choose a reason for hiding this comment

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

Consider dynamic ellipsis width calculation.

The ellipsisWidth is hardcoded. Consider dynamically calculating it based on the actual rendered width for better accuracy.

- export const ellipsisWidth = 35; // Approximate width of the `... >` element
+ export const ellipsisWidth = measureEllipsisWidth(); // Function to measure actual width

Committable suggestion was skipped due to low confidence.

interface BreadcrumbItemProps extends BreadcrumbBase {
active?: boolean;
onClick: (value: string) => void;
separator?: ReactNode;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need default separator?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need "Hook" postfix in the filename?

ellipsisWidth: number;
}

export const useModel = <T,>({ items, ellipsisWidth }: UseModelProps<T>) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

useModel is a very generic name. I had to spend some time to realize this hook is specific to Breadcrumbs component. Would be nice to rename it to something more specific to make it more obvious


if (totalWidth <= containerWidth) {
// No overflow, display all items
setLeftHiddenItemIndex(-1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be easier and more obvious to check for null, instead of [-1; items.length]?
Plus, this interval kinda breaks the logic of "all items between two indexes need to be hidden"

import styles from './BreadcrumbItem.module.css';
import type { ReactNode } from 'react';

export interface BreadcrumbBase {
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: BreadcrumbBase doesn't sound like a label-value interface name. Maybe something like BreadcrumbItemValue?

@albaranau
Copy link
Contributor

I've tried to dynamically (on item click) change items prop, and it seems to break hidden items calculation:
image

@albaranau albaranau marked this pull request as draft September 12, 2024 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants