@dashx/react 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/dist/cjs/components/button.d.ts +2 -1
  2. package/dist/cjs/components/button.js +1 -1
  3. package/dist/cjs/components/button.js.map +3 -3
  4. package/dist/cjs/components/card.js +1 -1
  5. package/dist/cjs/components/card.js.map +2 -2
  6. package/dist/cjs/components/checkbox.d.ts +18 -0
  7. package/dist/cjs/components/checkbox.js +2 -0
  8. package/dist/cjs/components/checkbox.js.map +7 -0
  9. package/dist/cjs/components/flex.d.ts +321 -16
  10. package/dist/cjs/components/flex.js +1 -1
  11. package/dist/cjs/components/flex.js.map +3 -3
  12. package/dist/cjs/components/form.d.ts +11 -0
  13. package/dist/cjs/components/form.js +2 -0
  14. package/dist/cjs/components/form.js.map +7 -0
  15. package/dist/cjs/components/index.d.ts +5 -0
  16. package/dist/cjs/components/index.js +1 -1
  17. package/dist/cjs/components/index.js.map +2 -2
  18. package/dist/cjs/components/link.d.ts +10 -0
  19. package/dist/cjs/components/link.js +2 -0
  20. package/dist/cjs/components/link.js.map +7 -0
  21. package/dist/cjs/components/number-field.d.ts +11 -0
  22. package/dist/cjs/components/number-field.js +2 -0
  23. package/dist/cjs/components/number-field.js.map +7 -0
  24. package/dist/cjs/components/popover.d.ts +6 -6
  25. package/dist/cjs/components/text-area.d.ts +11 -0
  26. package/dist/cjs/components/text-area.js +2 -0
  27. package/dist/cjs/components/text-area.js.map +7 -0
  28. package/dist/cjs/components/text-field.d.ts +10 -1
  29. package/dist/cjs/components/text-field.js +1 -1
  30. package/dist/cjs/components/text-field.js.map +3 -3
  31. package/dist/cjs/components/text.d.ts +1 -1
  32. package/dist/cjs/components/text.js +1 -1
  33. package/dist/cjs/components/text.js.map +3 -3
  34. package/dist/cjs/components/theme.d.ts +2 -0
  35. package/dist/cjs/components/theme.js +1 -1
  36. package/dist/cjs/components/theme.js.map +3 -3
  37. package/dist/cjs/components/tooltip.js +1 -1
  38. package/dist/cjs/components/tooltip.js.map +2 -2
  39. package/dist/cjs/hooks/index.d.ts +1 -0
  40. package/dist/cjs/hooks/index.js +1 -1
  41. package/dist/cjs/hooks/index.js.map +3 -3
  42. package/dist/cjs/hooks/use-in-app.js +1 -1
  43. package/dist/cjs/hooks/use-in-app.js.map +3 -3
  44. package/dist/cjs/hooks/use-product-release.d.ts +6 -0
  45. package/dist/cjs/hooks/use-product-release.js +2 -0
  46. package/dist/cjs/hooks/use-product-release.js.map +7 -0
  47. package/dist/cjs/providers/DashXProvider.d.ts +7 -2
  48. package/dist/cjs/providers/DashXProvider.js +1 -1
  49. package/dist/cjs/providers/DashXProvider.js.map +3 -3
  50. package/dist/cjs/providers/index.d.ts +1 -1
  51. package/dist/cjs/providers/index.js +1 -1
  52. package/dist/cjs/providers/index.js.map +2 -2
  53. package/dist/cjs/utils/helpers.d.ts +2 -0
  54. package/dist/cjs/utils/helpers.js +2 -0
  55. package/dist/cjs/utils/helpers.js.map +7 -0
  56. package/dist/cjs/variants/base-element.d.ts +91 -0
  57. package/dist/cjs/variants/base-element.js +1 -1
  58. package/dist/cjs/variants/base-element.js.map +2 -2
  59. package/dist/cjs/variants/base-field.d.ts +236 -0
  60. package/dist/cjs/variants/base-field.js +2 -0
  61. package/dist/cjs/variants/base-field.js.map +7 -0
  62. package/dist/cjs/variants/base-input.d.ts +5 -0
  63. package/dist/cjs/variants/base-input.js +2 -0
  64. package/dist/cjs/variants/base-input.js.map +7 -0
  65. package/dist/cjs/variants/button.d.ts +122 -15
  66. package/dist/cjs/variants/button.js +1 -1
  67. package/dist/cjs/variants/button.js.map +2 -2
  68. package/dist/cjs/variants/card.d.ts +2 -2
  69. package/dist/cjs/variants/card.js +1 -1
  70. package/dist/cjs/variants/card.js.map +2 -2
  71. package/dist/cjs/variants/checkbox.d.ts +41 -0
  72. package/dist/cjs/variants/checkbox.js +2 -0
  73. package/dist/cjs/variants/checkbox.js.map +7 -0
  74. package/dist/cjs/variants/field-error.d.ts +149 -0
  75. package/dist/cjs/variants/field-error.js +2 -0
  76. package/dist/cjs/variants/field-error.js.map +7 -0
  77. package/dist/cjs/variants/heading.d.ts +45 -0
  78. package/dist/cjs/variants/index.d.ts +2 -0
  79. package/dist/cjs/variants/index.js +1 -1
  80. package/dist/cjs/variants/index.js.map +2 -2
  81. package/dist/cjs/variants/link.d.ts +470 -0
  82. package/dist/cjs/variants/link.js +2 -0
  83. package/dist/cjs/variants/link.js.map +7 -0
  84. package/dist/cjs/variants/popover.d.ts +4 -4
  85. package/dist/cjs/variants/popover.js +1 -1
  86. package/dist/cjs/variants/popover.js.map +2 -2
  87. package/dist/cjs/variants/text-area.d.ts +298 -0
  88. package/dist/cjs/variants/text-area.js +2 -0
  89. package/dist/cjs/variants/text-area.js.map +7 -0
  90. package/dist/cjs/variants/text-field.d.ts +218 -13
  91. package/dist/cjs/variants/text-field.js +1 -1
  92. package/dist/cjs/variants/text-field.js.map +3 -3
  93. package/dist/cjs/variants/text.d.ts +48 -1
  94. package/dist/cjs/variants/text.js +1 -1
  95. package/dist/cjs/variants/text.js.map +2 -2
  96. package/dist/cjs/variants/tooltip.d.ts +1 -1
  97. package/dist/cjs/variants/tooltip.js +1 -1
  98. package/dist/cjs/variants/tooltip.js.map +2 -2
  99. package/dist/cjs/variants/typography.d.ts +35 -0
  100. package/dist/cjs/variants/typography.js +1 -1
  101. package/dist/cjs/variants/typography.js.map +2 -2
  102. package/dist/esm/components/button.d.ts +2 -1
  103. package/dist/esm/components/button.js +1 -1
  104. package/dist/esm/components/button.js.map +3 -3
  105. package/dist/esm/components/card.js +1 -1
  106. package/dist/esm/components/card.js.map +2 -2
  107. package/dist/esm/components/checkbox.d.ts +18 -0
  108. package/dist/esm/components/checkbox.js +2 -0
  109. package/dist/esm/components/checkbox.js.map +7 -0
  110. package/dist/esm/components/flex.d.ts +321 -16
  111. package/dist/esm/components/flex.js +1 -1
  112. package/dist/esm/components/flex.js.map +3 -3
  113. package/dist/esm/components/form.d.ts +11 -0
  114. package/dist/esm/components/form.js +2 -0
  115. package/dist/esm/components/form.js.map +7 -0
  116. package/dist/esm/components/index.d.ts +5 -0
  117. package/dist/esm/components/index.js +1 -1
  118. package/dist/esm/components/index.js.map +2 -2
  119. package/dist/esm/components/link.d.ts +10 -0
  120. package/dist/esm/components/link.js +2 -0
  121. package/dist/esm/components/link.js.map +7 -0
  122. package/dist/esm/components/number-field.d.ts +11 -0
  123. package/dist/esm/components/number-field.js +2 -0
  124. package/dist/esm/components/number-field.js.map +7 -0
  125. package/dist/esm/components/popover.d.ts +6 -6
  126. package/dist/esm/components/text-area.d.ts +11 -0
  127. package/dist/esm/components/text-area.js +2 -0
  128. package/dist/esm/components/text-area.js.map +7 -0
  129. package/dist/esm/components/text-field.d.ts +10 -1
  130. package/dist/esm/components/text-field.js +1 -1
  131. package/dist/esm/components/text-field.js.map +3 -3
  132. package/dist/esm/components/text.d.ts +1 -1
  133. package/dist/esm/components/text.js +1 -1
  134. package/dist/esm/components/text.js.map +3 -3
  135. package/dist/esm/components/theme.d.ts +2 -0
  136. package/dist/esm/components/theme.js +1 -1
  137. package/dist/esm/components/theme.js.map +3 -3
  138. package/dist/esm/components/tooltip.js +1 -1
  139. package/dist/esm/components/tooltip.js.map +2 -2
  140. package/dist/esm/hooks/index.d.ts +1 -0
  141. package/dist/esm/hooks/index.js +1 -1
  142. package/dist/esm/hooks/index.js.map +2 -2
  143. package/dist/esm/hooks/use-in-app.js +1 -1
  144. package/dist/esm/hooks/use-in-app.js.map +3 -3
  145. package/dist/esm/hooks/use-product-release.d.ts +6 -0
  146. package/dist/esm/hooks/use-product-release.js +2 -0
  147. package/dist/esm/hooks/use-product-release.js.map +7 -0
  148. package/dist/esm/providers/DashXProvider.d.ts +7 -2
  149. package/dist/esm/providers/DashXProvider.js +1 -1
  150. package/dist/esm/providers/DashXProvider.js.map +3 -3
  151. package/dist/esm/providers/index.d.ts +1 -1
  152. package/dist/esm/providers/index.js +1 -1
  153. package/dist/esm/providers/index.js.map +3 -3
  154. package/dist/esm/utils/helpers.d.ts +2 -0
  155. package/dist/esm/utils/helpers.js +2 -0
  156. package/dist/esm/utils/helpers.js.map +7 -0
  157. package/dist/esm/variants/base-element.d.ts +91 -0
  158. package/dist/esm/variants/base-element.js +1 -1
  159. package/dist/esm/variants/base-element.js.map +2 -2
  160. package/dist/esm/variants/base-field.d.ts +236 -0
  161. package/dist/esm/variants/base-field.js +2 -0
  162. package/dist/esm/variants/base-field.js.map +7 -0
  163. package/dist/esm/variants/base-input.d.ts +5 -0
  164. package/dist/esm/variants/base-input.js +2 -0
  165. package/dist/esm/variants/base-input.js.map +7 -0
  166. package/dist/esm/variants/button.d.ts +122 -15
  167. package/dist/esm/variants/button.js +1 -1
  168. package/dist/esm/variants/button.js.map +2 -2
  169. package/dist/esm/variants/card.d.ts +2 -2
  170. package/dist/esm/variants/card.js +1 -1
  171. package/dist/esm/variants/card.js.map +2 -2
  172. package/dist/esm/variants/checkbox.d.ts +41 -0
  173. package/dist/esm/variants/checkbox.js +2 -0
  174. package/dist/esm/variants/checkbox.js.map +7 -0
  175. package/dist/esm/variants/field-error.d.ts +149 -0
  176. package/dist/esm/variants/field-error.js +2 -0
  177. package/dist/esm/variants/field-error.js.map +7 -0
  178. package/dist/esm/variants/heading.d.ts +45 -0
  179. package/dist/esm/variants/index.d.ts +2 -0
  180. package/dist/esm/variants/index.js +1 -1
  181. package/dist/esm/variants/index.js.map +2 -2
  182. package/dist/esm/variants/link.d.ts +470 -0
  183. package/dist/esm/variants/link.js +2 -0
  184. package/dist/esm/variants/link.js.map +7 -0
  185. package/dist/esm/variants/popover.d.ts +4 -4
  186. package/dist/esm/variants/popover.js +1 -1
  187. package/dist/esm/variants/popover.js.map +2 -2
  188. package/dist/esm/variants/text-area.d.ts +298 -0
  189. package/dist/esm/variants/text-area.js +2 -0
  190. package/dist/esm/variants/text-area.js.map +7 -0
  191. package/dist/esm/variants/text-field.d.ts +218 -13
  192. package/dist/esm/variants/text-field.js +1 -1
  193. package/dist/esm/variants/text-field.js.map +3 -3
  194. package/dist/esm/variants/text.d.ts +48 -1
  195. package/dist/esm/variants/text.js +1 -1
  196. package/dist/esm/variants/text.js.map +2 -2
  197. package/dist/esm/variants/tooltip.d.ts +1 -1
  198. package/dist/esm/variants/tooltip.js +1 -1
  199. package/dist/esm/variants/tooltip.js.map +2 -2
  200. package/dist/esm/variants/typography.d.ts +35 -0
  201. package/dist/esm/variants/typography.js +1 -1
  202. package/dist/esm/variants/typography.js.map +2 -2
  203. package/package.json +5 -6
  204. package/src/components/button.tsx +17 -21
  205. package/src/components/card.tsx +2 -2
  206. package/src/components/checkbox.tsx +255 -0
  207. package/src/components/flex.tsx +17 -7
  208. package/src/components/form.tsx +30 -0
  209. package/src/components/index.ts +5 -0
  210. package/src/components/link.tsx +90 -0
  211. package/src/components/number-field.tsx +174 -0
  212. package/src/components/text-area.tsx +107 -0
  213. package/src/components/text-field.tsx +103 -3
  214. package/src/components/text.tsx +13 -4
  215. package/src/components/theme.tsx +16 -4
  216. package/src/components/tooltip.tsx +1 -1
  217. package/src/hooks/index.ts +1 -0
  218. package/src/hooks/use-in-app.ts +17 -58
  219. package/src/hooks/use-product-release.ts +38 -0
  220. package/src/providers/DashXProvider.tsx +91 -5
  221. package/src/providers/index.ts +1 -1
  222. package/src/styles/index.css +180 -43
  223. package/src/utils/helpers.ts +21 -0
  224. package/src/variants/base-element.ts +18 -5
  225. package/src/variants/base-field.ts +42 -0
  226. package/src/variants/base-input.ts +13 -0
  227. package/src/variants/button.ts +47 -27
  228. package/src/variants/card.ts +3 -3
  229. package/src/variants/checkbox.ts +33 -0
  230. package/src/variants/field-error.ts +29 -0
  231. package/src/variants/index.ts +2 -0
  232. package/src/variants/link.ts +34 -0
  233. package/src/variants/popover.ts +5 -5
  234. package/src/variants/text-area.ts +26 -0
  235. package/src/variants/text-field.ts +14 -3
  236. package/src/variants/text.ts +2 -1
  237. package/src/variants/tooltip.ts +1 -1
  238. package/src/variants/typography.ts +14 -9
  239. package/styles.css +546 -124
  240. package/dist/cjs/tsconfig.tsbuildinfo +0 -1
  241. package/dist/esm/tsconfig.tsbuildinfo +0 -1
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { tv } from 'tailwind-variants';
3
+ import { Slot } from '@radix-ui/react-slot';
3
4
 
