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

272 slider component #357

Open
wants to merge 17 commits into
base: beta
Choose a base branch
from
Open

272 slider component #357

wants to merge 17 commits into from

Conversation

lehju
Copy link
Contributor

@lehju lehju commented Dec 11, 2024

Description

Add slider component

Reference

Issues #272

Summary by CodeRabbit

  • New Features

    • Introduced a new slider component (MucSlider) utilizing the Splide library for enhanced carousel functionality.
    • Added a slider item component (MucSliderItem) for customizable slide content.
    • Implemented Storybook configuration for visual representation of the MucSlider component.
  • Chores

    • Updated project dependencies to include @splidejs/vue-splide version 0.6.12.

@lehju lehju self-assigned this Dec 11, 2024
@lehju lehju linked an issue Dec 11, 2024 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Ze project has undergone a significant enhancement by introducing a new slider component system. Ze changes include adding ze Splide library dependency, creating a MucSlider and MucSliderItem components, and updating ze component index files to expose zese new slider-related components. Ze implementation provides a flexible and reusable slider mechanism for ze application.

Changes

File Change Summary
package.json Added dependency @splidejs/[email protected]
src/components/Slider/... • Added MucSlider.vue - Main slider component
• Added MucSliderItem.vue - Individual slide component
• Added MucSlider.stories.ts - Storybook configuration
• Added index.ts - Component exports
src/components/index.ts Imported and exported new slider components

Sequence Diagram

sequenceDiagram
    participant User
    participant MucSlider
    participant MucSliderItem
    participant Splide Library

    User->>MucSlider: Interact with Slider
    MucSlider->>Splide Library: Initialize Slider
    Splide Library-->>MucSlider: Slider Ready
    User->>MucSlider: Navigate Slides
    MucSlider->>Splide Library: Change Slide
    Splide Library-->>MucSliderItem: Update Active Slide
Loading

Poem

Ach, ze slider rolls along,
Splide's magic makes it strong!
Components dance with glee,
A Vue carousel to see!
Mein engineering art complete,
Zis slider looks so neat! 🎠


🪧 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.

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.

@lehju lehju requested a review from FabianWilms December 17, 2024 14:58
@lehju lehju marked this pull request as ready for review December 17, 2024 14:58
@FabianWilms
Copy link
Member

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

🧹 Nitpick comments (4)
src/components/Slider/MucSliderItem.vue (1)

11-14: Ze slot documentation könnte be more descriptiv!

Ze current documentation ist very basic. Consider adding more details about:

  • Expected content types
  • Any size restrictions
  • Example usage
 /**
- * Elements can be put into this slot.
+ * Slot for slide content such as MucCard, images, or any other components.
+ * Content should maintain consistent dimensions for optimal display.
+ * @example
+ * <MucSliderItem>
+ *   <MucCard title="Example" />
+ * </MucSliderItem>
  */
src/components/Slider/MucSlider.stories.ts (1)

22-39: Ze template could use some improvements!

  1. Consider using :key with unique identifier instead of index:
-<MucSliderItem v-for="index in 5" :key="index">
+<MucSliderItem v-for="index in 5" :key="`slide-${index}`">
  1. Ze example ist very basic. Consider adding:
  • Different card variations
  • Different content types
  • Example with navigation options

Also, it vould be gut to add more stories showing different use cases:

export const WithImages = () => ({
  components: { MucSlider, MucSliderItem },
  template: `
    <MucSlider>
      <MucSliderItem v-for="index in 3" :key="'image-'+index">
        <img :src="'https://picsum.photos/400/300?random='+index" alt="Sample image" />
      </MucSliderItem>
    </MucSlider>
  `
});
src/components/Slider/MucSlider.vue (2)

9-13: Gut implementation of ze slider section!

Ze accessibility attributes sind very gut! However, ve could improve ze loading state handling.

Consider adding a loading state like zis:

 <section
   class="m-slider m-slider--visible-preview"
   aria-label="Slider mit Elementen"
