Skip to content

Conversation

@discreted66
Copy link
Collaborator

@discreted66 discreted66 commented Apr 10, 2025

PR

日历视图支持点击事件,优化inut边框显示

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Introduced an interactive date-click event that displays detailed feedback when a date is selected in the calendar.
  • Tests

    • Expanded test coverage to ensure reliable date selection and accurate display of associated events.
  • Style

    • Enhanced visual cues with pointer indicators and new highlight styles for current and interactive dates.
  • Documentation

    • Updated calendar event descriptions for clearer user guidance on the new functionality.

@coderabbitai
Copy link

coderabbitai bot commented Apr 10, 2025

Walkthrough

This pull request introduces a new event named date-click into the calendar component. The change spans multiple demo files, Vue components, test cases, and documentation to integrate and handle the new event. It adds corresponding event handler methods (e.g., dateClick), updates the renderless API by adding functions such as computedSelectDay and dealEvents, and refines styling and interactivity features such as pointer cursors and visual indicators. The modifications ensure that clicking a date triggers the appropriate feedback and event emissions.

Changes

File(s) Change Summary
examples/sites/demos/…/apis/calendar-view.js, …/mobile-first/app/calendar-view/calendar-event.vue, …/pc/app/calendar-view/calendar-event-composition-api.vue, …/pc/app/calendar-view/calendar-event.vue, …/pc/app/calendar-view/calendar-event.spec.ts, …/pc/app/calendar-view/webdoc/calendar-view.js Added new date-click event with bilingual descriptions; integrated corresponding event handler methods in demo components; updated tests and documentation to reflect the new event.
packages/renderless/src/calendar-view/index.ts, packages/renderless/src/calendar-view/vue.ts Introduced new functions computedSelectDay and dealEvents; updated selectDay function signature to include an api parameter to support enhanced event handling for date-click.
packages/theme-saas/src/calendar-view/index.less, packages/theme/src/base/reset.less, packages/theme/src/calendar-view/index.less, packages/theme/src/month-table/index.less Modified styling: added pointer cursors for interactive elements, updated color schemes (e.g., .is-today and .current classes), adjusted scroll bar background, and ensured full-width for month tables.
packages/vue/src/calendar-view/src/mobile-first.vue, packages/vue/src/calendar-view/src/pc.vue, packages/vue/src/date-panel/src/pc.vue, packages/vue/src/date-range/src/pc.vue, packages/vue/src/year-range/src/pc.vue Updated calendar components to include click event handlers invoking selectDay and dateClick; improved conditional class bindings for current date highlighting and sidebar presence based on shortcuts availability.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant C as Calendar Component
    participant R as Renderless API
    participant M as TinyModal

    U->>C: Click on a date
    C->>R: Invoke selectDay(date) with API
    R->>R: Process day selection and filter events via dealEvents
    R-->>C: Return processed date and event data
    C->>M: Call TinyModal with date & event info
    M-->>C: Display modal with formatted details
Loading

Possibly related PRs

Poem

I'm a rabbit in the code, so spry and quick,
Hopping through dates with just a click.
"date-click" sings a brand new tune,
With events and modals under the moon.
In my calendar hop, everything's in bloom! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

examples/sites/demos/pc/app/calendar-view/calendar-event.spec.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

examples/sites/demos/mobile-first/app/calendar-view/calendar-event.vue

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

examples/sites/demos/pc/app/calendar-view/calendar-event-composition-api.vue

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

  • 11 others

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 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 8d22be2 and 36ecfe3.

