UNPKG

vuestic-ui

Version:
1 lines 1.42 kB
{"version":3,"file":"useFormField.mjs","sources":["../../../../src/composables/useFormField.ts"],"sourcesContent":["import { computed, ExtractPropTypes } from 'vue'\n\nimport { useBem } from './useBem'\nimport { pick } from '../utils/pick'\n\nexport const useFormFieldProps = {\n disabled: { type: Boolean, default: false },\n readonly: { type: Boolean, default: false },\n}\n\nexport const useFormFieldPropsWithId = {\n ...useFormFieldProps,\n id: { type: [String, Number], default: undefined },\n name: { type: [String, Number], default: undefined },\n}\n\n/**\n * @description creates `readonly` and `disabled` BEM modifiers.\n * @param prefix string that classes start with (base BEM class).\n * @param props component props.\n * @returns computed classes object starting with `prefix` and ending with form state BEM modifier.\n */\nexport const useFormField = <Prefix extends string = ''>(\n prefix: Prefix,\n props: ExtractPropTypes<typeof useFormFieldProps>,\n) => {\n const computedClasses = useBem<'disabled' | 'readonly', Prefix>(prefix, computed(() => pick(props, ['disabled', 'readonly'])))\n return { computedClasses }\n}\n"],"names":[],"mappings":";;;AAKO,MAAM,oBAAoB;AAAA,EAC/B,UAAU,EAAE,MAAM,SAAS,SAAS,MAAM;AAAA,EAC1C,UAAU,EAAE,MAAM,SAAS,SAAS,MAAM;AAC5C;AAca,MAAA,eAAe,CAC1B,QACA,UACG;AACH,QAAM,kBAAkB,OAAwC,QAAQ,SAAS,MAAM,KAAK,OAAO,CAAC,YAAY,UAAU,CAAC,CAAC,CAAC;AAC7H,SAAO,EAAE,gBAAgB;AAC3B;"}