Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(Modal): refactor jsx examples to tsx #2218

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react'
import ComponentBox from '../../../../shared/tags/ComponentBox'

import { Modal, P, Button } from '@dnb/eufemia/src'
import { Modal, P, Button, Input, HelpButton } from '@dnb/eufemia/src'

export const ExampleCard = ({ children }) => (
<div
Expand Down Expand Up @@ -77,3 +77,43 @@ export const ModalExampleCloseByHandler = () => (
</Modal>
</ComponentBox>
)

export const ModalExampleSuffix = () => (
<ComponentBox hidePreview>
<Input
label="Input"
placeholder="Placeholder ..."
suffix={<HelpButton>Help text</HelpButton>}
/>
</ComponentBox>
)

export const ModalExampleTriggerProps = () => (
<ComponentBox hidePreview>
<Modal triggerAttributes={{ icon: 'bell' }} right="small">
... content ...
</Modal>
</ComponentBox>
)

export const ModalExampleOnClosePrevent = () => (
<ComponentBox hidePreview>
<Modal
preventClose={true}
onClosePrevent={({ triggeredBy, close /* id, event */ }) => {
switch (triggeredBy) {
case 'keyboard':
case 'button':
close()
break
case 'overlay': {
const timeout = setTimeout(close, 1e3)
return () => clearTimeout(timeout) // clear timeout on unmount
}
}
}}
>
...
</Modal>
</ComponentBox>
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,12 @@ showTabs: true
---

import ModalEventTable from 'Docs/uilib/components/modal/event-table'
import { ModalExampleOnClosePrevent } from 'Docs/uilib/components/modal/Examples'

## Events

<ModalEventTable />

### Selective on_close_prevent

```jsx
<Modal
...
preventClose={true}
onClosePrevent={({ triggeredBy, close /* id, event */ }) => {
switch (triggeredBy) {
case 'keyboard':
case 'button':
close()
break
case 'overlay': {
const timeout = setTimeout(close, 1e3)
return () => clearTimeout(timeout) // clear timeout on unmount
}
}
}}
>
...
</Modal>
```
<ModalExampleOnClosePrevent />
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
showTabs: true
---

import { ModalExampleSuffix } from 'Docs/uilib/components/modal/Examples'

## Description

Modal is the root component for [Drawer](/uilib/components/drawer) and [Dialog](/uilib/components/dialog). If one of these satisfy your needs, you want to use those rather than directly using Modal. Using the Modal, it's possible to implement other modal variants than we provide as of now(Drawer and Dialog).
Expand All @@ -18,13 +20,7 @@ As the Modal is very often used in combination with other components and often a

You can also use the broadly available `suffix` property, like so:

```jsx
<Input
label="Input"
placeholder="Placeholder ..."
suffix={<HelpButton>Help text</HelpButton>}
/>
```
<ModalExampleSuffix />

### Accessibility

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ showTabs: true
---

import ModalPropTable from 'Docs/uilib/components/modal/prop-table'
import { ModalExampleTriggerProps } from 'Docs/uilib/components/modal/Examples'

## Modal Properties

Expand All @@ -12,8 +13,4 @@ import ModalPropTable from 'Docs/uilib/components/modal/prop-table'

Properties targeting the trigger component (Button), but they will be set the same way as all the other properties:

```jsx
<Modal triggerAttributes={{ icon: 'primary_icon' }} right="small">
... content ...
</Modal>
```
<ModalExampleTriggerProps />