-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(demos): use react-router in history-service demo (#477)
- Loading branch information
1 parent
29e7bc7
commit bd94620
Showing
11 changed files
with
122 additions
and
109 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 was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
packages/demos/src/history-service/history-consumer/history-consumer.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,42 @@ | ||
import {Card, H5} from '@blueprintjs/core'; | ||
import * as React from 'react'; | ||
import Media from 'react-media'; | ||
import {Route} from 'react-router'; | ||
import {NewPathControl} from './new-path-control'; | ||
import {PathnameLabel} from './pathname-label'; | ||
|
||
interface HistoryConsumerProps { | ||
readonly historyKey: string; | ||
} | ||
|
||
export function HistoryConsumer({ | ||
historyKey | ||
}: HistoryConsumerProps): JSX.Element { | ||
const specifier = historyKey.slice(historyKey.length - 1); | ||
|
||
return ( | ||
<Card style={{margin: '20px'}}> | ||
<H5>History Consumer {specifier.toUpperCase()}</H5> | ||
|
||
<Route> | ||
{({location}) => ( | ||
<PathnameLabel specifier={specifier} pathname={location.pathname} /> | ||
)} | ||
</Route> | ||
|
||
<Media query="(max-width: 370px)"> | ||
{matches => ( | ||
<Route> | ||
{({history}) => ( | ||
<NewPathControl | ||
history={history} | ||
specifier={specifier} | ||
vertical={matches} | ||
/> | ||
)} | ||
</Route> | ||
)} | ||
</Media> | ||
</Card> | ||
); | ||
} |
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
46 changes: 46 additions & 0 deletions
46
packages/demos/src/history-service/history-consumer/new-path-control.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,46 @@ | ||
import {Button, ControlGroup, InputGroup} from '@blueprintjs/core'; | ||
import {History} from 'history'; | ||
import * as React from 'react'; | ||
|
||
export interface NewPathControlProps { | ||
readonly history: History; | ||
readonly specifier: string; | ||
readonly vertical?: boolean; | ||
} | ||
|
||
export function NewPathControl({ | ||
history, | ||
specifier, | ||
vertical | ||
}: NewPathControlProps): JSX.Element { | ||
const inputElement = React.useRef<HTMLInputElement | null>(null); | ||
|
||
const changePath = (method: 'push' | 'replace') => { | ||
if (!inputElement.current) { | ||
return; | ||
} | ||
|
||
history[method](inputElement.current.value); | ||
inputElement.current.value = ''; | ||
}; | ||
|
||
return ( | ||
<ControlGroup vertical={vertical}> | ||
<InputGroup | ||
id={`new-path-${specifier}`} | ||
placeholder="Enter a new path..." | ||
inputRef={ref => (inputElement.current = ref)} | ||
/> | ||
<Button | ||
id={`push-${specifier}`} | ||
text="Push" | ||
onClick={() => changePath('push')} | ||
/> | ||
<Button | ||
id={`replace-${specifier}`} | ||
text="Replace" | ||
onClick={() => changePath('replace')} | ||
/> | ||
</ControlGroup> | ||
); | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/demos/src/history-service/history-consumer/pathname-label.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,19 @@ | ||
import {InputGroup, Label} from '@blueprintjs/core'; | ||
import * as React from 'react'; | ||
|
||
export interface PathnameLabelProps { | ||
readonly specifier: string; | ||
readonly pathname: string; | ||
} | ||
|
||
export function PathnameLabel({ | ||
specifier, | ||
pathname | ||
}: PathnameLabelProps): JSX.Element { | ||
return ( | ||
<Label> | ||
Pathname | ||
<InputGroup id={`pathname-${specifier}`} value={pathname} disabled /> | ||
</Label> | ||
); | ||
} |
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