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

feat: Add prop 'clearable' to input #1438

Merged
merged 1 commit into from
Sep 21, 2024
Merged

feat: Add prop 'clearable' to input #1438

merged 1 commit into from
Sep 21, 2024

Conversation

cintek
Copy link
Contributor

@cintek cintek commented Sep 20, 2024

πŸ“‘ Description

With this PR you can add the property clearable so users can remove the input with a single click.

clearable

Status

  • Not Completed
  • Completed

βœ… Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • I have checked the page with https://validator.unl.edu/
  • All the tests have passed
  • My pull request is based on the latest commit (not the npm version).

Summary by CodeRabbit

  • New Features
    • Introduced a clearable input field feature, allowing users to clear input with a single click.
  • Documentation
    • Added a new section in the input field documentation to demonstrate the clearable functionality with examples.

Copy link

vercel bot commented Sep 20, 2024

@cintek is attempting to deploy a commit to the Themesberg Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Sep 20, 2024

Walkthrough

The changes introduce a new clearable property to the Input.svelte component, enabling users to clear the input field with a button when it contains a value. The component's structure is enhanced to conditionally render the clear button based on the clearable property. Additionally, the documentation for the input field is updated to include a new section demonstrating the usage of the clearable feature, while the previous content remains unchanged.

Changes

Files Change Summary
src/lib/forms/Input.svelte Added a clearable property, modified input class logic for right padding, defined a clearAll function, and adjusted rendering logic for the clear button.
src/routes/docs/forms/input-field.md Introduced a new "Clearable" section with an example of the clearable input field using the Input component.

Poem

In a field of code, oh what a sight,
A button to clear, making it right.
With a click, the text disappears,
A hop of joy, let’s give three cheers!
For every input, now clear and bright,
Thanks to the changes, all feels just right! πŸ‡βœ¨


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 235523d and 639334c.

Files selected for processing (2)
  • src/lib/forms/Input.svelte (4 hunks)
  • src/routes/docs/forms/input-field.md (1 hunks)
Additional comments not posted (9)
src/lib/forms/Input.svelte (8)

11-11: LGTM!

The import statement for createEventDispatcher is correct and necessary for dispatching custom events in the component.


13-13: LGTM!

The import statement for the CloseButton component is correct and necessary for rendering the clear button in the input field.


15-15: LGTM!

The usage of createEventDispatcher is correct and follows the common pattern for event handling in Svelte components.


19-19: LGTM!

The export statement for the clearable prop is correct and aligns with the PR objective. The default value of false is appropriate.


58-58: LGTM!

The change in the inputClass logic to conditionally include the right padding class based on the clearable prop or the presence of the right slot is implemented correctly and is necessary for accommodating the clear button.


61-65: LGTM!

The implementation of the clearAll function is correct and aligns with the expected behavior of the clear button. It properly handles the click event, clears the input value, and dispatches a change event.


77-84: LGTM!

The code block for rendering the right slot and conditionally rendering the clear button based on the clearable prop and the presence of a non-empty value is implemented correctly. It properly handles the rendering logic and binds the clearAll function to the click event of the clear button.


94-94: LGTM!

The documentation of the clearable prop using the @prop annotation is correct and provides clarity to the users of the component. It aligns with the PR objective and follows the proper documentation format.

src/routes/docs/forms/input-field.md (1)

125-136: Excellent addition to the documentation!

The new "Clearable" section provides a clear explanation and a concise code example demonstrating how to use the clearable prop on the Input component. This will help users quickly understand and utilize this feature.


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

Copy link

vercel bot commented Sep 21, 2024

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
flowbite-svelte βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Sep 21, 2024 1:46pm

@shinokada
Copy link
Collaborator

Why don't you do it like this?

<script lang="ts">
  import { Label, Input, CloseButton } from '$lib'
  let value = 'hi'
</script>

<Label class="space-y-2">
  <span>Default input - right icon</span>
  <Input type="email" placeholder="[email protected]" bind:value size="md">
    <CloseButton slot="right" on:click={() => (value = '')} />
  </Input>
</Label>

@cintek
Copy link
Contributor Author

cintek commented Sep 21, 2024

Why don't you do it like this?

[...]

What exactly do you mean? Why I started a PR for a simple prop like this although you could easily implement an own component with such a functionality? Simply for more convenience for developers. Other frameworks like Vuetify also offer such simple props. It's nice if you don't have to implement every detail yourself :)

@shinokada shinokada merged commit 233ad40 into themesberg:main Sep 21, 2024
1 check passed
@shinokada
Copy link
Collaborator

Thank you for the PR.

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.

2 participants