Skip to content

Commit

Permalink
docs: add ssr to local example
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdyman committed Apr 7, 2023
1 parent 5c73eca commit 9e52683
Show file tree
Hide file tree
Showing 19 changed files with 399 additions and 321 deletions.
13 changes: 0 additions & 13 deletions docs/example/index.html

This file was deleted.

13 changes: 9 additions & 4 deletions docs/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@
"private": true,
"version": "0.0.0",
"type": "module",
"packageManager": "pnpm@8.1.1",
"scripts": {
"start": "pnpm run dev",
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-compare-slider": "*",
"react-dom": "^18.2.0"
"react-compare-slider": "*"
},
"devDependencies": {
"@types/react": "^18.0.33",
"@types/react-dom": "^18.0.11",
"@vitejs/plugin-react": "^3.1.0",
"modern-normalize": "^1.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.10.0",
"typescript": "^5.0.3",
"vite": "^4.2.0"
"vite": "^4.2.0",
"vite-plugin-ssr": "^0.4.111"
}
}
28 changes: 28 additions & 0 deletions docs/example/pages/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@import 'modern-normalize/modern-normalize.css';

:root {
font-family: system-ui, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}

html,
body,
#root,
#page-view {
display: flex;
width: 100%;
height: 100%;
min-height: 100%;
overflow: hidden;
}
44 changes: 44 additions & 0 deletions docs/example/pages/index.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import { ReactCompareSlider, ReactCompareSliderImage } from 'react-compare-slider';

import './index.css';

function Page(): JSX.Element {
return (
<div style={{ width: '100%', height: '100%', flexGrow: 1 }}>
<ReactCompareSlider
itemOne={
<ReactCompareSliderImage
src="https://github.com/nerdyman/stuff/raw/main/libs/react-compare-slider/demo-images/sydney-opera-house-1.jpg"
alt="Image one"
/>
}
itemTwo={
<ReactCompareSliderImage
src="https://github.com/nerdyman/stuff/raw/main/libs/react-compare-slider/demo-images/sydney-opera-house-2.jpg"
alt="Image two"
/>
}
style={{ width: '100%', height: '50%' }}
/>
<ReactCompareSlider
portrait
itemOne={
<ReactCompareSliderImage
src="https://github.com/nerdyman/stuff/raw/main/libs/react-compare-slider/demo-images/sydney-opera-house-1.jpg"
alt="Image one"
/>
}
itemTwo={
<ReactCompareSliderImage
src="https://github.com/nerdyman/stuff/raw/main/libs/react-compare-slider/demo-images/sydney-opera-house-2.jpg"
alt="Image two"
/>
}
style={{ width: '100%', height: '50%' }}
/>
</div>
);
}

export { Page };
13 changes: 0 additions & 13 deletions docs/example/pages/index.tsx

This file was deleted.

1 change: 0 additions & 1 deletion docs/example/public/vite.svg

This file was deleted.

5 changes: 5 additions & 0 deletions docs/example/renderer/PageLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

export const PageLayout: React.FC<React.PropsWithChildren> = ({ children }) => {
return <React.StrictMode>{children}</React.StrictMode>;
};
14 changes: 14 additions & 0 deletions docs/example/renderer/_default.page.client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { hydrateRoot } from 'react-dom/client';

import { PageLayout } from './PageLayout';

export async function render(pageContext: any) {
const { Page } = pageContext;
hydrateRoot(
document.getElementById('page-view') as HTMLElement,
<PageLayout>
<Page />
</PageLayout>,
);
}
29 changes: 29 additions & 0 deletions docs/example/renderer/_default.page.server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { renderToString } from 'react-dom/server';
import { dangerouslySkipEscape, escapeInject } from 'vite-plugin-ssr/server';

import { PageLayout } from './PageLayout';

export async function render(pageContext: any) {
const { Page } = pageContext;
const viewHtml = dangerouslySkipEscape(
renderToString(
<PageLayout>
<Page />
</PageLayout>,
),
);

return escapeInject/*html*/ `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Compare Slider &ndash; Example</title>
</head>
<body>
<div id="page-view">${viewHtml}</div>
</body>
</html>`;
}
8 changes: 0 additions & 8 deletions docs/example/src/App.css

This file was deleted.

21 changes: 0 additions & 21 deletions docs/example/src/App.tsx

This file was deleted.

1 change: 0 additions & 1 deletion docs/example/src/assets/react.svg

This file was deleted.

69 changes: 0 additions & 69 deletions docs/example/src/index.css

This file was deleted.

12 changes: 0 additions & 12 deletions docs/example/src/main.tsx

This file was deleted.

1 change: 0 additions & 1 deletion docs/example/src/vite-env.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion docs/example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"],
"include": ["pages", "renderer"],
"references": [{ "path": "./tsconfig.node.json" }]
}
4 changes: 3 additions & 1 deletion docs/example/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import ssr from 'vite-plugin-ssr/plugin';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
plugins: [react(), ssr()],
optimizeDeps: { include: ['react/jsx-dev-runtime'] },
});
4 changes: 2 additions & 2 deletions docs/storybook/content/05-only-handle-draggable.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const isTouchDevice = window.matchMedia('(pointer: coarse)').matches;
</Canvas>

<Canvas>
<Story id="recipies-detect-touch-devices--detect-touch-devices" />
<Story id="recipies-detecttouchdevices--detect-touch-devices" />
</Canvas>

<Canvas>
Expand All @@ -43,5 +43,5 @@ const isTouchDevice = window.matchMedia('(pointer: coarse)').matches;

Also checkout the
[Only Handle Draggable](/story/docs--only-handle-draggable) and
[Detect Touch Devices](/story/recipies-detect-touch-devices--detect-touch-devices) and
[Detect Touch Devices](/story/recipies-detecttouchdevices--detect-touch-devices) and
[Google Maps](/story/recipies-googlemaps--google-maps) demos.

0 comments on commit 9e52683

Please sign in to comment.