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

Add JSR support #322

Closed
wants to merge 2 commits into from
Closed
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
23 changes: 23 additions & 0 deletions jsr.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@bureaudouble/vaul",
"version": "0.0.3",
"compilerOptions": {
"jsx": "react-jsx",
"lib": [
"es2022",
"dom",
"dom.iterable",
"dom.asynciterable"
]
},
"exclude": ["**/*", "!README.md", "!LICENSE.md", "!src", "!jsr.jsonc"],
"imports": {
"react": "npm:react@^18.2.0",
"react-style-singleton": "jsr:@bureaudouble-forks/react-style-singleton@^0.0.1",
"@radix-ui/react-dialog": "jsr:@radix-ui-fork/react-dialog@^0.0.7"
},
"exports": {
".": "./src/index.tsx"
}
}

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
},
"packageManager": "[email protected]",
"dependencies": {
"react-style-singleton": "^2.2.1",
"@radix-ui/react-dialog": "^1.0.4"
}
}
3 changes: 2 additions & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @deno-types="npm:@types/react@^18.2.0"
import React from 'react';
import { DrawerDirection } from './types';
import { DrawerDirection } from './types.ts';

interface DrawerContextValue {
drawerRef: React.RefObject<HTMLDivElement>;
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DrawerDirection } from './types';
import { DrawerDirection } from './types.ts';

interface Style {
[key: string]: string;
Expand Down
33 changes: 20 additions & 13 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
'use client';

import * as DialogPrimitive from '@radix-ui/react-dialog';
// @deno-types="npm:@types/react@^18.2.0"
import React from 'react';
import { DrawerContext, useDrawerContext } from './context';
import './style.css';
import { usePreventScroll, isInput, isIOS } from './use-prevent-scroll';
import { useComposedRefs } from './use-composed-refs';
import { usePositionFixed } from './use-position-fixed';
import { useSnapPoints } from './use-snap-points';
import { set, reset, getTranslate, dampenValue, isVertical } from './helpers';
import { TRANSITIONS, VELOCITY_THRESHOLD } from './constants';
import { DrawerDirection } from './types';
import { styleHookSingleton } from 'react-style-singleton';
import style from "./style.ts";
import { DrawerContext, useDrawerContext } from './context.ts';
import { usePreventScroll, isInput, isIOS } from './use-prevent-scroll.ts';
import { useComposedRefs } from './use-composed-refs.ts';
import { usePositionFixed } from './use-position-fixed.ts';
import { useSnapPoints } from './use-snap-points.ts';
import { set, reset, getTranslate, dampenValue, isVertical } from './helpers.ts';
import { TRANSITIONS, VELOCITY_THRESHOLD } from './constants.ts';
import { DrawerDirection } from './types.ts';

const CLOSE_THRESHOLD = 0.25;

Expand Down Expand Up @@ -55,6 +57,8 @@ type DialogProps = {
disablePreventScroll?: boolean;
} & (WithFadeFromProps | WithoutFadeFromProps);

const useStyle: ReturnType<typeof styleHookSingleton> = styleHookSingleton();

function Root({
open: openProp,
onOpenChange,
Expand All @@ -76,7 +80,8 @@ function Root({
direction = 'bottom',
preventScrollRestoration = true,
disablePreventScroll = false,
}: DialogProps) {
}: DialogProps): React.JSX.Element {
useStyle(style);
const [isOpen = false, setIsOpen] = React.useState<boolean>(false);
const [hasBeenOpened, setHasBeenOpened] = React.useState<boolean>(false);
// Not visible = translateY(100%)
Expand Down Expand Up @@ -760,7 +765,8 @@ function Root({
);
}

const Overlay = React.forwardRef<HTMLDivElement, React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>>(
const Overlay: React.ForwardRefExoticComponent<Omit<typeof DialogPrimitive.Overlay, "ref"> & React.RefAttributes<HTMLDivElement>> =
React.forwardRef<HTMLDivElement, React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>>(
function ({ children, ...rest }, ref) {
const { overlayRef, snapPoints, onRelease, shouldFade, isOpen, visible } = useDrawerContext();
const composedRef = useComposedRefs(ref, overlayRef);
Expand All @@ -786,7 +792,8 @@ type ContentProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Conten
onAnimationEnd?: (open: boolean) => void;
};

const Content = React.forwardRef<HTMLDivElement, ContentProps>(function (
const Content: React.ForwardRefExoticComponent<Omit<ContentProps, "ref"> & React.RefAttributes<HTMLDivElement>>
= React.forwardRef<HTMLDivElement, ContentProps>(function (
{ onOpenAutoFocus, onPointerDownOutside, onAnimationEnd, style, ...rest },
ref,
) {
Expand Down Expand Up @@ -901,7 +908,7 @@ const Content = React.forwardRef<HTMLDivElement, ContentProps>(function (

Content.displayName = 'Drawer.Content';

function NestedRoot({ onDrag, onOpenChange, ...rest }: DialogProps) {
function NestedRoot({ onDrag, onOpenChange, ...rest }: DialogProps): React.JSX.Element {
const { onNestedDrag, onNestedOpenChange, onNestedRelease } = useDrawerContext();

if (!onNestedDrag) {
Expand Down
4 changes: 4 additions & 0 deletions src/style.css → src/style.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const style: string = /* css */`
[vaul-drawer] {
touch-action: none;
transition: transform 0.5s cubic-bezier(0.32, 0.72, 0, 1);
Expand Down Expand Up @@ -113,3 +114,6 @@
to {
}
}
`;

export default style;
1 change: 1 addition & 0 deletions src/use-composed-refs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This code comes from https://github.com/radix-ui/primitives/tree/main/packages/react/compose-refs

// @deno-types="npm:@types/react@^18.2.0"
import * as React from 'react';

type PossibleRef<T> = React.Ref<T> | undefined;
Expand Down
1 change: 1 addition & 0 deletions src/use-controllable-state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This code comes from https://github.com/radix-ui/primitives/blob/main/packages/react/use-controllable-state/src/useControllableState.tsx

// @deno-types="npm:@types/react@^18.2.0"
import React from 'react';

type UseControllableStateParams<T> = {
Expand Down
1 change: 1 addition & 0 deletions src/use-position-fixed.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @deno-types="npm:@types/react@^18.2.0"
import React from 'react';

let previousBodyPosition: Record<string, string> | null = null;
Expand Down
1 change: 1 addition & 0 deletions src/use-prevent-scroll.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This code comes from https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/overlays/src/usePreventScroll.ts

// @deno-types="npm:@types/react@^18.2.0"
import { useEffect, useLayoutEffect } from 'react';

export const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
Expand Down
9 changes: 5 additions & 4 deletions src/use-snap-points.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @deno-types="npm:@types/react@^18.2.0"
import React from 'react';
import { set, isVertical } from './helpers';
import { TRANSITIONS, VELOCITY_THRESHOLD } from './constants';
import { useControllableState } from './use-controllable-state';
import { DrawerDirection } from './types';
import { set, isVertical } from './helpers.ts';
import { TRANSITIONS, VELOCITY_THRESHOLD } from './constants.ts';
import { useControllableState } from './use-controllable-state.ts';
import { DrawerDirection } from './types.ts';

export function useSnapPoints({
activeSnapPointProp,
Expand Down