From 46e1390c295530561d2454559463529fa7a49dcb Mon Sep 17 00:00:00 2001 From: Devon Rueckner Date: Tue, 20 Apr 2021 20:05:11 -0700 Subject: [PATCH] kswitch - hedge api --- lib/KSwitch.vue | 58 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/lib/KSwitch.vue b/lib/KSwitch.vue index f6ef49e41..033362ed7 100644 --- a/lib/KSwitch.vue +++ b/lib/KSwitch.vue @@ -42,47 +42,88 @@ export default { name: 'KSwitch', props: { + /** + * Current value of the switch state: on or off + */ + value: { + type: Boolean, + required: true, + }, + /** + * @ignore + * does this need to be exposed? + */ name: { type: String, default: null, }, + /** + * If provided, show a text label next to the switch + */ label: { type: String, - required: true, + default: null, }, + /** + * @ignore + * does this need to be exposed? + */ tabindex: { type: [String, Number], default: null, }, - value: { - type: Boolean, - required: true, - }, + /** + * @ignore + * might not be used + */ trueValue: { type: Boolean, default: true, }, + /** + * @ignore + * might not be used + */ falseValue: { type: Boolean, default: false, }, + /** + * @ignore + * might not be used + */ submittedValue: { type: String, default: 'on', // HTML default }, + /** + * @ignore + * seems redundant with 'value' + */ checked: { type: Boolean, default: false, }, + /** + * @ignore + * not used + */ color: { type: String, // 'primary' by default, but could add more later default: 'primary', }, + /** + * @ignore + * not used + */ switchPosition: { type: String, default: 'left', // 'left' or 'right' }, + /** + * Whether or not the switch is disabled + */ disabled: { type: Boolean, default: false, @@ -118,8 +159,15 @@ onClick(e) { const isCheckedPrevious = this.isChecked; const isChecked = e.target.checked; + /** + * Emitted on each change with new `value` + */ this.$emit('input', isChecked ? this.trueValue : this.falseValue, e); if (isCheckedPrevious !== isChecked) { + /** + * @ignore + * does this need to be exposed? + */ this.$emit('change', isChecked ? this.trueValue : this.falseValue, e); } },