4
5
  import { cn } from '../utils/cn.js';
5
6
 
@@ -9,8 +10,10 @@ const flexVariants = tv({
9
10
  base: 'flex',
10
11
  variants: {
11
12
  direction: {
12
- column: ['flex-col'],
13
- row: ['flex-row'],
13
+ column: 'flex-col',
14
+ row: 'flex-row',
15
+ 'column-reverse': 'flex-col-reverse',
16
+ 'row-reverse': 'flex-row-reverse',
14
17
  },
15
18
  gap: {
16
19
  1: 'gap-1',
@@ -29,25 +32,32 @@ const flexVariants = tv({
29
32
  32: 'gap-32',
30
33
  },
31
34
  justify: {
35
+ baseline: 'justify-baseline',
32
36
  center: 'justify-center',
33
37
  between: 'justify-between',
38
+ start: 'justify-start',
39
+ end: 'justify-end',
34
40
  },
35
41
  align: {
36
42
  baseline: 'items-baseline',
37
43
  center: 'items-center',
44
+ start: 'items-start',
45
+ end: 'items-end',
38
46
  },
39
47
  },
40
48
  });
41
49
 
42
- type FlexProps = VariantProps<typeof flexVariants>;
50
+ type FlexProps = VariantProps<typeof flexVariants> & {
51
+ asChild?: boolean;
52
+ };
43
53
 
44
54
  const Flex = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement> & FlexProps>(
45
55
  (props, ref) => {
46
- const { className, direction, gap, justify, align, ...rest } = props;
47
-
56
+ const { className, direction, gap, justify, align, asChild, ...rest } = props;
57
+ const Comp = asChild ? Slot : 'div';
48
58
  return (
49
- <div
50
- className={cn(flexVariants({ direction, gap, justify, align }), className)}
59
+ <Comp
60
+ className={flexVariants({ direction, gap, justify, align, className })}
51
61
  ref={ref}
52
62
  {...rest}
53
63
  />
@@ -0,0 +1,30 @@
1
+ import { FormContext } from 'react-aria-components';
2
+ import { FormValidationContext } from 'react-stately';
3
+ import { forwardRef } from 'react';
4
+
5
+ import type { FormProps as _FormProps } from '@react-types/form';
6
+ import type { CSSProperties, ForwardedRef, ReactNode } from 'react';
7
+ import type { DOMProps } from '@react-types/shared';
8
+
9
+ export interface FormProps extends _FormProps, DOMProps {
10
+ className?: string;
11
+ style?: CSSProperties;
12
+ children?: ReactNode;
13
+ noValidate?: boolean;
14
+ }
15
+
16
+ function _Form(props: FormProps, ref: ForwardedRef<HTMLFormElement>) {
17
+ let { validationErrors, children, className, ...domProps } = props;
18
+ return (
19
+ <form {...domProps} ref={ref} className={className}>
20
+ <FormContext.Provider value={{ validationBehavior: props.noValidate ? 'aria' : 'native' }}>
21
+ <FormValidationContext.Provider value={validationErrors ?? {}}>
22
+ {children}
23
+ </FormValidationContext.Provider>
24
+ </FormContext.Provider>
25
+ </form>
26
+ );
27
+ }
28
+
29
+ const Form = forwardRef(_Form);
30
+ export { Form };
@@ -1,11 +1,16 @@
1
1
  export * from './button.js';
2
2
  export * from './card.js';
3
+ export * from './checkbox.js';
3
4
  export * from './flex.js';
5
+ export * from './form.js';
4
6
  export * from './heading.js';
5
7
  export * from './icon-button.js';
8
+ export * from './link.js';
9
+ export * from './number-field.js';
6
10
  export * as Popover from './popover.js';
7
11
  export * from './toast.js';
8
12
  export * from './text.js';
13
+ export * from './text-area.js';
9
14
  export * from './text-field.js';
10
15
  export * from './theme.js';
11
16
  export * as Tooltip from './tooltip.js';
@@ -0,0 +1,90 @@
1
+ import { LinkContext, TextContext, useContextProps, type SlotProps } from 'react-aria-components';
2
+ import { filterDOMProps, mergeRefs } from '@react-aria/utils';
3
+ import {
4
+ forwardRef,
5
+ isValidElement,
6
+ type ElementType,
7
+ type ForwardedRef,
8
+ type ReactNode,
9
+ } from 'react';
10
+ import { mergeProps, useFocusRing, useHover, useLink } from 'react-aria';
11
+ import { Slot } from '@radix-ui/react-slot';
12
+ import { useRef } from 'react';
13
+ import type { AriaLinkOptions, HoverEvents } from 'react-aria';
14
+
15
+ import { link, type LinkVariantProps } from '../variants/index.js';
16
+ import { fallbackEventTo } from '../utils/helpers.js';
17
+
18
+ export interface LinkProps
19
+ extends Omit<AriaLinkOptions, 'elementType'>,
20
+ SlotProps,
21
+ HoverEvents,
22
+ LinkVariantProps {
23
+ asChild?: boolean;
24
+ children?: ReactNode;
25
+ }
26
+
27
+ function _Link(props: LinkProps, ref: ForwardedRef<HTMLAnchorElement>) {
28
+ // @ts-ignore
29
+ [props, ref] = useContextProps(props, ref, TextContext);
30
+ [props, ref] = useContextProps(props, ref, LinkContext);
31
+ const { asChild, children, size, align, color, variant, weight, transform, underline } = props;
32
+ let elementType = asChild
33
+ ? (isValidElement(children) && (children?.type as ElementType)) || 'a'
34
+ : 'a';
35
+
36
+ const [onPress, onClick] = fallbackEventTo(props, 'onPress', 'onClick');
37
+ const [onPressStart, onPointerDown] = fallbackEventTo(props, 'onPressStart', 'onPointerDown');
38
+ const [onHoverStart, onPointerMove] = fallbackEventTo(props, 'onHoverStart', 'onPointerMove');
39
+ const [onHoverEnd, onPointerLeave] = fallbackEventTo(props, 'onHoverEnd', 'onPointerLeave');
40
+ const innerRef = useRef<HTMLAnchorElement>(null);
41
+ let { linkProps, isPressed } = useLink(
42
+ {
43
+ ...props,
44
+ // @ts-ignore
45
+ elementType,
46
+ onPress,
47
+ onPressStart,
48
+ // @ts-ignore
49
+ onClick,
50
+ // @ts-ignore
51
+ onPointerDown,
52
+ // @ts-ignore
53
+ onPointerMove,
54
+ // @ts-ignore
55
+ onPointerLeave,
56
+ },
57
+ innerRef,
58
+ );
59
+ let { focusProps, isFocused, isFocusVisible } = useFocusRing(props);
60
+
61
+ let { hoverProps, isHovered } = useHover({
62
+ ...props,
63
+ onHoverStart,
64
+ onHoverEnd,
65
+ });
66
+
67
+ let Comp = asChild ? Slot : 'a';
68
+
69
+ return (
70
+ <Comp
71
+ {...filterDOMProps(props)}
72
+ {...mergeProps(linkProps, focusProps, hoverProps)}
73
+ slot={props.slot || undefined}
74
+ ref={mergeRefs(ref, innerRef)}
75
+ data-disabled={props.isDisabled || undefined}
76
+ data-pressed={isPressed || undefined}
77
+ data-hovered={isHovered || undefined}
78
+ data-focused={isFocused || undefined}
79
+ data-focus-visible={isFocusVisible || undefined}
80
+ // @ts-ignore
81
+ data-current={!!props['aria-current'] || undefined}
82
+ className={link({ size, align, color, variant, weight, transform, underline })}
83
+ >
84
+ {children}
85
+ </Comp>
86
+ );
87
+ }
88
+
89
+ const Link = /*#__PURE__*/ forwardRef(_Link);
90
+ export { Link };
@@ -0,0 +1,174 @@
1
+ import { useRect } from '@radix-ui/react-use-rect';
2
+ import { NumberFieldContext, useContextProps } from 'react-aria-components';
3
+ import { useNumberFieldState } from 'react-stately';
4
+ import { cn } from '../utils/cn.js';
5
+ import { fieldError } from '../variants/field-error.js';
6
+ import { textField } from '../variants/index.js';
7
+ import { Button, Flex, Text } from './index.js';
8
+ import { filterDOMProps } from '@react-aria/utils';
9
+ import { ChevronDown, ChevronUp } from 'lucide-react';
10
+ import { forwardRef, useRef, useState, type ReactNode } from 'react';
11
+ import { useLocale, useNumberField } from 'react-aria';
12
+ import { removeDataAttributes } from '../utils/helpers.js';
13
+ import type {
14
+ NumberFieldProps as BaseNumberFieldProps,
15
+ ValidationResult,
16
+ } from 'react-aria-components';
17
+ import type { TextFieldVariantProps } from '../variants/index.js';
18
+
19
+ interface NumberFieldProps extends BaseNumberFieldProps, TextFieldVariantProps {
20
+ placeholder?: string;
21
+ label?: string;
22
+ description?: string | ReactNode;
23
+ errorMessage?: string | ((validation: ValidationResult) => string);
24
+ }
25
+
26
+ function _NumberField(
27
+ {
28
+ label,
29
+ description,
30
+ errorMessage,
31
+ size = 'medium',
32
+ roundness = 'medium',
33
+ elevation = 'medium',
34
+ ...props
35
+ }: NumberFieldProps,
36
+ ref: React.ForwardedRef<HTMLDivElement>,
37
+ ) {
38
+ const [appendEl, setAppendEl] = useState<HTMLDivElement | null>(null);
39
+ const appendRect = useRect(appendEl);
40
+ [props, ref] = useContextProps(props, ref, NumberFieldContext);
41
+
42
+ let { locale } = useLocale();
43
+ let state = useNumberFieldState({
44
+ ...props,
45
+ locale,
46
+ });
47
+
48
+ let inputRef = useRef<HTMLInputElement>(null);
49
+
50
+ let {
51
+ labelProps,
52
+ groupProps,
53
+ inputProps,
54
+ incrementButtonProps,
55
+ decrementButtonProps,
56
+ descriptionProps,
57
+ errorMessageProps,
58
+ ...validation
59
+ } = useNumberField(
60
+ {
61
+ ...removeDataAttributes(props),
62
+ label,
63
+ },
64
+ state,
65
+ inputRef,
66
+ );
67
+
68
+ return (
69
+ <>
70
+ <Flex
71
+ gap={2}
72
+ direction="column"
73
+ {...filterDOMProps(props)}
74
+ ref={ref}
75
+ slot={props.slot || undefined}
76
+ data-disabled={props.isDisabled || undefined}
77
+ data-invalid={validation.isInvalid || undefined}
78
+ >
79
+ {label && (
80
+ <Text
81
+ {...labelProps}
82
+ size={1}
83
+ transform="uppercase"
84
+ weight="semibold"
85
+ variant="tertiary"
86
+ color="gray"
87
+ >
88
+ {label}
89
+ </Text>
90
+ )}
91
+ <div {...groupProps} className="relative" data-radius={roundness} data-shadow={elevation}>
92
+ <input
93
+ {...inputProps}
94
+ ref={inputRef}
95
+ style={{
96
+ // @ts-ignore
97
+ '--append-padding-right': appendRect ? `${appendRect.width}px` : 0,
98
+ }}
99
+ className={cn('dx', 'w-full', textField({ size, roundness, elevation }))}
100
+ data-disabled={props.isDisabled || undefined}
101
+ data-invalid={validation.isInvalid || undefined}
102
+ data-readonly={props.isReadOnly || undefined}
103
+ data-required={props.isRequired || undefined}
104
+ />
105
+ <Flex
106
+ ref={setAppendEl}
107
+ direction={['large', 'extralarge'].includes(size) ? 'column' : 'row-reverse'}
108
+ align={['large', 'extralarge'].includes(size) ? 'start' : 'center'}
109
+ justify={['large', 'extralarge'].includes(size) ? 'center' : 'start'}
110
+ className={cn('absolute top-[0] bottom-[0] transform', {
111
+ 'right-3': ['extrasmall', 'small'].includes(size),
112
+ 'right-4': ['medium', 'large'].includes(size),
113
+ 'right-6': size === 'extralarge',
114
+ })}
115
+ >
116
+ <Button
117
+ {...incrementButtonProps}
118
+ size="extrasmall"
119
+ shape="square"
120
+ variant="ghost"
121
+ mode="subtle"
122
+ inset="right"
123
+ slot="increment"
124
+ >
125
+ <ChevronUp />
126
+ </Button>
127
+ <Button
128
+ {...decrementButtonProps}
129
+ size="extrasmall"
130
+ shape="square"
131
+ variant="ghost"
132
+ mode="subtle"
133
+ inset="right"
134
+ slot="decrement"
135
+ >
136
+ <ChevronDown />
137
+ </Button>
138
+ </Flex>
139
+ {validation.isInvalid && (
140
+ <Text
141
+ {...errorMessageProps}
142
+ size={1}
143
+ className={cn('dx', fieldError({ size, roundness, elevation }))}
144
+ >
145
+ {errorMessage
146
+ ? typeof errorMessage === 'string'
147
+ ? errorMessage
148
+ : errorMessage(validation)
149
+ : validation.validationErrors.length === 0
150
+ ? undefined
151
+ : validation.validationErrors.join(' ')}
152
+ </Text>
153
+ )}
154
+ </div>
155
+ {description && (
156
+ <Text size={1} variant="tertiary" {...descriptionProps}>
157
+ {description}
158
+ </Text>
159
+ )}
160
+ </Flex>
161
+ {props.name && (
162
+ <input
163
+ type="hidden"
164
+ name={props.name}
165
+ value={isNaN(state.numberValue) ? '' : state.numberValue}
166
+ />
167
+ )}
168
+ </>
169
+ );
170
+ }
171
+
172
+ const NumberField = forwardRef(_NumberField);
173
+
174
+ export { NumberField };
@@ -0,0 +1,107 @@
1
+ import { useContextProps, TextFieldContext } from 'react-aria-components';
2
+ import { cn } from '../utils/cn.js';
3
+
4
+ import { Flex, Text } from './index.js';
5
+ import { fieldError } from '../variants/field-error.js';
6
+ import { filterDOMProps } from '@react-aria/utils';
7
+ import { useTextField } from 'react-aria';
8
+ import { forwardRef, useRef, type ReactNode } from 'react';
9
+ import { removeDataAttributes } from '../utils/helpers.js';
10
+
11
+ import type { TextFieldProps, ValidationResult } from 'react-aria-components';
12
+ import { textArea, type TextAreaVariantProps } from '../variants/text-area.js';
13
+
14
+ interface TextAreaProps extends TextFieldProps, TextAreaVariantProps {
15
+ placeholder?: string;
16
+ label?: string;
17
+ description?: string | ReactNode;
18
+ errorMessage?: string | ((validation: ValidationResult) => string);
19
+ }
20
+
21
+ function _TextArea(
22
+ {
23
+ label,
24
+ description,
25
+ errorMessage,
26
+ size = 'medium',
27
+ roundness = 'medium',
28
+ elevation = 'medium',
29
+ ...props
30
+ }: TextAreaProps,
31
+ ref: React.ForwardedRef<HTMLDivElement>,
32
+ ) {
33
+ [props, ref] = useContextProps(props, ref, TextFieldContext);
34
+ let inputRef = useRef(null);
35
+
36
+ let { labelProps, inputProps, descriptionProps, errorMessageProps, ...validation } =
37
+ useTextField<any>(
38
+ {
39
+ ...removeDataAttributes(props),
40
+ inputElementType: 'text-area',
41
+ label,
42
+ },
43
+ inputRef,
44
+ );
45
+
46
+ return (
47
+ <Flex
48
+ {...filterDOMProps(props)}
49
+ gap={2}
50
+ direction="column"
51
+ ref={ref}
52
+ slot={props.slot || undefined}
53
+ data-disabled={props.isDisabled || undefined}
54
+ data-invalid={validation.isInvalid || undefined}
55
+ data-readonly={props.isReadOnly || undefined}
56
+ data-required={props.isRequired || undefined}
57
+ >
58
+ {label && (
59
+ <Text
60
+ {...labelProps}
61
+ size={1}
62
+ transform="uppercase"
63
+ weight="semibold"
64
+ variant="tertiary"
65
+ color="gray"
66
+ >
67
+ {label}
68
+ </Text>
69
+ )}
70
+ <div role="group" className="relative" data-radius={roundness} data-shadow={elevation}>
71
+ <textarea
72
+ {...inputProps}
73
+ ref={inputRef}
74
+ className={cn('dx', 'w-full', textArea({ size, roundness, elevation }))}
75
+ data-disabled={props.isDisabled || undefined}
76
+ data-invalid={validation.isInvalid || undefined}
77
+ data-readonly={props.isReadOnly || undefined}
78
+ data-required={props.isRequired || undefined}
79
+ />
80
+ {validation.isInvalid && (
81
+ <Text
82
+ {...errorMessageProps}
83
+ size={1}
84
+ className={cn('dx', fieldError({ size, roundness, elevation }))}
85
+ >
86
+ {errorMessage
87
+ ? typeof errorMessage === 'string'
88
+ ? errorMessage
89
+ : errorMessage(validation)
90
+ : validation.validationErrors.length === 0
91
+ ? undefined
92
+ : validation.validationErrors.join(' ')}
93
+ </Text>
94
+ )}
95
+ </div>
96
+ {description && (
97
+ <Text size={1} variant="tertiary" {...descriptionProps}>
98
+ {description}
99
+ </Text>
100
+ )}
101
+ </Flex>
102
+ );
103
+ }
104
+
105
+ const TextArea = forwardRef(_TextArea);
106
+
107
+ export { TextArea };
@@ -1,7 +1,107 @@
1
- import React from 'react';
1
+ import { useContextProps, TextFieldContext } from 'react-aria-components';
2
+ import { cn } from '../utils/cn.js';
3
+ import { textField } from '../variants/index.js';
4
+ import { Flex, Text } from './index.js';
5
+ import { fieldError } from '../variants/field-error.js';
6
+ import { filterDOMProps } from '@react-aria/utils';
7
+ import { useTextField } from 'react-aria';
8
+ import { forwardRef, useRef, type ReactNode } from 'react';
9
+ import { removeDataAttributes } from '../utils/helpers.js';
2
10
 
3
- function TextField() {
4
- return <input />;
11
+ import type { TextFieldVariantProps } from '../variants/index.js';
12
+ import type { TextFieldProps as BaseTextFieldProps, ValidationResult } from 'react-aria-components';
13
+
14
+ interface TextFieldProps extends BaseTextFieldProps, TextFieldVariantProps {
15
+ placeholder?: string;
16
+ label?: string;
17
+ description?: string | ReactNode;
18
+ errorMessage?: string | ((validation: ValidationResult) => string);
19
+ }
20
+
21
+ function _TextField(
22
+ {
23
+ label,
24
+ description,
25
+ errorMessage,
26
+ size = 'medium',
27
+ roundness = 'medium',
28
+ elevation = 'medium',
29
+ ...props
30
+ }: TextFieldProps,
31
+ ref: React.ForwardedRef<HTMLDivElement>,
32
+ ) {
33
+ [props, ref] = useContextProps(props, ref, TextFieldContext);
34
+ let inputRef = useRef(null);
35
+
36
+ let { labelProps, inputProps, descriptionProps, errorMessageProps, ...validation } =
37
+ useTextField<any>(
38
+ {
39
+ ...removeDataAttributes(props),
40
+ inputElementType: 'input',
41
+ label,
42
+ },
43
+ inputRef,
44
+ );
45
+
46
+ return (
47
+ <Flex
48
+ {...filterDOMProps(props)}
49
+ gap={2}
50
+ direction="column"
51
+ ref={ref}
52
+ slot={props.slot || undefined}
53
+ data-disabled={props.isDisabled || undefined}
54
+ data-invalid={validation.isInvalid || undefined}
55
+ data-readonly={props.isReadOnly || undefined}
56
+ data-required={props.isRequired || undefined}
57
+ >
58
+ {label && (
59
+ <Text
60
+ {...labelProps}
61
+ size={1}
62
+ transform="uppercase"
63
+ weight="semibold"
64
+ variant="tertiary"
65
+ color="gray"
66
+ >
67
+ {label}
68
+ </Text>
69
+ )}
70
+ <div role="group" className="relative" data-radius={roundness} data-shadow={elevation}>
71
+ <input
72
+ {...inputProps}
73
+ ref={inputRef}
74
+ className={cn('dx', 'w-full', textField({ size, roundness, elevation }))}
75
+ data-disabled={props.isDisabled || undefined}
76
+ data-invalid={validation.isInvalid || undefined}
77
+ data-readonly={props.isReadOnly || undefined}
78
+ data-required={props.isRequired || undefined}
79
+ />
80
+ {validation.isInvalid && (
81
+ <Text
82
+ {...errorMessageProps}
83
+ size={1}
84
+ className={cn('dx', fieldError({ size, roundness, elevation }))}
85
+ >
86
+ {errorMessage
87
+ ? typeof errorMessage === 'string'
88
+ ? errorMessage
89
+ : errorMessage(validation)
90
+ : validation.validationErrors.length === 0
91
+ ? undefined
92
+ : validation.validationErrors.join(' ')}
93
+ </Text>
94
+ )}
95
+ </div>
96
+ {description && (
97
+ <Text size={1} variant="tertiary" {...descriptionProps}>
98
+ {description}
99
+ </Text>
100
+ )}
101
+ </Flex>
102
+ );
5
103
  }
6
104
 
105
+ const TextField = forwardRef(_TextField);
106
+
7
107
  export { TextField };
@@ -1,3 +1,4 @@
1
+ import { useContextProps, LinkContext, TextContext } from 'react-aria-components';
1
2
  import React from 'react';
2
3
  import { Slot } from '@radix-ui/react-slot';
3
4
 
@@ -16,7 +17,8 @@ type TextPProps = { as: 'p' } & React.HTMLAttributes<HTMLParagraphElement>;
16
17
 
17
18
  type TextProps = TextOwnProps & (TextSpanProps | TextDivProps | TextLabelProps | TextPProps);
18
19
 
19
- const Text = React.forwardRef<HTMLDivElement, TextProps>((props, ref) => {
20
+ const Text = React.forwardRef<HTMLElement, TextProps>((props, ref) => {
21
+ [props, ref] = useContextProps(props, ref, TextContext);
20
22
  const {
21
23
  as: Tag = 'span',
22
24
  asChild,
@@ -27,13 +29,20 @@ const Text = React.forwardRef<HTMLDivElement, TextProps>((props, ref) => {
27
29
  color,
28
30
  variant,
29
31
  weight,
32
+ transform,
30
33
  ...rest
31
34
  } = props;
32
35
 
33
36
  return (
34
- <Slot className={text({ size, align, color, variant, className, weight })} ref={ref} {...rest}>
35
- {asChild ? children : <Tag>{children}</Tag>}
36
- </Slot>
37
+ <TextContext.Provider value={props}>
38
+ <Slot
39
+ className={text({ className, size, align, color, variant, weight, transform })}
40
+ ref={ref}
41
+ {...rest}
42
+ >
43
+ {asChild ? children : <Tag>{children}</Tag>}
44
+ </Slot>
45
+ </TextContext.Provider>
37
46
  );
38
47
  });
39
48