accept children for button label
This commit is contained in:
@@ -8,6 +8,11 @@ export type ButtonSharedProps = {
|
|||||||
/** The text on the button. Rich formatting (markdown) is not supported here. */
|
/** The text on the button. Rich formatting (markdown) is not supported here. */
|
||||||
label?: ReactNode
|
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. */
|
/** When true, the button will be slightly faded, and cannot be clicked. */
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { randomUUID } from "node:crypto"
|
import { randomUUID } from "node:crypto"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import type { Except } from "type-fest"
|
|
||||||
import type { ButtonSharedProps } from "./button-shared-props"
|
import type { ButtonSharedProps } from "./button-shared-props"
|
||||||
import type { ComponentEvent } from "./component-event"
|
import type { ComponentEvent } from "./component-event"
|
||||||
import { Node } from "./node"
|
import { Node } from "./node"
|
||||||
@@ -27,18 +26,18 @@ export type ButtonProps = ButtonSharedProps & {
|
|||||||
*/
|
*/
|
||||||
export type ButtonClickEvent = ComponentEvent
|
export type ButtonClickEvent = ComponentEvent
|
||||||
|
|
||||||
export function Button({ label, ...props }: ButtonProps) {
|
export function Button({ label, children, ...props }: ButtonProps) {
|
||||||
return (
|
return (
|
||||||
<ReacordElement
|
<ReacordElement
|
||||||
name="button"
|
name="button"
|
||||||
createNode={() => new ButtonNode(props)}
|
createNode={() => new ButtonNode(props)}
|
||||||
nodeProps={props}
|
nodeProps={props}
|
||||||
>
|
>
|
||||||
{label}
|
{label ?? children}
|
||||||
</ReacordElement>
|
</ReacordElement>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ButtonNode extends Node<Except<ButtonProps, "label">> {
|
export class ButtonNode extends Node<ButtonProps> {
|
||||||
readonly customId = randomUUID()
|
readonly customId = randomUUID()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user