Skip to content

Commit

Permalink
Added Toggle block (#9)
Browse files Browse the repository at this point in the history
* feat: toggle

* style: toggle

* feat. toggle

* docs: delete Toggle
  • Loading branch information
myjeong19 authored Sep 22, 2024
1 parent 7305bc3 commit 0b29f3b
Show file tree
Hide file tree
Showing 8 changed files with 619 additions and 238 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"prettier": "^3.3.3"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,md,mdx}": [
"*.{js,jsx,ts,tsx,md,mdx,css}": [
"prettier --write --ignore-unknown"
]
}
Expand Down
3 changes: 1 addition & 2 deletions packages/react-notion-custom/CONTRIBUTING-KR.md
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ fetchNotionPage();
| Bulleted List Item | ❌ No | `bulleted_list_item` | |
| Numbered List Item | ❌ No | `numbered_list_item` | |
| To-do | ❌ No | `to_do` | |
| Toggle | ❌ No | `toggle` | |
| Toggle | ✅ Yes | `toggle` | |
| Quote | ❌ No | `quote` | |
| Callout | ❌ No | `callout` | |
| Equation | ❌ No | `equation` | |
Expand Down Expand Up @@ -700,7 +700,6 @@ react-notion-custom 프로젝트의 향후 개발 계획을 소개합니다. 이
- Bulleted List Item
- Numbered List Item
- To-do
- Toggle
- Quote
- Callout
- Image
Expand Down
3 changes: 1 addition & 2 deletions packages/react-notion-custom/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ Here's a list of Notion block types currently supported in react-notion-custom.
| Bulleted List Item | ❌ No | `bulleted_list_item` | |
| Numbered List Item | ❌ No | `numbered_list_item` | |
| To-do | ❌ No | `to_do` | |
| Toggle | ❌ No | `toggle` | |
| Toggle | ✅ Yes | `toggle` | |
| Quote | ❌ No | `quote` | |
| Callout | ❌ No | `callout` | |
| Equation | ❌ No | `equation` | |
Expand Down Expand Up @@ -703,7 +703,6 @@ We plan to implement support for the following Notion block types first:
- Bulleted List Item
- Numbered List Item
- To-do
- Toggle
- Quote
- Callout
- Image
Expand Down
2 changes: 2 additions & 0 deletions packages/react-notion-custom/src/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Heading1 from "./heading-1";
import Heading2 from "./heading-2";
import Heading3 from "./heading-3";
import Paragraph from "./paragraph";
import Toggle from "./toggle";

export { Heading1, Heading2, Heading3, Paragraph };

Expand All @@ -10,4 +11,5 @@ export default {
heading_2: Heading2,
heading_3: Heading3,
paragraph: Paragraph,
toggle: Toggle,
};
42 changes: 42 additions & 0 deletions packages/react-notion-custom/src/lib/components/toggle.tsx
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;
Loading

0 comments on commit 0b29f3b

Please sign in to comment.