@regardio/react 0.6.0 → 0.7.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 (102) hide show
  1. package/dist/background-slideshow/index.d.mts +1 -3
  2. package/dist/blurry-gradient/index.d.mts +4 -5
  3. package/dist/button/index.d.mts +1 -1
  4. package/dist/carousel/index.d.mts +42 -8
  5. package/dist/carousel/index.mjs +11 -16
  6. package/dist/checkbox/index.d.mts +7 -16
  7. package/dist/checkbox-group/index.d.mts +3 -4
  8. package/dist/countdown/index.d.mts +1 -3
  9. package/dist/field/index.d.mts +40 -38
  10. package/dist/fieldset/index.d.mts +15 -14
  11. package/dist/form/index.d.mts +2 -3
  12. package/dist/generic-error/index.d.mts +20 -23
  13. package/dist/grid/index.d.mts +77 -1173
  14. package/dist/grid/index.mjs +5 -7
  15. package/dist/heading/index.d.mts +7 -11
  16. package/dist/heading/index.mjs +2 -3
  17. package/dist/highlight/index.d.mts +2 -3
  18. package/dist/hooks/use-current-route-data.d.mts +4 -4
  19. package/dist/hooks/use-current-route-data.mjs +3 -1
  20. package/dist/hooks/use-focus-search.mjs +2 -0
  21. package/dist/hooks/use-matches-data.d.mts +5 -5
  22. package/dist/hooks/use-matches-data.mjs +2 -0
  23. package/dist/hooks/use-media-query.d.mts +4 -4
  24. package/dist/hooks/use-media-query.mjs +2 -0
  25. package/dist/hooks/use-mobile.mjs +2 -0
  26. package/dist/hooks/use-nonce.d.mts +2 -4
  27. package/dist/hooks/use-orientation.d.mts +6 -6
  28. package/dist/hooks/use-orientation.mjs +2 -0
  29. package/dist/hooks/use-user.d.mts +23 -25
  30. package/dist/icon-button/index.d.mts +4 -5
  31. package/dist/if/index.d.mts +2 -4
  32. package/dist/if/index.mjs +4 -4
  33. package/dist/{index-Bm-tWhsb.d.mts → index-Bj5_XfEC.d.mts} +2 -3
  34. package/dist/{index-YT2CkvL6.d.mts → index-C_evL5vG.d.mts} +4 -5
  35. package/dist/input/index.d.mts +1 -1
  36. package/dist/link/index.d.mts +9 -11
  37. package/dist/link/index.mjs +3 -3
  38. package/dist/list/index.d.mts +39 -38
  39. package/dist/list/index.mjs +7 -7
  40. package/dist/markdown-container/index.d.mts +1 -1
  41. package/dist/markdown-container/index.mjs +1 -1
  42. package/dist/password-input/index.d.mts +4 -5
  43. package/dist/picture/index.d.mts +10 -10
  44. package/dist/protected-email/index.d.mts +9 -11
  45. package/dist/radio/index.d.mts +7 -16
  46. package/dist/radio-group/index.d.mts +3 -4
  47. package/dist/slider/index.d.mts +19 -41
  48. package/dist/switch/index.d.mts +7 -16
  49. package/dist/text/index.d.mts +2 -3
  50. package/dist/{text-CPlUND-Z.mjs → text-EQC4zJbE.mjs} +7 -13
  51. package/dist/toggle/index.d.mts +4 -38
  52. package/dist/utils/text/index.d.mts +5 -5
  53. package/dist/utils/text/index.mjs +1 -1
  54. package/package.json +170 -11
  55. package/src/background-slideshow/background-slideshow.tsx +1 -2
  56. package/src/blurry-gradient/blurry-gradient.tsx +1 -1
  57. package/src/button/button.stories.tsx +1 -1
  58. package/src/button/button.tsx +7 -1
  59. package/src/carousel/carousel-content.tsx +17 -14
  60. package/src/carousel/carousel-item.tsx +18 -18
  61. package/src/carousel/carousel-next.tsx +21 -16
  62. package/src/carousel/carousel-previous.tsx +21 -16
  63. package/src/carousel/carousel-root.tsx +91 -86
  64. package/src/checkbox/checkbox.tsx +14 -3
  65. package/src/checkbox-group/checkbox-group.tsx +1 -1
  66. package/src/countdown/countdown.tsx +1 -1
  67. package/src/field/field.stories.tsx +1 -1
  68. package/src/field/field.tsx +27 -6
  69. package/src/fieldset/fieldset.stories.tsx +1 -1
  70. package/src/fieldset/fieldset.tsx +14 -3
  71. package/src/form/form.stories.tsx +1 -1
  72. package/src/form/form.tsx +1 -1
  73. package/src/generic-error/generic-error.tsx +2 -3
  74. package/src/grid/grid-item.tsx +77 -36
  75. package/src/grid/grid-root.tsx +49 -22
  76. package/src/heading/heading.tsx +7 -3
  77. package/src/highlight/highlight.tsx +1 -1
  78. package/src/hooks/use-current-route-data.ts +4 -2
  79. package/src/hooks/use-focus-search.ts +3 -1
  80. package/src/hooks/use-matches-data.ts +2 -0
  81. package/src/hooks/use-media-query.ts +2 -0
  82. package/src/hooks/use-mobile.ts +3 -1
  83. package/src/hooks/use-nonce.ts +3 -3
  84. package/src/hooks/use-orientation.ts +2 -0
  85. package/src/hooks/use-user.tsx +3 -2
  86. package/src/icon-button/icon-button.tsx +1 -1
  87. package/src/if/if.tsx +3 -1
  88. package/src/input/input.stories.tsx +1 -1
  89. package/src/input/input.tsx +1 -1
  90. package/src/link/link.tsx +4 -3
  91. package/src/list/list-item.tsx +10 -13
  92. package/src/list/list-root-context.ts +3 -3
  93. package/src/list/list-root.tsx +10 -13
  94. package/src/password-input/password-input.tsx +1 -1
  95. package/src/protected-email/protected-email.tsx +6 -1
  96. package/src/radio/radio.tsx +14 -3
  97. package/src/radio-group/radio-group.tsx +5 -1
  98. package/src/slider/slider.tsx +29 -7
  99. package/src/switch/switch.tsx +14 -3
  100. package/src/text/text.tsx +6 -1
  101. package/src/toggle/toggle.tsx +3 -3
  102. package/src/utils/text/text.tsx +8 -16