📒 Files selected for processing (18)
  • examples/sites/demos/apis/calendar-view.js (1 hunks)
  • examples/sites/demos/mobile-first/app/calendar-view/calendar-event.vue (2 hunks)
  • examples/sites/demos/pc/app/calendar-view/calendar-event-composition-api.vue (2 hunks)
  • examples/sites/demos/pc/app/calendar-view/calendar-event.spec.ts (2 hunks)
  • examples/sites/demos/pc/app/calendar-view/calendar-event.vue (2 hunks)
  • examples/sites/demos/pc/app/calendar-view/webdoc/calendar-view.js (3 hunks)
  • packages/renderless/src/calendar-view/index.ts (3 hunks)
  • packages/renderless/src/calendar-view/vue.ts (3 hunks)
  • packages/theme-saas/src/calendar-view/index.less (3 hunks)
  • packages/theme/src/base/reset.less (1 hunks)
  • packages/theme/src/calendar-view/index.less (3 hunks)
  • packages/theme/src/month-table/index.less (1 hunks)
  • packages/vue/src/calendar-view/__tests__/calendar-view.test.tsx (1 hunks)
  • packages/vue/src/calendar-view/src/mobile-first.vue (3 hunks)
  • packages/vue/src/calendar-view/src/pc.vue (1 hunks)
  • packages/vue/src/date-panel/src/pc.vue (1 hunks)
  • packages/vue/src/date-range/src/pc.vue (1 hunks)
  • packages/vue/src/year-range/src/pc.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (17)
  • packages/theme/src/month-table/index.less
  • packages/theme-saas/src/calendar-view/index.less
  • examples/sites/demos/pc/app/calendar-view/calendar-event-composition-api.vue
  • packages/vue/src/year-range/src/pc.vue
  • packages/vue/src/date-panel/src/pc.vue
  • examples/sites/demos/pc/app/calendar-view/calendar-event.vue
  • examples/sites/demos/mobile-first/app/calendar-view/calendar-event.vue
  • packages/theme/src/calendar-view/index.less
  • packages/vue/src/calendar-view/src/mobile-first.vue
  • packages/vue/src/calendar-view/tests/calendar-view.test.tsx
  • packages/vue/src/date-range/src/pc.vue
  • examples/sites/demos/apis/calendar-view.js
  • examples/sites/demos/pc/app/calendar-view/webdoc/calendar-view.js
  • packages/theme/src/base/reset.less
  • packages/renderless/src/calendar-view/vue.ts
  • packages/vue/src/calendar-view/src/pc.vue
  • examples/sites/demos/pc/app/calendar-view/calendar-event.spec.ts
🔇 Additional comments (4)
packages/renderless/src/calendar-view/index.ts (4)

310-319: Looks good! New computedSelectDay function handles selection state well.

The function correctly determines if a day is selected based on the current state and selection mode. It properly handles undefined values, disabled days, and differentiates between single and multi-select modes.


322-322: Good update to include the API in the function parameters.

Adding the api parameter to the function signature allows access to methods needed for the new date-click functionality.


337-341: Successfully implemented date-click event emission for multi-select mode.

The code correctly retrieves events associated with selected dates and emits them along with the dates in the new date-click event.


359-362: Successfully implemented date-click event emission for single-select mode.

The implementation properly handles the single date case by wrapping it in an array for the dealEvents function and then emitting only the first item of the resulting array.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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.

@github-actions github-actions bot added the enhancement New feature or request (功能增强) label Apr 10, 2025
@petercat-assistant
Copy link

Walkthrough

此PR为日历视图组件添加了日期点击事件的支持,允许用户在点击日期时触发回调函数,并接收当前点击的日期和相关日程事件作为参数。此外,还优化了输入框的边框显示。

Changes

文件 概要
examples/sites/demos/apis/calendar-view.js 添加了日期点击事件的描述和示例配置。
examples/sites/demos/mobile-first/app/calendar-view/calendar-event.vue 添加了日期点击事件的处理方法。
examples/sites/demos/pc/app/calendar-view/calendar-event-composition-api.vue 添加了日期点击事件的处理方法。
examples/sites/demos/pc/app/calendar-view/calendar-event.spec.ts 添加了日期点击事件的测试用例。
examples/sites/demos/pc/app/calendar-view/calendar-event.vue 添加了日期点击事件的处理方法。
examples/sites/demos/pc/app/calendar-view/webdoc/calendar-view.js 更新了文档以包含日期点击事件。
packages/renderless/src/calendar-view/index.ts 添加了日期选择的计算属性和事件处理逻辑。
packages/renderless/src/calendar-view/vue.ts 更新了选择日期的逻辑以支持日期点击事件。
packages/theme-saas/src/calendar-view/index.less 添加了光标样式以支持日期点击。
packages/theme/src/base/reset.less 修改了滚动条样式。
packages/theme/src/calendar-view/index.less 添加了光标样式以支持日期点击。
packages/theme/src/month-table/index.less 调整了月表格的宽度。
packages/vue/src/calendar-view/src/mobile-first.vue 添加了日期点击事件的处理逻辑。
packages/vue/src/calendar-view/src/pc.vue 添加了日期点击事件的处理逻辑。
packages/vue/src/date-panel/src/pc.vue 修复了侧边栏的显示逻辑。
packages/vue/src/date-range/src/pc.vue 修复了侧边栏的显示逻辑。
packages/vue/src/year-range/src/pc.vue 修复了侧边栏的显示逻辑。

}
}

