-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove react-router dependency from playground (#2686)
Added some basic hash routing, but routing should mainly be the concern of the application importing the playground, not the playground itself.
- Loading branch information
Showing
9 changed files
with
388 additions
and
352 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,53 @@ | ||
import * as React from "react"; | ||
import { ButtonDemo } from "./demo/form/button/button-demo"; | ||
import { ComboBoxDemo } from "./demo/form/combobox/combobox-demo"; | ||
import { SearchBoxDemo } from "./demo/form/searchbox/searchbox-demo"; | ||
import { TextFieldDemo } from "./demo/form/textfield/textfield-demo"; | ||
import { CertificateDisplayDemo } from "./demo/display/certificate/certificate-display-demo"; | ||
import { ActionFormDemo } from "./demo/form/action-form-demo"; | ||
import { DropdownDemo } from "./demo/form/dropdown-demo"; | ||
import { RadioButtonDemo } from "./demo/form/radiobutton/radiobutton-demo"; | ||
import { CheckboxDemo } from "./demo/form/checkbox/checkbox-demo"; | ||
|
||
export const DEMO_MAP = { | ||
default: () => <DefaultPane />, | ||
actionform: () => <ActionFormDemo />, | ||
button: () => <ButtonDemo />, | ||
checkbox: () => <CheckboxDemo />, | ||
radiobutton: () => <RadioButtonDemo />, | ||
combobox: () => <ComboBoxDemo />, | ||
dropdown: () => <DropdownDemo />, | ||
searchbox: () => <SearchBoxDemo />, | ||
textfield: () => <TextFieldDemo />, | ||
certificatedisplay: () => <CertificateDisplayDemo />, | ||
}; | ||
|
||
export type DemoName = keyof typeof DEMO_MAP; | ||
|
||
const DEMO_HASH_REGEX = /#\/demos\/(?<demo>\w+)/; | ||
|
||
export function getDemoHash(demoName: DemoName) { | ||
return `#/demos/${demoName}`; | ||
} | ||
|
||
export function getDemoFromUrl(): DemoName { | ||
let demoName: DemoName = "default"; | ||
if (location.hash) { | ||
const match = location.hash.match(DEMO_HASH_REGEX); | ||
if (match) { | ||
const d = match.groups?.demo as DemoName | undefined; | ||
if (d && DEMO_MAP[d]) { | ||
demoName = d; | ||
} | ||
} | ||
} | ||
return demoName; | ||
} | ||
|
||
export const DefaultPane: React.FC = () => { | ||
return ( | ||
<span style={{ width: "100%", textAlign: "center" }}> | ||
Select a demo from the list | ||
</span> | ||
); | ||
}; |
50 changes: 8 additions & 42 deletions
50
packages/playground/src/ui-playground/layout/demo-main-content.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 |
---|---|---|
@@ -1,45 +1,11 @@ | ||
import * as React from "react"; | ||
import { Route, Switch } from "react-router"; | ||
import { ButtonDemo } from "../demo/form/button/button-demo"; | ||
import { ComboBoxDemo } from "../demo/form/combobox/combobox-demo"; | ||
import { SearchBoxDemo } from "../demo/form/searchbox/searchbox-demo"; | ||
import { TextFieldDemo } from "../demo/form/textfield/textfield-demo"; | ||
import { CertificateDisplayDemo } from "../demo/display/certificate/certificate-display-demo"; | ||
import { ActionFormDemo } from "../demo/form/action-form-demo"; | ||
import { DropdownDemo } from "../demo/form/dropdown-demo"; | ||
import { RadioButtonDemo } from "../demo/form/radiobutton/radiobutton-demo"; | ||
import { CheckboxDemo } from "../demo/form/checkbox/checkbox-demo"; | ||
import { DemoName, DEMO_MAP } from "../demo-routes"; | ||
|
||
export const DemoMainContent: React.FC = () => { | ||
return ( | ||
<Switch> | ||
<Route path="/playground/actionform"> | ||
<ActionFormDemo /> | ||
</Route> | ||
<Route path="/playground/button"> | ||
<ButtonDemo /> | ||
</Route> | ||
<Route path="/playground/checkbox"> | ||
<CheckboxDemo /> | ||
</Route> | ||
<Route path="/playground/radiobutton"> | ||
<RadioButtonDemo /> | ||
</Route> | ||
<Route path="/playground/combobox"> | ||
<ComboBoxDemo /> | ||
</Route> | ||
<Route path="/playground/dropdown"> | ||
<DropdownDemo /> | ||
</Route> | ||
<Route path="/playground/searchbox"> | ||
<SearchBoxDemo /> | ||
</Route> | ||
<Route path="/playground/textfield"> | ||
<TextFieldDemo /> | ||
</Route> | ||
<Route path="/playground/displays/certificate"> | ||
<CertificateDisplayDemo /> | ||
</Route> | ||
</Switch> | ||
); | ||
export interface DemoMainContentProps { | ||
demoName?: DemoName; | ||
} | ||
|
||
export const DemoMainContent: React.FC<DemoMainContentProps> = (props) => { | ||
const demoName = props.demoName ?? "default"; | ||
return DEMO_MAP[demoName](); | ||
}; |
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
Oops, something went wrong.