@@ -1,12 +1,6 @@
1
1
  'use client';
2
2
 
3
- import {
4
- type ComponentPropsWithoutRef,
5
- type ElementType,
6
- type ForwardedRef,
7
- forwardRef,
8
- type ReactNode,
9
- } from 'react';
3
+ import type { ComponentPropsWithoutRef, ElementType, ReactNode } from 'react';
10
4
  import { useListRootContext } from './list-root-context';
11
5
 
12
6
  type ListItemElement = 'li' | 'dd' | 'dt' | 'div' | 'span';
@@ -24,15 +18,18 @@ export type ListItemProps<T extends ListItemElement = 'li'> = Omit<
24
18
  * The content of the list item.
25
19
  */
26
20
  children?: ReactNode;
21
+ /**
22
+ * Ref to the root element.
23
+ */
24
+ ref?: React.Ref<HTMLElement>;
27
25
  };
28
26
 
29
27
  function ListItemImpl<T extends ListItemElement = 'li'>(
30
28
  props: ListItemProps<T>,
31
- ref: ForwardedRef<HTMLElement>,
32
- ) {
29
+ ): React.JSX.Element {
33
30
  const context = useListRootContext();
34
31
 
35
- const { render, children, className, ...elementProps } = props;
32
+ const { render, children, className, ref, ...elementProps } = props;
36
33
 
37
34
  const resolvedElement = render ?? context?.defaultItemElement ?? 'li';
38
35
  const resolvedClassName = context?.defaultItemClassName
@@ -54,9 +51,9 @@ function ListItemImpl<T extends ListItemElement = 'li'>(
54
51
  );
55
52
  }
