add action row component
This commit is contained in:
26
library/core/components/action-row.tsx
Normal file
26
library/core/components/action-row.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { ReactNode } from "react"
|
||||
import React from "react"
|
||||
import { ReacordElement } from "../../internal/element.js"
|
||||
import type { MessageOptions } from "../../internal/message"
|
||||
import { Node } from "../../internal/node.js"
|
||||
|
||||
export type ActionRowProps = {
|
||||
children?: ReactNode
|
||||
}
|
||||
|
||||
export function ActionRow(props: ActionRowProps) {
|
||||
return (
|
||||
<ReacordElement props={props} createNode={() => new ActionRowNode(props)}>
|
||||
{props.children}
|
||||
</ReacordElement>
|
||||
)
|
||||
}
|
||||
|
||||
class ActionRowNode extends Node<{}> {
|
||||
override modifyMessageOptions(options: MessageOptions): void {
|
||||
options.actionRows.push([])
|
||||
for (const child of this.children) {
|
||||
child.modifyMessageOptions(options)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ export type MessageOptions = {
|
||||
actionRows: ActionRow[]
|
||||
}
|
||||
|
||||
type ActionRow = Array<
|
||||
export type ActionRow = Array<
|
||||
MessageButtonOptions | MessageLinkOptions | MessageSelectOptions
|
||||
>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from "./core/adapters/adapter"
|
||||
export * from "./core/adapters/discord-js-adapter"
|
||||
export * from "./core/components/action-row"
|
||||
export * from "./core/components/button"
|
||||
export * from "./core/components/embed"
|
||||
export * from "./core/components/embed-author"
|
||||
|
||||
40
test/action-row.test.tsx
Normal file
40
test/action-row.test.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import React from "react"
|
||||
import { ActionRow, Button, Select } from "../library/main"
|
||||
import { setupReacordTesting } from "./setup-testing"
|
||||
|
||||
const { assertRender } = setupReacordTesting()
|
||||
|
||||
test("action row", async () => {
|
||||
await assertRender(
|
||||
<>
|
||||
<Button label="outside button" onClick={() => {}} />
|
||||
<ActionRow>
|
||||
<Button label="button inside action row" onClick={() => {}} />
|
||||
</ActionRow>
|
||||
<Select />
|
||||
<Button label="last row 1" onClick={() => {}} />
|
||||
<Button label="last row 2" onClick={() => {}} />
|
||||
</>,
|
||||
[
|
||||
{
|
||||
content: "",
|
||||
embeds: [],
|
||||
actionRows: [
|
||||
[{ type: "button", style: "secondary", label: "outside button" }],
|
||||
[
|
||||
{
|
||||
type: "button",
|
||||
style: "secondary",
|
||||
label: "button inside action row",
|
||||
},
|
||||
],
|
||||
[{ type: "select", options: [], values: [] }],
|
||||
[
|
||||
{ type: "button", style: "secondary", label: "last row 1" },
|
||||
{ type: "button", style: "secondary", label: "last row 2" },
|
||||
],
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user