44 * you may not use this file except in compliance with the Elastic License.
55 */
66
7- import React , { FC , useState , useEffect } from 'react' ;
7+ import React , { FC , useState } from 'react' ;
88import PropTypes from 'prop-types' ;
99import { EuiFlexGroup , EuiFlexItem , EuiSelect , EuiSpacer , EuiButtonGroup } from '@elastic/eui' ;
1010import { FontValue } from 'src/plugins/expressions' ;
@@ -15,7 +15,7 @@ import { fontSizes } from './font_sizes';
1515
1616const { TextStylePicker : strings } = ComponentStrings ;
1717
18- interface BaseProps {
18+ export interface StyleProps {
1919 family ?: FontValue ;
2020 size ?: number ;
2121 align ?: 'left' | 'center' | 'right' ;
@@ -25,9 +25,9 @@ interface BaseProps {
2525 italic ?: boolean ;
2626}
2727
28- interface Props extends BaseProps {
28+ export interface Props extends StyleProps {
2929 colors ?: string [ ] ;
30- onChange : ( props : BaseProps ) => void ;
30+ onChange : ( style : StyleProps ) => void ;
3131}
3232
3333type StyleType = 'bold' | 'italic' | 'underline' ;
@@ -68,20 +68,26 @@ const styleButtons = [
6868 } ,
6969] ;
7070
71- export const TextStylePicker : FC < Props > = ( props ) => {
72- const [ style , setStyle ] = useState < Props > ( props ) ;
73-
74- const {
75- align = 'left' ,
71+ export const TextStylePicker : FC < Props > = ( {
72+ align = 'left' ,
73+ color,
74+ colors,
75+ family,
76+ italic = false ,
77+ onChange,
78+ size = 14 ,
79+ underline = false ,
80+ weight = 'normal' ,
81+ } ) => {
82+ const [ style , setStyle ] = useState < StyleProps > ( {
83+ align,
7684 color,
77- colors,
7885 family,
79- italic = false ,
80- onChange,
81- size = 14 ,
82- underline = false ,
83- weight = 'normal' ,
84- } = style ;
86+ italic,
87+ size,
88+ underline,
89+ weight,
90+ } ) ;
8591
8692 const stylesSelectedMap : Record < StyleType , boolean > = {
8793 [ 'bold' ] : weight === 'bold' ,
@@ -94,10 +100,10 @@ export const TextStylePicker: FC<Props> = (props) => {
94100 fontSizes . sort ( ( a , b ) => a - b ) ;
95101 }
96102
97- useEffect ( ( ) => onChange ( style ) , [ onChange , style ] ) ;
98-
99- const doChange = ( propName : keyof Props , value : string | boolean | number ) => {
100- setStyle ( { ... style , [ propName ] : value } ) ;
103+ const doChange = ( propName : keyof StyleProps , value : string | boolean | number ) => {
104+ const newStyle = { ... style , [ propName ] : value } ;
105+ setStyle ( newStyle ) ;
106+ onChange ( newStyle ) ;
101107 } ;
102108
103109 const onStyleChange = ( optionId : string ) => {
0 commit comments