廓形仪rn版本-技术调研
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

  1. 'use client';
  2. import React from 'react';
  3. import { Switch as RNSwitch } from 'react-native';
  4. import { createSwitch } from '@gluestack-ui/switch';
  5. import { tva } from '@gluestack-ui/nativewind-utils/tva';
  6. import { withStyleContext } from '@gluestack-ui/nativewind-utils/withStyleContext';
  7. import type { VariantProps } from '@gluestack-ui/nativewind-utils';
  8. const UISwitch = createSwitch({
  9. Root: withStyleContext(RNSwitch),
  10. });
  11. const switchStyle = tva({
  12. base: 'data-[focus=true]:outline-0 data-[focus=true]:ring-2 data-[focus=true]:ring-indicator-primary web:cursor-pointer disabled:cursor-not-allowed data-[disabled=true]:opacity-40 data-[invalid=true]:border-error-700 data-[invalid=true]:rounded-xl data-[invalid=true]:border-2',
  13. variants: {
  14. size: {
  15. sm: 'scale-75',
  16. md: '',
  17. lg: 'scale-125',
  18. },
  19. },
  20. });
  21. type ISwitchProps = React.ComponentProps<typeof UISwitch> &
  22. VariantProps<typeof switchStyle>;
  23. const Switch = React.forwardRef<
  24. React.ComponentRef<typeof UISwitch>,
  25. ISwitchProps
  26. >(function Switch({ className, size = 'md', ...props }, ref) {
  27. return (
  28. <UISwitch
  29. ref={ref}
  30. {...props}
  31. className={switchStyle({ size, class: className })}
  32. />
  33. );
  34. });
  35. Switch.displayName = 'Switch';
  36. export { Switch };