diff --git a/package-lock.json b/package-lock.json index 5f03d521..b382cfe2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@karnama/vueish", - "version": "0.18.0", + "version": "0.19.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@karnama/vueish", - "version": "0.18.0", + "version": "0.19.0", "license": "mit", "devDependencies": { "@babel/core": "^7.13.16", diff --git a/package.json b/package.json index 2cb0c02f..a52f5152 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@karnama/vueish", - "version": "0.18.0", + "version": "0.19.0", "files": [ "dist", "types" diff --git a/src/assets/styles/main.scss b/src/assets/styles/main.scss index 32b557e3..01925b16 100755 --- a/src/assets/styles/main.scss +++ b/src/assets/styles/main.scss @@ -42,3 +42,13 @@ color: theme('colors.red.500') !important; } } + +.ui-error-text { + @extend .text-color-error; + @apply text-sm mt-1; +} + +.ui-help-text { + @extend .text-color-muted; + @apply text-gray-400 text-sm mt-1; +} diff --git a/src/components/input/Demo.vue b/src/components/input/Demo.vue index 3e0adad9..88639710 100644 --- a/src/components/input/Demo.vue +++ b/src/components/input/Demo.vue @@ -175,6 +175,27 @@ type="number" placeholder="Placeholder text." label="Placeholder" /> + + + + + + @@ -200,6 +221,8 @@ export default defineComponent({ const suffixProp = ref('100'); const suffixSlot = ref('Feather-weight'); const placeholder = ref(null); + const helpProp = ref('I\'m an input!'); + const helpSlot = ref('I\'m an input!'); const large = ref(false); const small = ref(false); const error = ref(''); @@ -224,6 +247,8 @@ export default defineComponent({ suffixProp, suffixSlot, placeholder, + helpProp, + helpSlot, large, error, loading, diff --git a/src/components/input/UIInput.test.ts b/src/components/input/UIInput.test.ts index 63660290..4f78988c 100644 --- a/src/components/input/UIInput.test.ts +++ b/src/components/input/UIInput.test.ts @@ -320,4 +320,83 @@ describe('UIInput', () => { expect(wrapper.lastEventValue()).toBeUndefined(); }); }); + + it('should display the error text when passed as a slot', () => { + const error = 'error'; + const errorContainer = `${error}`; + + const wrapper = mount(UIInput, { + props: { + modelValue: '', + name: 'input' + }, + slots: { + error: errorContainer + } + }); + + expect(wrapper.get('#error').text()).toBe(error); + }); + + it('should display the error text when passed as a prop', () => { + const error = 'error'; + + const wrapper = mount(UIInput, { + props: { + modelValue: '', + name: 'input', + error + } + }); + + expect(wrapper.get('.ui-error-text').text()).toBe(error); + }); + + it('should display the help text when passed as a slot', () => { + const help = 'help'; + const helpContainer = `${help}`; + + const wrapper = mount(UIInput, { + props: { + modelValue: '', + name: 'input' + }, + slots: { + help: helpContainer + } + }); + + expect(wrapper.get('#help').text()).toBe(help); + }); + + it('should display the help text when passed as a prop', () => { + const help = 'help'; + + const wrapper = mount(UIInput, { + props: { + modelValue: '', + name: 'input', + help + } + }); + + expect(wrapper.get('.ui-help-text').text()).toBe(help); + }); + + it('should display the only error text when both help and error are passed as prop', () => { + const help = 'help'; + const error = 'error'; + + const wrapper = mount(UIInput, { + props: { + modelValue: '', + name: 'input', + help, + error + } + }); + + expect(wrapper.find('.ui-help-text').exists()).toBe(false); + expect(wrapper.get('.ui-error-text').text()).toBe(error); + }); }); diff --git a/src/components/input/UIInput.vue b/src/components/input/UIInput.vue index f3a9a43c..76363879 100644 --- a/src/components/input/UIInput.vue +++ b/src/components/input/UIInput.vue @@ -119,10 +119,16 @@ -

+

{{ error }}

+ + +

+ {{ help }} +

+
@@ -226,6 +232,14 @@ export default defineComponent({ type: [Number, String] }, + + /** + * Help message to show below the input. + */ + help: { + type: String + }, + large, small, prefix,