-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui-lib(new-component): added text input component in the c-lib
- Loading branch information
1 parent
401f13f
commit aad8d84
Showing
14 changed files
with
428 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<template> | ||
<h2>Default</h2> | ||
|
||
<c-input-text value="qsd" /> | ||
|
||
<h2>With placeholder</h2> | ||
|
||
<c-input-text placeholder="Placeholder" /> | ||
|
||
<h2>With label</h2> | ||
|
||
<c-input-text label="Label" mb-2 /> | ||
<c-input-text label="Label" mb-2 label-position="left" /> | ||
<c-input-text label="Label" mb-2 label-position="left" label-width="100px" /> | ||
<c-input-text label="Label" mb-2 label-position="left" label-width="100px" label-align="right" /> | ||
|
||
<h2>Readonly</h2> | ||
|
||
<c-input-text value="value" readonly /> | ||
|
||
<h2>Disabled</h2> | ||
|
||
<c-input-text value="value" disabled /> | ||
|
||
<h2>Validation</h2> | ||
|
||
<c-input-text | ||
v-model:value="value" | ||
:validation-rules="[{ message: 'Length must be > 10', validator: (value) => value.length > 10 }]" | ||
/> | ||
|
||
<h2>Clearable</h2> | ||
|
||
<c-input-text v-model:value="value" clearable /> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
const value = ref('value'); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { describe, expect, it, beforeEach } from 'vitest'; | ||
import { shallowMount } from '@vue/test-utils'; | ||
import { setActivePinia, createPinia } from 'pinia'; | ||
import _ from 'lodash'; | ||
import CInputText from './c-input-text.vue'; | ||
|
||
describe('CInputText', () => { | ||
beforeEach(() => { | ||
setActivePinia(createPinia()); | ||
}); | ||
|
||
it('Renders a label', () => { | ||
const wrapper = shallowMount(CInputText, { | ||
props: { | ||
label: 'Label', | ||
}, | ||
}); | ||
|
||
expect(wrapper.get('.label').text()).to.equal('Label'); | ||
}); | ||
|
||
it('Renders a placeholder', () => { | ||
const wrapper = shallowMount(CInputText, { | ||
props: { | ||
placeholder: 'Placeholder', | ||
}, | ||
}); | ||
|
||
expect(wrapper.get('.input').attributes('placeholder')).to.equal('Placeholder'); | ||
}); | ||
|
||
it('Renders a value', () => { | ||
const wrapper = shallowMount(CInputText, { | ||
props: { | ||
value: 'Value', | ||
}, | ||
}); | ||
|
||
expect(wrapper.vm.value).to.equal('Value'); | ||
}); | ||
|
||
it('Renders a provided id', () => { | ||
const wrapper = shallowMount(CInputText, { | ||
props: { | ||
id: 'id', | ||
}, | ||
}); | ||
|
||
expect(wrapper.get('.input').attributes('id')).to.equal('id'); | ||
}); | ||
|
||
it('updates value on input', async () => { | ||
const wrapper = shallowMount(CInputText); | ||
|
||
await wrapper.get('input').setValue('Hello'); | ||
|
||
expect(_.get(wrapper.emitted(), 'update:value.0.0')).to.equal('Hello'); | ||
}); | ||
|
||
it('cannot be edited when disabled', async () => { | ||
const wrapper = shallowMount(CInputText, { | ||
props: { | ||
disabled: true, | ||
}, | ||
}); | ||
|
||
await wrapper.get('input').setValue('Hello'); | ||
|
||
expect(_.get(wrapper.emitted(), 'update:value')).toBeUndefined(); | ||
}); | ||
|
||
it('renders a feedback message for invalid rules', async () => { | ||
const wrapper = shallowMount(CInputText, { | ||
props: { rules: [{ validator: () => false, message: 'Message' }] }, | ||
}); | ||
|
||
expect(wrapper.get('.feedback').text()).to.equal('Message'); | ||
}); | ||
|
||
it('feedback does not render for valid rules', async () => { | ||
const wrapper = shallowMount(CInputText, { | ||
props: { rules: [{ validator: () => true, message: 'Message' }] }, | ||
}); | ||
|
||
expect(wrapper.find('.feedback').exists()).to.equal(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { defineThemes } from '../theme/theme.models'; | ||
|
||
export const { useTheme } = defineThemes({ | ||
dark: { | ||
backgroundColor: '#333333', | ||
borderColor: '#333333', | ||
|
||
focus: { | ||
backgroundColor: '#1ea54c1a', | ||
}, | ||
}, | ||
light: { | ||
backgroundColor: '#ffffff', | ||
borderColor: '#e0e0e69e', | ||
|
||
focus: { | ||
backgroundColor: '#ffffff', | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.