gbs-add-block 0.0.68 → 0.0.69

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.
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "gbs-add-block",
3
- "version": "0.0.68",
3
+ "version": "0.0.69",
4
4
  "description": "React Component Library",
5
+ "type": "module",
5
6
  "files": [
6
7
  "index.js",
7
8
  "source"
@@ -19,7 +20,6 @@
19
20
  "author": "Anandhu Remanan",
20
21
  "license": "ISC",
21
22
  "dependencies": {
22
- "fs-extra": "^11.2.0",
23
23
  "path": "^0.12.7",
24
24
  "yargs": "^17.7.2"
25
25
  },
@@ -11,7 +11,7 @@
11
11
  import { GridMemoised as GridComponent } from "./layout";
12
12
  import { memo } from "react";
13
13
 
14
- const Grid = memo(GridComponent, (prevProps, nextProps) => {
14
+ const DataGrid = memo(GridComponent, (prevProps, nextProps) => {
15
15
  // Custom comparison function
16
16
  return (
17
17
  prevProps.dataSource === nextProps.dataSource &&
@@ -23,4 +23,4 @@ const Grid = memo(GridComponent, (prevProps, nextProps) => {
23
23
  );
24
24
  });
25
25
 
26
- export { Grid };
26
+ export { DataGrid };
@@ -15,7 +15,7 @@ import React, {
15
15
  } from "react";
16
16
  import Icon from "../icon/Icon";
17
17
  import { check, search, upDown, x } from "../icon/iconPaths";
18
- import type { SelectHandle, SelectProps } from "./types";
18
+ import type { ItemsProps, SelectHandle, SelectProps } from "./types";
19
19
  import { selectStyle } from "./style";
20
20
  import { iconClass, popUp, primary } from "../globalStyle";
21
21
  import {
@@ -23,6 +23,7 @@ import {
23
23
  useSelectData,
24
24
  useClickOutside,
25
25
  applyScrollbarStyles,
26
+ useKeyboardNavigation,
26
27
  } from "@grampro/headless-helpers";
27
28
 
28
29
  const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
@@ -71,6 +72,26 @@ const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
71
72
  setShowPopover(false)
72
73
  );
73
74
 
75
+ // Update the handleSelect to accept a SelectItem
76
+ const handleSelect = useCallback(
77
+ (item: ItemsProps) => {
78
+ setSelectedItem(item.value);
79
+ setShowPopover(false);
80
+ setSearchTerm("");
81
+ if (onSelect) onSelect(item.value);
82
+ },
83
+ [onSelect, setSelectedItem, setShowPopover, setSearchTerm]
84
+ );
85
+
86
+ // Set up keyboard navigation with the correct item type
87
+ const { focusedIndex, setFocusedIndex, itemRefs, handleKeyDown } =
88
+ useKeyboardNavigation<ItemsProps>({
89
+ items: filteredItems,
90
+ isOpen: showPopover,
91
+ onSelect: handleSelect,
92
+ onClose: () => setShowPopover(false),
93
+ });
94
+
74
95
  useEffect(() => {
75
96
  if (showPopover) {
76
97
  inputRef.current?.focus();
@@ -83,16 +104,6 @@ const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
83
104
  }
84
105
  }, [initialSelectedItem, setSelectedItem]);
85
106
 
86
- const handleSelect = useCallback(
87
- (value: string) => {
88
- setSelectedItem(value);
89
- setShowPopover(false);
90
- setSearchTerm("");
91
- if (onSelect) onSelect(value);
92
- },
93
- [onSelect, setSelectedItem, setShowPopover, setSearchTerm]
94
- );
95
-
96
107
  const handleClear = () => {
97
108
  if (disabled) return;
98
109
  clearSelected();
@@ -110,7 +121,12 @@ const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
110
121
  }));
111
122
 
112
123
  return (
113
- <div className="relative w-full" ref={selectRef} id={id}>
124
+ <div
125
+ className="relative w-full mt-2"
126
+ ref={selectRef}
127
+ id={id}
128
+ onKeyDown={handleKeyDown}
129
+ >
114
130
  <div className="w-full relative">
115
131
  <button
116
132
  className={`${error ? primary["error-border"] : "border"} ${
@@ -164,16 +180,21 @@ const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
164
180
  onChange={(e) => {
165
181
  setSearchTerm(e.target.value);
166
182
  if (onFiltering) onFiltering(e.target.value);
183
+ setFocusedIndex(-1);
167
184
  }}
168
185
  />
169
186
  </div>
170
187
  )}
171
188
  {filteredItems.length > 0 ? (
172
- filteredItems.map(({ value, label }) => (
189
+ filteredItems.map(({ value, label }, index) => (
173
190
  <button
174
191
  key={value}
175
- className={selectStyle["filter-button"]}
176
- onClick={() => handleSelect(value)}
192
+ ref={(el: any) => (itemRefs.current[index] = el)}
193
+ className={`${selectStyle["filter-button"]} ${
194
+ focusedIndex === index ? "bg-gray-100" : ""
195
+ }`}
196
+ onClick={() => handleSelect({ value, label })}
197
+ onMouseEnter={() => setFocusedIndex(index)}
177
198
  >
178
199
  <Icon
179
200
  elements={check}