File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
packages/dataviews/src/components/dataform/stories Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -391,6 +391,7 @@ const ValidationComponent = ( {
391391 email : string ;
392392 telephone : string ;
393393 url : string ;
394+ color : string ;
394395 integer : number ;
395396 boolean : boolean ;
396397 customEdit : string ;
@@ -401,6 +402,7 @@ const ValidationComponent = ( {
401402 email : 'hi@example.com' ,
402403 telephone : '+306978241796' ,
403404 url : 'https://example.com' ,
405+ color : '#ff6600' ,
404406 integer : 2 ,
405407 boolean : true ,
406408 customEdit : 'custom control' ,
@@ -434,6 +436,13 @@ const ValidationComponent = ( {
434436
435437 return null ;
436438 } ;
439+ const customColorRule = ( value : ValidatedItem ) => {
440+ if ( ! / ^ # [ 0 - 9 A - F a - f ] { 6 } $ / . test ( value . color ) ) {
441+ return 'Color must be a valid hex format (e.g., #ff6600).' ;
442+ }
443+
444+ return null ;
445+ } ;
437446 const customIntegerRule = ( value : ValidatedItem ) => {
438447 if ( value . integer % 2 !== 0 ) {
439448 return 'Integer must be an even number.' ;
@@ -485,6 +494,15 @@ const ValidationComponent = ( {
485494 custom : maybeCustomRule ( customUrlRule ) ,
486495 } ,
487496 } ,
497+ {
498+ id : 'color' ,
499+ type : 'color' ,
500+ label : 'Color' ,
501+ isValid : {
502+ required,
503+ custom : maybeCustomRule ( customColorRule ) ,
504+ } ,
505+ } ,
488506 {
489507 id : 'integer' ,
490508 type : 'integer' ,
@@ -519,6 +537,7 @@ const ValidationComponent = ( {
519537 'email' ,
520538 'telephone' ,
521539 'url' ,
540+ 'color' ,
522541 'integer' ,
523542 'boolean' ,
524543 'customEdit' ,
You can’t perform that action at this time.
0 commit comments