+  :aria-busy="isLoading"
   data-m-slider-splide="m-slider-comment"
 >
+  <div v-if="isLoading" class="m-slider__loading">
+    Loading...
+  </div>

62-68: Ze event name could be more specific!

Ze 'changeSlide' event name ist a bit generic. In ze component library, ve should use more specific names.

Consider renaming like zis:

-  changeSlide: [index: number];
+  sliderIndexChange: [index: number];
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d044c17 and db65b8b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • package.json (1 hunks)
  • src/components/Slider/MucSlider.stories.ts (1 hunks)
  • src/components/Slider/MucSlider.vue (1 hunks)
  • src/components/Slider/MucSliderItem.vue (1 hunks)
  • src/components/Slider/index.ts (1 hunks)
  • src/components/index.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/components/Slider/index.ts
🔇 Additional comments (3)
src/components/Slider/MucSliderItem.vue (1)

1-5: Ze template structure looks gut!

Ze component correctly wraps ze SplideSlide component und provides a slot for content injection.

src/components/index.ts (1)

24-24: Ja, ze exports look ordentlich!

Ze new slider components are properly imported und exported, maintaining ze alphabetical order.

Also applies to: 52-53

package.json (1)

80-81: 🛠️ Refactor suggestion

Achtung! Ze version of @splidejs/vue-splide ist not ze latest!

Ze current version 0.6.12 ist quite old. Ze latest version ist 1.0.1 mit many improvements und bug fixes. Ve should upgrade, ja?

Let me check ze security advisories:

Comment on lines +13 to +16
component: `A wrapping layout to show elements in a carousel and slide them, for example [MucCards](/docs/muccard--docs).

🔗 Patternlab-Docs (https://patternlab.muenchen.space/?p=components-slider-quote)
`,
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Ze documentation link ist not accessible!

I have checked ze URL und it returns 401 Unauthorized error. Zis means ze documentation ist either:

  • Behind authentication
  • Moved to a different location
  • No longer available

Please update ze documentation link to ze correct und publicly accessible URL or remove it if ze documentation ist no longer available.

🔗 Analysis chain

Ze documentation link needs verification!

Please ensure zat ze Patternlab-Docs link ist still valid und accessible.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the documentation URL is accessible
curl -s -I "https://patternlab.muenchen.space/?p=components-slider-quote" | head -n 1

Length of output: 113

Comment on lines +124 to +151
const sliderOptions: Options = {
autoplay: false,
keyboard: true,
slideFocus: true,
lazyLoad: false,
arrows: false,
perMove: 1,
gap: "0",
type: "slide",
perPage: 1,
pagination: false,
speed: 350,
mediaQuery: "min",
breakpoints: {
1: {
perPage: 1,
gap: "1.5rem",
},
768: {
perPage: 1,
gap: "1.5rem",
},
1200: {
perPage: 1,
gap: "2rem",
},
},
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ze slider needs better mobile optimization!

Ze breakpoints configuration ist redundant since all have ze same perPage value. Also, ve are missing important touch options for mobile users!

Here ist how ve can improve it:

 const sliderOptions: Options = {
   autoplay: false,
   keyboard: true,
   slideFocus: true,
   lazyLoad: false,
   arrows: false,
   perMove: 1,
   gap: "0",
   type: "slide",
   perPage: 1,
   pagination: false,
   speed: 350,
+  drag: true,
+  swipe: true,
+  swipeThreshold: 50,
   mediaQuery: "min",
   breakpoints: {
-    1: {
-      perPage: 1,
-      gap: "1.5rem",
-    },
-    768: {
-      perPage: 1,
-      gap: "1.5rem",
-    },
-      perPage: 1,
       gap: "2rem",
     },
   },
 };
