@kushagradhawan/kookie-ui 0.1.71 → 0.1.72

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 (96) hide show
  1. package/README.md +4 -0
  2. package/components.css +63 -380
  3. package/dist/cjs/components/_internal/base-button.d.ts.map +1 -1
  4. package/dist/cjs/components/_internal/base-button.js +1 -1
  5. package/dist/cjs/components/_internal/base-button.js.map +3 -3
  6. package/dist/cjs/components/button.d.ts.map +1 -1
  7. package/dist/cjs/components/button.js +1 -1
  8. package/dist/cjs/components/button.js.map +3 -3
  9. package/dist/cjs/components/chatbar.d.ts.map +1 -1
  10. package/dist/cjs/components/chatbar.js.map +2 -2
  11. package/dist/cjs/components/icon-button.d.ts.map +1 -1
  12. package/dist/cjs/components/icon-button.js +2 -2
  13. package/dist/cjs/components/icon-button.js.map +3 -3
  14. package/dist/cjs/components/shell.d.ts.map +1 -1
  15. package/dist/cjs/components/shell.js +1 -1
  16. package/dist/cjs/components/shell.js.map +3 -3
  17. package/dist/cjs/components/toggle-button.d.ts.map +1 -1
  18. package/dist/cjs/components/toggle-button.js +1 -1
  19. package/dist/cjs/components/toggle-button.js.map +3 -3
  20. package/dist/cjs/components/toggle-icon-button.d.ts.map +1 -1
  21. package/dist/cjs/components/toggle-icon-button.js +1 -1
  22. package/dist/cjs/components/toggle-icon-button.js.map +3 -3
  23. package/dist/cjs/hooks/index.d.ts +2 -0
  24. package/dist/cjs/hooks/index.d.ts.map +1 -1
  25. package/dist/cjs/hooks/index.js +1 -1
  26. package/dist/cjs/hooks/index.js.map +3 -3
  27. package/dist/cjs/hooks/use-live-announcer.d.ts.map +1 -1
  28. package/dist/cjs/hooks/use-live-announcer.js +2 -2
  29. package/dist/cjs/hooks/use-live-announcer.js.map +3 -3
  30. package/dist/cjs/hooks/use-toggle-state.d.ts +37 -0
  31. package/dist/cjs/hooks/use-toggle-state.d.ts.map +1 -0
  32. package/dist/cjs/hooks/use-toggle-state.js +2 -0
  33. package/dist/cjs/hooks/use-toggle-state.js.map +7 -0
  34. package/dist/cjs/hooks/use-tooltip-wrapper.d.ts +29 -0
  35. package/dist/cjs/hooks/use-tooltip-wrapper.d.ts.map +1 -0
  36. package/dist/cjs/hooks/use-tooltip-wrapper.js +2 -0
  37. package/dist/cjs/hooks/use-tooltip-wrapper.js.map +7 -0
  38. package/dist/esm/components/_internal/base-button.d.ts.map +1 -1
  39. package/dist/esm/components/_internal/base-button.js +1 -1
  40. package/dist/esm/components/_internal/base-button.js.map +3 -3
  41. package/dist/esm/components/button.d.ts.map +1 -1
  42. package/dist/esm/components/button.js +1 -1
  43. package/dist/esm/components/button.js.map +3 -3
  44. package/dist/esm/components/chatbar.d.ts.map +1 -1
  45. package/dist/esm/components/chatbar.js.map +2 -2
  46. package/dist/esm/components/icon-button.d.ts.map +1 -1
  47. package/dist/esm/components/icon-button.js +2 -2
  48. package/dist/esm/components/icon-button.js.map +3 -3
  49. package/dist/esm/components/shell.d.ts.map +1 -1
  50. package/dist/esm/components/shell.js +1 -1
  51. package/dist/esm/components/shell.js.map +3 -3
  52. package/dist/esm/components/toggle-button.d.ts.map +1 -1
  53. package/dist/esm/components/toggle-button.js +1 -1
  54. package/dist/esm/components/toggle-button.js.map +3 -3
  55. package/dist/esm/components/toggle-icon-button.d.ts.map +1 -1
  56. package/dist/esm/components/toggle-icon-button.js +1 -1
  57. package/dist/esm/components/toggle-icon-button.js.map +3 -3
  58. package/dist/esm/hooks/index.d.ts +2 -0
  59. package/dist/esm/hooks/index.d.ts.map +1 -1
  60. package/dist/esm/hooks/index.js +1 -1
  61. package/dist/esm/hooks/index.js.map +3 -3
  62. package/dist/esm/hooks/use-live-announcer.d.ts.map +1 -1
  63. package/dist/esm/hooks/use-live-announcer.js +2 -2
  64. package/dist/esm/hooks/use-live-announcer.js.map +3 -3
  65. package/dist/esm/hooks/use-toggle-state.d.ts +37 -0
  66. package/dist/esm/hooks/use-toggle-state.d.ts.map +1 -0
  67. package/dist/esm/hooks/use-toggle-state.js +2 -0
  68. package/dist/esm/hooks/use-toggle-state.js.map +7 -0
  69. package/dist/esm/hooks/use-tooltip-wrapper.d.ts +29 -0
  70. package/dist/esm/hooks/use-tooltip-wrapper.d.ts.map +1 -0
  71. package/dist/esm/hooks/use-tooltip-wrapper.js +2 -0
  72. package/dist/esm/hooks/use-tooltip-wrapper.js.map +7 -0
  73. package/package.json +4 -4
  74. package/schemas/base-button.json +1 -1
  75. package/schemas/button.json +1 -1
  76. package/schemas/icon-button.json +1 -1
  77. package/schemas/index.json +6 -6
  78. package/schemas/toggle-button.json +1 -1
  79. package/schemas/toggle-icon-button.json +1 -1
  80. package/src/components/_internal/base-button.css +136 -614
  81. package/src/components/_internal/base-button.tsx +15 -13
  82. package/src/components/button.tsx +13 -42
  83. package/src/components/chatbar.tsx +1 -13
  84. package/src/components/icon-button.tsx +20 -44
  85. package/src/components/image.css +10 -8
  86. package/src/components/shell.tsx +13 -9
  87. package/src/components/toggle-button.tsx +30 -59
  88. package/src/components/toggle-icon-button.tsx +29 -51
  89. package/src/hooks/index.ts +2 -0
  90. package/src/hooks/use-live-announcer.ts +34 -7
  91. package/src/hooks/use-toggle-state.ts +72 -0
  92. package/src/hooks/use-tooltip-wrapper.ts +28 -0
  93. package/src/styles/tokens/color.css +11 -1
  94. package/styles.css +70 -381
  95. package/tokens/base.css +7 -1
  96. package/tokens.css +7 -1
