-
-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
355 additions
and
61 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,21 @@ | ||
.Info { | ||
display: flex; | ||
gap: 10px; | ||
align-items: center; | ||
justify-content: stretch; | ||
padding: 16px 24px; | ||
color: rgba(0,37,158, 0.9); | ||
background-color: rgba(1,68,255,0.059); | ||
border: 1px solid rgb(0 37 158 / 17%); | ||
border-radius: 10px; | ||
} | ||
|
||
.Info > p { | ||
color: inherit; | ||
margin: 0; | ||
} | ||
|
||
.Info > svg { | ||
width: 20px; | ||
height: 20px; | ||
} |
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,29 @@ | ||
import React, {type PropsWithChildren} from 'react'; | ||
|
||
import styles from './Info.module.css'; | ||
|
||
const icon = ( | ||
<svg | ||
width="15" | ||
height="15" | ||
viewBox="0 0 15 15" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M7.49991 0.876892C3.84222 0.876892 0.877075 3.84204 0.877075 7.49972C0.877075 11.1574 3.84222 14.1226 7.49991 14.1226C11.1576 14.1226 14.1227 11.1574 14.1227 7.49972C14.1227 3.84204 11.1576 0.876892 7.49991 0.876892ZM1.82707 7.49972C1.82707 4.36671 4.36689 1.82689 7.49991 1.82689C10.6329 1.82689 13.1727 4.36671 13.1727 7.49972C13.1727 10.6327 10.6329 13.1726 7.49991 13.1726C4.36689 13.1726 1.82707 10.6327 1.82707 7.49972ZM8.24992 4.49999C8.24992 4.9142 7.91413 5.24999 7.49992 5.24999C7.08571 5.24999 6.74992 4.9142 6.74992 4.49999C6.74992 4.08577 7.08571 3.74999 7.49992 3.74999C7.91413 3.74999 8.24992 4.08577 8.24992 4.49999ZM6.00003 5.99999H6.50003H7.50003C7.77618 5.99999 8.00003 6.22384 8.00003 6.49999V9.99999H8.50003H9.00003V11H8.50003H7.50003H6.50003H6.00003V9.99999H6.50003H7.00003V6.99999H6.50003H6.00003V5.99999Z" | ||
fill="currentColor" | ||
fillRule="evenodd" | ||
clipRule="evenodd" | ||
></path> | ||
</svg> | ||
); | ||
|
||
export function Info({children}: PropsWithChildren) { | ||
return ( | ||
<div className={styles.Info}> | ||
{icon} | ||
<p>{children}</p> | ||
</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 @@ | ||
export {Info} from './Info'; |
File renamed without changes.
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
File renamed without changes.
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,3 @@ | ||
export {Code} from './Code'; | ||
export {Info} from './Info'; | ||
export {Preview} from './Preview'; |
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
68 changes: 68 additions & 0 deletions
68
apps/docs/stories/react/Draggable/Modifiers/docs/ModifierDocs.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import {RestrictToElement} from '@dnd-kit/dom/modifiers'; | ||
|
||
import {Info, Preview} from '../../../../components'; | ||
import {DraggableExample} from '../../DraggableExample'; | ||
|
||
# Modifiers | ||
|
||
Modify or restrict the behavior of draggable elements. | ||
|
||
<Preview id="modifier-hero" hero> | ||
<DraggableExample | ||
modifiers={[ | ||
RestrictToElement.configure({ | ||
element() { | ||
return document.getElementById('modifier-hero'); | ||
}, | ||
}), | ||
]} | ||
/> | ||
</Preview> | ||
|
||
Modifiers let you dynamically modify the movement coordinates that are detected by sensors. They can be used for a wide range of use cases, for example: | ||
|
||
- Restricting motion to a single axis | ||
- Restricting motion to the draggable node container's bounding rectangle | ||
- Restricting motion to the draggable node's scroll container bounding rectangle | ||
- Applying resistance or clamping the motion | ||
|
||
## Usage | ||
|
||
Modifiers can be applied globally or to individual draggable elements. | ||
|
||
### Global modifiers | ||
|
||
Modifiers can be applied globally by passing them to the `<DragDropProvider>` component. | ||
|
||
```jsx | ||
import {DragDropProvider} from '@dnd-kit/react'; | ||
import {RestrictToVerticalAxis} from '@dnd-kit/abstract/modifiers'; | ||
import {RestrictToWindow} from '@dnd-kit/dom/modifiers'; | ||
|
||
function App() { | ||
return ( | ||
<DragDropProvider modifiers={[RestrictToWindow, RestrictToVerticalAxis]}> | ||
{...} | ||
</DragDropProvider> | ||
) | ||
} | ||
``` | ||
|
||
### Local modifiers | ||
|
||
<Info>Local modifiers take precedence over global modifiers.</Info> | ||
|
||
Modifiers can also be applied to individual draggable elements by passing them to the `modifiers` prop. | ||
|
||
```jsx | ||
import {useDraggable} from '@dnd-kit/react'; | ||
import {RestrictToVerticalAxis} from '@dnd-kit/abstract/modifiers'; | ||
import {RestrictToWindow} from '@dnd-kit/dom/modifiers'; | ||
|
||
function Draggable({id}) { | ||
const {ref} = useDraggable({ | ||
id, | ||
modifiers: [RestrictToVerticalAxis, RestrictToWindow], | ||
}); | ||
} | ||
``` |
22 changes: 22 additions & 0 deletions
22
apps/docs/stories/react/Draggable/Sensors/Sensors.stories.tsx
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 type {Meta, StoryObj} from '@storybook/react'; | ||
|
||
import docs from './docs/SensorDocs.mdx'; | ||
import {DraggableExample} from '../DraggableExample'; | ||
|
||
const meta: Meta<typeof DraggableExample> = { | ||
title: 'React/Draggable/Sensors', | ||
component: DraggableExample, | ||
tags: ['autodocs'], | ||
parameters: { | ||
docs: { | ||
page: docs, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof DraggableExample>; | ||
|
||
export const Pointer: Story = { | ||
name: 'Default sensors', | ||
}; |
Oops, something went wrong.