Использование
Компонент AuthForm собран на Form: форма входа для внешнего приложения или личного кабинета. Её кладут прямо на страницу или в PageCard.
Поля
Форма строится по пропсу fields, состояние она хранит сама.
Пропс fields — массив объектов со свойствами:
name: stringtype: 'checkbox' | 'select' | 'otp' | 'InputHTMLAttributes['type']'
Свойство type выбирает поле и его пропсы: checkbox — пропсы Checkbox, select — SelectMenu, otp — PinInput, остальные типы — Input.
Каждому полю можно передать и любой пропс FormField.
<script setup lang="ts">
import type { AuthFormField } from '@bxshefby/b24ui-nuxt'
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'email',
label: 'Эл. почта',
placeholder: 'Введите эл. почту',
required: true
},
{
name: 'password',
type: 'password',
label: 'Пароль',
placeholder: 'Введите пароль',
required: true
},
{
name: 'city',
type: 'select',
label: 'Город',
placeholder: 'Выберите город',
items: [
{
label: 'Минск',
value: 'minsk'
},
{
label: 'Москва',
value: 'moscow'
},
{
label: 'Алматы',
value: 'almaty'
},
{
label: 'Ташкент',
value: 'tashkent'
}
]
},
{
name: 'otp',
type: 'otp',
label: 'Код из СМС',
length: 6,
placeholder: '○'
},
{
name: 'remember',
type: 'checkbox',
label: 'Запомнить меня',
description: 'Вход сохранится на 30 дней.'
}
])
</script>
<template>
<B24AuthForm :fields="fields" class="max-w-sm" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { AuthFormField } from '@bxshefby/b24ui-nuxt'
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'email',
label: 'Эл. почта',
placeholder: 'Введите эл. почту',
required: true
},
{
name: 'password',
type: 'password',
label: 'Пароль',
placeholder: 'Введите пароль',
required: true
},
{
name: 'city',
type: 'select',
label: 'Город',
placeholder: 'Выберите город',
items: [
{
label: 'Минск',
value: 'minsk'
},
{
label: 'Москва',
value: 'moscow'
},
{
label: 'Алматы',
value: 'almaty'
},
{
label: 'Ташкент',
value: 'tashkent'
}
]
},
{
name: 'otp',
type: 'otp',
label: 'Код из СМС',
length: 6,
placeholder: '○'
},
{
name: 'remember',
type: 'checkbox',
label: 'Запомнить меня',
description: 'Вход сохранится на 30 дней.'
}
])
</script>
<template>
<B24AuthForm :fields="fields" class="max-w-sm" />
</template>
Заголовок
Пропс title задаёт заголовок формы.
<script setup lang="ts">
import type { AuthFormField } from '@bxshefby/b24ui-nuxt'
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm title="Вход" :fields="fields" class="max-w-md" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { AuthFormField } from '@bxshefby/b24ui-nuxt'
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm title="Вход" :fields="fields" class="max-w-md" />
</template>
div. Чтобы сделать его заголовком, передайте в пропс as объект, например :as="{ title: 'h3' }". Корневой элемент задаётся так же: :as="{ root: 'section', title: 'h3' }".Описание
Пропс description задаёт пояснение под заголовком.
<script setup lang="ts">
import type { AuthFormField } from '@bxshefby/b24ui-nuxt'
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm
title="Вход"
description="Введите данные, чтобы войти в аккаунт."
:fields="fields"
class="max-w-md"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { AuthFormField } from '@bxshefby/b24ui-nuxt'
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm
title="Вход"
description="Введите данные, чтобы войти в аккаунт."
:fields="fields"
class="max-w-md"
/>
</template>
Иконка
Пропс icon задаёт иконку над заголовком.
<script setup lang="ts">
import type { AuthFormField } from '@bxshefby/b24ui-nuxt'
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm
title="Вход"
description="Введите данные, чтобы войти в аккаунт."
icon="i-bx24-outline-person"
:fields="fields"
class="max-w-md"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { AuthFormField } from '@bxshefby/b24ui-nuxt'
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm
title="Вход"
description="Введите данные, чтобы войти в аккаунт."
icon="i-bx24-outline-person"
:fields="fields"
class="max-w-md"
/>
</template>
Сервисы входа
Пропс providers добавляет кнопки входа через сервисы. Каждой кнопке можно передать любой пропс Button: color, to и другие.
<script setup lang="ts">
import type { ButtonProps, AuthFormField } from '@bxshefby/b24ui-nuxt'
const providers = ref<ButtonProps[]>([
{
label: 'Битрикс24',
icon: 'i-bx24-common-service-bitrix24'
},
{
label: 'Яндекс',
icon: 'i-bx24-common-service-yandex'
}
])
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm
title="Вход"
description="Введите данные, чтобы войти в аккаунт."
icon="i-bx24-outline-person"
:providers="providers"
:fields="fields"
class="max-w-md"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ButtonProps, AuthFormField } from '@bxshefby/b24ui-nuxt'
const providers = ref<ButtonProps[]>([
{
label: 'Битрикс24',
icon: 'i-bx24-common-service-bitrix24'
},
{
label: 'Яндекс',
icon: 'i-bx24-common-service-yandex'
}
])
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm
title="Вход"
description="Введите данные, чтобы войти в аккаунт."
icon="i-bx24-outline-person"
:providers="providers"
:fields="fields"
class="max-w-md"
/>
</template>
Разделитель
Пропс separator меняет Separator между кнопками сервисов и полями. По умолчанию — подпись из локали (или в русской).
<script setup lang="ts">
import type { ButtonProps, AuthFormField } from '@bxshefby/b24ui-nuxt'
const providers = ref<ButtonProps[]>([
{
label: 'Битрикс24',
icon: 'i-bx24-common-service-bitrix24'
},
{
label: 'Яндекс',
icon: 'i-bx24-common-service-yandex'
}
])
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm
title="Вход"
description="Введите данные, чтобы войти в аккаунт."
icon="i-bx24-outline-person"
:providers="providers"
:fields="fields"
class="max-w-md"
separator="Или по почте"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ButtonProps, AuthFormField } from '@bxshefby/b24ui-nuxt'
const providers = ref<ButtonProps[]>([
{
label: 'Битрикс24',
icon: 'i-bx24-common-service-bitrix24'
},
{
label: 'Яндекс',
icon: 'i-bx24-common-service-yandex'
}
])
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm
title="Вход"
description="Введите данные, чтобы войти в аккаунт."
icon="i-bx24-outline-person"
:providers="providers"
:fields="fields"
class="max-w-md"
separator="Или по почте"
/>
</template>
Разделителю можно передать любой пропс Separator.
<script setup lang="ts">
import type { ButtonProps, AuthFormField } from '@bxshefby/b24ui-nuxt'
const providers = ref<ButtonProps[]>([
{
label: 'Битрикс24',
icon: 'i-bx24-common-service-bitrix24'
},
{
label: 'Яндекс',
icon: 'i-bx24-common-service-yandex'
}
])
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm
title="Вход"
description="Введите данные, чтобы войти в аккаунт."
icon="i-bx24-outline-person"
:providers="providers"
:fields="fields"
class="max-w-md"
:separator="{
icon: 'i-bx24-outline-person'
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ButtonProps, AuthFormField } from '@bxshefby/b24ui-nuxt'
const providers = ref<ButtonProps[]>([
{
label: 'Битрикс24',
icon: 'i-bx24-common-service-bitrix24'
},
{
label: 'Яндекс',
icon: 'i-bx24-common-service-yandex'
}
])
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm
title="Вход"
description="Введите данные, чтобы войти в аккаунт."
icon="i-bx24-outline-person"
:providers="providers"
:fields="fields"
class="max-w-md"
:separator="{
icon: 'i-bx24-outline-person'
}"
/>
</template>
Кнопка отправки
Пропс submit меняет кнопку отправки формы. Ей можно передать любой пропс Button, кроме ссылочных: color, size и другие.
<script setup lang="ts">
import type { AuthFormField } from '@bxshefby/b24ui-nuxt'
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm
title="Вход"
description="Введите данные, чтобы войти в аккаунт."
icon="i-bx24-outline-person"
:fields="fields"
class="max-w-md"
:submit="{
label: 'Войти',
color: 'air-primary-success'
}"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { AuthFormField } from '@bxshefby/b24ui-nuxt'
const fields = ref<AuthFormField[]>([
{
name: 'email',
type: 'text',
label: 'Эл. почта'
},
{
name: 'password',
type: 'password',
label: 'Пароль'
}
])
</script>
<template>
<B24AuthForm
title="Вход"
description="Введите данные, чтобы войти в аккаунт."
icon="i-bx24-outline-person"
:fields="fields"
class="max-w-md"
:submit="{
label: 'Войти',
color: 'air-primary-success'
}"
/>
</template>
Примеры
На странице
Оберните AuthForm в PageCard, чтобы показать её, например, на странице login.vue.
API
Пропсы
Слоты
События
Доступ через ref
Типизированный экземпляр компонента (с formRef и state) доступен через useTemplateRef. Например, в отдельной форме сброса пароля:
<script setup lang="ts">
const authForm = useTemplateRef('authForm')
</script>
<template>
<B24AuthForm ref="authForm" />
</template>
Доступны свойства:
Тема
Tooltip
Небольшое окно с подробностями, которое появляется при наведении мыши на элемент.
BlogPost
Статья блога: картинка, дата, метка, заголовок, анонс и авторы.
Была ли страница полезна?