UNPKG

vuestic-ui

Version:
1 lines 1.49 kB
{"version":3,"file":"useMaxSelections.mjs","sources":["../../../../src/composables/useMaxSelections.ts"],"sourcesContent":["import { Ref } from 'vue'\n\n/**\n * You could add these props to any component by destructuring them inside props option.\n * @example\n * props: { ...useMaxSelectionsProps, componentsOwnProp, etc. }\n * It's better to add props at the beginning, to make sure that Component own props will be used instead in case of collision\n */\nexport const useMaxSelectionsProps = {\n maxSelections: {\n type: [Number, String],\n default: undefined,\n },\n}\n\nexport function useMaxSelections (\n selections: Ref<any[]>,\n maxSelections: Ref<number | string | undefined>,\n) {\n const exceedsMaxSelections = (): boolean => {\n if (maxSelections.value === undefined || isNaN(+maxSelections.value)) { return false }\n return selections.value.length >= Number(maxSelections.value)\n }\n\n const addOption = <T>(optionToAdd: T) => {\n return [...selections.value, optionToAdd]\n }\n\n return {\n exceedsMaxSelections,\n addOption,\n }\n}\n"],"names":[],"mappings":"AAQO,MAAM,wBAAwB;AAAA,EACnC,eAAe;AAAA,IACb,MAAM,CAAC,QAAQ,MAAM;AAAA,IACrB,SAAS;AAAA,EACX;AACF;AAEgB,SAAA,iBACd,YACA,eACA;AACA,QAAM,uBAAuB,MAAe;AAC1C,QAAI,cAAc,UAAU,UAAa,MAAM,CAAC,cAAc,KAAK,GAAG;AAAS,aAAA;AAAA,IAAM;AACrF,WAAO,WAAW,MAAM,UAAU,OAAO,cAAc,KAAK;AAAA,EAAA;AAGxD,QAAA,YAAY,CAAI,gBAAmB;AACvC,WAAO,CAAC,GAAG,WAAW,OAAO,WAAW;AAAA,EAAA;AAGnC,SAAA;AAAA,IACL;AAAA,IACA;AAAA,EAAA;AAEJ;"}