We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
ui/packages/components-vue/src/composables/input.ts
Line 17 in 50ab5f5
import type { iFormInput, tFormAutocomplete, tPluginLocaleKey, tTextInputType, } from "@open-xamu-co/ui-common-types"; import { useI18n } from "@open-xamu-co/ui-common-helpers"; import { eFormType } from "@open-xamu-co/ui-common-enums"; import useHelpers from "../composables/helpers"; export default function useInput({ input }: { input: iFormInput }) { const { t, tet } = useHelpers(useI18n); /** * custom error message * TODO: support warning messages */ function getInputError(): string { switch (input.type) { case eFormType.EMAIL: return t("form_use_valid_email"); case eFormType.PHONE: return t("form_use_valid_phone"); case eFormType.CELLPHONE: return t("form_use_valid_cellphone"); case eFormType.NEW_PASSWORD: return t("form_unmatching_passwords"); default: return t("form_invalid_data"); } } /** * get valid text input type * @values "text", "email", "password", "search", "url", "number", "tel" */ function getInputTextType(): tTextInputType { switch (input.type) { case eFormType.PASSWORD: return "password"; case eFormType.EMAIL: return "email"; case eFormType.NUMBER: return "number"; case eFormType.PHONE: case eFormType.CELLPHONE: return "tel"; default: return "text"; } } /** * Get input placeholder * If no placeholder is provided then it takes one of the suggested options */ function getInputPlaceholder(index = 0): string { /** * Add ellipsis */ const p = (s: tPluginLocaleKey): string => { if (input.placeholder) return `${tet(input.placeholder).replace("...", "")}...`; return `${t(s)}...`; }; switch (input.type) { case eFormType.LOCATION: return [p("form_country"), p("form_state"), p("form_city")][index]; case eFormType.NEW_PASSWORD: return [p("form_desired_password"), p("form_confirm_password")][index]; case eFormType.PASSWORD: return [p("form_password")][index]; case eFormType.EMAIL: return [p("form_email")][index]; case eFormType.PHONE: return [p("form_phone_line")][index]; case eFormType.CELLPHONE: return [p("form_cellphone")][index]; case eFormType.ID: return [p("form_id_number")][index]; default: return [p("form_complete_the_field")][index]; } } /** * get valid input autocomplete string */ function getInputAutocomplete(): tFormAutocomplete { if (input.autocomplete) return input.autocomplete; switch (input.type) { case eFormType.NEW_PASSWORD: return "new-password"; case eFormType.PASSWORD: return "current-password"; case eFormType.EMAIL: return "email"; case eFormType.PHONE: return "tel-local"; case eFormType.CELLPHONE: return "tel-national"; default: return "on"; } } return { getInputError, getInputAutocomplete, getInputPlaceholder, getInputTextType, }; }
The text was updated successfully, but these errors were encountered:
Added support for warning styles: 0851135
Sorry, something went wrong.
No branches or pull requests
ui/packages/components-vue/src/composables/input.ts
Line 17 in 50ab5f5
The text was updated successfully, but these errors were encountered: