Skip to content

Commit

Permalink
add BlockAIControl story
Browse files Browse the repository at this point in the history
  • Loading branch information
dhasilva committed Apr 18, 2024
1 parent 8dc1b40 commit 299946d
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/**
* External dependencies
*/
import { action } from '@storybook/addon-actions';
import { Notice } from '@wordpress/components';
import { useState } from '@wordpress/element';
import React from 'react';
/**
* Internal dependencies
*/
import { GuidelineMessage, ErrorMessage, UpgradeMessage } from '../../message/index.js';
import { BlockAIControl } from '../index.js';

export default {
title: 'JS Packages/AI Client/AI Control/Block AI Control',
component: BlockAIControl,
decorators: [
Story => (
<div style={ { backgroundColor: 'white' } }>
<Story />
</div>
),
],
argTypes: {
state: {
control: {
type: 'select',
},
options: [ 'init', 'requesting', 'suggesting', 'done', 'error' ],
},
errorComponent: {
control: {
type: 'select',
},
options: [ 'None', 'Error notice' ],
mapping: {
None: null,
'Error notice': (
<Notice status="error" isDismissible={ true }>
Error message
</Notice>
),
},
},
customFooter: {
control: {
type: 'select',
},
options: [ 'None', 'Guideline message', 'Error message', 'Upgrade message' ],
mapping: {
None: null,
'Guideline message': <GuidelineMessage />,
'Error message': <ErrorMessage onTryAgainClick={ action( 'onTryAgainClick' ) } />,
'Upgrade message': (
<UpgradeMessage requestsRemaining={ 10 } onUpgradeClick={ action( 'onUpgradeClick' ) } />
),
},
},
},
parameters: {
controls: {
exclude: /on[A-Z].*/,
},
},
};

const DefaultTemplate = args => {
const [ value, setValue ] = useState( '' );

const handleChange = ( newValue: string ) => {
setValue( newValue );
args?.onChange?.( newValue );
};

const handleSend = () => {
args?.onSend?.( value );
};

const handleStop = () => {
args?.onStop?.();
};

const handleAccept = () => {
args?.onAccept?.();
};

const handleDiscard = () => {
args?.onDiscard?.();
};

return (
<BlockAIControl
{ ...args }
onChange={ handleChange }
onSend={ handleSend }
onStop={ handleStop }
onAccept={ handleAccept }
onDiscard={ handleDiscard }
value={ args?.value ?? value }
/>
);
};

const DefaultArgs = {
placeholder: 'Placeholder',
acceptLabel: 'Accept',
showButtonLabels: true,
disabled: false,
isTransparent: false,
state: 'init',
showAccept: true,
showGuideLine: true,
customFooter: null,
onChange: action( 'onChange' ),
onSend: action( 'onSend' ),
onStop: action( 'onStop' ),
onAccept: action( 'onAccept' ),
onDiscard: action( 'onDiscard' ),
showRemove: false,
bannerComponent: null,
errorComponent: null,
};

export const Default = DefaultTemplate.bind( {} );
Default.args = DefaultArgs;

0 comments on commit 299946d

Please sign in to comment.