1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-03 02:45:21 +03:00

feat: nested widget components rendering PoC

This commit is contained in:
louistiti 2024-08-06 08:25:45 +08:00
parent 29f44f3aed
commit 7a69714efb
2 changed files with 88 additions and 8 deletions

View File

@ -133,6 +133,12 @@ export default class Chatbot {
}
}
// When children is a component, then wrap it in an array to render properly
const isComponent = !!component.props?.children?.component
if (isComponent) {
component.props.children = [component.props.children]
}
if (
component.props?.children &&
Array.isArray(component.props.children)

View File

@ -1,6 +1,14 @@
import { Widget, type WidgetOptions } from '@sdk/widget'
import { type WidgetComponent } from '@sdk/widget-component'
import { Button } from '@sdk/aurora'
import {
Button,
Flexbox,
List,
ListHeader,
ListItem,
Checkbox,
Link
} from '@sdk/aurora'
interface Params {
value1: string
@ -34,13 +42,79 @@ export class PlaygroundTestWidget extends Widget<Params> {
public render(): WidgetComponent {
const children = this.params.value1 + ' ' + this.params.value2
return new Button({
children,
secondary: true,
// TODO
onClick: () => {
return runSkillAction('test', 'param1')
}
// TODO: timer
// TODO
return new Flexbox({
gap: 'md',
flexDirection: 'column',
children: [
new Link({
href: 'https://getleon.ai',
children: 'Test link'
}),
new List({
children: [
new ListHeader({
children: 'Shopping List'
}),
new ListItem({
children: new Checkbox({
value: 'Milk',
label: 'Milk',
checked: true
})
}),
new ListItem({
children: new Checkbox({
value: 'Eggs',
label: 'Eggs',
checked: false
})
}),
new ListItem({
children: new Checkbox({
value: 'Bread',
label: 'Bread',
checked: true
})
})
]
}),
new List({
children: [
new ListHeader({
children: 'Select your music provider'
}),
new ListItem({
children: new Button({
children: 'Spotify',
onClick: () => {
return runSkillAction('play_music', 'spotify')
}
})
}),
new ListItem({
children: new Button({
children: 'Apple Music',
onClick: () => {
return runSkillAction('play_music', 'apple_music')
}
})
}),
new ListItem({
children: new Button({
children: 'YouTube Music',
onClick: () => {
return runSkillAction('play_music', 'youtube_music')
}
})
})
]
})
// TODO: form input
]
})
}
}