Buefy-next

repository·dev·Indexed 41 days ago

https://github.com/ntohq/buefy-next

A lightweight library of responsive UI components for Vue 3 based on the Bulma CSS framework. Version 0.2.1 provides a Vue 3 compatible version of the original Buefy library, including components like BAutocomplete, BBreadcrumb, BButton, BCarousel, BCheckbox, and BClockpicker.

Tokens
25.2K
Snippets
123
Records
148
Agent score
50%

What's inside Buefy-next

  1. Understand v-model changes in Vue 3

    dev

    When migrating to Vue 3, the default v-model behavior has changed. If you are creating or customizing components that use v-model, you must use the following mapping:

    • Prop: value is now modelValue.
    • Event: input is now update:modelValue.

    Note that in Vue 3, you cannot use a name other than modelValue for the default v-model binding.

  2. Declare emitted events in the emits field

    dev

    In Vue 3, all events emitted from a component must be explicitly listed in the emits field.

    Failing to declare an event in emits can lead to accidental attribute binding when using v-bind="$attrs". For example, if Taginput emits a typing event but does not declare it in emits, a listener on a parent component might be triggered twice if a child component (like Autocomplete) also emits a typing event.

  3. Handle event listeners and $listeners removal

    dev

    Vue 3 has removed $listeners. Event listeners are now part of $attrs. To pass a listener through a component, use the on prefix followed by the event name (e.g., onClick for the click event).

    Warning for Dialog/Modal users: In some Buefy components like Dialog and Modal, props like onConfirm and onCancel were previously renamed to confirmCallback and cancelCallback to avoid being interpreted as event listeners. However, compatibility has been restored, so you should use onConfirm and onCancel to programmatically open a Dialog.

  4. Use the global h function and resolve components

    dev

    In Vue 3, the render function no longer takes a h (create element) argument; instead, h is a globally available function.

    When using the global h API:

    • Props: The second argument (props) is simplified. staticClass is now class, and the on property is removed (listeners are now handled via on{EventName} props).
    • Component Resolution: The h API does not automatically resolve component names. You must use the resolveComponent global API to resolve components by name.
    • Built-in Components: For built-in components like Transition, it is recommended to import the dedicated object directly from vue.
    import { Transition, resolveComponent } from 'vue';
    
    // Example of resolving a component manually
    const MyComponent = resolveComponent('MyComponent');
    // h(MyComponent, { ... });
  5. Handle boolean attribute behavior in Vue 3

    dev

    In Vue 2, setting a boolean attribute to false automatically removed it from the element. In Vue 3, setting a boolean attribute to false does not remove it. To remove a boolean attribute in Vue 3, you must explicitly specify null or undefined.

    Buefy components (such as Switch, Checkbox, Pagination, Taginput, etc.) have been updated to use computed values that resolve to true or undefined to ensure correct behavior in Vue 3.

  6. Import and use Buefy in Vue 3

    dev

    You can use Buefy in your Vue 3 application by either importing the entire library or selecting individual components to keep your bundle size small.

    // Option 1: Bundle everything
    import { createApp } from 'vue';
    import Buefy from 'buefy';
    import 'buefy/dist/buefy.css';
    
    const app = createApp();
    app.use(Buefy);
    
    // Option 2: Individual Components
    import { createApp } from 'vue'
    import { Field, Input } from 'buefy'
    import 'buefy/dist/buefy.css'
    
    const app = createApp();
    app.use(Field)
    app.use(Input)
  7. Include Material Design Icons

    dev

    Buefy supports Material Design Icons. To use them, include the following stylesheet in your HTML:

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@5.8.55/css/materialdesignicons.min.css">
  8. Install developer releases from GitHub npm Registry

    dev

    To access the latest features from the development branch, you can install developer releases from the GitHub npm registry.

    Warning: These packages may be unstable and can be deleted or retracted without notice.

    1. Configure npm

    Generate a Personal Access Token on GitHub with read access to the GitHub Packages registry, then run:

    npm login --auth-type=legacy --registry=https://npm.pkg.github.com
    # Use your GitHub username and the Personal Access Token as the password
    
    echo "@ntohq:registry=https://npm.pkg.github.com" > .npmrc

    2. Install a specific developer release

    Developer releases follow the format @ntohq/buefy-next@<package version>-<dev commit hash>. You can install a specific version or the latest snapshot:

    # Install a specific developer release
    npm install buefy@npm:@ntohq/buefy-next@<package version>-<dev commit hash>
    
    # Install the latest developer snapshot (not recommended for production)
    npm install buefy@npm:@ntohq/buefy-next@latest
  9. Install Buefy-next via npm

    dev

    To install the buefy-next fork for Vue 3, use the following command. This installs @ntohq/buefy-next under the buefy alias, which allows for a smoother transition when the package becomes stable.

    Note: This version is specifically for Vue 3.0+ and is not compatible with Vue 2.

    npm install buefy@npm:@ntohq/buefy-next
  10. How Timepicker handles time constraints

    dev

    The Timepicker component implements logic to disable specific time units based on provided constraints:

    1. Range Constraints: If minTime or maxTime is provided, the component calculates valid hours, minutes, and seconds. For example, if minTime is 10:30, the component will disable hours before 10 and minutes before 30 within the 10th hour.
    2. Unselectable Times: If unselectableTimes is provided, the component checks the current selection against this list. If a specific combination of hour, minute, and (optionally) second matches an entry in unselectableTimes, that time becomes disabled.
    3. Step Increments: The incrementHours, incrementMinutes, and incrementSeconds props control the granularity of the picker. Setting these to values $> 1$ will skip values in the selection lists.
  11. Use the Dialog component and programmatic API

    dev

    The Dialog component can be used in two ways: as a standard Vue component in your templates or via a programmatic API for imperative dialog control (like alert, confirm, or prompt).

    1. Declarative Usage (Component)

    Import BDialog to use it directly in your Vue templates. It accepts standard DialogProps.

    2. Programmatic Usage (Imperative)

    Use the DialogProgrammatic class to trigger dialogs from your logic. This is useful for quick alerts or confirmation flows without managing component state in your templates.

    • alert(params): Displays a simple message with no cancel option.
    • confirm(params): Displays a dialog with confirm/cancel actions.
    • prompt(params): Displays a dialog with an input field.

    If config.defaultProgrammaticPromise is enabled, these methods return a Promise that resolves when the dialog is closed.

    import { BDialog, DialogProgrammatic } from '@ntohq/buefy-next'
    
    // Declarative
    <template>
      <BDialog v-model="showDialog" message="Hello!" />
    </template>
    
    // Programmatic
    const dialog = new DialogProgrammatic()
    
    // Alert
    dialog.alert('This is an alert')
    
    // Confirm
    dialog.confirm({ message: 'Are you sure?' }).then(result => {
      console.log('User confirmed:', result.result)
    })
    
    // Prompt
    dialog.prompt({ message: 'Enter your name' }).then(result => {
      console.log('Input:', result.result)
    })