-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move remote-ui example into kitchen sink
- Loading branch information
1 parent
95367d7
commit e1536a2
Showing
27 changed files
with
160 additions
and
683 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 was deleted.
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
96 changes: 96 additions & 0 deletions
96
examples/kitchen-sink/app/remote/examples/react-remote-ui.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,96 @@ | ||
/** @jsxRuntime automatic */ | ||
/** @jsxImportSource react */ | ||
import {retain} from '@quilted/threads'; | ||
|
||
import {createRemoteReactComponent} from '@remote-ui/react'; | ||
import { | ||
ButtonProperties, | ||
ModalProperties, | ||
RenderAPI, | ||
StackProperties, | ||
TextProperties, | ||
} from '../../types'; | ||
import {useState} from 'react'; | ||
import {createRoot, createRemoteRoot} from '@remote-ui/react'; | ||
import {RemoteChannel} from '@remote-ui/core'; | ||
|
||
const Button = createRemoteReactComponent< | ||
'Button', | ||
ButtonProperties & {modal?: React.ReactNode} | ||
>('Button', {fragmentProps: ['modal']}); | ||
|
||
const Text = createRemoteReactComponent<'Text', TextProperties>('Text'); | ||
const Stack = createRemoteReactComponent<'Stack', StackProperties>('Stack'); | ||
const Modal = createRemoteReactComponent< | ||
'Modal', | ||
ModalProperties & {primaryAction?: React.ReactNode} | ||
>('Modal', {fragmentProps: ['primaryAction']}); | ||
|
||
export function renderUsingReactRemoteUI( | ||
channel: RemoteChannel, | ||
api: RenderAPI, | ||
) { | ||
retain(api); | ||
retain(channel); | ||
|
||
const remoteRoot = createRemoteRoot(channel, { | ||
components: ['Button', 'Text', 'Stack', 'Modal'], | ||
}); | ||
|
||
createRoot(remoteRoot).render(<App api={api} />); | ||
remoteRoot.mount(); | ||
} | ||
|
||
function App({api}: {api: RenderAPI}) { | ||
return ( | ||
<Stack spacing> | ||
<Text> | ||
Rendering example: <Text emphasis>{api.example}</Text> | ||
</Text> | ||
<Text> | ||
Rendering in sandbox: <Text emphasis>{api.sandbox}</Text> | ||
</Text> | ||
<Button modal={<CountModal {...api} />}>Open modal</Button> | ||
</Stack> | ||
); | ||
} | ||
|
||
function CountModal({alert, closeModal}: RenderAPI) { | ||
const [count, setCount] = useState(0); | ||
|
||
const primaryAction = ( | ||
<Button | ||
onPress={() => { | ||
closeModal(); | ||
}} | ||
> | ||
Close | ||
</Button> | ||
); | ||
|
||
return ( | ||
<Modal | ||
primaryAction={primaryAction} | ||
onClose={() => { | ||
if (count > 0) { | ||
alert(`You clicked ${count} times!`); | ||
} | ||
|
||
setCount(0); | ||
}} | ||
> | ||
<Stack spacing> | ||
<Text> | ||
Click count: <Text emphasis>{count}</Text> | ||
</Text> | ||
<Button | ||
onPress={() => { | ||
setCount((count) => count + 1); | ||
}} | ||
> | ||
Click me! | ||
</Button> | ||
</Stack> | ||
</Modal> | ||
); | ||
} |
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
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.
Oops, something went wrong.