Skip to content

Conversation

@gweesin
Copy link
Contributor

@gweesin gweesin commented Mar 4, 2025

PR

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: #3022

What is the new behavior?

validate size property

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Refactor
    • Improved the Button Group component by restricting the available size options to specific values ("medium", "small", "mini"). This change enhances validation and consistency, ensuring that only valid size options are used in the interface.

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2025

Walkthrough

This PR updates the type declaration for the size property in the button-group component. In the demo Javascript file, the generic string type is replaced with a union of specific string literals ('medium' | 'small' | 'mini'). In the package’s TypeScript file, the size property is redefined as an object that includes a type, a default value (''), and a validator function that restricts the value to 'medium', 'small', 'mini', or an empty string.

Changes

File(s) Change Summary
examples/sites/.../apis/button-group.js,
packages/vue/.../button-group/src/index.ts
Updated the size property: In the demo file, changed from a generic string to a union literal (`'medium'

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • zzcr
  • chenxi-20

Poem

I'm a rabbit in the code field, hopping with delight,
Nibbling on bugs and errors, making everything right.
With tiny steps and careful bounds, my patches bring a smile,
Validations crisp as fresh carrots—code now runs in style!
Hoppy changes lead the way, let's celebrate for a while.

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/apis/button-group.js

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.

packages/vue/src/button-group/src/index.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.

✨ Finishing Touches
  • 📝 Generate Docstrings

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

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

CodeRabbit Commands (Invoked using PR comments)

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

Other keywords and placeholders

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

CodeRabbit Configuration File (.coderabbit.yaml)

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

Documentation and Community

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

@github-actions github-actions bot added the bug Something isn't working label Mar 4, 2025
@petercat-assistant
Copy link

Walkthrough

This pull request updates the size prop type for the button-group component to accept only specific string values ('medium', 'small', 'mini') and adds a validator to ensure the prop value is one of the allowed options. This change addresses a bug related to size validation.

Changes

File Summary
examples/sites/demos/apis/button-group.js Updated the size prop type to accept specific string values.
packages/vue/src/button-group/src/index.ts Modified the size prop to include a validator function ensuring the value is one of the allowed options.

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

🧹 Nitpick comments (2)
examples/sites/demos/apis/button-group.js (2)

69-69: Type definition improved to reflect valid options.

The change from a generic string type to a specific union type ('medium' | 'small' | 'mini') enhances the API documentation by explicitly listing the valid values for the size property. This improves developer experience by making it clear what options are available.

Consider including the empty string ('') in the type definition to fully match the validator implementation in the component, which accepts an empty string as a valid value:

-          type: "'medium' | 'small' | 'mini'",
+          type: "'medium' | 'small' | 'mini' | ''",

93-93: Inconsistent type notation for v-model.

While unrelated to the current changes, there's an inconsistency in the type notation. Here you're using 'Number / String' format, but elsewhere TypeScript-style union types are used.

Consider standardizing the type notation to match TypeScript conventions:

-          type: 'Number / String',
+          type: 'number | string',
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 04edfe7 and fe2cc0b.

📒 Files selected for processing (2)
  • examples/sites/demos/apis/button-group.js (1 hunks)
  • packages/vue/src/button-group/src/index.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (2)
packages/vue/src/button-group/src/index.ts (2)

19-23: Well-implemented validator for size property.

Good implementation of the validator function to restrict the size property to only valid values. The addition of a default value and proper validation enhances the component's robustness.

The validator correctly includes both the documented values ('medium', 'small', 'mini') and the empty string ('') as a valid value, which likely represents a default or auto size. This ensures backward compatibility with existing code.


19-23:

❓ Verification inconclusive

Verify that existing usages comply with the new validator.

Since you've added a validator that restricts the size property to specific values, it's important to ensure that all existing usages of the component comply with these restrictions.


🏁 Script executed:

#!/bin/bash
# Find all usages of the button-group component with a size prop
# This might help identify if there are any instances using invalid size values

echo "Searching for button-group usages with size prop..."
# Look for Vue template usages
rg -i "<tiny-button-group[^>]*size=['\"][^'\"]*['\"]" --type html --type vue

# Look for JSX usages
rg -i "TinyButtonGroup[^>]*size=['\"][^'\"]*['\"]" --type js --type jsx --type tsx

# Look for programmatic usages
rg -i "buttonGroup[^\.]*\.size\s*=" --type js --type ts

Length of output: 402


Verify that all usages of the size property conform to the new restrictions.

The updated code limits the size prop to ['medium', 'small', 'mini', '']. However, our automated search scripts returned file type errors (unrecognized file types: vue, jsx), meaning the search results aren’t reliable. Please manually verify that every instance of the button-group (or TinyButtonGroup) component is using one of the permitted size values or adjust the search parameters to ensure proper coverage.

@zzcr zzcr linked an issue Mar 5, 2025 that may be closed by this pull request
@zzcr zzcr merged commit d4c22d5 into opentiny:dev Mar 5, 2025
11 checks passed
@gweesin gweesin deleted the fix/btn-group-docs branch March 5, 2025 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [Bug]: ButtonGroup 尺寸选项应当为枚举

2 participants