-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(input): DLT-1945 add clear slot prop to rightIcon (#455)
- Loading branch information
1 parent
606cfb3
commit 0f90dd4
Showing
7 changed files
with
305 additions
and
5 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
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
131 changes: 131 additions & 0 deletions
131
packages/dialtone-vue2/components/input/input_search_variant.story.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,131 @@ | ||
<template> | ||
<dt-input | ||
ref="input" | ||
v-model="inputValue" | ||
autocomplete="on" | ||
:type="$attrs.type" | ||
:messages="$attrs.messages" | ||
:size="$attrs.size" | ||
:label="$attrs.label" | ||
:messages-child-props="$attrs.messagesChildProps" | ||
:name="$attrs.name" | ||
:disabled="$attrs.disabled" | ||
:show-messages="$attrs.showMessages" | ||
:messages-class="$attrs.messagesClass" | ||
:placeholder="$attrs.placeholder" | ||
:input-class="$attrs.inputClass" | ||
:retain-warning="$attrs.retainWarning" | ||
:input-wrapper-class="$attrs.inputWrapperClass" | ||
:current-length="$attrs.currentLength" | ||
:validate="validationConfig" | ||
@blur="$attrs.onBlur" | ||
@input="$attrs.onInput" | ||
@clear="$attrs.onClear" | ||
@focus="$attrs.onFocus" | ||
@focusin="$attrs.onFocusIn" | ||
@focusout="$attrs.onFocusOut" | ||
@update:length="updateLength" | ||
@update:invalid="$attrs.onUpdateIsInvalid" | ||
> | ||
<template | ||
v-if="$attrs.labelSlot" | ||
#labelSlot | ||
> | ||
<span v-html="$attrs.labelSlot" /> | ||
</template> | ||
<template | ||
v-if="$attrs.description" | ||
#description | ||
> | ||
<span v-html="$attrs.description" /> | ||
</template> | ||
<template #leftIcon="{ iconSize }"> | ||
<dt-icon | ||
name="search" | ||
:size="iconSize" | ||
/> | ||
</template> | ||
<template | ||
v-if="inputValue.length !== 0" | ||
#rightIcon="{ clear }" | ||
> | ||
<dt-button | ||
kind="muted" | ||
importance="clear" | ||
size="xs" | ||
circle | ||
aria-label="Clear search" | ||
@click="clear" | ||
> | ||
<template #icon="{ iconSize }"> | ||
<dt-icon | ||
name="close" | ||
:size="iconSize" | ||
/> | ||
</template> | ||
</dt-button> | ||
</template> | ||
</dt-input> | ||
</template> | ||
|
||
<script> | ||
import DtInput from './input.vue'; | ||
import { DtButton } from '@/components/button'; | ||
import { DtIcon } from '@/components/icon'; | ||
export default { | ||
name: 'InputSearchVariant', | ||
components: { DtInput, DtIcon, DtButton }, | ||
inheritAttrs: false, | ||
data () { | ||
return { | ||
inputValue: '', | ||
inputLength: 0, | ||
}; | ||
}, | ||
computed: { | ||
validationMessage () { | ||
const remainingCharacters = this.$attrs.validate?.length?.max - this.inputLength; | ||
if (remainingCharacters < 0) { | ||
return `${Math.abs(remainingCharacters)} characters over limit`; | ||
} else { | ||
return `${remainingCharacters} characters left`; | ||
} | ||
}, | ||
validationConfig () { | ||
if (!this?.$attrs?.validate?.length) { | ||
return null; | ||
} | ||
// Deep clone validate object | ||
const validateConfigData = JSON.parse(JSON.stringify(this.$attrs.validate)); | ||
// Adds validation message | ||
validateConfigData.length.message = this?.$attrs?.validate?.length?.message | ||
? this.$attrs.validate.length.message | ||
: this.validationMessage; | ||
return validateConfigData; | ||
}, | ||
}, | ||
watch: { | ||
modelValue (val) { | ||
this.inputValue = val; | ||
}, | ||
}, | ||
methods: { | ||
updateLength ($event) { | ||
this.inputLength = $event; | ||
this.$attrs.onUpdateLength($event); | ||
}, | ||
}, | ||
}; | ||
</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
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
Oops, something went wrong.