@keybindy/react 1.1.8 → 1.1.10
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/dist/ShortcutLabel.js +39 -22
- package/dist/index.d.ts +36 -31
- package/package.json +1 -1
package/dist/ShortcutLabel.js
CHANGED
|
@@ -2,13 +2,7 @@ import { jsx, jsxs } from 'react/jsx-runtime';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* It accepts an array of keys (e.g. `["Ctrl", "S"]`) and renders a styled label using platform-aware
|
|
8
|
-
* symbols (⌘ for Mac, Ctrl for others). Users can also provide a custom render function to override
|
|
9
|
-
* the default display logic for advanced layouts or custom themes.
|
|
10
|
-
*
|
|
11
|
-
* @component
|
|
5
|
+
* ... (rest of the description) ...
|
|
12
6
|
*
|
|
13
7
|
* @example
|
|
14
8
|
* // Default usage
|
|
@@ -19,24 +13,45 @@ import React from 'react';
|
|
|
19
13
|
* <ShortcutLabel keys={[['ctrl', 's'], ['meta', 's']]} />
|
|
20
14
|
*
|
|
21
15
|
* @example
|
|
22
|
-
* // With custom
|
|
16
|
+
* // With custom render prop
|
|
17
|
+
* <ShortcutLabel
|
|
18
|
+
* keys={['ctrl', 'shift', 'a']}
|
|
19
|
+
* render={(keys) => {
|
|
20
|
+
* // 'keys' here will be ['ctrl', 'shift', 'a']
|
|
21
|
+
* return keys.map((key) => (
|
|
22
|
+
* <span key={key} style={{ color: '#00eaff' }}>
|
|
23
|
+
* {key.toUpperCase()}
|
|
24
|
+
* </span>
|
|
25
|
+
* ));
|
|
26
|
+
* }}
|
|
27
|
+
* />
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // With custom render prop for multiple bindings
|
|
23
31
|
* <ShortcutLabel
|
|
24
|
-
* keys={['ctrl', '
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
32
|
+
* keys={[['ctrl', 's'], ['meta', 's']]}
|
|
33
|
+
* render={(bindings) => {
|
|
34
|
+
* // 'bindings' here will be [['ctrl', 's'], ['meta', 's']]
|
|
35
|
+
* return bindings.map((binding, bindingIndex) => (
|
|
36
|
+
* <React.Fragment key={bindingIndex}>
|
|
37
|
+
* {binding.map((key, keyIndex) => (
|
|
38
|
+
* <span key={keyIndex} style={{ fontWeight: 'bold' }}>
|
|
39
|
+
* {key}
|
|
40
|
+
* </span>
|
|
41
|
+
* ))}
|
|
42
|
+
* {bindingIndex < bindings.length - 1 && ' or '}
|
|
43
|
+
* </React.Fragment>
|
|
44
|
+
* ));
|
|
45
|
+
* }}
|
|
31
46
|
* />
|
|
32
47
|
*
|
|
33
48
|
* @param {ShortcutLabelProps} props - Props for the ShortcutLabel component
|
|
34
49
|
* @param {string[] | string[][]} props.keys - The list of keys to display.
|
|
35
|
-
* @param {Function} [props.
|
|
50
|
+
* @param {Function} [props.render] - Optional custom render function for full control over how your keys are rendered.
|
|
36
51
|
*
|
|
37
52
|
* @returns {JSX.Element} Rendered shortcut label
|
|
38
53
|
*/
|
|
39
|
-
const ShortcutLabel = ({ keys,
|
|
54
|
+
const ShortcutLabel = ({ keys, render, style, ...props }) => {
|
|
40
55
|
const isMac = typeof navigator !== 'undefined' && /Mac/.test(navigator.userAgent);
|
|
41
56
|
const defaultRenderKey = (key) => {
|
|
42
57
|
switch (key.toLowerCase()) {
|
|
@@ -54,9 +69,9 @@ const ShortcutLabel = ({ keys, renderKey, style, ...props }) => {
|
|
|
54
69
|
return key.toUpperCase();
|
|
55
70
|
}
|
|
56
71
|
};
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
return
|
|
72
|
+
const renderBinding = (binding) => {
|
|
73
|
+
if (render) {
|
|
74
|
+
return render(binding);
|
|
60
75
|
}
|
|
61
76
|
return binding.map(key => defaultRenderKey(key)).join(' + ');
|
|
62
77
|
};
|
|
@@ -70,8 +85,10 @@ const ShortcutLabel = ({ keys, renderKey, style, ...props }) => {
|
|
|
70
85
|
userSelect: 'none',
|
|
71
86
|
...style,
|
|
72
87
|
}, ...props, children: isNestedArray
|
|
73
|
-
?
|
|
74
|
-
|
|
88
|
+
? render
|
|
89
|
+
? renderBinding(keys)
|
|
90
|
+
: keys.map((binding, index) => (jsxs(React.Fragment, { children: [renderBinding(binding), index < keys.length - 1 && ' / '] }, index)))
|
|
91
|
+
: renderBinding(keys) }));
|
|
75
92
|
};
|
|
76
93
|
|
|
77
94
|
export { ShortcutLabel };
|
package/dist/index.d.ts
CHANGED
|
@@ -63,30 +63,14 @@ interface ShortcutLabelProps extends React.DetailedHTMLProps<React.HTMLAttribute
|
|
|
63
63
|
*/
|
|
64
64
|
keys: AllowedKeys[] | AllowedKeys[][];
|
|
65
65
|
/**
|
|
66
|
-
* Custom render function for
|
|
66
|
+
* Custom render function for full control over how your keys are rendered.
|
|
67
|
+
* This function receives the entire `keys` array (either `string[]` or `string[][]`)
|
|
68
|
+
* and should return the ReactNode to be displayed.
|
|
67
69
|
*/
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* The key to render
|
|
71
|
-
*/
|
|
72
|
-
key: string,
|
|
73
|
-
/**
|
|
74
|
-
* The index of the key in the array
|
|
75
|
-
*/
|
|
76
|
-
index: number,
|
|
77
|
-
/**
|
|
78
|
-
* All keys in the current binding
|
|
79
|
-
*/
|
|
80
|
-
allKeys: string[]) => React.ReactNode;
|
|
70
|
+
render?: (keys: AllowedKeys[] | AllowedKeys[][]) => React.ReactNode;
|
|
81
71
|
}
|
|
82
72
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* It accepts an array of keys (e.g. `["Ctrl", "S"]`) and renders a styled label using platform-aware
|
|
86
|
-
* symbols (⌘ for Mac, Ctrl for others). Users can also provide a custom render function to override
|
|
87
|
-
* the default display logic for advanced layouts or custom themes.
|
|
88
|
-
*
|
|
89
|
-
* @component
|
|
73
|
+
* ... (rest of the description) ...
|
|
90
74
|
*
|
|
91
75
|
* @example
|
|
92
76
|
* // Default usage
|
|
@@ -97,24 +81,45 @@ interface ShortcutLabelProps extends React.DetailedHTMLProps<React.HTMLAttribute
|
|
|
97
81
|
* <ShortcutLabel keys={[['ctrl', 's'], ['meta', 's']]} />
|
|
98
82
|
*
|
|
99
83
|
* @example
|
|
100
|
-
* // With custom
|
|
84
|
+
* // With custom render prop
|
|
85
|
+
* <ShortcutLabel
|
|
86
|
+
* keys={['ctrl', 'shift', 'a']}
|
|
87
|
+
* render={(keys) => {
|
|
88
|
+
* // 'keys' here will be ['ctrl', 'shift', 'a']
|
|
89
|
+
* return keys.map((key) => (
|
|
90
|
+
* <span key={key} style={{ color: '#00eaff' }}>
|
|
91
|
+
* {key.toUpperCase()}
|
|
92
|
+
* </span>
|
|
93
|
+
* ));
|
|
94
|
+
* }}
|
|
95
|
+
* />
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // With custom render prop for multiple bindings
|
|
101
99
|
* <ShortcutLabel
|
|
102
|
-
* keys={['ctrl', '
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
100
|
+
* keys={[['ctrl', 's'], ['meta', 's']]}
|
|
101
|
+
* render={(bindings) => {
|
|
102
|
+
* // 'bindings' here will be [['ctrl', 's'], ['meta', 's']]
|
|
103
|
+
* return bindings.map((binding, bindingIndex) => (
|
|
104
|
+
* <React.Fragment key={bindingIndex}>
|
|
105
|
+
* {binding.map((key, keyIndex) => (
|
|
106
|
+
* <span key={keyIndex} style={{ fontWeight: 'bold' }}>
|
|
107
|
+
* {key}
|
|
108
|
+
* </span>
|
|
109
|
+
* ))}
|
|
110
|
+
* {bindingIndex < bindings.length - 1 && ' or '}
|
|
111
|
+
* </React.Fragment>
|
|
112
|
+
* ));
|
|
113
|
+
* }}
|
|
109
114
|
* />
|
|
110
115
|
*
|
|
111
116
|
* @param {ShortcutLabelProps} props - Props for the ShortcutLabel component
|
|
112
117
|
* @param {string[] | string[][]} props.keys - The list of keys to display.
|
|
113
|
-
* @param {Function} [props.
|
|
118
|
+
* @param {Function} [props.render] - Optional custom render function for full control over how your keys are rendered.
|
|
114
119
|
*
|
|
115
120
|
* @returns {JSX.Element} Rendered shortcut label
|
|
116
121
|
*/
|
|
117
|
-
declare const ShortcutLabel: ({ keys,
|
|
122
|
+
declare const ShortcutLabel: ({ keys, render, style, ...props }: ShortcutLabelProps) => react_jsx_runtime.JSX.Element;
|
|
118
123
|
|
|
119
124
|
type UseKeybindyReturn = {
|
|
120
125
|
register: (keys: Keys[] | Keys[][], handler: ShortcutHandler, options?: ShortcutOptions) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keybindy/react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "Keybindy for React: Simple, scoped keyboard shortcuts that require little setup. designed to smoothly blend in with your React applications, allowing for robust keybinding functionality without the overhead.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "PRASSamin",
|