diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index d0ae8bfc..6f9c94df 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - node-version: [18.x, 20.x, 22.x] + node-version: [20.x, 22.x, 24.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: diff --git a/.gitignore b/.gitignore index eea2f24c..63b88a7d 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ test/fixtures/components/lodash-component/_package test/fixtures/components/no-containers/_package test/fixtures/components/welcome/_package test/fixtures/components/welcome-with-optional-parameters/_package +test/fixtures/components/hello-world-custom-cookies/_package logintervals.md dist/ diff --git a/src/registry/routes/component-info.ts b/src/registry/routes/component-info.ts index 524f94f3..09ddaf41 100644 --- a/src/registry/routes/component-info.ts +++ b/src/registry/routes/component-info.ts @@ -14,9 +14,17 @@ function getParams(component: Component) { params = Object.fromEntries( Object.entries(component.oc.parameters || {}) .filter(([, param]) => { - return !!param.mandatory && 'example' in param; + // Include parameters that have either a default value or an example + return param.default !== undefined || param.example !== undefined; + }) + .map(([paramName, param]) => { + // Prefer default value over example + const value = + param.default !== undefined + ? String(param.default) + : param.example!; + return [paramName, value]; }) - .map(([paramName, param]) => [paramName, param.example!]) ); } diff --git a/src/registry/views/info.tsx b/src/registry/views/info.tsx index 9ea65df5..b46e04ab 100644 --- a/src/registry/views/info.tsx +++ b/src/registry/views/info.tsx @@ -149,7 +149,7 @@ export default function Info(vm: Vm) { selectedVersion={component.version} /> -

+

{component.description} {componentState()}

{statsAvailable ? ( @@ -184,7 +184,22 @@ export default function Info(vm: Vm) { ) : ( '' )} - + { + return param.default !== undefined || param.example !== undefined; + }) + .map(([paramName, param]) => { + const value = + param.default !== undefined + ? String(param.default) + : param.example!; + return [paramName, value]; + }) + )} + />

Code

You can edit the following area and then @@ -192,7 +207,7 @@ export default function Info(vm: Vm) { {' '} refresh{' '} - to apply the change into the preview window. + or hit Enter to apply the change into the preview window.

Component's href:

diff --git a/src/registry/views/partials/component-author.tsx b/src/registry/views/partials/component-author.tsx index 392bcfac..8cbea14a 100644 --- a/src/registry/views/partials/component-author.tsx +++ b/src/registry/views/partials/component-author.tsx @@ -8,15 +8,15 @@ const componentAuthor = (props: {

Author:

{!name && !email && !url && not available} - {name && {name} } + {!!name && {name} } {email && ( {email}  )} - {url && ( + {!!url && ( - + {url} diff --git a/src/registry/views/partials/component-parameters.tsx b/src/registry/views/partials/component-parameters.tsx index 115e9a88..7ecc7203 100644 --- a/src/registry/views/partials/component-parameters.tsx +++ b/src/registry/views/partials/component-parameters.tsx @@ -1,9 +1,11 @@ import type { OcParameter } from '../../../types'; const componentParameters = ({ - parameters + parameters, + currentValues }: { parameters?: Record; + currentValues?: Record; }) => { if (!parameters) { return ( @@ -16,32 +18,94 @@ const componentParameters = ({ const parameterRow = (param: OcParameter, paramName: string) => { const mandatory = param.mandatory ? 'mandatory' : 'optional'; + const defaultValue = + param.default !== undefined ? String(param.default) : ''; + const exampleValue = + param.example !== undefined ? String(param.example) : ''; + const currentValue = + currentValues?.[paramName] || defaultValue || exampleValue; + + const renderInput = () => { + switch (param.type) { + case 'number': + return ( + + ); + case 'boolean': { + const isChecked = String(currentValue) === 'true'; + return ( + + ); + } + default: + return ( + + ); + } + }; + return (
- {paramName} + + {paramName} + ({param.type}, {mandatory})
- {param.description && ( + {!!param.description && ( <> - {param.description} + {param.description}

)} - Example: - {param.example} - {!param.mandatory && param.default && ( + {param.type !== 'boolean' && !!param.example && ( <> + Example: + {param.example}

+ + )} + {!param.mandatory && !!param.default && ( + <> Default: - {param.default} + {String(param.default)} +
+
)} + + {param.type === 'boolean' ? 'Enabled:' : 'Value:'} + + {renderInput()}
); @@ -51,10 +115,6 @@ const componentParameters = ({

Parameters

-
-
Parameters
-
-
{Object.keys(parameters).map((parameterName) => parameterRow(parameters[parameterName], parameterName) )} diff --git a/src/registry/views/partials/component-versions.tsx b/src/registry/views/partials/component-versions.tsx index 71c6d03c..e7cd19ec 100644 --- a/src/registry/views/partials/component-versions.tsx +++ b/src/registry/views/partials/component-versions.tsx @@ -8,7 +8,7 @@ const componentVersions = ({ return (