Skip to content

Commit

Permalink
refactor(editor): Create N8nCheckbox Vue component (#3678)
Browse files Browse the repository at this point in the history
* ✨ Implementing N8nCheckbox Vue component

* ✨ Added checkbox support to N8nFormInput component

* 👌 Updating n8n-checkbox component so it supports indeterminate state and input event

* 💄 Adding the `labelSize` property to the `N8nCheckbox` component
  • Loading branch information
MiloradFilipovic authored Jul 11, 2022
1 parent 6f95121 commit a847190
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* tslint:disable:variable-name */
import N8nCheckbox from "./Checkbox.vue";
import { StoryFn } from '@storybook/vue';
import { action } from '@storybook/addon-actions';

export default {
title: 'Atoms/Checkbox',
component: N8nCheckbox,
};

const methods = {
onInput: action('input'),
onFocus: action('focus'),
onChange: action('change'),
};

const DefaultTemplate: StoryFn = (args, { argTypes }) => ({
props: Object.keys(argTypes),
components: {
N8nCheckbox,
},
data: () => ({
isChecked: false,
}),
template: '<n8n-checkbox v-model="isChecked" v-bind="$props" @input="onInput"></n8n-checkbox>',
methods,
});

export const Default = DefaultTemplate.bind({});
Default.args = {
label: 'This is a default checkbox',
tooltipText: 'Checkbox tooltip',
disabled: false,
indeterminate: false,
size: 'small',
};
66 changes: 66 additions & 0 deletions packages/design-system/src/components/N8nCheckbox/Checkbox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<template>
<el-checkbox
v-bind="$props"
:disabled="disabled"
:indeterminate="indeterminate"
:value="value"
@change="onChange"
>
<n8n-input-label
:label="label"
:tooltipText="tooltipText"
:bold="false"
:size="labelSize"
></n8n-input-label>
</el-checkbox>
</template>

<script lang="ts">
import Vue from 'vue';
import ElCheckbox from 'element-ui/lib/checkbox';
import N8nInputLabel from '../N8nInputLabel';
export default Vue.extend({
name: 'n8n-checkbox',
components: {
ElCheckbox,
N8nInputLabel,
},
props: {
label: {
type: String,
required: true,
},
disabled: {
type: Boolean,
default: false,
},
tooltipText: {
type: String,
required: false,
},
indeterminate: {
type: Boolean,
default: false,
},
value: {
type: Boolean,
default: false,
},
labelSize: {
type: String,
default: 'medium',
validator: (value: string): boolean =>
['small', 'medium'].includes(value),
},
},
methods: {
onChange(e) {
this.$emit("input", e);
},
}
});
</script>

<style lang="scss" module>
</style>
3 changes: 3 additions & 0 deletions packages/design-system/src/components/N8nCheckbox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import N8nCheckbox from './Checkbox.vue';

export default N8nCheckbox;
17 changes: 16 additions & 1 deletion packages/design-system/src/components/N8nFormInput/FormInput.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<template>
<n8n-input-label :label="label" :tooltipText="tooltipText" :required="required && showRequiredAsterisk">
<n8n-checkbox
v-if="type === 'checkbox'"
v-bind="$props"
@input="onInput"
@focus="onFocus"
ref="input"
></n8n-checkbox>
<n8n-input-label v-else :label="label" :tooltipText="tooltipText" :required="required && showRequiredAsterisk">
<div :class="showErrors ? $style.errorInput : ''" @keydown.stop @keydown.enter="onEnter">
<slot v-if="hasDefaultSlot"></slot>
<n8n-select
Expand Down Expand Up @@ -56,6 +63,7 @@ import N8nInput from '../N8nInput';
import N8nSelect from '../N8nSelect';
import N8nOption from '../N8nOption';
import N8nInputLabel from '../N8nInputLabel';
import N8nCheckbox from '../N8nCheckbox';
import { getValidationError, VALIDATORS } from './validators';
import { Rule, RuleGroup, IValidator } from "../../types";
Expand All @@ -70,6 +78,7 @@ export default mixins(Locale).extend({
N8nInputLabel,
N8nOption,
N8nSelect,
N8nCheckbox,
},
data() {
return {
Expand Down Expand Up @@ -135,6 +144,12 @@ export default mixins(Locale).extend({
focusInitially: {
type: Boolean,
},
labelSize: {
type: String,
default: 'medium',
validator: (value: string): boolean =>
['small', 'medium'].includes(value),
},
},
mounted() {
this.$emit('validate', !this.validationError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ FormInputs.args = {
],
},
},
{
name: 'agree',
properties: {
type: 'checkbox',
label: 'Signup for newsletter Signup for newsletter Signup for newsletter vSignup for newsletter Signup for newsletter Signup for newsletter Signup for newsletter Signup for newsletter Signup for newsletter Signup for newsletter v vSignup for newsletter Signup for newsletter Signup for newsletter Signup for newsletter',
labelSize: 'small',
tooltipText: 'Check this if you agree to be contacted by our marketing team Check this if you agree to be contacted by our marketing team Check this if you agree to be contacted by our marketing team Check this if you agree to be contacted by our marketing team'
}
}
],
};

0 comments on commit a847190

Please sign in to comment.