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

feat: added checkbox support#86 #92

Merged
merged 1 commit into from
Nov 24, 2021
Merged
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
30 changes: 30 additions & 0 deletions src/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,37 @@ export const Block: React.FC<Block> = props => {
const start = getListNumber(blockValue.id, blockMap);

return isTopLevel ? wrapList(output, start) : output;
case "to_do":
/**
* There are only 3 possible cases when no nested to_dos:
* 1. properties: {title: [["test"]], checked: [["No"]]}
* 2. properties: {title: [["test"]], checked: [["Yes"]]}
* 3. properties: {title: [["test"]]}
*/
const checkbox = block.value.properties;
const { id } = block.value;

// remove other styles in to-do.
const label: string = checkbox?.title
.flat(1) // only flatten the first level
.filter((ele: string | Array<string>) => typeof ele === "string")
.join("");

const isChecked =
checkbox?.checked && checkbox?.checked[0][0] === "Yes";

return (
<div>
<input
className="notion-checkbox"
type="checkbox"
name=""
id={id}
checked={isChecked}
/>
<label htmlFor={id}>{label}</label>
</div>
);
case "image":
case "embed":
case "figma":
Expand Down
4 changes: 4 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ img.notion-page-icon {
padding-left: 0px;
}

.notion-checkbox {
accent-color: #eb5757;
}

.notion-asset-wrapper {
margin: 0.5rem auto 0.5rem;
max-width: 100%;
Expand Down