size.mjs 913 B

123456789101112131415161718192021222324252627282930
  1. // Utilities
  2. import { convertToUnit, destructComputed, getCurrentInstanceName, includes, propsFactory } from "../util/index.mjs"; // Types
  3. const predefinedSizes = ['x-small', 'small', 'default', 'large', 'x-large'];
  4. // Composables
  5. export const makeSizeProps = propsFactory({
  6. size: {
  7. type: [String, Number],
  8. default: 'default'
  9. }
  10. }, 'size');
  11. export function useSize(props) {
  12. let name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getCurrentInstanceName();
  13. return destructComputed(() => {
  14. let sizeClasses;
  15. let sizeStyles;
  16. if (includes(predefinedSizes, props.size)) {
  17. sizeClasses = `${name}--size-${props.size}`;
  18. } else if (props.size) {
  19. sizeStyles = {
  20. width: convertToUnit(props.size),
  21. height: convertToUnit(props.size)
  22. };
  23. }
  24. return {
  25. sizeClasses,
  26. sizeStyles
  27. };
  28. });
  29. }
  30. //# sourceMappingURL=size.mjs.map