-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: toggle * style: toggle * feat. toggle * docs: delete Toggle
- Loading branch information
Showing
8 changed files
with
619 additions
and
238 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
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
42 changes: 42 additions & 0 deletions
42
packages/react-notion-custom/src/lib/components/toggle.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,42 @@ | ||
"use client"; | ||
|
||
import React, { useState, useCallback } from "react"; | ||
import type { ToggleArgs } from "../types"; | ||
import { getColorCss } from "../utils"; | ||
import RichText from "./internal/rich-text"; | ||
|
||
type ToggleProps = { | ||
children?: React.ReactNode; | ||
} & ToggleArgs; | ||
|
||
const Toggle: React.FC<ToggleProps> = ({ children, ...props }) => { | ||
const { | ||
toggle: { color, rich_text: texts }, | ||
} = props; | ||
|
||
const [open, setOpen] = useState(false); | ||
|
||
const toggleOpen = useCallback(() => setOpen((prevOpen) => !prevOpen), []); | ||
|
||
return ( | ||
<div | ||
className={`notion-block notion-toggle ${getColorCss(color)} ${open ? "notion-toggle-open" : ""}`} | ||
aria-expanded={open} | ||
> | ||
<div className="notion-toggle-content"> | ||
<button onClick={toggleOpen} className="notion-toggle-button"> | ||
<div | ||
className={`notion-toggle-button-arrow ${open ? "notion-toggle-button-arrow-opened" : ""}`} | ||
/> | ||
</button> | ||
<p> | ||
<RichText props={texts} /> | ||
</p> | ||
</div> | ||
|
||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Toggle; |
Oops, something went wrong.