From 823e88500c35508d6322242bca5749d711fb2b31 Mon Sep 17 00:00:00 2001 From: Csaba Tuncsik Date: Thu, 11 May 2023 15:28:05 +0200 Subject: [PATCH] feat(editor): Add color picker design system component (#6179) * feat(editor): Add color picker design system component * fix(editor): remove type imports * fix(editor): fix v-model * fix(editor): fix props * fix(editor): color picker view model * test(editor): add some basic test to color picker * fix(editor): update color picker styles * fix(editor): color picker view model * test(editor): update snapshot --- .../N8nColorPicker/ColorPicker.stories.ts | 59 ++++ .../components/N8nColorPicker/ColorPicker.vue | 99 +++++++ .../__tests__/ColorPicker.spec.ts | 16 ++ .../__snapshots__/ColorPicker.spec.ts.snap | 269 ++++++++++++++++++ .../src/components/N8nColorPicker/index.ts | 3 + .../design-system/src/components/index.ts | 1 + packages/design-system/src/plugin.ts | 2 + 7 files changed, 449 insertions(+) create mode 100644 packages/design-system/src/components/N8nColorPicker/ColorPicker.stories.ts create mode 100644 packages/design-system/src/components/N8nColorPicker/ColorPicker.vue create mode 100644 packages/design-system/src/components/N8nColorPicker/__tests__/ColorPicker.spec.ts create mode 100644 packages/design-system/src/components/N8nColorPicker/__tests__/__snapshots__/ColorPicker.spec.ts.snap create mode 100644 packages/design-system/src/components/N8nColorPicker/index.ts diff --git a/packages/design-system/src/components/N8nColorPicker/ColorPicker.stories.ts b/packages/design-system/src/components/N8nColorPicker/ColorPicker.stories.ts new file mode 100644 index 0000000000000..65ac0d6dfe561 --- /dev/null +++ b/packages/design-system/src/components/N8nColorPicker/ColorPicker.stories.ts @@ -0,0 +1,59 @@ +import { action } from '@storybook/addon-actions'; +import type { StoryFn } from '@storybook/vue'; +import N8nColorPicker from './ColorPicker.vue'; + +export default { + title: 'Atoms/ColorPicker', + component: N8nColorPicker, + argTypes: { + disabled: { + control: 'boolean', + }, + size: { + control: 'select', + options: ['mini', 'small', 'medium', 'large'], + }, + showAlpha: { + control: 'boolean', + }, + colorFormat: { + control: 'select', + options: ['hsl', 'hsv', 'hex', 'rgb'], + }, + popperClass: { + control: 'text', + }, + predefine: { + control: 'array', + }, + }, +}; + +const methods = { + onChange: action('change'), + onActiveChange: action('active-change'), + onInput: action('input'), +}; + +const DefaultTemplate: StoryFn = (args, { argTypes }) => ({ + props: Object.keys(argTypes), + components: { + N8nColorPicker, + }, + data: () => ({ + color: null, + }), + template: + '', + methods, +}); + +export const Default = DefaultTemplate.bind({}); +Default.args = { + disabled: false, + size: 'medium', + showAlpha: false, + colorFormat: '', + popperClass: '', + showInput: true, +}; diff --git a/packages/design-system/src/components/N8nColorPicker/ColorPicker.vue b/packages/design-system/src/components/N8nColorPicker/ColorPicker.vue new file mode 100644 index 0000000000000..5a52c6d109350 --- /dev/null +++ b/packages/design-system/src/components/N8nColorPicker/ColorPicker.vue @@ -0,0 +1,99 @@ + + + + + diff --git a/packages/design-system/src/components/N8nColorPicker/__tests__/ColorPicker.spec.ts b/packages/design-system/src/components/N8nColorPicker/__tests__/ColorPicker.spec.ts new file mode 100644 index 0000000000000..0367928bc4beb --- /dev/null +++ b/packages/design-system/src/components/N8nColorPicker/__tests__/ColorPicker.spec.ts @@ -0,0 +1,16 @@ +import { render } from '@testing-library/vue'; +import N8nColorPicker from '../ColorPicker.vue'; + +describe('components', () => { + describe('N8nColorPicker', () => { + it('should render with input', () => { + const { container } = render(N8nColorPicker); + expect(container).toMatchSnapshot(); + }); + + it('should render without input', () => { + const { container } = render(N8nColorPicker, { props: { showInput: false } }); + expect(container).toMatchSnapshot(); + }); + }); +}); diff --git a/packages/design-system/src/components/N8nColorPicker/__tests__/__snapshots__/ColorPicker.spec.ts.snap b/packages/design-system/src/components/N8nColorPicker/__tests__/__snapshots__/ColorPicker.spec.ts.snap new file mode 100644 index 0000000000000..1e4756cfee719 --- /dev/null +++ b/packages/design-system/src/components/N8nColorPicker/__tests__/__snapshots__/ColorPicker.spec.ts.snap @@ -0,0 +1,269 @@ +// Vitest Snapshot v1 + +exports[`components > N8nColorPicker > should render with input 1`] = ` +
+ +
+ +
+ + + + +
+ +