// url=?node-id=18787-39352 // source=./index.tsx // component=ComboboxTree import figma from 'figma' const instance = figma.selectedInstance const state = instance.getEnum('State', { Normal: undefined, Error: 'error', Warning: 'warning', }) const variant = instance.getEnum('Variant', { 'Single select': 'single', 'Multi select': 'multi', }) ?? 'single' const withLabel = instance.getBoolean('Label', { true: 'With label', false: undefined, }) const defaultOpen = instance.getEnum('List', { On: 'defaultOpen', Off: undefined, }) const options = [ { label: 'Parent 1', value: 'parent1', children: [ { label: 'Child 1', value: 'child1' }, { label: 'Child 2', value: 'child2' }, ], }, { label: 'Parent 2', value: 'parent2' }, ] let label let message if (withLabel) { const labelInstance = instance.findInstance('Form label') if (labelInstance.type !== 'ERROR') { const labelText = labelInstance.findText('Label') if (labelText.type === 'TEXT') { label = labelText.textContent } } label ??= 'Label' } if (state === 'error' || state === 'warning') { const messageInstance = instance.findInstance('Form inline message') if (messageInstance.type !== 'ERROR') { const messageText = messageInstance.findText('Label') if (messageText.type === 'TEXT') { message = messageText.textContent } } message ??= 'Message' } const propLines = [ label ? `label=${JSON.stringify(label)}` : undefined, `options={${figma.helpers.react.stringifyObject(options)}}`, variant === 'multi' ? 'multiSelectable' : undefined, variant === 'multi' ? 'defaultValue={[]}' : 'defaultValue={null}', defaultOpen, state === 'error' && message ? `error=${JSON.stringify(message)}` : undefined, state === 'warning' && message ? `warning=${JSON.stringify(message)}` : undefined, ].filter((line): line is string => Boolean(line)) const propsBlock = `\n ${propLines.join('\n ')}\n` export default { id: 'FormComboboxTree', imports: ['import { ComboboxTree } from "@planview/pv-form"'], example: figma.tsx``, metadata: { nestable: true, }, }