index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { createNamespace } from '../utils';
  2. import { FieldMixin } from '../mixins/field';
  3. import { ParentMixin } from '../mixins/relation';
  4. var _createNamespace = createNamespace('checkbox-group'),
  5. createComponent = _createNamespace[0],
  6. bem = _createNamespace[1];
  7. export default createComponent({
  8. mixins: [ParentMixin('vanCheckbox'), FieldMixin],
  9. props: {
  10. max: [Number, String],
  11. disabled: Boolean,
  12. direction: String,
  13. iconSize: [Number, String],
  14. checkedColor: String,
  15. value: {
  16. type: Array,
  17. default: function _default() {
  18. return [];
  19. }
  20. }
  21. },
  22. watch: {
  23. value: function value(val) {
  24. this.$emit('change', val);
  25. }
  26. },
  27. methods: {
  28. // @exposed-api
  29. toggleAll: function toggleAll(options) {
  30. if (options === void 0) {
  31. options = {};
  32. }
  33. if (typeof options === 'boolean') {
  34. options = {
  35. checked: options
  36. };
  37. }
  38. var _options = options,
  39. checked = _options.checked,
  40. skipDisabled = _options.skipDisabled;
  41. var children = this.children.filter(function (item) {
  42. if (item.disabled && skipDisabled) {
  43. return item.checked;
  44. }
  45. return checked != null ? checked : !item.checked;
  46. });
  47. var names = children.map(function (item) {
  48. return item.name;
  49. });
  50. this.$emit('input', names);
  51. }
  52. },
  53. render: function render() {
  54. var h = arguments[0];
  55. return h("div", {
  56. "class": bem([this.direction])
  57. }, [this.slots()]);
  58. }
  59. });