- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com>
//
// SPDX-License-Identifier: Apache-2.0
/** @jsx h */
import { h } from "../../../../deps/deno.land/x/nano_jsx/mod.ts";
import { css } from "../../css.ts";
import * as LucideIcons from "../lucide_icons.tsx";
const enum C {
TaskItem = "fh-tl--i",
Checkbox = "fh-tl--c",
Check = "fh-tl--h",
Text = "fh-tl--t",
}
export const styles = css`
.${C.TaskItem} {
display: flex;
align-items: start;
list-style: none;
}
.${C.Checkbox} {
display: flex;
align-items: stretch;
justify-content: stretch;
width: calc(1em - 2px);
height: calc(1em - 2px);
aspect-ratio: 1 / 1;
border: 1px solid currentColor;
margin: 0;
margin-block-start: calc((var(--baseline) * 1rem - 1em) * 0.5 + 1px);
margin-inline-start: calc(-1em - 2px);
margin-inline-end: 4px;
border-radius: 2px;
}
.${C.Check} {
min-width: 0px;
min-height: 0px;
height: 100%;
}
.${C.Text} {
line-height: calc(var(--baseline) * 1rem);
}
`;
export interface MacanaGfmTaskListProps {
ordered?: "" | false;
children: unknown;
}
export function MacanaGfmTaskList(
{ ordered, children }: MacanaGfmTaskListProps,
) {
const Tag = ordered ? "ol" : "ul";
return (
<Tag>
{children}
</Tag>
);
}
let checkCounter = 0;
export interface MacanaGfmTaskListItemProps {
is_task: "" | false;
checked?: "" | false;
children: unknown;
}
export function MacanaGfmTaskListItem(
{ children, checked, is_task }: MacanaGfmTaskListItemProps,
) {
if (typeof is_task !== "string") {
return <li>{children}</li>;
}
const isChecked = typeof checked === "string";
const labelId = `__macana_tcheck_lbl__${checkCounter++}`;
return (
<li className={C.TaskItem}>
<span
className={C.Checkbox}
role="checkbox"
aria-disabled="true"
tabindex="0"
aria-checked={isChecked.toString()}
aria-labelledby={labelId}
>
{isChecked && (
<LucideIcons.Check className={C.Check} aria-hidden="true" />
)}
</span>
<span id={labelId} className={C.Text}>{children}</span>
</li>
);
}