2024-07-10 16:17:23 +08:00
|
|
|
import { css, cx } from "@emotion/css";
|
|
|
|
import type { List } from "@yozora/ast";
|
|
|
|
import React from "react";
|
|
|
|
import { astClasses } from "../context";
|
|
|
|
import { NodesRenderer } from "../NodesRenderer";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render `list`.
|
|
|
|
*
|
|
|
|
* @see https://www.npmjs.com/package/@yozora/ast#list
|
|
|
|
* @see https://www.npmjs.com/package/@yozora/tokenizer-list
|
|
|
|
*/
|
|
|
|
export class ListRenderer extends React.Component<List> {
|
2024-07-10 16:34:28 +08:00
|
|
|
public override shouldComponentUpdate(nextProperties: Readonly<List>): boolean {
|
|
|
|
const properties = this.props;
|
2024-07-10 16:17:23 +08:00
|
|
|
return (
|
2024-07-10 16:34:28 +08:00
|
|
|
properties.ordered !== nextProperties.ordered ||
|
|
|
|
properties.orderType !== nextProperties.orderType ||
|
|
|
|
properties.start !== nextProperties.start ||
|
|
|
|
properties.children !== nextProperties.children
|
2024-07-10 16:17:23 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override render(): React.ReactElement {
|
|
|
|
const { ordered, orderType, start, children } = this.props;
|
|
|
|
|
|
|
|
if (ordered) {
|
|
|
|
return (
|
|
|
|
<ol className={cls} type={orderType} start={start}>
|
|
|
|
<NodesRenderer nodes={children} />
|
|
|
|
</ol>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ul className={cls}>
|
|
|
|
<NodesRenderer nodes={children} />
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const cls = cx(
|
|
|
|
astClasses.list,
|
|
|
|
css({
|
|
|
|
padding: "0px",
|
|
|
|
margin: "0 0 1em 2em",
|
|
|
|
lineHeight: "2",
|
|
|
|
"> :last-child": {
|
|
|
|
marginBottom: "0px",
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|