-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StoryBook: Add story for colors-gradient
- Loading branch information
1 parent
041ca27
commit 7603a17
Showing
1 changed file
with
148 additions
and
0 deletions.
There are no files selected for viewing
148 changes: 148 additions & 0 deletions
148
packages/block-editor/src/components/colors-gradients/stories/index.story.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ColorGradientControl from '../control.js'; | ||
|
||
const meta = { | ||
title: 'BlockEditor/ColorGradientControl', | ||
component: ColorGradientControl, | ||
parameters: { | ||
docs: { | ||
canvas: { sourceState: 'shown' }, | ||
description: { | ||
component: | ||
'A control to select and customize colors or gradients.', | ||
}, | ||
}, | ||
}, | ||
argTypes: { | ||
colors: { | ||
control: 'object', | ||
description: 'Array of available colors.', | ||
table: { | ||
type: { summary: 'object[]' }, | ||
}, | ||
}, | ||
gradients: { | ||
control: 'object', | ||
description: 'Array of available gradients.', | ||
table: { | ||
type: { summary: 'object[]' }, | ||
}, | ||
}, | ||
disableCustomColors: { | ||
control: 'boolean', | ||
description: 'Disable custom color selection.', | ||
table: { | ||
type: { summary: 'boolean' }, | ||
}, | ||
}, | ||
disableCustomGradients: { | ||
control: 'boolean', | ||
description: 'Disable custom gradient selection.', | ||
table: { | ||
type: { summary: 'boolean' }, | ||
}, | ||
}, | ||
colorValue: { | ||
control: 'text', | ||
description: 'Current selected color value.', | ||
table: { | ||
type: { summary: 'string' }, | ||
}, | ||
}, | ||
gradientValue: { | ||
control: 'text', | ||
description: 'Current selected gradient value.', | ||
table: { | ||
type: { summary: 'string' }, | ||
}, | ||
}, | ||
onColorChange: { | ||
action: 'onColorChange', | ||
control: { type: null }, | ||
description: 'Callback to handle color change.', | ||
table: { | ||
type: { summary: 'function' }, | ||
}, | ||
}, | ||
onGradientChange: { | ||
action: 'onGradientChange', | ||
control: { type: null }, | ||
description: 'Callback to handle gradient change.', | ||
table: { | ||
type: { summary: 'function' }, | ||
}, | ||
}, | ||
enableAlpha: { | ||
control: 'boolean', | ||
description: 'Enable alpha transparency.', | ||
table: { | ||
type: { summary: 'boolean' }, | ||
}, | ||
}, | ||
clearable: { | ||
control: 'boolean', | ||
description: 'Allow clearing the selected color or gradient.', | ||
table: { | ||
type: { summary: 'boolean' }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default = { | ||
render: function Template( { onColorChange, onGradientChange, ...args } ) { | ||
const [ colorValue, setColorValue ] = useState( args.colorValue ); | ||
const [ gradientValue, setGradientValue ] = useState( | ||
args.gradientValue | ||
); | ||
|
||
return ( | ||
<ColorGradientControl | ||
{ ...args } | ||
colorValue={ colorValue } | ||
gradientValue={ gradientValue } | ||
onColorChange={ ( newColor ) => { | ||
setColorValue( newColor ); | ||
onColorChange( newColor ); | ||
} } | ||
onGradientChange={ ( newGradient ) => { | ||
setGradientValue( newGradient ); | ||
onGradientChange( newGradient ); | ||
} } | ||
/> | ||
); | ||
}, | ||
args: { | ||
colors: [ | ||
{ name: 'Red', color: '#ff0000' }, | ||
{ name: 'Green', color: '#00ff00' }, | ||
{ name: 'Blue', color: '#0000ff' }, | ||
], | ||
gradients: [ | ||
{ | ||
name: 'Sunset', | ||
gradient: 'linear-gradient(to right, #ff7e5f, #feb47b)', | ||
}, | ||
{ | ||
name: 'Ocean', | ||
gradient: 'linear-gradient(to right, #00c6ff, #0072ff)', | ||
}, | ||
], | ||
colorValue: '#00ff00', | ||
gradientValue: 'linear-gradient(to right, #ff7e5f, #feb47b)', | ||
disableCustomColors: false, | ||
disableCustomGradients: false, | ||
enableAlpha: true, | ||
clearable: true, | ||
label: 'Select Color or Gradient', | ||
}, | ||
}; |