Skip to content

Commit

Permalink
📝 Add examples to docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
SupremeTechnopriest committed Jan 25, 2023
1 parent 57c3797 commit 4ebf889
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 30 deletions.
14 changes: 7 additions & 7 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-icons": "^4.3.1",
"react-idle-timer": "^5.5.0",
"react-idle-timer": "^5.5.2",
"remark": "^14.0.2",
"remark-emoji": "^3.0.2",
"remark-gfm": "^3.0.1",
Expand Down
12 changes: 12 additions & 0 deletions docs/pages/docs/about/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
title: Changelog
description: IdleTimer Changelog
---
### 5.5.2
<Divider />

#### ✨ Enhancements
- Add defaults to `IdleTimerComponent` generic typescript types.

### 5.5.1
<Divider />

#### ✨ Enhancements
- Cross-tab related methods will no longer throw an error if the manager is not ready yet. It will instead return `null`.

## 5.5.0
<Divider />

Expand Down
13 changes: 10 additions & 3 deletions docs/pages/docs/api/idle-timer-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ and the `useIdleTimerContext` hook.
```jsx
import { IdleTimerProvider, useIdleTimerContext } from 'react-idle-timer'

export function Child (props) => {
export function Child () {
const idleTimer = useIdleTimerContext()
return (
<h1>{idleTimer.isIdle()}</h1>
Expand Down Expand Up @@ -203,7 +203,7 @@ To preserve types for your component's context, declare the type for the
component's context property.

```tsx
import { Component, ContextTypes } from 'react'
import { Component, ContextType } from 'react'
import { IIdleTimerContext, IdleTimerContext } from 'react-idle-timer'

export class Child extends Component<{}, {}> {
Expand All @@ -212,7 +212,7 @@ export class Child extends Component<{}, {}> {
static contextType = IdleTimerContext

// Declare a type for context to preserve typescript types
declare context: ContextType<IIdleTimerContext>
context!: ContextType<typeof IIdleTimerContext>

render () {
return (
Expand All @@ -221,3 +221,10 @@ export class Child extends Component<{}, {}> {
}
}
```

## Examples

<Flex direction='column' mt={8}>
<CodeSandboxButton name='functional-context-provider-jz4y77'>Functional Context Provider</CodeSandboxButton>
<CodeSandboxButton name='class-context-provider-mfujuj'>Class Context Provider</CodeSandboxButton>
</Flex>
10 changes: 9 additions & 1 deletion docs/pages/docs/api/use-idle-timer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,12 @@ export const App = () => {
}
```

For more examples, see the [Features](/docs/features/idle-detection) section.
## Examples

<Flex direction='column' mt={8}>
<CodeSandboxButton name='idle-timer-hook-03790m'>Idle Detection</CodeSandboxButton>
<CodeSandboxButton name='activity-detection-tmn5bp'>Activity Detection</CodeSandboxButton>
<CodeSandboxButton name='cross-tab-2e1tbp'>Cross Tab Support</CodeSandboxButton>
<CodeSandboxButton name='confirm-prompt-y8ew9s'>Confirm Prompt</CodeSandboxButton>
<CodeSandboxButton name='presence-change-handler-2grrwh'>Presence Change Handler</CodeSandboxButton>
</Flex>
6 changes: 5 additions & 1 deletion docs/pages/docs/api/with-idle-timer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,8 @@ const element = document.getElementById('root')
render(<Root />, element)
```

For more examples, see the [Features](/docs/features) section.
## Examples

<Flex direction='column' mt={8}>
<CodeSandboxButton name='higher-order-component-9fyvnr'>Higher Order Component</CodeSandboxButton>
</Flex>
6 changes: 2 additions & 4 deletions docs/pages/docs/features/activity-detection.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,5 @@ The methods associated with activity detection are:
- [getElapsedTime](/docs/api/methods#getelapsedtime): Returns the ammount of milliseconds since the host component was mounted.
{/* cspell:enable */}

### Examples

> Examples will be added once v5 is out of beta. For now you can check out the
> simple examples in the [API](/docs/api/use-idle-timer) section.
### Example
<CodeSandbox name='activity-detection-tmn5bp' />
6 changes: 2 additions & 4 deletions docs/pages/docs/features/confirm-prompt.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ The methods associated with the confirm prompt feature are:
- [isPrompted()](/docs/api/methods#isprompted): Returns true if the prompt is displayed.
{/* cspell:enable */}

### Examples

> Examples will be added once v5 is out of beta. For now you can check out the
> simple examples in the [API](/docs/api/use-idle-timer) section.
### Example
<CodeSandbox name='confirm-prompt-y8ew9s' />
6 changes: 2 additions & 4 deletions docs/pages/docs/features/cross-tab.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,5 @@ The methods associated with the cross tab feature are:
- [getTabId()](/docs/api/methods#gettabid): Returns the current tab's id.
{/* cspell:enable */}

### Examples

> Examples will be added once v5 is out of beta. For now you can check out the
> simple examples in the [API](/docs/api/use-idle-timer) section.
### Example
<CodeSandbox name='cross-tab-2e1tbp' />
6 changes: 2 additions & 4 deletions docs/pages/docs/features/idle-detection.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,5 @@ The methods associated with idle detection are:
- [getTotalIdleTime](/docs/api/methods#gettotalidletime): Returns time in milliseconds the user was idle since the component mounted.
{/* cspell:enable */}

### Examples

> Examples will be added once v5 is out of beta. For now you can check out the
> simple examples in the [API](/docs/api/use-idle-timer) section.
### Example
<CodeSandbox name='idle-timer-hook-03790m' />
17 changes: 17 additions & 0 deletions docs/src/components/mdx/CodeSandbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export function CodeSandbox (props: { name: string }) {
return (
<iframe src={`https://codesandbox.io/embed/${props.name}?fontsize=14&hidenavigation=1&module=%2Fsrc%2FApp.tsx&theme=dark&view=editor`}
style={{
width: '100%',
height: '500px',
border: 0,
borderRadius: '4px',
overflow: 'hidden',
marginTop: '2em'
}}
title="activity-detection"
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
/>
)
}
22 changes: 22 additions & 0 deletions docs/src/components/mdx/CodeSandboxButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { PropsWithChildren } from 'react'
import { Button, Link } from '@chakra-ui/react'
import { FiCodesandbox } from 'react-icons/fi'

export function CodeSandboxButton (props: PropsWithChildren<{ name: string }>) {
return (
<Link
href={`https://codesandbox.io/s/${props.name}`}
_hover={{ textDecoration: 'none' }}
isExternal
mb={2}
>
<Button
variant='ghost'
leftIcon={<FiCodesandbox />}
colorScheme='red'
>
{props.children}
</Button>
</Link>
)
}
6 changes: 5 additions & 1 deletion docs/src/components/mdx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Anchor } from '@components/mdx/Anchor'
import { Pre } from '@components/mdx/Pre'
import { CodeBlock } from '@components/mdx/CodeBlock'
import { Property } from '@components/mdx/Property'
import { CodeSandbox } from '@components/mdx/CodeSandbox'
import { CodeSandboxButton } from '@components/mdx/CodeSandboxButton'

const { Alert, Box, chakra } = Chakra

Expand Down Expand Up @@ -46,5 +48,7 @@ export const MDXComponents = {
my='1.5rem'
{...props}
/>
)
),
CodeSandbox,
CodeSandboxButton
}

1 comment on commit 4ebf889

@vercel
Copy link

@vercel vercel bot commented on 4ebf889 Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.