GithubHelp home page GithubHelp logo

bartlomieju / doc_components Goto Github PK

View Code? Open in Web Editor NEW

This project forked from denoland/doc_components

0.0 1.0 0.0 288 KB

A set of components for rendering deno_doc doc nodes

Home Page: https://deno-doc-components.deno.dev

License: MIT License

TypeScript 100.00%

doc_components's Introduction

deno_doc_components

deno doc Build Status - Cirrus Twitter handle Discord Chat

A set of components used to render deno_doc DocNodes.

Showcase

The repository contains a showcase application to see example rendering of the components in the _showcase directory. It can be run locally using:

> deno task showcase

It is also available on deno-doc-components.deno.dev.

Usage

JSX runtime

These components are abstracted away from any specific JSX engine, and require the JSX runtime to be configured before any of the components can be rendered. To do this, import the setup() function from services.ts and provide it with the runtime.

You will want to invoke setup() as you are bootstrapping your application, but before you attempt to render any JSX.

For example with Nano JSX:

import { Fragment, h } from "https://deno.land/x/nano_jsx/mod.ts";
import { setup } from "https://deno.land/x/deno_doc_components/services.ts";

await setup({ runtime: { Fragment, h } });

For example with Preact:

import { Fragment, h } from "https://esm.sh/pract";
import { setup } from "https://deno.land/x/deno_doc_components/services.ts";

await setup({ runtime: { Fragment, h } });

For example with fresh:

import {
  Fragment,
  h,
} from "https://raw.githubusercontent.com/lucacasonato/fresh/main/runtime.ts";
import { setup } from "https://deno.land/x/deno_doc_components/services.ts";

await setup({ runtime: { Fragment, h } });

For example with aleph (but validate the version of React that the version of aleph you are using uses):

import { createElement as h, Fragment } from "https://esm.sh/[email protected]";
import { setup } from "https://deno.land/x/deno_doc_components/services.ts";

await setup({ runtime: { Fragment, h } });

The tests use Nano JSX, and provide an example of how to setup the runtime.

Other services

There are other services that may need to be provided to integrate the components into an application. These can also be provided via setup() and will override the default behavior.

href()

The function href() should return a link string value which will be used at points in rendering when linking off to other modules and symbols. It has the following signature:

interface Configuration {
  href?: (path: string, symbol?: string) => string;
}

The path will be set to the module being requested (e.g. /mod.ts) and optionally a symbol will be provided, if targeting a specific exported symbol from that module.

lookupSymbolHref()

The function lookupSymbolHref() is used when the components are trying to resolve a link to a specific symbol. An implementation should attempt to resolve the symbol from the current namespace to the current module, to the global namespace, returning a link to the first matching symbol it finds. If the symbol cannot be found, undefined should be returned.

interface Configuration {
  lookupSymbolHref?: (
    current: string,
    namespace: string | undefined,
    symbol: string,
  ) => string | undefined;
}

The current will be set to the module that is the current reference point (e.g. /mod.ts), any namespace that is in the current scope (e.g. errors) and the symbol that is being looked for (e.g. Uint8Array). If the current namespace is with another namespace, they will be separated by a . (e.g. custom.errors).

twind

twind has some shared hidden state, which means that doc_components needs to share the same versions of the remote twind modules. In order to do that, doc_components from the bare specifiers twind, twind/colors, twind/css. Also, if you are setting up twind to SSR in a client application, you will end up needing items from twind/sheets.

Therefore it is expected that you will use an import map to provide the specific version of twind you are using in your end application. This repository contains an example which is used for the showcase.

You can specify a twind setup configuration by passing a property of tw when performing a setup. For example:

import { setup } from "https://deno.land/x/deno_doc_components/services.ts";

await setup({
  tw: {
    theme: {
      colors: {
        transparent: "transparent",
      },
    },
  },
});

The /services.ts module exports a theme object which is the default theme settings that the doc_components use with twind, which can be used when you are performing setup from twind yourself:

import { setup } from "twind";
import { theme } from "https://deno.land/x/deno_doc_components/services.ts";

setup({ theme });

Copyright 2021-2022 the Deno authors. All rights reserved. MIT License.

doc_components's People

Contributors

kitsonk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.