const dealEvents = (props, api, date) => {

Choose a reason for hiding this comment

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

The dealEvents function is defined but not exported, which might limit its reusability in other parts of the codebase. Consider exporting it if it needs to be used elsewhere.

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Walkthrough

This PR adds support for date click events to the calendar view component, allowing users to trigger a callback function when they click on a date and receive the current clicked date and related schedule events as parameters. In addition, the border display of the input box is also optimized.

Changes

Documents Summary
examples/sites/demos/apis/calendar-view.js Added description and sample configuration for date click events.
examples/sites/demos/mobile-first/app/calendar-view/calendar-event.vue Added a handling method for date click events.
examples/sites/demos/pc/app/calendar-view/calendar-event-composition-api.vue Added a handling method for date click events.
examples/sites/demos/pc/app/calendar-view/calendar-event.spec.ts Added a test case for date click events.
examples/sites/demos/pc/app/calendar-view/calendar-event.vue Added a handling method for date click events.
examples/sites/demos/pc/app/calendar-view/webdoc/calendar-view.js Updated document to include date click events.
packages/renderless/src/calendar-view/index.ts Added calculation properties and event handling logic for date selection.
packages/renderless/src/calendar-view/vue.ts Updated the logic for selecting dates to support date click events.
packages/theme-saas/src/calendar-view/index.less Added cursor style to support date clicks.
packages/theme/src/base/reset.less Modified scrollbar style.
packages/theme/src/calendar-view/index.less Added cursor style to support date clicks.
packages/theme/src/month-table/index.less Adjusted the width of the month table.
packages/vue/src/calendar-view/src/mobile-first.vue Added processing logic for date click events.
packages/vue/src/calendar-view/src/pc.vue Added processing logic for date click events.
packages/vue/src/date-panel/src/pc.vue Fixed the display logic of the sidebar.
packages/vue/src/date-range/src/pc.vue Fixed the display logic of the sidebar.
packages/vue/src/year-range/src/pc.vue Fixed the display logic of the sidebar.

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

♻️ Duplicate comments (1)
packages/renderless/src/calendar-view/index.ts (1)

366-376: Consider exporting the dealEvents utility function

The dealEvents function is defined but not exported, which might limit its reusability in other parts of the codebase.

-const dealEvents = (props, api, date) => {
+export const dealEvents = (props, api, date) => {
  return date.map(item => {
    let event = api.getEventByTime(item, props._constants.DAY_START_TIME, props._constants.DAY_END_TIME)
    event.forEach(e => {
      delete e.dayArr;
      delete e.dayNumber;
    });
    return event
  })
}
🧹 Nitpick comments (2)
examples/sites/demos/pc/app/calendar-view/calendar-event.vue (1)

30-32: Well implemented date click handler

The dateClick method properly displays the clicked date and related events in a message modal, providing good visual feedback to users.

Consider whether this implementation needs internationalization support for the message text "点击日期" to accommodate non-Chinese users in the future.

packages/renderless/src/calendar-view/index.ts (1)

369-372: Consider using object destructuring for cleaner property removal

Rather than using delete operations, consider using object destructuring to create new objects without the unwanted properties, which can be more efficient and clearer.

-    event.forEach(e => {
-      delete e.dayArr;
-      delete e.dayNumber;
-    });
+    event = event.map(e => {
+      const { dayArr, dayNumber, ...rest } = e;
+      return rest;
+    });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 24baa79 and 236e0c8.

📒 Files selected for processing (17)
  • examples/sites/demos/apis/calendar-view.js (1 hunks)
  • examples/sites/demos/mobile-first/app/calendar-view/calendar-event.vue (2 hunks)
  • examples/sites/demos/pc/app/calendar-view/calendar-event-composition-api.vue (2 hunks)
  • examples/sites/demos/pc/app/calendar-view/calendar-event.spec.ts (2 hunks)
  • examples/sites/demos/pc/app/calendar-view/calendar-event.vue (2 hunks)
  • examples/sites/demos/pc/app/calendar-view/webdoc/calendar-view.js (3 hunks)
  • packages/renderless/src/calendar-view/index.ts (3 hunks)
  • packages/renderless/src/calendar-view/vue.ts (3 hunks)
  • packages/theme-saas/src/calendar-view/index.less (3 hunks)
  • packages/theme/src/base/reset.less (1 hunks)
  • packages/theme/src/calendar-view/index.less (3 hunks)
  • packages/theme/src/month-table/index.less (1 hunks)
  • packages/vue/src/calendar-view/src/mobile-first.vue (3 hunks)
  • packages/vue/src/calendar-view/src/pc.vue (1 hunks)
  • packages/vue/src/date-panel/src/pc.vue (1 hunks)
  • packages/vue/src/date-range/src/pc.vue (1 hunks)
  • packages/vue/src/year-range/src/pc.vue (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/renderless/src/calendar-view/vue.ts (1)
packages/renderless/src/calendar-view/index.ts (2)
  • selectDay (321-364)
  • computedSelectDay (310-319)
🔇 Additional comments (38)
packages/vue/src/year-range/src/pc.vue (1)

7-7: Improved conditional class application for sidebar

This change enhances the conditional logic for applying the has-sidebar class by checking for the presence of shortcuts rather than just the existence of the shortcuts object. Using state.shortcuts?.length ensures the class is only applied when there are actual shortcut items to display, making it consistent with the rendering condition on line 14.

packages/vue/src/date-range/src/pc.vue (1)

18-18: Improved conditional class application for sidebar

This change enhances the conditional logic for applying the has-sidebar class by checking for the presence of shortcuts rather than just the existence of the shortcuts object. Using state.shortcuts?.length ensures the class is only applied when there are actual shortcut items to display, making it consistent with the rendering condition on line 27.

packages/vue/src/date-panel/src/pc.vue (1)

18-18: Improved conditional class application for sidebar

This change enhances the conditional logic for applying the has-sidebar class by checking for the presence of shortcuts rather than just the existence of the shortcuts object. Using state.shortcuts?.length ensures the class is only applied when there are actual shortcut items to display, making it consistent with the rendering condition on line 28.

packages/theme/src/month-table/index.less (1)

27-27: Improved layout with full-width table.

This change ensures the month table occupies the full width of its parent container, providing a better visual experience and consistent layout across different screen sizes.

examples/sites/demos/mobile-first/app/calendar-view/calendar-event.vue (2)

6-6: LGTM: Date click event binding added.

The event binding is properly added to the calendar view component, enabling date click functionality.


29-31: LGTM: Date click handler implementation.

The dateClick method correctly handles the date click event, displaying the clicked date and associated events in a modal. The implementation is consistent with other event handlers in this component.

examples/sites/demos/apis/calendar-view.js (1)

241-250: LGTM: Well-documented new event.

The date-click event is properly documented with clear descriptions in both Chinese and English. The documentation accurately describes the callback parameters and correctly references the demo files.

examples/sites/demos/pc/app/calendar-view/calendar-event-composition-api.vue (2)

6-6: LGTM: Date click event binding added.

The event binding is properly added to the calendar view component, enabling date click functionality.


23-25: LGTM: Date click handler with Composition API.

The dateClick method is correctly implemented using the Composition API style. It properly displays the clicked date and associated events in a modal, consistent with other event handlers.

examples/sites/demos/pc/app/calendar-view/calendar-event.vue (1)

6-6: Great addition of date-click event listener!

The date-click event has been properly integrated into the calendar view component, enhancing interactivity by allowing users to interact with individual dates.

packages/theme/src/base/reset.less (2)

162-162: Simplified scrollbar corner styling

Changed from using a CSS variable to a transparent background, which makes the styling simpler and more consistent.


167-167: Simplified scrollbar track styling

Similar to the corner styling, changed from using a CSS variable to a transparent background. This provides a cleaner appearance when scrolling and is more consistent with modern UIs.

packages/theme-saas/src/calendar-view/index.less (4)

65-65: Enhanced interactivity with pointer cursor

Adding the cursor pointer to list items in the header improves the UX by visually indicating clickable elements to users.


355-355: Consistent pointer cursor for all interactive elements

Adding the same cursor pointer styling here maintains consistency across different calendar views, reinforcing the interactive nature of these elements.


363-370: Improved styling for today and current date

The addition of dedicated styling for .is-today and .current classes ensures visual consistency when highlighting the current date in the calendar. Using the brand color makes the current date more prominent.


416-422: Consistent styling for week day indicators

Similar to the date styling, these changes ensure that both .is-today and .current classes for week days have the same visual treatment, maintaining consistency throughout the calendar component.

examples/sites/demos/pc/app/calendar-view/calendar-event.spec.ts (2)

14-15: Good test coverage with appropriate locators

These new locators are well-defined for testing the date click functionality, targeting both the date element to click and the message that appears afterward.


33-35: Complete test coverage for date click feature

The test now verifies that clicking on a date triggers the expected behavior, ensuring the new feature works correctly. The wait time allows for the modal to be fully displayed before checking its visibility.

packages/theme/src/calendar-view/index.less (3)

361-364: Good addition of cursor pointer for interactive dates

Adding the cursor: pointer style to the list items clearly indicates to users that the dates are clickable, which improves the user experience.


374-377: Good addition of .current class for highlighting selected dates

Adding the .current class that uses the same styling as .is-today provides consistent visual feedback when a date is selected, enhancing the user experience.


425-431: Consistent styling for both today and selected date indicators

The updates to use CSS variables for the text color and the addition of the .current class for week days ensures consistent styling between today's date and selected dates.

packages/renderless/src/calendar-view/vue.ts (3)

1-5: Good addition of computedSelectDay import

Including this import is necessary for the date-click functionality to work correctly.


45-52: Properly exposed computedSelectDay in API

The computedSelectDay function is now correctly exposed in the API list, making it available to components.


275-276: Enhanced selectDay with props and api parameters

The selectDay function now receives additional parameters (props, api) which allows it to access and use event data through the dealEvents function. This is crucial for the date-click functionality to work properly.

packages/vue/src/calendar-view/src/mobile-first.vue (3)

162-164: Good implementation of date click handler

Adding both the cursor-pointer class and click event handler makes the dates interactive. The click event correctly triggers the selectDay function with the date parameter.


173-175: Enhanced visual feedback for selected dates

The class binding now checks both the current date and the selected date using computedSelectDay, providing consistent visual feedback to users.


184-186: Consistent styling for week day indicators

The styling for week day text is now consistent with the date styling, changing color when either the date is today or is selected.

examples/sites/demos/pc/app/calendar-view/webdoc/calendar-view.js (4)

168-171: Good documentation of new date-click event

The documentation clearly explains the new date-click event in Chinese, which is essential for developers to understand this new feature.


180-182: Good English documentation for date-click event

The documentation includes both Chinese and English explanations, making it accessible to a wider audience of developers.


376-377: Updated feature description with new event

The feature description is properly updated to include the new date-click event in the list of available events.


380-382: Added date-click to API list

The date-click event is now properly listed in the APIs array, making it discoverable when browsing the component documentation.

packages/vue/src/calendar-view/src/pc.vue (3)

110-110: Good addition of click handler for date selection

Adding the @click="selectDay(date)" handler to the week date list items enables users to interact with dates directly, improving usability of the calendar component.


118-119: Good visual feedback for selected dates

Adding the current class when computedSelectDay(date) is true provides visual feedback to users when a date is selected, enhancing the UX by making the current selection clear.


126-128: Consistent styling for week day display

Adding the same current class to the week day span ensures consistent styling between date and weekday elements when a date is selected.

packages/renderless/src/calendar-view/index.ts (4)

310-319: Well-structured helper function for date selection state

The computedSelectDay function appropriately handles both multi-select and single-select cases, providing a clean abstraction for determining if a date is selected.


321-323: Good addition of API parameter to selectDay function

Adding the api parameter to the selectDay function enables access to other API methods, specifically for retrieving date events. This is a necessary change to support the new click event feature.


337-338: Good implementation of event data retrieval

The code correctly retrieves events related to selected dates using the dealEvents helper function, ensuring that both dates and their associated events are available for the click handler.

Also applies to: 359-360


341-342: Proper event emission with date and event data

The code properly emits the date-click event with both the selected date(s) and related events, providing consumers with all the data they need to handle date selections effectively.

Also applies to: 362-363

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

♻️ Duplicate comments (1)
packages/renderless/src/calendar-view/index.ts (1)

366-376: The dealEvents function is defined but not exported.

The function correctly processes events for selected dates, but it's not exported which might limit its reusability in other parts of the codebase.

Consider exporting this function if it needs to be used elsewhere:

- const dealEvents = (props, api, date) => {
+ export const dealEvents = (props, api, date) => {
🧹 Nitpick comments (2)
packages/vue/src/calendar-view/__tests__/calendar-view.test.tsx (1)

1-15: Good start on test coverage, but consider expanding it.

The test successfully verifies that the component renders correctly, but it doesn't test the new date-click functionality.

Consider adding a test case that simulates a date click and verifies that the date-click event is emitted with the correct parameters:

+ test('date-click event', async () => {
+   const onDateClick = vi.fn()
+   const wrapper = mount(() => <CalendarView year={2023} month={5} onDateClick={onDateClick}></CalendarView>)
+   
+   await nextTick()
+   // Find a date element and trigger click
+   const dateElement = wrapper.find('.tiny-calendar-view__day:not(.is-disabled)')
+   await dateElement.trigger('click')
+   
+   // Verify event was emitted with correct parameters
+   expect(onDateClick).toHaveBeenCalled()
+   // Additional assertions on the parameters if needed
+ })
packages/renderless/src/calendar-view/index.ts (1)

358-363: New date-click event for single-select mode.

The implementation correctly handles the single-select case, but there's an inconsistency in the emitted payload format compared to multi-select mode.

In multi-select mode, you emit (selectedDates, dateEvent) while in single-select mode you emit (selectedDate, dateEvent[0]). This inconsistency could make it harder for consumers to handle the event. Consider normalizing the event payload structure:

- emit('date-click', state.selectedDate, dateEvent[0])
+ emit('date-click', [state.selectedDate], dateEvent[0])

Or alternatively, normalize the multi-select case to match the single-select format.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 236e0c8 and 8d22be2.

📒 Files selected for processing (18)
  • examples/sites/demos/apis/calendar-view.js (1 hunks)
  • examples/sites/demos/mobile-first/app/calendar-view/calendar-event.vue (2 hunks)
  • examples/sites/demos/pc/app/calendar-view/calendar-event-composition-api.vue (2 hunks)
  • examples/sites/demos/pc/app/calendar-view/calendar-event.spec.ts (2 hunks)
  • examples/sites/demos/pc/app/calendar-view/calendar-event.vue (2 hunks)
  • examples/sites/demos/pc/app/calendar-view/webdoc/calendar-view.js (3 hunks)
  • packages/renderless/src/calendar-view/index.ts (3 hunks)
  • packages/renderless/src/calendar-view/vue.ts (3 hunks)
  • packages/theme-saas/src/calendar-view/index.less (3 hunks)
  • packages/theme/src/base/reset.less (1 hunks)
  • packages/theme/src/calendar-view/index.less (3 hunks)
  • packages/theme/src/month-table/index.less (1 hunks)
  • packages/vue/src/calendar-view/__tests__/calendar-view.test.tsx (1 hunks)
  • packages/vue/src/calendar-view/src/mobile-first.vue (3 hunks)
  • packages/vue/src/calendar-view/src/pc.vue (1 hunks)
  • packages/vue/src/date-panel/src/pc.vue (1 hunks)
  • packages/vue/src/date-range/src/pc.vue (1 hunks)
  • packages/vue/src/year-range/src/pc.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (15)
  • packages/theme/src/month-table/index.less
  • packages/vue/src/year-range/src/pc.vue
  • packages/vue/src/date-range/src/pc.vue
  • examples/sites/demos/mobile-first/app/calendar-view/calendar-event.vue
  • examples/sites/demos/apis/calendar-view.js
  • packages/vue/src/date-panel/src/pc.vue
  • packages/theme/src/base/reset.less
  • packages/theme/src/calendar-view/index.less
  • packages/theme-saas/src/calendar-view/index.less
  • packages/vue/src/calendar-view/src/mobile-first.vue
  • examples/sites/demos/pc/app/calendar-view/webdoc/calendar-view.js
  • packages/renderless/src/calendar-view/vue.ts
  • examples/sites/demos/pc/app/calendar-view/calendar-event.vue
  • packages/vue/src/calendar-view/src/pc.vue
  • examples/sites/demos/pc/app/calendar-view/calendar-event.spec.ts
🔇 Additional comments (5)
examples/sites/demos/pc/app/calendar-view/calendar-event-composition-api.vue (2)

6-6: LGTM! Event handler added for date clicks.

The @date-click event binding correctly connects to the new handler function.


23-25: Good implementation of the dateClick handler.

The function correctly receives both the clicked date and associated events as parameters and displays them in a formatted message. This matches the pattern used by other event handlers in this file.

packages/renderless/src/calendar-view/index.ts (3)

310-319: LGTM! New helper function to determine if a day is selected.

The computedSelectDay function correctly handles both multi-select and single-select modes, properly checking disabled states and empty values.


321-323: API parameter added to support the new event functionality.

The function signature update enables access to the API needed for the new feature.


337-341: New date-click event for multi-select mode.

The implementation correctly handles the multi-select case by retrieving associated events and emitting them with the selected dates.

@zzcr zzcr merged commit 1eb4208 into opentiny:dev Apr 11, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request (功能增强)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants