useProps.mjs 997 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { get, isEqual } from "lodash-unified";
  2. import { ref, watch } from "vue";
  3. //#region ../../packages/components/select-v2/src/useProps.ts
  4. const defaultProps = {
  5. label: "label",
  6. value: "value",
  7. disabled: "disabled",
  8. options: "options"
  9. };
  10. function useProps(props) {
  11. const aliasProps = ref({
  12. ...defaultProps,
  13. ...props.props
  14. });
  15. let cache = { ...props.props };
  16. watch(() => props.props, (val) => {
  17. if (!isEqual(val, cache)) {
  18. aliasProps.value = {
  19. ...defaultProps,
  20. ...val
  21. };
  22. cache = { ...val };
  23. }
  24. }, { deep: true });
  25. const getLabel = (option) => get(option, aliasProps.value.label);
  26. const getValue = (option) => get(option, aliasProps.value.value);
  27. const getDisabled = (option) => get(option, aliasProps.value.disabled);
  28. const getOptions = (option) => get(option, aliasProps.value.options);
  29. return {
  30. aliasProps,
  31. getLabel,
  32. getValue,
  33. getDisabled,
  34. getOptions
  35. };
  36. }
  37. //#endregion
  38. export { defaultProps, useProps };
  39. //# sourceMappingURL=useProps.mjs.map