aboutsummaryrefslogtreecommitdiff
path: root/src/components/checkbox/checkbox.js
blob: 324a7597d6cc7998bbb7b473277ff7b5db9f22b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// TODO: Template-based functional component is supported in vue-loader 13.3.0+.
// Also, somehow, props are not provided through 'context' even though they are defined.
// Need to upgrade vue-loader

import './checkbox.scss'

export default {
  functional: true,
  name: 'Checkbox',
  model: {
    prop: 'checked',
    event: 'change'
  },
  render (createElement, { data, children }) {
    const { props = {}, attrs = {}, on = {}, ...rest } = data
    const { name, checked, disabled, readonly, ...restAttrs } = attrs
    const { change, ...restListeners } = on
    const wrapperProps = {
      attrs: restAttrs,
      on: restListeners,
      ...rest
    }
    const inputProps = {
      attrs: {
        name,
        checked,
        disabled,
        readonly,
        ...props
      },
      on: {}
    }
    if (change) {
      inputProps.on.change = e => change(e.target.checked)
    }
    return (
      <label class="checkbox" {...wrapperProps}>
        <input type="checkbox" {...inputProps} />
        <i />
        {children && <span>{children}</span>}
      </label>
    )
  }
}