accept children for button label

This commit is contained in:
itsMapleLeaf
2022-07-26 12:15:48 -05:00
parent 4e3f1cc7cb
commit 91c250f63f
2 changed files with 8 additions and 4 deletions

View File

@@ -8,6 +8,11 @@ export type ButtonSharedProps = {
/** The text on the button. Rich formatting (markdown) is not supported here. */
label?: ReactNode
/** The text on the button. Rich formatting (markdown) is not supported here.
* If both `label` and `children` are passed, `children` will be ignored.
*/
children?: ReactNode
/** When true, the button will be slightly faded, and cannot be clicked. */
disabled?: boolean

View File

@@ -1,6 +1,5 @@
import { randomUUID } from "node:crypto"
import React from "react"
import type { Except } from "type-fest"
import type { ButtonSharedProps } from "./button-shared-props"
import type { ComponentEvent } from "./component-event"
import { Node } from "./node"
@@ -27,18 +26,18 @@ export type ButtonProps = ButtonSharedProps & {
*/
export type ButtonClickEvent = ComponentEvent
export function Button({ label, ...props }: ButtonProps) {
export function Button({ label, children, ...props }: ButtonProps) {
return (
<ReacordElement
name="button"
createNode={() => new ButtonNode(props)}
nodeProps={props}
>
{label}
{label ?? children}
</ReacordElement>
)
}
export class ButtonNode extends Node<Except<ButtonProps, "label">> {
export class ButtonNode extends Node<ButtonProps> {
readonly customId = randomUUID()
}