Skip to content

Commit 3b94261

Browse files
committed
implement working <EzqlPrompt />
1 parent ab8c7a3 commit 3b94261

24 files changed

+1016
-291
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Project
22
dist
3+
src/react-ezql/dist
34
demo/web/bundle.*
45

56
# Logs

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"build:umd": "rollup --config config/rollup.config.js --bundleConfigAsCjs",
2727
"update:demo": "npm run build:umd && node demo/copy-assets.mjs",
2828
"prepare": "husky install",
29-
"prepack": "npm run build"
29+
"prepack": "rm -rf ./dist && npm run build"
3030
},
3131
"repository": {
3232
"type": "git",

src/react-ezql/README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
## Installation
2+
3+
```sh
4+
npm install --save-dev react-ezql
5+
```
6+
7+
## Usage
8+
9+
**Minimal usage**
10+
11+
```tsx
12+
import EzqlPrompt from 'react-ezql'
13+
14+
<EzqlPrompt
15+
setShouldDisplayEzql={setShouldDisplayEzql}
16+
suggestions={['How many books sold last week', 'How many new users signed up today']}
17+
didSubmitWithValue={(value) => {
18+
console.log(`query: ${value}`)
19+
setShouldDisplayEzql(false)
20+
}}
21+
onResults={(json) => console.dir(json)}
22+
className="optional-for-styling-convenience"
23+
/>
24+
```
25+
26+
**Example App.tsx**
27+
Here lies a demonstration conditionally showing/hiding the prompt
28+
29+
```tsx
30+
import './App.css'
31+
import EzqlPrompt from 'react-ezql'
32+
import { useEffect, useState } from 'react'
33+
34+
const TRIGGERS = ['KeyK', 'Slash']
35+
36+
function App() {
37+
const [shouldDisplayEzql, setShouldDisplayEzql] = useState(false)
38+
const suggestions = ['How many books sold last week', 'How many new users signed up today']
39+
40+
// listen for the trigger to display the modal
41+
useEffect(() => {
42+
function ezqlTriggerListener(ev: KeyboardEvent) {
43+
if (TRIGGERS.includes(ev.code) && ev.getModifierState('Meta')) {
44+
setShouldDisplayEzql(true)
45+
}
46+
}
47+
48+
// BEGIN listening for the trigger(s)
49+
document.addEventListener('keydown', ezqlTriggerListener)
50+
51+
return () => {
52+
// STOP listening for the trigger(s)
53+
document.removeEventListener('keydown', ezqlTriggerListener)
54+
}
55+
}, [])
56+
57+
return (
58+
<>
59+
{shouldDisplayEzql && (
60+
<EzqlPrompt
61+
setShouldDisplayEzql={setShouldDisplayEzql}
62+
suggestions={suggestions}
63+
didSubmitWithValue={(value) => {
64+
console.log(`query: ${value}`)
65+
setShouldDisplayEzql(false)
66+
}}
67+
onResults={(json) => console.dir(json)}
68+
className="optional-for-styling-convenience"
69+
/>
70+
)}
71+
</>
72+
)
73+
}
74+
75+
export default App
76+
```
77+
78+
## Styling
79+
80+
<!-- TODO? Perhaps we make it possible to utilize CSS variables (when defined) -->
81+
82+
Each HTML Element has been an assigned a meaningful classname that you can style in your own CSS
83+
84+
- Use the web inspector to reveal which class names are assigned to which elements
85+
- You may optionally pass `className` to the component, i.e. `<EzqlPrompt className="arbitrary-value">`. This allows more precise scoping of CSS:
86+
87+
```css
88+
.arbitrary-value.ezql-prompt-modal {
89+
background-color: black;
90+
}
91+
,
92+
.arbitrary-value .input-container {
93+
color: white;
94+
}
95+
```

0 commit comments

Comments
 (0)