-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Enterwell/stage
Stage
- Loading branch information
Showing
27 changed files
with
267 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { parse as parseJsDoc } from 'comment-parser'; | ||
import { Mdx } from './Mdx'; | ||
import { Fragment } from 'react'; | ||
import hooksApi from '@enterwell/hooks/dist/hooks.api.json'; | ||
import uiApi from '@enterwell/ui/dist/ui.api.json'; | ||
|
||
type ComponentDocsProps = { | ||
component: React.FunctionComponent; | ||
}; | ||
|
||
const api = [ | ||
...hooksApi.members.find((m: any) => m.kind === "EntryPoint")?.members ?? [], | ||
...uiApi.members.find((m: any) => m.kind === "EntryPoint")?.members ?? [] | ||
]; | ||
|
||
function componentMember(component: React.FunctionComponent) { | ||
return api?.find((m: any) => m.name === component.name); | ||
} | ||
|
||
function componentComment(component: React.FunctionComponent) { | ||
const member = componentMember(component); | ||
const comments = member ? parseJsDoc(member.docComment) : undefined; | ||
return comments?.at(0); | ||
} | ||
|
||
export function ComponentDescription({ component }: ComponentDocsProps) { | ||
const comment = componentComment(component); | ||
const { description } = comment || {}; | ||
|
||
return ( | ||
<Mdx>{description}</Mdx> | ||
) | ||
} | ||
|
||
export function ComponentParameters({ component }: ComponentDocsProps) { | ||
const member = componentMember(component); | ||
const comment = componentComment(component); | ||
const params = member?.parameters?.map((param) => ({ | ||
name: param.parameterName, | ||
description: comment?.tags?.find((tag) => tag.tag === 'param' && tag.name === param.parameterName)?.description, | ||
optional: param.isOptional, | ||
type: member.excerptTokens.slice(param.parameterTypeTokenRange.startIndex, param.parameterTypeTokenRange.endIndex).map(t => t.text).join(' '), | ||
})); | ||
|
||
if (!params?.length) { | ||
return ( | ||
<div className="text-center text-gray-400"> | ||
<p>No parameters</p> | ||
</div> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className="grid grid-cols-1 sm:grid-cols-[auto_auto_1fr] gap-x-4 gap-y-1 items-center mt-2"> | ||
{params?.map((param: any) => ( | ||
<Fragment key={param.name}> | ||
<div> | ||
<span className="text-xl font-bold">{param.name}</span> | ||
</div> | ||
<div> | ||
{param.type && <span className="text-muted-foreground">{param.type}</span>} | ||
{param.optional && <span className="text-muted-foreground"> (optional)</span>} | ||
</div> | ||
<div> | ||
<Mdx>{param.description?.trim().slice(1)}</Mdx> | ||
</div> | ||
<hr className="sm:hidden" /> | ||
</Fragment> | ||
))} | ||
</div> | ||
) | ||
} |
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,20 @@ | ||
import { evaluateSync } from "@mdx-js/mdx"; | ||
import * as provider from "@mdx-js/react"; | ||
import { useMDXComponents } from "nextra/mdx"; | ||
import React from "react"; | ||
import * as runtime from "react/jsx-runtime"; | ||
|
||
export function Mdx({ children }: { children?: string }) { | ||
if (!children) return null; | ||
|
||
const { default: MDXContent } = evaluateSync(children, { | ||
...runtime, | ||
...provider, | ||
useMDXComponents, | ||
format: "mdx", | ||
development: false, | ||
Fragment: React.Fragment | ||
}); | ||
|
||
return <MDXContent />; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useDebouncedEffect } from '@enterwell/hooks'; | ||
import { ComponentDescription, ComponentParameters } from '../../../components/docs/ComponentDocs'; | ||
|
||
# useDebouncedEffect | ||
|
||
## Description | ||
|
||
<ComponentDescription component={useDebouncedEffect} /> | ||
|
||
### Parameters | ||
|
||
<ComponentParameters component={useDebouncedEffect} /> | ||
|
||
## Example | ||
|
||
```ts filename="example.ts" {3-5} | ||
import { useDebouncedEffect } from '@enterwell/hooks'; | ||
|
||
useDebouncedEffect(() => { | ||
// Do effect stuff here | ||
}, [], 500); | ||
``` |
15 changes: 12 additions & 3 deletions
15
apps/docs/pages/hooks/hooks/use-isomorphic-layout-effect.mdx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
import { DropdownButton } from '@enterwell/ui'; | ||
import { ComponentWithSource } from '../../../components/docs/ComponentWithSource.tsx'; | ||
import { ExampleDropdownButton } from '../../../components/ExampleDropdownButton.tsx'; | ||
import { ComponentDescription, ComponentParameters } from '../../../components/docs/ComponentDocs'; | ||
|
||
# DropdownButton | ||
|
||
## Description | ||
|
||
<ComponentDescription component={DropdownButton} /> | ||
|
||
### Parameters | ||
|
||
<ComponentParameters component={DropdownButton} /> | ||
|
||
## Example | ||
|
||
<ComponentWithSource component={ExampleDropdownButton} centered /> |
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 |
---|---|---|
@@ -1,6 +1,18 @@ | ||
import { PageDrawer } from '@enterwell/ui'; | ||
import { ComponentWithSource } from '../../../components/docs/ComponentWithSource.tsx'; | ||
import { ExamplePageDrawer } from '../../../components/ExamplePageDrawer.tsx'; | ||
import { ComponentDescription, ComponentParameters } from '../../../components/docs/ComponentDocs'; | ||
|
||
# PageDrawer | ||
# DropdownButton | ||
|
||
## Description | ||
|
||
<ComponentDescription component={PageDrawer} /> | ||
|
||
### Parameters | ||
|
||
<ComponentParameters component={PageDrawer} /> | ||
|
||
## Example | ||
|
||
<ComponentWithSource component={ExamplePageDrawer} /> |
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
Empty file.
Empty file.
Empty file.
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useEffect } from "react"; | ||
|
||
/** | ||
* Hook that provides the debouncing functionality with a given callback. | ||
* | ||
* @param effect - Effect function to call on debounce | ||
* @param deps - Effect dependencies | ||
* @param delay - Debounce delay | ||
* @public | ||
*/ | ||
export function useDebouncedEffect(effect: Function, deps: unknown[], delay: number) { | ||
useEffect(() => { | ||
const handler = setTimeout(() => effect(), delay); | ||
|
||
return () => clearTimeout(handler); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [...(deps || []), delay]); | ||
} |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { useEffect, useLayoutEffect } from 'react' | ||
|
||
/** | ||
* Isomorphic layout effect hook. | ||
* Use `useIsomorphicLayoutEffect` to run layout effects in both the server and the client. | ||
* | ||
* This hook runs `useLayoutEffect` on the client and `useEffect` on the server. | ||
* @public | ||
*/ | ||
export const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// hook exports | ||
export * from "./hooks/useDebouncedEffect"; | ||
export * from "./hooks/useDebounce"; | ||
export * from "./hooks/useIsomorphicLayoutEffect"; | ||
export * from "./hooks/useResizeObserver"; |
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
Empty file.
Empty file.
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use client'; | ||
|
||
// component exports | ||
export * from "./DropdownButton"; | ||
export * from "./PageDrawer"; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.