Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(vue3): Nc*Field rename default to icon slot #4543

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/components/NcInputField/NcInputField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ For a list of all available props and attributes, please check the [HTMLInputEle
:class="[inputClass,
{
'input-field__input--trailing-icon': showTrailingButton || hasTrailingIcon,
'input-field__input--leading-icon': hasLeadingIcon,
'input-field__input--leading-icon': !!$slots.icon,
'input-field__input--label-outside': labelOutside,
'input-field__input--success': success,
'input-field__input--error': error,
Expand All @@ -59,16 +59,16 @@ For a list of all available props and attributes, please check the [HTMLInputEle
class="input-field__label"
:class="[{
'input-field__label--trailing-icon': showTrailingButton || hasTrailingIcon,
'input-field__label--leading-icon': hasLeadingIcon,
'input-field__label--leading-icon': !!$slots.icon,
}]"
:for="computedId">
{{ label }}
</label>

<!-- Leading icon -->
<div v-show="hasLeadingIcon" class="input-field__icon input-field__icon--leading">
<div v-show="!!$slots.icon" class="input-field__icon input-field__icon--leading">
<!-- Leading material design icon in the text field, set the size to 18 -->
<slot />
<slot name="icon" />
</div>

<!-- trailing button -->
Expand Down Expand Up @@ -109,7 +109,6 @@ For a list of all available props and attributes, please check the [HTMLInputEle
<script>
import NcButton from '../NcButton/index.js'
import GenRandomId from '../../utils/GenRandomId.js'
import isSlotPopulated from '../../utils/isSlotPopulated.js'

import AlertCircle from 'vue-material-design-icons/AlertCircleOutline.vue'
import Check from 'vue-material-design-icons/Check.vue'
Expand Down Expand Up @@ -266,10 +265,6 @@ export default {
return 'input' + GenRandomId()
},

hasLeadingIcon() {
return isSlotPopulated(this.$slots.default?.())
},

hasTrailingIcon() {
return this.success
},
Expand Down
18 changes: 15 additions & 3 deletions src/components/NcPasswordField/NcPasswordField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@ General purpose password field component.
label="Good new password"
:success="true"
placeholder="Min. 12 characters"
helper-text="Password is secure" />
helper-text="Password is secure">
<template #icon>
<Lock :size="20" />
</template>
</NcPasswordField>

<NcPasswordField v-model:value="text5"
:disabled="true"
label="Disabled" />
</div>
</template>
<script>
import Lock from 'vue-material-design-icons/Lock'

export default {
data() {
return {
Expand All @@ -70,6 +76,10 @@ export default {
text5: '',
}
},

components: {
Lock,
},
}
</script>
<style lang="scss" scoped>
Expand Down Expand Up @@ -107,8 +117,10 @@ export default {
:minlength="rules.minlength"
@trailing-button-click="togglePasswordVisibility"
@input="handleInput">
<!-- Default slot for the leading icon -->
<slot />
<template v-if="!!$slots.icon" #icon>
<!-- Default slot for the leading icon -->
<slot name="icon" />
</template>
<template #trailing-button-icon>
<Eye v-if="isPasswordHidden" :size="18" />
<EyeOff v-else :size="18" />
Expand Down
14 changes: 10 additions & 4 deletions src/components/NcTextField/NcTextField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ and `minlength`.
trailing-button-icon="close"
:show-trailing-button="text1 !== ''"
@trailing-button-click="clearText">
<Magnify :size="20" />
<template #icon>
<Magnify :size="20" />
</template>
</NcTextField>
<NcTextField :value.sync="text4"
label="Internal label"
placeholder="That can be used together with placeholder"
trailing-button-icon="close"
:show-trailing-button="text4 !== ''"
@trailing-button-click="clearText">
<Lock :size="20" />
<template #icon>
<Lock :size="20" />
</template>
</NcTextField>
<NcTextField v-model:value="text2"
label="Success state"
Expand Down Expand Up @@ -136,8 +140,10 @@ export default {
ref="inputField"
:trailing-button-label="clearTextLabel"
@input="handleInput">
<!-- Default slot for the leading icon -->
<slot />
<template v-if="!!$slots.icon" #icon>
<!-- Default slot for the leading icon -->
<slot name="icon" />
</template>

<!-- Trailing icon slot, except for search type input as the browser already adds a trailing close icon -->
<template v-if="type !== 'search'" #trailing-button-icon>
Expand Down
Loading