@@ -1,15 +1,23 @@
1
1
  import * as React from 'react';
2
2
 
3
+ /**
4
+ * Reference counter to track how many components are using the live region.
5
+ * Only remove the live region when no components are using it.
6
+ */
7
+ let liveRegionRefCount = 0;
8
+
3
9
  /**
4
10
  * Hook for making live announcements to screen readers
5
11
  * Creates a hidden aria-live region for announcing dynamic content changes
6
12
  */
7
13
  export function useLiveAnnouncer() {
14
+ // Track the timeout so we can clean it up on unmount
15
+ const timeoutRef = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
8
16
 
9
17
  // Create aria-live region if it doesn't exist
10
18
  React.useEffect(() => {
11
19
  let liveRegion = document.getElementById('rt-live-announcer');
12
-
20
+
13
21
  if (!liveRegion) {
14
22
  liveRegion = document.createElement('div');
15
23
  liveRegion.id = 'rt-live-announcer';
@@ -27,10 +35,24 @@ export function useLiveAnnouncer() {
27
35
  document.body.appendChild(liveRegion);
28
36
  }
29
37
 
38
+ // Increment ref count when component mounts
39
+ liveRegionRefCount++;
40
+
30
41
  return () => {
31
- // Clean up on unmount if no other components are using it
32
- if (liveRegion && !liveRegion.hasChildNodes()) {
33
- liveRegion.remove();
42
+ // Decrement ref count when component unmounts
43
+ liveRegionRefCount--;
44
+
45
+ // Clean up timeout on unmount
46
+ if (timeoutRef.current) {
47
+ clearTimeout(timeoutRef.current);
48
+ }
49
+
50
+ // Only remove the live region if no components are using it
51
+ if (liveRegionRefCount === 0) {
52
+ const region = document.getElementById('rt-live-announcer');
53
+ if (region) {
54
+ region.remove();
55
+ }
34
56
  }
35
57
  };
36
58
  }, []);
@@ -38,15 +60,20 @@ export function useLiveAnnouncer() {
38
60
  const announce = React.useCallback((message: string) => {
39
61
  const liveRegion = document.getElementById('rt-live-announcer');
40
62
  if (liveRegion) {
63
+ // Clear any pending timeout
64
+ if (timeoutRef.current) {
65
+ clearTimeout(timeoutRef.current);
66
+ }
67
+
41
68
  // Clear previous announcements
42
69
  liveRegion.textContent = '';
43
-
70
+
44
71
  // Add new announcement with a small delay to ensure it's announced
45
- setTimeout(() => {
72
+ timeoutRef.current = setTimeout(() => {
46
73
  liveRegion.textContent = message;
47
74
  }, 100);
48
75
  }
49
76
  }, []);
50
77
 
51
78
  return announce;
52
- }
79
+ }
@@ -0,0 +1,72 @@
1
+ import * as React from 'react';
2
+ import { useLiveAnnouncer } from './use-live-announcer.js';
3
+
4
+ /**
5
+ * Options for the useToggleState hook
6
+ */
7
+ interface UseToggleStateOptions {
8
+ /** Controlled pressed state */
9
+ pressed?: boolean;
10
+ /** Callback when pressed state changes */
11
+ onPressedChange?: (pressed: boolean) => void;
12
+ /** Function to get the accessible name for announcements */
13
+ getAccessibleName: () => string;
14
+ /** Component name for warning messages */
15
+ componentName: string;
16
+ }
17
+
18
+ /**
19
+ * Hook for shared toggle button state management.
20
+ * Provides accessibility announcements and controlled/uncontrolled warnings.
21
+ *
22
+ * @param options - Configuration options for the toggle state
23
+ * @returns Object containing the handlePressedChange callback
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * const getAccessibleName = React.useCallback(() => 'Toggle button', []);
28
+ *
29
+ * const { handlePressedChange } = useToggleState({
30
+ * pressed,
31
+ * onPressedChange,
32
+ * getAccessibleName,
33
+ * componentName: 'ToggleButton',
34
+ * });
35
+ * ```
36
+ */
37
+ export function useToggleState({ pressed, onPressedChange, getAccessibleName, componentName }: UseToggleStateOptions) {
38
+ const announce = useLiveAnnouncer();
39
+
40
+ // Track if we've already warned about controlled without handler
41
+ const warnedRef = React.useRef(false);
42
+
43
+ /**
44
+ * Memoized handler for state changes with accessibility announcements.
45
+ * Announces the new state immediately for screen readers.
46
+ */
47
+ const handlePressedChange = React.useCallback(
48
+ (newPressed: boolean) => {
49
+ const accessibleName = getAccessibleName();
50
+ // Announce the state change for screen readers
51
+ announce(`${accessibleName} ${newPressed ? 'pressed' : 'unpressed'}`);
52
+ // Call the user's change handler
53
+ onPressedChange?.(newPressed);
54
+ },
55
+ [announce, onPressedChange, getAccessibleName],
56
+ );
57
+
58
+ // Development-only warning for controlled/uncontrolled pattern
59
+ // Only warns once to avoid console spam
60
+ React.useEffect(() => {
61
+ if (process.env.NODE_ENV === 'development' && pressed !== undefined && onPressedChange === undefined && !warnedRef.current) {
62
+ warnedRef.current = true;
63
+ console.warn(
64
+ `${componentName}: You provided a \`pressed\` prop without an \`onPressedChange\` handler. ` +
65
+ 'This will result in a read-only toggle button. If you want the button to be interactive, ' +
66
+ 'you should provide an `onPressedChange` handler.',
67
+ );
68
+ }
69
+ }, [pressed, onPressedChange, componentName]);
70
+
71
+ return { handlePressedChange };
72
+ }
@@ -0,0 +1,28 @@
1
+ import * as React from 'react';
2
+
3
+ /**
4
+ * Hook for managing tooltip accessibility props and conditional rendering.
5
+ * Encapsulates tooltip ID generation and aria-describedby binding.
6
+ *
7
+ * @param tooltip - The tooltip content (if any)
8
+ * @returns Object containing tooltipId, hasTooltip flag, and accessibility props
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const { tooltipId, hasTooltip, accessibilityProps } = useTooltipWrapper(tooltip);
13
+ *
14
+ * const button = <button {...accessibilityProps}>Click me</button>;
15
+ *
16
+ * if (!hasTooltip) return button;
17
+ *
18
+ * return <Tooltip id={tooltipId} content={tooltip}>{button}</Tooltip>;
19
+ * ```
20
+ */
21
+ export function useTooltipWrapper(tooltip: React.ReactNode) {
22
+ const tooltipId = React.useId();
23
+ const hasTooltip = Boolean(tooltip);
24
+
25
+ const accessibilityProps = React.useMemo(() => (hasTooltip ? { 'aria-describedby': tooltipId } : {}), [hasTooltip, tooltipId]);
26
+
27
+ return { tooltipId, hasTooltip, accessibilityProps };
28
+ }
@@ -16,6 +16,10 @@
16
16
  --color-surface-translucent: rgba(255, 255, 255, var(--surface-opacity));
17
17
  --color-dialog-solid: white;
18
18
  --color-dialog-translucent: rgba(255, 255, 255, var(--dialog-opacity));
19
+
20
+ /* Material system defaults (solid) - controls color-mix blending for component backgrounds */
21
+ --material-blend: 100%;
22
+ --material-alpha: 0;
19
23
  }
20
24
  :is(.dark, .dark-theme),
21
25
  :is(.dark, .dark-theme) :where(.radix-themes:not(.light, .light-theme)) {
@@ -130,13 +134,16 @@
130
134
  /* * * * * * * * * * * * * * * * * * * */
131
135
 
132
136
  .radix-themes {
133
- &:where([data-panel-background='solid']) {
137
+ &:where([data-panel-background='solid'], [data-material='solid']) {
134
138
  --color-panel: var(--color-panel-solid);
135
139
  --color-surface: var(--color-surface-solid);
136
140
  --color-dialog: var(--color-dialog-solid);
137
141
  --backdrop-filter-panel: none;
138
142
  --backdrop-filter-components: none;
139
143
  --backdrop-filter-dialog: none;
144
+ /* Material system for component backgrounds */
145
+ --material-blend: 100%;
146
+ --material-alpha: 0;
140
147
  }
141
148
  &:where([data-panel-background='translucent'], [data-material='translucent']) {
142
149
  --color-panel: var(--color-panel-translucent);
@@ -145,6 +152,9 @@
145
152
  --backdrop-filter-panel: blur(var(--backdrop-blur-panel));
146
153
  --backdrop-filter-components: blur(var(--backdrop-blur-components));
147
154
  --backdrop-filter-dialog: blur(var(--backdrop-blur-dialog));
155
+ /* Material system for component backgrounds */
156
+ --material-blend: 60%;
157
+ --material-alpha: 1;
148
158
  }
149
159
  }
150
160