📝 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 sliderOptions: Options = {
autoplay: false,
keyboard: true,
slideFocus: true,
lazyLoad: false,
arrows: false,
perMove: 1,
gap: "0",
type: "slide",
perPage: 1,
pagination: false,
speed: 350,
mediaQuery: "min",
breakpoints: {
1: {
perPage: 1,
gap: "1.5rem",
},
768: {
perPage: 1,
gap: "1.5rem",
},
1200: {
perPage: 1,
gap: "2rem",
},
},
};
const sliderOptions: Options = {
autoplay: false,
keyboard: true,
slideFocus: true,
lazyLoad: false,
arrows: false,
perMove: 1,
gap: "0",
type: "slide",
perPage: 1,
pagination: false,
speed: 350,
drag: true,
swipe: true,
swipeThreshold: 50,
mediaQuery: "min",
breakpoints: {
1200: {
gap: "2rem",
},
},
};

Comment on lines 112 to 122
onMounted(() => {
if (splide.value && splide.value.splide) {
splideLength.value = splide.value.length;
splide.value.splide.on("move", () => {
if (splide.value) {
currentSlide.value = splide.value.splide.index;
emit("changeSlide", splide.value.splide.index);
}
});
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ve need better error handling in ze mounted hook!

Ze initialization could fail und cause runtime errors. Ve should add proper error handling, ja?

Here ist ze fix:

 onMounted(() => {
+  try {
     if (splide.value && splide.value.splide) {
       splideLength.value = splide.value.length;
       splide.value.splide.on("move", () => {
         if (splide.value) {
           currentSlide.value = splide.value.splide.index;
           emit("sliderIndexChange", splide.value.splide.index);
         }
       });
     }
+  } catch (error) {
+    console.error("Failed to initialize slider:", error);
+    // Consider emitting an error event here
+  }
 });
📝 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
onMounted(() => {
if (splide.value && splide.value.splide) {
splideLength.value = splide.value.length;
splide.value.splide.on("move", () => {
if (splide.value) {
currentSlide.value = splide.value.splide.index;
emit("changeSlide", splide.value.splide.index);
}
});
}
});
onMounted(() => {
try {
if (splide.value && splide.value.splide) {
splideLength.value = splide.value.length;
splide.value.splide.on("move", () => {
if (splide.value) {
currentSlide.value = splide.value.splide.index;
emit("sliderIndexChange", splide.value.splide.index);
}
});
}
} catch (error) {
console.error("Failed to initialize slider:", error);
// Consider emitting an error event here
}
});

@FabianWilms
Copy link
Member

@lehju I needed to use the fork-Version of vue-splide as the project isn't being actively maintained anymore (read more here Splidejs/vue-splide#92 (comment)).

The alternative was to use the node tool "patch-package" but that was definitely not a cleaner solution.

@langehm
Copy link
Contributor

langehm commented Dec 20, 2024

@lehju I needed to use the fork-Version of vue-splide as the project isn't being actively maintained anymore (read more here Splidejs/vue-splide#92 (comment)).

The alternative was to use the node tool "patch-package" but that was definitely not a cleaner solution.

Should we even use a project like this if it is not actively maintained? What happens if we need to update some peer-dependencies ... are there other libraries we can consider?

@FabianWilms
Copy link
Member

FabianWilms commented Dec 20, 2024

are there other libraries we can consider?

There probably are, but we are forced to use it as this is what the MDE uses and we shouldn't be reinventing the wheel here.

In the long term, when MDE publishes the components as webcomponents we won't need to include the library in our lib anymore. For now it will be the best solution we have.

@langehm
Copy link
Contributor

langehm commented Dec 20, 2024

understandable

@langehm langehm self-requested a review December 20, 2024 11:03
Comment on lines +118 to +145
const sliderOptions: Options = {
autoplay: false,
keyboard: true,
slideFocus: true,
lazyLoad: false,
arrows: false,
perMove: 1,
gap: "0",
type: "slide",
perPage: 1,
pagination: false,
speed: 350,
mediaQuery: "min",
breakpoints: {
1: {
perPage: 1,
gap: "1.5rem",
},
768: {
perPage: 1,
gap: "1.5rem",
},
1200: {
perPage: 1,
gap: "2rem",
},
},
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I would outsource this information into another file to keep the component clean

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.

✨ "Slider"-Component
3 participants