Skip to content

Conversation

liangguanhui0117
Copy link

@liangguanhui0117 liangguanhui0117 commented Sep 5, 2025

#16

Summary by CodeRabbit

  • New Features

    • Search Box now supports a size option, including a compact “small” variant for tighter layouts. Set size="small" to use it.
  • Documentation

    • Added “尺寸” example page demonstrating size usage.
    • Updated the “案例” sidebar with a new “尺寸” entry for quick access.

Copy link

coderabbitai bot commented Sep 5, 2025

Walkthrough

Adds a size prop to TinySearchBox with a new "small" variant, propagating to nested components and styles via classes and CSS variables. Updates types, Less variables, and styles. Adds docs: sidebar entry, example page, and a Vue demo showcasing default vs small sizes.

Changes

Cohort / File(s) Summary
Docs Navigation
packages/docs/.vitepress/config.mts
Adds "尺寸" link (/examples/size) under "案例" in sidebar.
Docs Example
packages/docs/examples/size.md, packages/docs/search-box/size.vue
New example page and demo: two tiny-search-box instances (default and size="small"). Note: stray size="small" line present between components in demo.
SearchBox Size Feature
packages/search-box/src/index.vue, packages/search-box/src/index.type.ts, packages/search-box/src/index.less, packages/search-box/src/vars.less
Introduces size prop (''

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant A as App Page
  participant SB as TinySearchBox
  participant Sub as TinyTag/TinyForm/TinyDropdown
  participant CSS as CSS Vars & Classes

  U->>A: Open Size example
  A->>SB: Render with v-model, items (size="")
  SB->>CSS: Apply default classes/vars
  SB->>Sub: Render children (no size)
  Note over SB,Sub: Default size flow

  U->>A: View second instance (size="small")
  A->>SB: Render with size="small"
  SB->>CSS: Add class tvp-search-box--small
  SB->>Sub: Pass size="small"
  CSS-->>SB: Small variant styles (min-height, padding, tag font)
  Note over SB,CSS: Small-specific variables and offsets
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble code like clover sprigs,
A smaller box now softly digs—
With tiny tags and tidy trim,
The search feels light, the edges slim.
Hop! A tweak of size so small,
Yet crisp as leaves in autumn fall. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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 Sep 5, 2025
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: 1

🧹 Nitpick comments (12)
packages/docs/examples/size.md (1)

1-5: Clarify allowed values, default, and show a quick usage snippet

Make the accepted values and default explicit to reduce ambiguity, and add a tiny example for discoverability.

 ## 尺寸

-通过 size 属性可以设置尺寸。
+通过 size 属性可以设置尺寸,支持:''(默认)和 'small'。
+
+示例:
+```vue
+<TinySearchBox />
+<TinySearchBox size="small" />
+```

 <preview path="../search-box/size.vue"></preview>

Also consider adding size 到 “API > props” 页面以保持文档一致性。

packages/search-box/src/index.type.ts (1)

194-195: Document the default and centralize allowed values

Type is fine, but an empty-string literal is easy to mistype. Document the default, and optionally expose a canonical list to reuse in docs/validators.

-// SearchBox 尺寸
-export type ISearchBoxSize = '' | 'small'
+/** SearchBox 尺寸(默认:'';可选:'' | 'small') */
+export type ISearchBoxSize = '' | 'small'
+
+// 可选:导出枚举式列表,便于复用(校验、文档展示等)
+export const SEARCH_BOX_SIZES = ['' as const, 'small' as const]
+export type ISearchBoxSizeEnum = typeof SEARCH_BOX_SIZES[number]

If you prefer explicitness, consider 'default' | 'small' in a future minor; for now this keeps backwards compatibility.

packages/search-box/src/vars.less (1)

30-30: Add comments for new small-size variables

Minor readability: add comments matching the surrounding style so themers know what each small-* var controls.

-  --tvp-SearchBox-small-min-height: var(--tv-size-height-sm, 28px);
+  // 小号输入框最小高度
+  --tvp-SearchBox-small-min-height: var(--tv-size-height-sm, 28px);
@@
-  --tvp-SearchBox-small-padding-left: var(--tv-size-height-sm, 28px);
+  // 小号输入框左内边距(为前缀图标留位)
+  --tvp-SearchBox-small-padding-left: var(--tv-size-height-sm, 28px);
@@
-  --tvp-SearchBox-small-tag-font-size: var(--tv-font-size-sm, 12px);
+  // 小号标签字号
+  --tvp-SearchBox-small-tag-font-size: var(--tv-font-size-sm, 12px);

Also applies to: 33-33, 54-54

packages/search-box/src/index.less (1)

420-437: Small variant styles look consistent; remove stray blank line and consider avoiding magic numbers

The overrides read well and map to the new vars. Two tiny nits:

  • Remove the extra blank line (Line 429).
  • Optional: extract the 10px/12px prefix left offsets to a var to avoid magic numbers across sizes.
   &--small {
     min-height: var(--tvp-SearchBox-small-min-height);
     padding-left: var(--tvp-SearchBox-small-padding-left);

     & > .@{search-box-prefix-cls}__prefix {
       top: calc((var(--tvp-SearchBox-small-min-height) - var(--tvp-SearchBox-left-icon-font-size)) / 2 - 1px);
       left: 10px;
     }
-
     
     .@{search-box-prefix-cls}__prop {
       font-size: var(--tvp-SearchBox-small-tag-font-size);

       span {
         padding-left: 8px;
       }
     }
   }
packages/docs/search-box/size.vue (2)

5-5: Type the ref to avoid Ref<never[]> inference.

TS infers ref([]) as Ref<never[]>, which can cause assignment/type issues.

Apply this diff:

-const tags = ref([])
+const tags = ref<any[]>([])

8-14: Consider separating models for clearer demo.

Using the same v-model for both boxes makes them mirror each other; independent refs better showcase size-only differences.

packages/search-box/src/index.vue (6)

94-98: Validate incoming size at runtime.

Adds a guard to prevent unsupported values from slipping in.

Apply this diff:

   // 尺寸
   size: {
     type: String as PropType<ISearchBoxSize>,
-    default: ''
+    default: '',
+    validator: (v: ISearchBoxSize) => v === '' || v === 'small'
   }

320-323: Prefer object syntax for class binding to avoid empty strings.

Cleaner and avoids rendering a blank class token.

Apply this diff:

-  <div 
-    :class="['tvp-search-box', size === 'small' ? 'tvp-search-box--small' : '']"
+  <div
+    :class="['tvp-search-box', { 'tvp-search-box--small': size === 'small' }]"
     @click.stop="showPopover(state, false)"
   >

329-329: Don’t pass empty string to child size props.

Use undefined when default to avoid invalid/unknown-size warnings downstream.

Apply this diff:

-      :size="size === 'small' ? 'small' : ''"
+      :size="size || undefined"

344-344: Same here: let the prop be omitted when default.

Apply this diff:

-      :size="size === 'small' ? 'small' : ''"
+      :size="size || undefined"

362-362: Same here for dropdown size propagation.

Apply this diff:

-          :size="size === 'small' ? 'small' : ''"
+          :size="size || undefined"

319-641: Optional: centralize size logic to reduce repetition.

Create a computed childSize once and reuse.

Apply this diff (snippet):

 // script
+const childSize = computed(() => (props.size ? 'small' : undefined))
 
 // template (examples)
-:size="size || undefined"
+:size="childSize"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0223e13 and fae276a.

📒 Files selected for processing (7)
  • packages/docs/.vitepress/config.mts (1 hunks)
  • packages/docs/examples/size.md (1 hunks)
  • packages/docs/search-box/size.vue (1 hunks)
  • packages/search-box/src/index.less (1 hunks)
  • packages/search-box/src/index.type.ts (1 hunks)
  • packages/search-box/src/index.vue (5 hunks)
  • packages/search-box/src/vars.less (2 hunks)
🔇 Additional comments (4)
packages/docs/.vitepress/config.mts (1)

60-60: Docs nav entry looks good

Sidebar item “尺寸” correctly links to /examples/size and matches the new page.

packages/search-box/src/index.less (1)

420-427: Confirmed small variant class on rootindex.vue binds tvp-search-box--small on the root element when size === 'small', so the CSS plumbing is correct.

packages/search-box/src/index.vue (2)

29-33: LGTM on type import wiring.

Imports the new ISearchBoxSize cleanly; aligns with the added prop.


320-641: Verify small size propagation to child inputs/selects.
Ensure that passing size="small" to <tiny-form> correctly sets the height on inner <tiny-input> and <tiny-select>; if it doesn’t, add :size="childSize" to those components.

<template>
<ClientOnly>
<tiny-search-box v-model="tags" :items="dataSource" />
size="small"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove stray text node: it renders literally on the page.

The standalone size="small" between components becomes visible text in docs.

Apply this diff:

   <ClientOnly>
     <tiny-search-box v-model="tags" :items="dataSource" />
-    size="small"
     <tiny-search-box v-model="tags" :items="dataSource" size="small" />
   </ClientOnly>
📝 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
size="small"
<ClientOnly>
<tiny-search-box v-model="tags" :items="dataSource" />
<tiny-search-box v-model="tags" :items="dataSource" size="small" />
</ClientOnly>
🤖 Prompt for AI Agents
In packages/docs/search-box/size.vue around line 11 there is a stray text node
`size="small"` that renders literally on the page; remove this standalone text
node and either delete it entirely or move it into the appropriate component as
an attribute/prop (i.e., attach size="small" to the intended component tag) so
it is not rendered as plain text.

@kagol
Copy link
Member

kagol commented Sep 24, 2025

@liangguanhui0117 感谢你的贡献,可以加上 small medium large 三个尺寸,参考 Input 等组件的效果设定具体宽高和间距

@Issues-translate-bot
Copy link

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


@liangguanhui0117 Thank you for your contribution, you can add three sizes of small medium large, refer to the effect of Input and other components to set the specific width, height and spacing

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