Skip to content

Commit

Permalink
feat: new [components <Head> and <Config>](https://vike.dev/useCo…
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Aug 8, 2024
1 parent f6b423a commit 647aa49
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 0 deletions.
17 changes: 17 additions & 0 deletions vike-solid/components/Config/Config-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export { Config };

// Same as ./Config-server.ts but importing useConfig-client.js

import { useConfig } from "../../hooks/useConfig/useConfig-client.js";
import type { ConfigFromHook } from "../../types/Config.js";

/**
* Set configurations inside React components.
*
* https://vike.dev/useConfig
*/
function Config(props: ConfigFromHook): null {
const config = useConfig();
config(props);
return null;
}
17 changes: 17 additions & 0 deletions vike-solid/components/Config/Config-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export { Config };

// Same as ./Config-client.ts but importing useConfig-server.js

import { useConfig } from "../../hooks/useConfig/useConfig-server.js";
import type { ConfigFromHook } from "../../types/Config.js";

/**
* Set configurations inside React components.
*
* https://vike.dev/useConfig
*/
function Config(props: ConfigFromHook): null {
const config = useConfig();
config(props);
return null;
}
19 changes: 19 additions & 0 deletions vike-solid/components/Head/Head-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export { Head };

// Same as ./Head-server.ts but importing useConfig-client.js

import { useConfig } from "../../hooks/useConfig/useConfig-client.js";
import type { JSX } from "solid-js/jsx-runtime";

/**
* Add arbitrary `<head>` tags.
*
* (The children are teleported to `<head>`.)
*
* https://vike.dev/Head
*/
function Head({ children }: { children: JSX.Element }): null {
const config = useConfig();
config({ Head: children });
return null;
}
19 changes: 19 additions & 0 deletions vike-solid/components/Head/Head-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export { Head };

// Same as ./Head-client.ts but importing useConfig-server.js

import { useConfig } from "../../hooks/useConfig/useConfig-server.js";
import type { JSX } from "solid-js/jsx-runtime";

/**
* Add arbitrary `<head>` tags.
*
* (The children are teleported to `<head>`.)
*
* https://vike.dev/Head
*/
function Head({ children }: { children: JSX.Element }): null {
const config = useConfig();
config({ Head: children });
return null;
}
14 changes: 14 additions & 0 deletions vike-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
"browser": "./dist/hooks/useConfig/useConfig-client.js",
"default": "./dist/hooks/useConfig/useConfig-server.js"
},
"./Config": {
"browser": "./dist/components/Config/Config-client.js",
"default": "./dist/components/Config/Config-server.js"
},
"./Head": {
"browser": "./dist/components/Head/Head-client.js",
"default": "./dist/components/Head/Head-server.js"
},
"./clientOnly": "./dist/helpers/clientOnly.js",
"./renderer/onRenderHtml": "./dist/renderer/onRenderHtml.js",
"./renderer/onRenderClient": "./dist/renderer/onRenderClient.js",
Expand Down Expand Up @@ -71,6 +79,12 @@
"useConfig": [
"dist/hooks/useConfig/useConfig-server.d.ts"
],
"Config": [
"./dist/components/Config/Config-server.d.ts"
],
"Head": [
"./dist/components/Head/Head-server.d.ts"
],
"clientOnly": [
"dist/helpers/clientOnly.d.ts"
]
Expand Down
12 changes: 12 additions & 0 deletions vike-solid/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export default [
"hooks/useData": "./hooks/useData.tsx",
"hooks/useConfig/useConfig-client": "./hooks/useConfig/useConfig-client.ts",
"hooks/useConfig/useConfig-server": "./hooks/useConfig/useConfig-server.ts",
"components/Config/Config-client": "./components/Config/Config-client.ts",
"components/Config/Config-server": "./components/Config/Config-server.ts",
"components/Head/Head-client": "./components/Head/Head-client.ts",
"components/Head/Head-server": "./components/Head/Head-server.ts",
"helpers/clientOnly": "./helpers/clientOnly.tsx",
},
ssr: true,
Expand All @@ -23,6 +27,10 @@ export default [
"hooks/useData": "./hooks/useData.tsx",
"hooks/useConfig/useConfig-client": "./hooks/useConfig/useConfig-client.ts",
"hooks/useConfig/useConfig-server": "./hooks/useConfig/useConfig-server.ts",
"components/Config/Config-client": "./components/Config/Config-client.ts",
"components/Config/Config-server": "./components/Config/Config-server.ts",
"components/Head/Head-client": "./components/Head/Head-client.ts",
"components/Head/Head-server": "./components/Head/Head-server.ts",
},
ssr: false,
external: ["vike/server", "vike/plugin", "vike/getPageContext"],
Expand All @@ -34,6 +42,10 @@ export default [
"./hooks/useData.tsx",
"./hooks/useConfig/useConfig-client.ts",
"./hooks/useConfig/useConfig-server.ts",
"./components/Config/Config-client.ts",
"./components/Config/Config-server.ts",
"./components/Head/Head-client.ts",
"./components/Head/Head-server.ts",
"./helpers/clientOnly.tsx",
"./vite-plugin-vike-solid.ts",
],
Expand Down

0 comments on commit 647aa49

Please sign in to comment.