-
Notifications
You must be signed in to change notification settings - Fork 25
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
1 parent
5d4cf0b
commit 4d9d967
Showing
17 changed files
with
551 additions
and
15 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,3 @@ | ||
{ | ||
"sideEffects": false | ||
} |
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,2 +1,2 @@ | ||
// experimental imports | ||
export * from "./resizable-panel/ResizablePanel"; | ||
export * from "../lib/drawer/drawer"; |
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,32 @@ | ||
import { render, waitFor } from "@testing-library/react"; | ||
import { describe, it } from "vitest"; | ||
import GoADrawer from "./drawer"; | ||
|
||
const noop = () => {/* nothing */} | ||
|
||
describe("Drawer", () => { | ||
it("renders", async () => { | ||
const content = render( | ||
<GoADrawer | ||
open={false} | ||
position="bottom" | ||
heading="The heading" | ||
maxSize="50ch" | ||
testId="the testid" | ||
onClose={noop} | ||
> | ||
The content | ||
</GoADrawer> | ||
); | ||
|
||
const el = content.container.querySelector("goa-drawer"); | ||
expect(el).toBeTruthy(); | ||
await waitFor(() => { | ||
expect(el?.getAttribute("open")).toBeNull(); | ||
expect(el?.getAttribute("position")).toBe("bottom"); | ||
expect(el?.getAttribute("heading")).toBe("The heading"); | ||
expect(el?.getAttribute("maxsize")).toBe("50ch"); | ||
expect(el?.getAttribute("data-testid")).toBe("the testid"); | ||
}) | ||
}); | ||
}); |
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,71 @@ | ||
import { ReactNode, useEffect, useRef } from "react"; | ||
|
||
type DrawerPosition = "bottom" | "left" | "right" | undefined; | ||
type DrawerSizeUnit = "px" | "rem" | "ch" | "vh" | "vw"; | ||
type DrawerSize = `${number}${DrawerSizeUnit}` | undefined; | ||
|
||
interface WCProps { | ||
open: boolean | undefined; | ||
position: DrawerPosition; | ||
heading?: string; | ||
maxsize?: DrawerSize; | ||
testid?: string; | ||
ref: React.RefObject<HTMLElement>; | ||
} | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace JSX { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
interface IntrinsicElements { | ||
"goa-drawer": WCProps & React.HTMLAttributes<HTMLElement>; | ||
} | ||
} | ||
} | ||
|
||
export interface GoADrawerProps { | ||
open: boolean; | ||
position: DrawerPosition; | ||
heading?: string; | ||
maxSize?: DrawerSize; | ||
testId?: string; | ||
children: ReactNode; | ||
onClose: () => void; | ||
} | ||
|
||
export function GoADrawer({ | ||
open, | ||
position, | ||
heading, | ||
maxSize, | ||
testId, | ||
children, | ||
onClose, | ||
}: GoADrawerProps): JSX.Element { | ||
const el = useRef<HTMLElement>(null); | ||
|
||
useEffect(() => { | ||
if (!el?.current || !onClose) { | ||
return; | ||
} | ||
el.current?.addEventListener("_close", onClose) | ||
return () => { | ||
el.current?.removeEventListener("_close", onClose) | ||
} | ||
}, [el, onClose]) | ||
|
||
return ( | ||
<goa-drawer | ||
ref={el} | ||
open={open ? true : undefined} | ||
position={position} | ||
heading={heading} | ||
maxsize={maxSize} | ||
data-testid={testId} | ||
> | ||
{children} | ||
</goa-drawer> | ||
); | ||
} | ||
|
||
export default GoADrawer; |
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,11 @@ | ||
{ | ||
"extends": "./tsconfig.lib.json", | ||
"include": [ | ||
"src/experimental/**/*.js", | ||
"src/experimental/**/*.jsx", | ||
"src/experimental/**/*.ts", | ||
"src/experimental/**/*.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
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,4 @@ | ||
// Drawer | ||
export type DrawerPosition = "bottom" | "left" | "right" | undefined; | ||
export type DrawerSizeUnit = "px" | "rem" | "ch" | "vh" | "vw"; | ||
export type DrawerSize = `${number}${DrawerSizeUnit}` | undefined; |
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
Oops, something went wrong.