Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { observer } from 'mobx-react-lite';

import { useBlock } from '@/hooks';
import { BlockDef, BlockComponent } from '@/stores';

import { styled } from '@mui/material';

const StyledLabel = styled('span')(({ theme }) => ({
marginBottom: '4px',
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-start',
justifyContent: 'center',
gap: '4px',
}));

export interface AudioBlockDef extends BlockDef<'audio-player'> {
widget: 'audio-player';
data: {
label: string;
autoplay: boolean;
controls: boolean;
loop: boolean;
source: string;
};
listeners: {
onClick: true;
};
}

const StyledContainer = styled('div')(({ theme }) => ({
padding: '4px',
}));

export const AudioBlock: BlockComponent = observer(({ id }) => {
const { attrs, data } = useBlock<AudioBlockDef>(id);

return (
<StyledContainer {...attrs}>
<StyledLabel>{data.label}</StyledLabel>
<audio
controls={data.controls}
autoPlay={data.autoplay}
loop={data.loop}
src={data.source}
></audio>
</StyledContainer>
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { CSSProperties } from 'react';
import { BlockConfig } from '@/stores';
import { InputSettings, QueryInputSettings } from '@/components/block-settings';

import { AudioBlockDef, AudioBlock } from './AudioBlock';
import HeadsetIcon from '@mui/icons-material/Headset';
import { BLOCK_TYPE_ACTION } from '../block-defaults.constants';
import { SwitchSettings } from '@/components/block-settings/shared/SwitchSettings';

export const DefaultStyles: CSSProperties = {};

// export the config for the block
export const config: BlockConfig<AudioBlockDef> = {
widget: 'audio-player',
type: BLOCK_TYPE_ACTION,
data: {
label: 'Audio Player',
autoplay: false,
controls: true,
loop: false,
source: '',
},
listeners: {
onClick: [],
},
slots: {},
render: AudioBlock,
icon: HeadsetIcon,
contentMenu: [
{
name: 'General',
children: [
{
description: 'Label',
render: ({ id }) => (
<InputSettings id={id} label="Label" path="label" />
),
},
{
description: 'Audio URL',
render: ({ id }) => (
<QueryInputSettings
id={id}
label="Audio URL"
path="source"
/>
),
},
{
description: 'Autoplay',
render: ({ id }) => (
<SwitchSettings
id={id}
label="Enable Autoplay"
path="autoplay"
description="This setting will enable autoplay of the audio"
/>
),
},
{
description: 'Controls',
render: ({ id }) => (
<SwitchSettings
id={id}
label="Enable controls"
path="controls"
description="This setting will enable controls like pause, play, volume-control on the audio player"
/>
),
},
{
description: 'Loop',
render: ({ id }) => (
<SwitchSettings
id={id}
label="Enable loop"
path="loop"
description="This setting will play the audio in a loop"
/>
),
},
],
},
],
styleMenu: [],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './config';
export * from './AudioBlock';
4 changes: 4 additions & 0 deletions packages/client/src/components/block-defaults/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Registry } from '@/stores';
import { config as AudioBlockConfig, AudioBlockDef } from './audio-block';
import { config as BodyBlockConfig, BodyBlockDef } from './body-block';
import { config as ButtonBlockConfig, ButtonBlockDef } from './button-block';
import { config as QueryBlockConfig, QueryBlockDef } from './query-block';
Expand Down Expand Up @@ -51,6 +52,7 @@ import { config as ModalBlockConfig, ModalBlockDef } from './modal-block';
import { config as StepperBlockConfig, StepperBlockDef } from './stepper-block';

export type DefaultBlockDefinitions =
| AudioBlockDef
| BodyBlockDef
| ButtonBlockDef
| CheckboxBlockDef
Expand Down Expand Up @@ -82,6 +84,7 @@ export type DefaultBlockDefinitions =
| ModalBlockDef;

export const DefaultBlocks: Registry<DefaultBlockDefinitions> = {
[AudioBlockConfig.widget]: AudioBlockConfig,
[ButtonBlockConfig.widget]: ButtonBlockConfig,
[CheckboxBlockConfig.widget]: CheckboxBlockConfig,
[CompareLLMBlockConfig.widget]: CompareLLMBlockConfig,
Expand Down Expand Up @@ -115,6 +118,7 @@ export function getTypeForBlock(widget: string) {
}

export {
AudioBlockConfig,
ButtonBlockConfig,
ContainerBlockConfig,
CheckboxBlockConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const StyledCard = styled(Card)(({ theme }) => ({
border: `1px solid rgba(0, 0, 0, 0.23)`,
//TODO: styled needs to be updated to match the theme
borderRadius: '12px', // theme.shape.borderRadiusLg
justifyContent: 'center',
}));

export interface AddBlocksMenuItemProps {
Expand Down
18 changes: 18 additions & 0 deletions packages/client/src/components/designer/designer.constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BlockJSON } from '@/stores';

import BLOCK_AUDIO_PLAYER from '@/assets/img/BLOCK_AUDIO_PLAYER.png';
import BLOCK_BUTTON from '@/assets/img/BLOCK_BUTTON.png';
import BLOCK_CHECKBOX from '@/assets/img/BLOCK_CHECKBOX.png';
import BLOCK_CONTAINER from '@/assets/img/BLOCK_CONTAINER.png';
Expand Down Expand Up @@ -116,6 +117,23 @@ export interface AddBlocksMenuItem {
* Show the default blocks menu
*/
export const DEFAULT_MENU: AddBlocksMenuItem[] = [
{
section: SECTION_INPUT,
image: BLOCK_AUDIO_PLAYER,
name: 'Audio Player',
json: {
widget: 'audio-player',
data: {
label: 'Audio Player',
autoplay: false,
controls: true,
loop: false,
source: '',
},
listeners: {},
slots: {} as BlockJSON['slots'],
},
},
{
section: SECTION_INPUT,
image: BLOCK_BUTTON,
Expand Down