@@ -3,7 +3,7 @@ import { Meta, StoryFn } from "@storybook/react";
33
44import textFieldTest from "../TextField/stories/TextField.stories" ;
55
6- import { ColorField } from "./ColorField" ;
6+ import { ColorField , ColorFieldProps } from "./ColorField" ;
77
88export default {
99 title : "Forms/ColorField" ,
@@ -24,10 +24,46 @@ Default.args = {
2424
2525export const NoPalettePresets = Template . bind ( { } ) ;
2626NoPalettePresets . args = {
27+ ...Default . args ,
2728 colorWeightFilter : [ ] ,
2829 paletteGroupFilter : [ ] ,
2930 allowCustomColor : true ,
30- onChange : ( e ) => {
31- alert ( e . target . value ) ;
32- } ,
31+ } ;
32+
33+ interface TemplateColorHashProps
34+ extends Pick < ColorFieldProps , "onChange" | "allowCustomColor" | "colorWeightFilter" | "paletteGroupFilter" > {
35+ stringForColorHashValue : string ;
36+ }
37+
38+ const TemplateColorHash : StoryFn < TemplateColorHashProps > = ( args : TemplateColorHashProps ) => (
39+ < ColorField
40+ allowCustomColor = { args . allowCustomColor }
41+ colorWeightFilter = { args . colorWeightFilter }
42+ paletteGroupFilter = { args . paletteGroupFilter }
43+ value = { ColorField . calculateColorHashValue ( args . stringForColorHashValue , {
44+ allowCustomColor : args . allowCustomColor ,
45+ colorWeightFilter : args . colorWeightFilter ,
46+ paletteGroupFilter : args . paletteGroupFilter ,
47+ } ) }
48+ />
49+ ) ;
50+
51+ /**
52+ * Component provides a helper function to calculate a color hash from a text,
53+ * that can be used as `value` or `defaultValue`.
54+ *
55+ * ```
56+ * <ColorField value={ColorField.calculateColorHashValue("MyText")} />
57+ * ```
58+ *
59+ * You can add `options` to set the config for the color palette filters.
60+ * The same default values like on `ColorField` are used for them.
61+ */
62+ export const ColorHashValue = TemplateColorHash . bind ( { } ) ;
63+ ColorHashValue . args = {
64+ ...Default . args ,
65+ allowCustomColor : true ,
66+ colorWeightFilter : [ 300 , 500 , 700 ] ,
67+ paletteGroupFilter : [ "layout" , "extra" ] ,
68+ stringForColorHashValue : "My text that will used to create a color hash as initial value." ,
3369} ;
0 commit comments