廓形仪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.

102 lines
2.8 KiB

  1. 'use client';
  2. import { createLink } from '@gluestack-ui/link';
  3. import { Pressable } from 'react-native';
  4. import { Text } from 'react-native';
  5. import { tva } from '@gluestack-ui/nativewind-utils/tva';
  6. import { withStyleContext } from '@gluestack-ui/nativewind-utils/withStyleContext';
  7. import { cssInterop } from 'nativewind';
  8. import type { VariantProps } from '@gluestack-ui/nativewind-utils';
  9. import React from 'react';
  10. export const UILink = createLink({
  11. Root: withStyleContext(Pressable),
  12. Text: Text,
  13. });
  14. cssInterop(UILink, { className: 'style' });
  15. cssInterop(UILink.Text, { className: 'style' });
  16. const linkStyle = tva({
  17. base: 'group/link web:outline-0 data-[disabled=true]:web:cursor-not-allowed data-[focus-visible=true]:web:ring-2 data-[focus-visible=true]:web:ring-indicator-primary data-[focus-visible=true]:web:outline-0 data-[disabled=true]:opacity-4 ',
  18. });
  19. const linkTextStyle = tva({
  20. base: 'underline text-info-700 data-[hover=true]:text-info-600 data-[hover=true]:no-underline data-[active=true]:text-info-700 font-normal font-body web:font-sans web:tracking-sm web:my-0 web:bg-transparent web:border-0 web:box-border web:display-inline web:list-none web:margin-0 web:padding-0 web:position-relative web:text-start web:whitespace-pre-wrap web:word-wrap-break-word',
  21. variants: {
  22. isTruncated: {
  23. true: 'web:truncate',
  24. },
  25. bold: {
  26. true: 'font-bold',
  27. },
  28. underline: {
  29. true: 'underline',
  30. },
  31. strikeThrough: {
  32. true: 'line-through',
  33. },
  34. size: {
  35. '2xs': 'text-2xs',
  36. 'xs': 'text-xs',
  37. 'sm': 'text-sm',
  38. 'md': 'text-base',
  39. 'lg': 'text-lg',
  40. 'xl': 'text-xl',
  41. '2xl': 'text-2xl',
  42. '3xl': 'text-3xl',
  43. '4xl': 'text-4xl',
  44. '5xl': 'text-5xl',
  45. '6xl': 'text-6xl',
  46. },
  47. sub: {
  48. true: 'text-xs',
  49. },
  50. italic: {
  51. true: 'italic',
  52. },
  53. highlight: {
  54. true: 'bg-yellow-500',
  55. },
  56. },
  57. });
  58. type ILinkProps = React.ComponentProps<typeof UILink> &
  59. VariantProps<typeof linkStyle> & { className?: string };
  60. const Link = React.forwardRef<React.ComponentRef<typeof UILink>, ILinkProps>(
  61. function Link({ className, ...props }, ref) {
  62. return (
  63. <UILink
  64. ref={ref}
  65. {...props}
  66. className={linkStyle({ class: className })}
  67. />
  68. );
  69. }
  70. );
  71. type ILinkTextProps = React.ComponentProps<typeof UILink.Text> &
  72. VariantProps<typeof linkTextStyle> & { className?: string };
  73. const LinkText = React.forwardRef<
  74. React.ComponentRef<typeof UILink.Text>,
  75. ILinkTextProps
  76. >(function LinkText({ className, size = 'md', ...props }, ref) {
  77. return (
  78. <UILink.Text
  79. ref={ref}
  80. {...props}
  81. className={linkTextStyle({
  82. class: className,
  83. size,
  84. })}
  85. />
  86. );
  87. });
  88. Link.displayName = 'Link';
  89. LinkText.displayName = 'LinkText';
  90. export { Link, LinkText };