Skip to content

Commit

Permalink
fix(editor): Fix ElButton overrides (#5605)
Browse files Browse the repository at this point in the history
* fix(editor): Fix ElButton overrides

* fix(editor): Fix ElButton overrides
  • Loading branch information
cstuncsik committed Mar 3, 2023
1 parent 523fa71 commit 2eba050
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,19 @@ describe('components', () => {
});

describe('overrides', () => {
it('should render correctly', () => {
it('should use default (`primary`) type when no type is given', () => {
const wrapper = render(ElButton, {
props: {
icon: 'plus-circle',
},
slots,
stubs,
});

expect(wrapper.html()).toMatchSnapshot();
});

it('should use given (`secondary`) type', () => {
const wrapper = render(ElButton, {
props: {
icon: 'plus-circle',
Expand All @@ -71,6 +83,32 @@ describe('components', () => {

expect(wrapper.html()).toMatchSnapshot();
});

it('should render as `secondary` when `text` is given as type', () => {
const wrapper = render(ElButton, {
props: {
icon: 'plus-circle',
type: 'text',
},
slots,
stubs,
});

expect(wrapper.html()).toMatchSnapshot();
});

it('should render as `tertiary` when `info` is given as type', () => {
const wrapper = render(ElButton, {
props: {
icon: 'plus-circle',
type: 'info',
},
slots,
stubs,
});

expect(wrapper.html()).toMatchSnapshot();
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Vitest Snapshot v1

exports[`components > N8nButton > overrides > should render correctly 1`] = `"<button aria-disabled=\\"false\\" aria-busy=\\"false\\" aria-live=\\"polite\\" class=\\"button button secondary medium icon\\" icon=\\"plus-circle\\" type=\\"secondary\\"><span class=\\"icon\\"><n8n-icon-stub icon=\\"plus-circle\\" size=\\"medium\\"></n8n-icon-stub></span><span>Button</span></button>"`;
exports[`components > N8nButton > overrides > should render as \`secondary\` when \`text\` is given as type 1`] = `"<button aria-disabled=\\"false\\" aria-busy=\\"false\\" aria-live=\\"polite\\" class=\\"button button secondary medium icon\\" icon=\\"plus-circle\\"><span class=\\"icon\\"><n8n-icon-stub icon=\\"plus-circle\\" size=\\"medium\\"></n8n-icon-stub></span><span>Button</span></button>"`;
exports[`components > N8nButton > overrides > should render as \`tertiary\` when \`info\` is given as type 1`] = `"<button aria-disabled=\\"false\\" aria-busy=\\"false\\" aria-live=\\"polite\\" class=\\"button button tertiary medium icon\\" icon=\\"plus-circle\\"><span class=\\"icon\\"><n8n-icon-stub icon=\\"plus-circle\\" size=\\"medium\\"></n8n-icon-stub></span><span>Button</span></button>"`;
exports[`components > N8nButton > overrides > should use default (\`primary\`) type when no type is given 1`] = `"<button aria-disabled=\\"false\\" aria-busy=\\"false\\" aria-live=\\"polite\\" class=\\"button button primary medium icon\\" icon=\\"plus-circle\\"><span class=\\"icon\\"><n8n-icon-stub icon=\\"plus-circle\\" size=\\"medium\\"></n8n-icon-stub></span><span>Button</span></button>"`;
exports[`components > N8nButton > overrides > should use given (\`secondary\`) type 1`] = `"<button aria-disabled=\\"false\\" aria-busy=\\"false\\" aria-live=\\"polite\\" class=\\"button button secondary medium icon\\" icon=\\"plus-circle\\"><span class=\\"icon\\"><n8n-icon-stub icon=\\"plus-circle\\" size=\\"medium\\"></n8n-icon-stub></span><span>Button</span></button>"`;
exports[`components > N8nButton > props > icon > should render icon button 1`] = `"<button aria-disabled=\\"false\\" aria-busy=\\"false\\" aria-live=\\"polite\\" class=\\"button button primary medium icon\\"><span class=\\"icon\\"><n8n-icon-stub icon=\\"plus-circle\\" size=\\"medium\\"></n8n-icon-stub></span><span>Button</span></button>"`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import N8nButton from '../Button.vue';
const classToTypeMap = {
'btn--cancel': 'secondary',
'el-picker-panel__link-btn': 'secondary',
};
export default Vue.extend({
Expand All @@ -18,16 +19,29 @@ export default Vue.extend({
},
computed: {
attrs() {
let type = 'primary';
let type = this.$attrs.type || 'primary';
/* Element UI Button can have 'text' or 'info' type which is not supported by n8n-button
so render it as 'secondary' or 'tertiary' */
if (type === 'text') {
type = 'secondary';
}
if (type === 'info') {
type = 'tertiary';
}
Object.entries(classToTypeMap).forEach(([className, mappedType]) => {
if (this.$refs.button && (this.$refs.button as Vue).$el.classList.contains(className)) {
type = mappedType;
}
});
delete this.$attrs.type;
return {
type,
...this.$attrs,
type,
};
},
},
Expand Down

0 comments on commit 2eba050

Please sign in to comment.