| 1 | import { type TDateElement } from "platejs"; |
| 2 | import { SlateElement, type SlateElementProps } from "platejs/static"; |
| 3 | |
| 4 | function formatDateElementLabel(date: string) { |
| 5 | return new Date(date).toLocaleDateString(undefined, { |
| 6 | day: "numeric", |
| 7 | month: "long", |
| 8 | year: "numeric", |
| 9 | }); |
| 10 | } |
| 11 | |
| 12 | export function DateElementStatic(props: SlateElementProps<TDateElement>) { |
| 13 | const { element } = props; |
| 14 | |
| 15 | return ( |
| 16 | <SlateElement className="inline-block" {...props}> |
| 17 | <span className="w-fit rounded-sm bg-muted px-1 text-muted-foreground"> |
| 18 | {element.date ? ( |
| 19 | formatDateElementLabel(element.date) |
| 20 | ) : ( |
| 21 | <span>Pick a date</span> |
| 22 | )} |
| 23 | </span> |
| 24 | {props.children} |
| 25 | </SlateElement> |
| 26 | ); |
| 27 | } |
| 28 |