clearer select option resolution

This commit is contained in:
MapleLeaf
2022-01-10 22:15:53 -06:00
parent 4803cb8478
commit 1a04e6093d
2 changed files with 26 additions and 13 deletions

View File

@@ -4,7 +4,11 @@ import React from "react"
import { isInstanceOf } from "../../../helpers/is-instance-of" import { isInstanceOf } from "../../../helpers/is-instance-of"
import { ReacordElement } from "../../internal/element.js" import { ReacordElement } from "../../internal/element.js"
import type { ComponentInteraction } from "../../internal/interaction" import type { ComponentInteraction } from "../../internal/interaction"
import type { ActionRow, MessageOptions } from "../../internal/message" import type {
ActionRow,
ActionRowItem,
MessageOptions,
} from "../../internal/message"
import { Node } from "../../internal/node.js" import { Node } from "../../internal/node.js"
import type { ComponentEvent } from "../component-event" import type { ComponentEvent } from "../component-event"
import { OptionNode } from "./option-node" import { OptionNode } from "./option-node"
@@ -108,19 +112,25 @@ class SelectNode extends Node<SelectProps> {
...props ...props
} = this.props } = this.props
actionRow.push({ const item: ActionRowItem = {
...props, ...props,
type: "select", type: "select",
customId: this.customId, customId: this.customId,
options, options,
// I'm not counting on people using value and values at the same time, values: [],
// but maybe we should resolve this differently anyhow? e.g. one should override the other }
// or just warn if there are both
// or... try some other alternative design entirely if (multiple) {
values: [...(values || []), ...(value ? [value] : [])], item.minValues = minValues
minValues: multiple ? minValues : undefined, item.maxValues = maxValues
maxValues: multiple ? Math.max(minValues, maxValues) : undefined, if (values) item.values = values
}) }
if (!multiple && value != undefined) {
item.values = [value]
}
actionRow.push(item)
} }
override handleComponentInteraction( override handleComponentInteraction(

View File

@@ -9,9 +9,12 @@ export type MessageOptions = {
actionRows: ActionRow[] actionRows: ActionRow[]
} }
export type ActionRow = Array< export type ActionRow = ActionRowItem[]
MessageButtonOptions | MessageLinkOptions | MessageSelectOptions
> export type ActionRowItem =
| MessageButtonOptions
| MessageLinkOptions
| MessageSelectOptions
export type MessageButtonOptions = { export type MessageButtonOptions = {
type: "button" type: "button"