GithubHelp home page GithubHelp logo

doc22940 / vue-bulma-components Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vouill/vue-bulma-components

1.0 0.0 0.0 496 KB

Translate Bulma css api to vue components

JavaScript 81.29% HTML 2.99% Vue 15.72%

vue-bulma-components's Introduction

vue-bulma-components

Build Status

The goal of this library is to use the bulma class syntax as components and props.

3kb minified

Demo and try the live demo too :)

Usage

Exemple with grid system

Original Bulma way:

<div class="columns is-mobile">
  <div class="column is-half is-offset-one-quarter">
    A column
   </div>
</div>

Vue-bulma-component way:

<b-columns is-mobile>
  <b-column is-half is-offset-one-quarter>
    A column
  </b-column>
</b-columns>

Using css class as directives at your advantage

One cool feature of using the Bulma css api as directives is toggling them. See how the is-loading class is handled

Ex:

<button class="button is-dark" :class="{ 'is-loading': bool }">
  Send
</button>

Vue-bulma-component way:

<b-button is-dark :is-loading="bool">
  Send
</b-button>

Much nicer right ? ;)

Note:

You can also use the Pascal case notation, example:

<BButton is-dark :is-loading="bool">
  Send
</BButton>

Using custom classes

If you want to add any other class simply use the normal class attribute

<b-button is-dark :class="my-custom-class">
  Send
</b-button>

Install

yarn add vue-bulma-components

or

npm install --save vue-bulma-components

Then install Bulma however you want :).

Use all components globally in your app

Inside your main.js

import vueBulmaComponents from 'vue-bulma-components'
Vue.use(vueBulmaComponents)

It will make globallly available all these bulma components with the prefix b- or B if you prefer the Pascal case component naming.

You can also change the default prefix of all the bulma components (to avoid collision with existing components in your project)

import vueBulmaComponents from 'vue-bulma-components'
Vue.use(vueBulmaComponents, {prefix: 'y-'})

Instead of using <b-columns/> you need to use <y-columns/>

Use specific bulma components in your components

<template>
  <b-box/>
</template>

<script>
  import { bulmaComponentGenerator } from 'vue-bulma-components'

  export default {
    components: {
        box: bulmaComponentGenerator('box')
    }
  }
</script>

Yes, you can actually create any vue-bulma-component by calling bulmaComponentGenerator(bulmaComponentStr).

Components

By default, most of the components are rendered as <div>. You can also use the prop outerElement="span" to change this behavior.

If you want to globally apply default outer element for some bulma component, you can use outerElement option on Vue.use().

import vueBulmaComponents from 'vue-bulma-components'
Vue.use(vueBulmaComponents, {
  outerElement: {
    'navbar': 'nav',
    'navbar-item': 'a'
  }
})

If you use the Vue.use() method to use the vue-bulma-components.

Most of the components are named after the bulma class they belong to. Ex: <box/> <card/> <panel/> ...

However, some bulma components are also named after native html element. This is why they are prefixed.

Ex :

  • Bulma : input
  • vue-component-bulma: <b-input>. This prefix is used to avoid collision with native html <input> element.

If you generate bulma components

<script>
  import { bulmaComponentGenerator } from 'vue-bulma-components'

  export default {
    components: {
        box: bulmaComponentGenerator('box', 'span')
    }
  }
</script>

Usage: bulmaComponentGenerator(bulma_coponent_name,rendered_outer_html_element ).

Note: rendered_outer_html_element is optional.

Known limitations:

Currently you cannot use v-model with <b-input> as expected. Because vue-bulma-components use functional components.

Don't worry, you can still bind a value to a <b-input> component using @input event (it's what v-model does under the hood):

<template>
  <b-control>
    <b-input :value="foo" @input="handleInputChange"/>
    {{foo}}
  </b-control>

</template>

<script>
  export default {
    data: () => ({
      foo: ''
    }),
    method: {
      handleInputChange (e) {
        this.foo = e.target.value
      }
    }
  }
</script>

Note: If you come from the version 1.x.x, there is a breaking change.

From 2.x.x when using Vue.use(vueBulmaComponents), default available components are prefixed by <b-[bulmacomponent]/> instead of <[bulmacomponent]/>

vue-bulma-components's People

Contributors

hkdnet avatar icesentry avatar lojaya avatar nandordudas-duna avatar riceflake avatar vouill avatar whatscs avatar yahtnif avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.