56
53
 
57
- export const ListItem = forwardRef(ListItemImpl) as <T extends ListItemElement = 'li'>(
58
- props: ListItemProps<T> & { ref?: ForwardedRef<HTMLElement> },
59
- ) => ReturnType<typeof ListItemImpl>;
54
+ export const ListItem = ListItemImpl as <T extends ListItemElement = 'li'>(
55
+ props: ListItemProps<T>,
56
+ ) => React.JSX.Element;
60
57
 
61
58
  export namespace ListItem {
62
59
  export type Props<T extends ListItemElement = 'li'> = ListItemProps<T>;
@@ -1,5 +1,3 @@
1
- 'use client';
2
-
3
1
  import { createContext, useContext } from 'react';
4
2
 
5
3
  export interface ListRootContextValue {
@@ -14,7 +12,9 @@ export interface ListRootContextValue {
14
12
  defaultItemClassName?: string;
15
13
  }
16
14
 
17
- export const ListRootContext = createContext<ListRootContextValue | undefined>(undefined);
15
+ export const ListRootContext: React.Context<ListRootContextValue | undefined> = createContext<
16
+ ListRootContextValue | undefined
17
+ >(undefined);
18
18
 
19
19
  export function useListRootContext(): ListRootContextValue | undefined {
20
20
  return useContext(ListRootContext);
@@ -1,13 +1,6 @@
1
1
  'use client';
2
2
 
3
- import {
4
- type ComponentPropsWithoutRef,
5
- type ElementType,
6
- type ForwardedRef,
7
- forwardRef,
8
- type ReactNode,
9
- useMemo,
10
- } from 'react';
3
+ import { type ComponentPropsWithoutRef, type ElementType, type ReactNode, useMemo } from 'react';
11
4
  import { ListRootContext, type ListRootContextValue } from './list-root-context';
12
5
 
13
6
  type ListRootElement = 'ul' | 'ol' | 'dl' | 'div' | 'menu' | 'nav';
@@ -34,17 +27,21 @@ export type ListRootProps<T extends ListRootElement = 'ul'> = Omit<
34
27
  * Default className to apply to all list items.
35
28
  */
36
29
  defaultItemClassName?: string;
30
+ /**
31
+ * Ref to the root element.
32
+ */
33
+ ref?: React.Ref<HTMLElement>;
37
34
  };
38
35
 
39
36
  function ListRootImpl<T extends ListRootElement = 'ul'>(
40
37
  props: ListRootProps<T>,
41
- ref: ForwardedRef<HTMLElement>,
42
- ) {
38
+ ): React.JSX.Element {
43
39
  const {
44
40
  render = 'ul' as T,
45
41
  children,
46
42
  defaultItemElement,
47
43
  defaultItemClassName,
44
+ ref,
48
45
  ...elementProps
49
46
  } = props;
50
47
 
@@ -72,9 +69,9 @@ function ListRootImpl<T extends ListRootElement = 'ul'>(
72
69
  );
73
70
  }
74
71
 
75
- export const ListRoot = forwardRef(ListRootImpl) as <T extends ListRootElement = 'ul'>(
76
- props: ListRootProps<T> & { ref?: ForwardedRef<HTMLElement> },
77
- ) => ReturnType<typeof ListRootImpl>;
72
+ export const ListRoot = ListRootImpl as <T extends ListRootElement = 'ul'>(
73
+ props: ListRootProps<T>,
74
+ ) => React.JSX.Element;
78
75
 
79
76
  export namespace ListRoot {
80
77
  export type Props<T extends ListRootElement = 'ul'> = ListRootProps<T>;
@@ -60,7 +60,7 @@ export const PasswordInput = ({
60
60
  inputVariant = 'default',
61
61
  showToggle = true,
62
62
  ...props
63
- }: PasswordInputProps) => {
63
+ }: PasswordInputProps): React.JSX.Element => {
64
64
  const [showPassword, setShowPassword] = useState(false);
65
65
 
66
66
  const togglePasswordVisibility = () => {
@@ -18,7 +18,12 @@ export interface ProtectedEmailProps {
18
18
  * @param text - Optional display text (defaults to username(at)domain)
19
19
  * @param className - Optional CSS class name
20
20
  */
21
- export function ProtectedEmail({ username, domain, text, className }: ProtectedEmailProps) {
21
+ export function ProtectedEmail({
22
+ username,
23
+ domain,
24
+ text,
25
+ className,
26
+ }: ProtectedEmailProps): React.JSX.Element {
22
27
  const [mounted, setMounted] = useState(false);
23
28
 
24
29
  // Only assemble the email on the client side
@@ -50,7 +50,11 @@ export interface RadioIndicatorProps
50
50
  className?: string;
51
51
  }
52
52
 
53
- export const RadioRoot = ({ className, size = 'md', ...props }: RadioRootProps) => {
53
+ export const RadioRoot = ({
54
+ className,
55
+ size = 'md',
56
+ ...props
57
+ }: RadioRootProps): React.JSX.Element => {
54
58
  return (
55
59
  <BaseUIRadio.Root
56
60
  className={radioRoot({
@@ -62,7 +66,11 @@ export const RadioRoot = ({ className, size = 'md', ...props }: RadioRootProps)
62
66
  );
63
67
  };
64
68
 
65
- export const RadioIndicator = ({ className, children, ...props }: RadioIndicatorProps) => {
69
+ export const RadioIndicator = ({
70
+ className,
71
+ children,
72
+ ...props
73
+ }: RadioIndicatorProps): React.JSX.Element => {
66
74
  return (
67
75
  <BaseUIRadio.Indicator
68
76
  className={radioIndicator({ className })}
@@ -86,7 +94,10 @@ export const RadioIndicator = ({ className, children, ...props }: RadioIndicator
86
94
  );
87
95
  };
88
96
 
89
- export const Radio = {
97
+ export const Radio: {
98
+ Indicator: typeof RadioIndicator;
99
+ Root: typeof RadioRoot;
100
+ } = {
90
101
  Indicator: RadioIndicator,
91
102
  Root: RadioRoot,
92
103
  };
@@ -23,7 +23,11 @@ export interface RadioGroupProps
23
23
  orientation?: RadioGroupOrientation;
24
24
  }
25
25
 
26
- export const RadioGroup = ({ className, orientation = 'vertical', ...props }: RadioGroupProps) => {
26
+ export const RadioGroup = ({
27
+ className,
28
+ orientation = 'vertical',
29
+ ...props
30
+ }: RadioGroupProps): React.JSX.Element => {
27
31
  return (
28
32
  <BaseUIRadioGroup
29
33
  className={radioGroup({
@@ -106,7 +106,11 @@ export interface SliderValueProps
106
106
  className?: string;
107
107
  }
108
108
 
109
- export const SliderRoot = ({ className, size = 'md', ...props }: SliderRootProps) => {
109
+ export const SliderRoot = ({
110
+ className,
111
+ size = 'md',
112
+ ...props
113
+ }: SliderRootProps): React.JSX.Element => {
110
114
  return (
111
115
  <BaseUISlider.Root
112
116
  className={sliderRoot({
@@ -118,7 +122,7 @@ export const SliderRoot = ({ className, size = 'md', ...props }: SliderRootProps
118
122
  );
119
123
  };
120
124
 
121
- export const SliderControl = ({ className, ...props }: SliderControlProps) => {
125
+ export const SliderControl = ({ className, ...props }: SliderControlProps): React.JSX.Element => {
122
126
  return (
123
127
  <BaseUISlider.Control
124
128
  className={sliderControl({ className })}
@@ -127,7 +131,11 @@ export const SliderControl = ({ className, ...props }: SliderControlProps) => {
127
131
  );
128
132
  };
129
133
 
130
- export const SliderTrack = ({ className, size = 'md', ...props }: SliderTrackProps) => {
134
+ export const SliderTrack = ({
135
+ className,
136
+ size = 'md',
137
+ ...props
138
+ }: SliderTrackProps): React.JSX.Element => {
131
139
  return (
132
140
  <BaseUISlider.Track
133
141
  className={sliderTrack({
@@ -139,7 +147,10 @@ export const SliderTrack = ({ className, size = 'md', ...props }: SliderTrackPro
139
147
  );
140
148
  };
141
149
 
142
- export const SliderIndicator = ({ className, ...props }: SliderIndicatorProps) => {
150
+ export const SliderIndicator = ({
151
+ className,
152
+ ...props
153
+ }: SliderIndicatorProps): React.JSX.Element => {
143
154
  return (
144
155
  <BaseUISlider.Indicator
145
156
  className={sliderIndicator({ className })}
@@ -148,7 +159,11 @@ export const SliderIndicator = ({ className, ...props }: SliderIndicatorProps) =
148
159
  );
149
160
  };
150
161
 
151
- export const SliderThumb = ({ className, size = 'md', ...props }: SliderThumbProps) => {
162
+ export const SliderThumb = ({
163
+ className,
164
+ size = 'md',
165
+ ...props
166
+ }: SliderThumbProps): React.JSX.Element => {
152
167
  return (
153
168
  <BaseUISlider.Thumb
154
169
  className={sliderThumb({
@@ -160,7 +175,7 @@ export const SliderThumb = ({ className, size = 'md', ...props }: SliderThumbPro
160
175
  );
161
176
  };
162
177
 
163
- export const SliderValue = ({ className, ...props }: SliderValueProps) => {
178
+ export const SliderValue = ({ className, ...props }: SliderValueProps): React.JSX.Element => {
164
179
  return (
165
180
  <BaseUISlider.Value
166
181
  className={sliderValue({ className })}
@@ -169,7 +184,14 @@ export const SliderValue = ({ className, ...props }: SliderValueProps) => {
169
184
  );
170
185
  };
171
186
 
172
- export const Slider = {
187
+ export const Slider: {
188
+ Control: typeof SliderControl;
189
+ Indicator: typeof SliderIndicator;
190
+ Root: typeof SliderRoot;
191
+ Thumb: typeof SliderThumb;
192
+ Track: typeof SliderTrack;
193
+ Value: typeof SliderValue;
194
+ } = {
173
195
  Control: SliderControl,
174
196
  Indicator: SliderIndicator,
175
197
  Root: SliderRoot,
@@ -71,7 +71,11 @@ export interface SwitchThumbProps
71
71
  size?: SwitchSize;
72
72
  }
73
73
 
74
- export const SwitchRoot = ({ className, size = 'md', ...props }: SwitchRootProps) => {
74
+ export const SwitchRoot = ({
75
+ className,
76
+ size = 'md',
77
+ ...props
78
+ }: SwitchRootProps): React.JSX.Element => {
75
79
  return (
76
80
  <BaseUISwitch.Root
77
81
  className={switchRoot({
@@ -83,7 +87,11 @@ export const SwitchRoot = ({ className, size = 'md', ...props }: SwitchRootProps
83
87
  );
84
88
  };
85
89
 
86
- export const SwitchThumb = ({ className, size = 'md', ...props }: SwitchThumbProps) => {
90
+ export const SwitchThumb = ({
91
+ className,
92
+ size = 'md',
93
+ ...props
94
+ }: SwitchThumbProps): React.JSX.Element => {
87
95
  return (
88
96
  <BaseUISwitch.Thumb
89
97
  className={switchThumb({
@@ -95,7 +103,10 @@ export const SwitchThumb = ({ className, size = 'md', ...props }: SwitchThumbPro
95
103
  );
96
104
  };
97
105
 
98
- export const Switch = {
106
+ export const Switch: {
107
+ Root: typeof SwitchRoot;
108
+ Thumb: typeof SwitchThumb;
109
+ } = {
99
110
  Root: SwitchRoot,
100
111
  Thumb: SwitchThumb,
101
112
  };
package/src/text/text.tsx CHANGED
@@ -31,7 +31,12 @@ export interface TextProps extends ComponentProps<'p'> {
31
31
  variant?: TextVariant;
32
32
  }
33
33
 
34
- export const Text = ({ children, className, variant, themeColor }: TextProps) => {
34
+ export const Text = ({
35
+ children,
36
+ className,
37
+ variant,
38
+ themeColor,
39
+ }: TextProps): React.JSX.Element => {
35
40
  return (
36
41
  <div
37
42
  className={text({
@@ -2,7 +2,7 @@ import { Toggle as BaseUIToggle } from '@base-ui/react/toggle';
2
2
  import { tv } from '@regardio/tailwind/utils';
3
3
  import type { ComponentProps, ReactNode } from 'react';
4
4
 
5
- const toggle = tv({
5
+ const toggle: ReturnType<typeof tv> = tv({
6
6
  base: [
7
7
  'inline-flex',
8
8
  'items-center',
@@ -51,7 +51,7 @@ const toggle = tv({
51
51
  ],
52
52
  },
53
53
  },
54
- });
54
+ } as const);
55
55
 
56
56
  export type ToggleVariant = keyof typeof toggle.variants.variant;
57
57
  export type ToggleSize = keyof typeof toggle.variants.size;
@@ -71,7 +71,7 @@ export const Toggle = ({
71
71
  title,
72
72
  children,
73
73
  ...props
74
- }: ToggleProps) => {
74
+ }: ToggleProps): React.JSX.Element => {
75
75
  return (
76
76
  <BaseUIToggle
77
77
  className={toggle({
@@ -1,5 +1,5 @@
1
1
  import { replaceShyInString, splitIntoSentences, typographicQuotes } from '@regardio/js/text';
2
- import React, { cloneElement, isValidElement, type ReactElement, type ReactNode } from 'react';
2
+ import { cloneElement, Fragment, isValidElement, type ReactElement, type ReactNode } from 'react';
3
3
 
4
4
  export const lowerCaseSzett = (text: ReactNode | string, _returnType?: 'string'): ReactNode => {
5
5
  // Helper function to process strings
@@ -24,21 +24,18 @@ export const lowerCaseSzett = (text: ReactNode | string, _returnType?: 'string')
24
24
  return processString(text);
25
25
  }
26
26
 
27
- // Handle valid React elements with correct type assertion
27
+ // Handle valid React elements
28
28
  if (isValidElement(text)) {
29
29
  const element = text as ReactElement<{ children?: ReactNode }>;
30
- const { children, ...props } = element.props;
30
+ const { children } = element.props;
31
31
 
32
- return cloneElement(element, {
33
- ...props,
34
- children: lowerCaseSzett(children),
35
- });
32
+ return cloneElement(element, element.props, lowerCaseSzett(children));
36
33
  }
37
34
 
38
35
  // Handle arrays
39
36
  if (Array.isArray(text)) {
40
37
  return text.map((child, index) => (
41
- <React.Fragment key={index.toString()}>{lowerCaseSzett(child as ReactNode)}</React.Fragment>
38
+ <Fragment key={index.toString()}>{lowerCaseSzett(child as ReactNode)}</Fragment>
42
39
  ));
43
40
  }
44
41
 
@@ -55,19 +52,14 @@ function replaceShyInReactNode(node: ReactNode): ReactNode {
55
52
 
56
53
  if (isValidElement(node)) {
57
54
  const element = node as ReactElement<{ children?: ReactNode }>;
58
- const { children, ...props } = element.props;
55
+ const { children } = element.props;
59
56
 
60
- return cloneElement(element, {
61
- ...props,
62
- children: replaceShyInReactNode(children),
63
- });
57
+ return cloneElement(element, element.props, replaceShyInReactNode(children));
64
58
  }
65
59
 
66
60
  if (Array.isArray(node)) {
67
61
  return node.map((child, index) => (
68
- <React.Fragment key={index.toString()}>
69
- {replaceShyInReactNode(child as ReactNode)}
70
- </React.Fragment>
62
+ <Fragment key={index.toString()}>{replaceShyInReactNode(child as ReactNode)}</Fragment>
71
63
  ));
72
64
  }
73
65