@@ -23,16 +23,30 @@ const defaultAngle: UnitValue = {
23
23
export const GradientControl = ( props : GradientControlProps ) => {
24
24
const [ stops , setStops ] = useState < Array < GradientStop > > ( props . gradient . stops ) ;
25
25
const [ selectedStop , setSelectedStop ] = useState < number | undefined > ( ) ;
26
- const positions = stops . map ( ( stop ) => stop . position ?. value ) ;
26
+ const positions = stops
27
+ . map ( ( stop ) => stop . position ?. value )
28
+ . filter ( ( item ) => item !== undefined ) ;
27
29
const hints = props . gradient . stops
28
30
. map ( ( stop ) => stop . hint ?. value )
29
- . filter ( Boolean ) ;
31
+ . filter ( ( item ) => item !== undefined ) ;
30
32
const background = reconstructLinearGradient ( {
31
33
stops,
32
34
sideOrCorner : props . gradient . sideOrCorner ,
33
35
angle : defaultAngle ,
34
36
} ) ;
35
37
38
+ // Every color stop should have a asociated position for us in-order to display the slider thumb.
39
+ // But when users manually enter linear-gradient from the advanced-panle. They might add something like this
40
+ // linear-gradient(to right, red, blue), or linear-gradient(150deg, red, blue 50%, yellow 50px)
41
+ // Browsers handles all these cases by following the rules of the css spec.
42
+ // https://www.w3.org/TR/css-images-4/#color-stop-fixup
43
+ // In order to handle such examples from the advanced tab too. We need to implement the color-stop-fix-up spec during parsing.
44
+ // But for now, we are just checking if every stop has a position or not. Since the main use-case if to add gradients from ui.
45
+ // We will never run into this case of a color-stop missing a position associated with it.
46
+ const isEveryStopHasAPosition = stops . every (
47
+ ( stop ) => stop . position !== undefined && stop . color !== undefined
48
+ ) ;
49
+
36
50
const handleValueChange = useCallback (
37
51
( newPositions : number [ ] ) => {
38
52
const newStops : GradientStop [ ] = stops . map ( ( stop , index ) => ( {
@@ -62,6 +76,10 @@ export const GradientControl = (props: GradientControlProps) => {
62
76
[ stops , selectedStop ]
63
77
) ;
64
78
79
+ if ( isEveryStopHasAPosition === false ) {
80
+ return ;
81
+ }
82
+
65
83
return (
66
84
< Flex
67
85
align = "end"
@@ -93,6 +111,16 @@ export const GradientControl = (props: GradientControlProps) => {
93
111
/>
94
112
) ) }
95
113
114
+ { /*
115
+ Hints are displayed as a chevron icon below the slider thumb.
116
+ Usually hints are used to display the behaviour of the color-stop that is preciding.
117
+ But, if we just move them along the UI. We will be basically altering the gradient itself.
118
+ Because the position of the hint is the position of the color-stop. And moving it along, might associate the hint
119
+ with a different color-stop. So, we are not allowing the user to move the hint along the slider.
120
+
121
+ None of the tools are even displaying the hints at the moment. We are just displaying them so users can know
122
+ they are hints associated too.
123
+ */ }
96
124
{ hints . map ( ( hint ) => {
97
125
return (
98
126
< Flex
0 commit comments