You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+59-21Lines changed: 59 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ $ npm i --save react-command-palette
35
35
36
36
Import into your react app and pass commands
37
37
38
-
```js
38
+
```jsx
39
39
importCommandPalettefrom'react-command-palette';
40
40
41
41
constcommands= [{
@@ -98,9 +98,7 @@ const commands = [{
98
98
99
99
* ```renderCommand``` a _React.func_. By default, react-command-palette will render the suggestion.name_ for each command. However, if passed a custom react component _renderCommand_ will display the command using any template you can imageine. The _renderCommand_ code signature follows the same coding pattern defined by react-autosuggest's renderSuggestion property.
100
100
101
-
```js
102
-
import"./commandStyles.css"; // or use inline styles
103
-
101
+
```jsx
104
102
functionRenderCommand(suggestion) {
105
103
// A suggestion object will be passed to your custom component for each command
106
104
const { id, color, name } = suggestion;
@@ -131,36 +129,76 @@ const commands = [{
131
129
132
130
Note: the _suggestion.hightlight_ will be passed and contains the rendered markup from (fuzzysort)[farzher/fuzzysort#fuzzysorthighlightresult-openb-closeb], see the ```options``` prop.
133
131
134
-
See [a full example](examples/sampleCustomCommand.js)
132
+
See [a full example](examples/sampleAtomCommand.js)
135
133
136
134
*Important:* _renderCommand_ must be a pure function (react-autosuggest, upon which this is based will optimize rendering performance based on this assumption).
137
135
138
136
* ```maxDisplayed``` a _number_ between 1 and 500 that determines the maxium number of commands that will be rendered on screen. Defaults to 7
139
137
140
138
* ```spinner``` a _string_ or a _React.ComponentType_ that is displayed when the user selects an item. If a custom spinner is not set then the default spinner will be used. If a custom component or string is provided then it will automatically be wrapped inside a div with a _role="status"_ attribute. If a component is provided then it will be be wrapped in a div that also contains a sibling node with a div contain "Loading..." visible only to screen readers.
141
139
142
-
* ```trigger``` a _string_ or a _React.ComponentType_ the opens the command palette when clicked. If a custom trigger is not set then by default a button will be used. If a custom component or string is provided then it will automatically be wrapped inside an accessible div that will allow it be keyboard accessible, clickable and focusable for assistive technologies.
140
+
* ```theme``` enables you to apply a sample or custom look-n-feel.
141
+
Two themes are included with the command palette, Chrome and Atom. The CommandPalette comes with the Atom theme enabled default.
Creating a new theme is also possible. There are four base components that should be styled, the _trigger_, _spinner_, _react-modal_ and _react-autosuggest_ components. All four can be styled at once via the `theme` prop.
144
+
145
+
There are two steps to styling. First create a theme object to map your custom class names to their associated components. Then add styles that use the rules mapped in the `theme` prop.
146
+
147
+
For example, to style the CommandPalette using CSS Modules, do:
When the trigger is clicked it will open the command palette, no custom handlers or events are required.
174
+
When not specified, `theme` defaults to the included _Atom_ theme. Complete sample themes are provided, see: [Chrome](examples/sampleChromeTheme.md) and [Atom](examples/sampleAtomTheme.md)
175
+
176
+
The following picture illustrates how `theme` keys correspond to CommandPalette DOM structure:
177
+
178
+

179
+
180
+
```trigger``` a _string_ or a _React.ComponentType_ the opens the command palette when clicked. If a custom trigger is not set then by default a button will be used. If a custom component or string is provided then it will automatically be wrapped inside an accessible div that will allow it be keyboard accessible, clickable and focusable for assistive technologies.
The easiest way to do this, is to do nothing because Atom is the default theme. However you may wish to tweak the theme to better meet your projects needs.
4
+
5
+
The CommandPalette comes with the Atom theme by default. There are four base components that need to be styled, the _trigger_, _spinner_, _react-modal_ and _react-autosuggest_ components. All three can be styled at once via the `theme` prop.
6
+
7
+
Try it on [CodeSandbox](https://codesandbox.io/s/hfqjn)
8
+
9
+
To custom style the CommandPalette you'll need a CSS file with rules that map to your _theme_ props' key/value pairs, ex:
10
+
11
+
```js
12
+
importReactfrom"react";
13
+
importCommandPalettefrom"react-command-palette";
14
+
15
+
// map CSS class names to CommandPalette components
16
+
// Note that we dont need to do this for the Atom theme because its the default
17
+
// When not otherwise specified, the theme defaults to:
The layout for each of the commands that appears in the command list can also be customized. For instance, the _Atom_ command palette has a list of commands that includes a command and associated keyboard shortcut when applicable. Because the default command is limited to just displaying the command's _name_ you'll need to make your own _renderCommand_ like the component included in [_sampleAtomCommand.js_](../examples/sampleAtomCommand.js).
43
+
44
+
The [_sampleAtomCommands.css_](../examples/sampleAtomCommand.css) file must be imported into the _renderCommand_ component. Of coure you can use your imagination to create any layout you like for each command. Note that `suggestion.highlight` will contain the raw HTML of the matching value.
A Chrome theme is available in the the _themes_ directory. There are four base components that need to be styled, _trigger_, _spinner_, _react-modal_ and _react-autosuggest_ components. All three can be styled at once via the `theme` prop.
4
+
5
+
For a complete example see this [CodeSandbox](https://codesandbox.io/s/gfx7l)
6
+
7
+
The simplest way to get started is to _import_ the Chrome [theme](../themes/chrome-theme.js) and [CSS](../themes/chrome.css) from the examples directory as follows:
The layout for each of the commands that appears in the command list can also be customized. For instance, _Chrome dev tools_ command palette has a list of commands that includes a category, command and associated keyboard shortcut when applicable. Because the default command is limited to just displaying the command's _name_ you'll need to make your own _renderCommand_ like the component included in [_sampleChromeCommand.js_](../examples/sampleChromeCommand.js).
45
+
46
+
The [_sampleChromeCommands.css_](../examples/sampleChromeCommand.css) file must be imported into the _renderCommand_ component. Of coure you can use your imagination to create any layout you like for each command. Note that `suggestion.highlight` will contain the raw HTML of the matching value.
0 commit comments