-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds revealable-input component (#46)
- Loading branch information
1 parent
288285f
commit 0a05ff6
Showing
7 changed files
with
161 additions
and
7 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
39 changes: 39 additions & 0 deletions
39
src/components/forms/revealable-text-field/RevealableTextField.spec.ts
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 @@ | ||
import { type ComponentMountingOptions, mount } from '@vue/test-utils'; | ||
import { describe, expect, it } from 'vitest'; | ||
import RevealableTextField from '@/components/forms/revealable-text-field/RevealableTextField.vue'; | ||
|
||
const createWrapper = ( | ||
options?: ComponentMountingOptions<typeof RevealableTextField> | ||
) => | ||
mount(RevealableTextField, { ...options, global: { stubs: ['rui-icon'] } }); | ||
|
||
describe('Forms/RevealableTextField', () => { | ||
it('renders properly', () => { | ||
const label = 'Password'; | ||
const wrapper = createWrapper({ | ||
props: { | ||
label, | ||
}, | ||
}); | ||
expect(wrapper.find('label').text()).toContain(label); | ||
}); | ||
|
||
it('toggle the type', async () => { | ||
const wrapper = createWrapper(); | ||
|
||
expect(wrapper.find('input').attributes().type).toBe('password'); | ||
expect(wrapper.find('rui-icon-stub').attributes().name).toBe( | ||
'eye-off-line' | ||
); | ||
|
||
await wrapper.find('button').trigger('click'); | ||
expect(wrapper.find('input').attributes().type).toBe('text'); | ||
expect(wrapper.find('rui-icon-stub').attributes().name).toBe('eye-line'); | ||
|
||
await wrapper.find('button').trigger('click'); | ||
expect(wrapper.find('input').attributes().type).toBe('password'); | ||
expect(wrapper.find('rui-icon-stub').attributes().name).toBe( | ||
'eye-off-line' | ||
); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
src/components/forms/revealable-text-field/RevealableTextField.stories.ts
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,49 @@ | ||
import { type Meta, type StoryFn } from '@storybook/vue3'; | ||
import { contextColors } from '@/consts/colors'; | ||
import RevealableTextField from './RevealableTextField.vue'; | ||
|
||
const render: StoryFn<typeof RevealableTextField> = (_, { argTypes }) => ({ | ||
components: { RevealableTextField }, | ||
props: Object.keys(argTypes), | ||
template: `<RevealableTextField v-bind="$props" />`, | ||
}); | ||
|
||
const meta: Meta<typeof RevealableTextField> = { | ||
title: 'Components/Forms/RevealableTextField', | ||
component: RevealableTextField, | ||
tags: ['autodocs'], | ||
render, | ||
argTypes: { | ||
modelValue: { control: 'text' }, | ||
label: { control: 'text' }, | ||
placeholder: { control: 'text' }, | ||
hint: { control: 'text' }, | ||
appendIcon: { control: 'text' }, | ||
prependIcon: { control: 'text' }, | ||
errorMessages: { control: 'text' }, | ||
hideDetails: { control: 'boolean' }, | ||
dense: { control: 'boolean' }, | ||
variant: { | ||
control: 'select', | ||
options: ['default', 'filled', 'outlined'], | ||
table: { category: 'State' }, | ||
}, | ||
disabled: { control: 'boolean', table: { category: 'State' } }, | ||
color: { control: 'select', options: contextColors }, | ||
}, | ||
parameters: { | ||
docs: { | ||
controls: { exclude: ['default'] }, | ||
}, | ||
}, | ||
}; | ||
|
||
export const Default = { | ||
args: { | ||
label: 'Password', | ||
placeholder: 'Placeholder', | ||
variant: 'outlined', | ||
}, | ||
}; | ||
|
||
export default meta; |
36 changes: 36 additions & 0 deletions
36
src/components/forms/revealable-text-field/RevealableTextField.vue
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,36 @@ | ||
<script setup lang="ts"> | ||
import { default as RuiTextField } from '@/components/forms/text-field/TextField.vue'; | ||
import { default as RuiButton } from '@/components/buttons/Button.vue'; | ||
import { default as RuiIcon } from '@/components/icons/Icon.vue'; | ||
const hidden: Ref<boolean> = ref(true); | ||
const attrs = useAttrs(); | ||
const slots = useSlots(); | ||
</script> | ||
|
||
<template> | ||
<rui-text-field v-bind="attrs" :type="hidden ? 'password' : 'text'"> | ||
<template v-if="slots.prepend" #prepend> | ||
<slot name="prepend" /> | ||
</template> | ||
<template #append> | ||
<div class="flex items-center"> | ||
<rui-button | ||
variant="text" | ||
icon | ||
class="-mr-1 !p-2" | ||
@click="hidden = !hidden" | ||
> | ||
<rui-icon | ||
class="text-black/[.54] dark:text-white/[.56]" | ||
size="20" | ||
:name="hidden ? 'eye-off-line' : 'eye-line'" | ||
/> | ||
</rui-button> | ||
|
||
<slot name="append" /> | ||
</div> | ||
</template> | ||
</rui-text-field> | ||
</template> |
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
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