Skip to content

Commit

Permalink
implement working <EzqlPrompt />
Browse files Browse the repository at this point in the history
  • Loading branch information
jmonster committed Mar 3, 2023
1 parent ab8c7a3 commit 9793409
Show file tree
Hide file tree
Showing 24 changed files with 1,014 additions and 290 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Project
dist
src/react-ezql/dist
demo/web/bundle.*

# Logs
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"build:umd": "rollup --config config/rollup.config.js --bundleConfigAsCjs",
"update:demo": "npm run build:umd && node demo/copy-assets.mjs",
"prepare": "husky install",
"prepack": "npm run build"
"prepack": "rm -rf ./dist && npm run build"
},
"repository": {
"type": "git",
Expand Down
95 changes: 95 additions & 0 deletions src/react-ezql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
## Installation

```sh
npm install --save-dev react-ezql
```

## Usage

**Minimal usage**

```tsx
import EzqlPrompt from 'react-ezql'

<EzqlPrompt
setShouldDisplayEzql={setShouldDisplayEzql}
suggestions={['How many books sold last week', 'How many new users signed up today']}
didSubmitWithValue={(value) => {
console.log(`query: ${value}`)
setShouldDisplayEzql(false)
}}
onResults={(json) => console.dir(json)}
className="optional-for-styling-convenience"
/>
```

**Example App.tsx**
Here lies a demonstration conditionally showing/hiding the prompt

```tsx
import './App.css'
import EzqlPrompt from 'react-ezql'
import { useEffect, useState } from 'react'

const TRIGGERS = ['KeyK', 'Slash']

function App() {
const [shouldDisplayEzql, setShouldDisplayEzql] = useState(false)
const suggestions = ['How many books sold last week', 'How many new users signed up today']

// listen for the trigger to display the modal
useEffect(() => {
function ezqlTriggerListener(ev: KeyboardEvent) {
if (TRIGGERS.includes(ev.code) && ev.getModifierState('Meta')) {
setShouldDisplayEzql(true)
}
}

// BEGIN listening for the trigger(s)
document.addEventListener('keydown', ezqlTriggerListener)

return () => {
// STOP listening for the trigger(s)
document.removeEventListener('keydown', ezqlTriggerListener)
}
}, [])

return (
<>
{shouldDisplayEzql && (
<EzqlPrompt
setShouldDisplayEzql={setShouldDisplayEzql}
suggestions={suggestions}
didSubmitWithValue={(value) => {
console.log(`query: ${value}`)
setShouldDisplayEzql(false)
}}
onResults={(json) => console.dir(json)}
className="optional-for-styling-convenience"
/>
)}
</>
)
}

export default App
```

## Styling

<!-- TODO? Perhaps we make it possible to utilize CSS variables (when defined) -->

Each HTML Element has been an assigned a meaningful classname that you can style in your own CSS

- Use the web inspector to reveal which class names are assigned to which elements
- You may optionally pass `className` to the component, i.e. `<EzqlPrompt className="arbitrary-value">`. This allows more precise scoping of CSS:

```css
.arbitrary-value.ezql-prompt-modal {
background-color: black;
}
,
.arbitrary-value .input-container {
color: white;
}
```
Loading

0 comments on commit 9793409

Please sign in to comment.