-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b01a07
commit c9c3511
Showing
7 changed files
with
183 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import SearchBox from "./searchBox"; | ||
|
||
export default SearchBox; |
34 changes: 34 additions & 0 deletions
34
packages/blocky-example/src/components/searchBox/searchBox.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
.blocky-example-search-box { | ||
display: flex; | ||
height: 28px; | ||
background-color: var(--bg-color); | ||
position: absolute; | ||
top: 12px; | ||
right: 18px; | ||
padding: 4px 8px; | ||
border-radius: 4px; | ||
z-index: 10; | ||
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; | ||
|
||
input { | ||
background-color: transparent; | ||
border: none; | ||
color: var(--primary-text-color); | ||
|
||
&:focus { | ||
outline: none; | ||
} | ||
} | ||
|
||
.result-display { | ||
padding: 0px 8px; | ||
line-height: 28px; | ||
font-size: 12px; | ||
color: var(--primary-text-color); | ||
} | ||
|
||
button { | ||
margin-left: 2px; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
packages/blocky-example/src/components/searchBox/searchBox.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Component, createRef, JSX } from "preact"; | ||
import Button from "@pkg/components/button"; | ||
import { flattenDisposable, IDisposable } from "blocky-common/es/disposable"; | ||
import "./searchBox.scss"; | ||
import { listenWindow } from "blocky-common/es/dom"; | ||
|
||
export interface SearchBoxProps { | ||
onClose?: () => void; | ||
} | ||
|
||
class SearchBox extends Component<SearchBoxProps> { | ||
private inputRef = createRef<HTMLInputElement>(); | ||
private disposables: IDisposable[] = []; | ||
private isFocused = false; | ||
|
||
override componentDidMount(): void { | ||
window.requestAnimationFrame(() => { | ||
this.inputRef.current!.focus(); | ||
}); | ||
|
||
this.disposables.push( | ||
listenWindow("keydown", (e: KeyboardEvent) => { | ||
if (this.isFocused) { | ||
this.props.onClose?.(); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
componentWillUnmount(): void { | ||
flattenDisposable(this.disposables).dispose(); | ||
} | ||
|
||
handleInputFocus = () => { | ||
this.isFocused = true; | ||
}; | ||
|
||
handleInputBlur = () => { | ||
this.isFocused = false; | ||
}; | ||
|
||
override render(props: SearchBoxProps) { | ||
return ( | ||
<div className="blocky-example-search-box"> | ||
<input | ||
onFocus={this.handleInputFocus} | ||
onBlur={this.handleInputBlur} | ||
placeholder="Find" | ||
ref={this.inputRef} | ||
onKeyDown={(e) => console.log(e)} | ||
/> | ||
<div className="result-display">No results</div> | ||
<Button>{"<"}</Button> | ||
<Button>{">"}</Button> | ||
<Button onClick={props.onClose}>{"X"}</Button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default SearchBox; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.