Skip to content

Commit

Permalink
fix(ui-color-picker): add a padding to colorpicker button
Browse files Browse the repository at this point in the history
Closes: INSTUI-3867

Adding a padding to color picker button calculated by
the text input children element's label height and margin.

This should be replaced in INSTUI v9 with a better solution.
  • Loading branch information
joyenjoyer committed Sep 29, 2023
1 parent 2c61afa commit de420dd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
26 changes: 24 additions & 2 deletions packages/ui-color-picker/src/ColorPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class ColorPicker extends Component<ColorPickerProps, ColorPickerState> {
hexCode: '',
showHelperErrorMessages: false,
openColorPicker: false,
mixedColor: ''
mixedColor: '',
labelHeight: 0
}
}

Expand All @@ -132,6 +133,23 @@ class ColorPicker extends Component<ColorPickerProps, ColorPickerState> {
}
}

inputContainerRef: Element | null = null

handleInputContainerRef = (el: Element | null) => {
this.inputContainerRef = el
this.setLabelHeight()
}

setLabelHeight = () => {
if (this.inputContainerRef) {
this.setState({
labelHeight:
this.inputContainerRef.getBoundingClientRect().y -
(this.inputContainerRef.parentElement?.getBoundingClientRect().y || 0)
})
}
}

componentDidMount() {
this.props.makeStyles?.({ ...this.state, isSimple: this.isSimple })
this.checkSettings()
Expand Down Expand Up @@ -591,14 +609,18 @@ class ColorPicker extends Component<ColorPickerProps, ColorPickerState> {
themeOverride={{ padding: '' }}
renderAfterInput={this.renderAfterInput()}
renderBeforeInput={this.renderBeforeInput()}
inputContainerRef={this.handleInputContainerRef}
value={this.state.hexCode}
onChange={(event, value) => this.handleOnChange(event, value)}
onPaste={(event) => this.handleOnPaste(event)}
onBlur={() => this.handleOnBlur()}
messages={this.renderMessages()}
/>
{!this.isSimple && (
<div css={this.props.styles?.colorMixerButtonContainer}>
<div
css={this.props.styles?.colorMixerButtonContainer}
style={{ paddingTop: this.state.labelHeight }}
>
<div css={this.props.styles?.colorMixerButtonWrapper}>
{this.renderPopover()}
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/ui-color-picker/src/ColorPicker/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ type ColorPickerState = {
showHelperErrorMessages: boolean
openColorPicker: boolean
mixedColor: string
labelHeight: number
}

type PropKeys = keyof ColorPickerOwnProps
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-color-picker/src/ColorPicker/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const generateStyle = (
},
colorMixerButtonContainer: {
label: 'colorPicker__colorMixerButtonContainer',
alignSelf: 'flex-end',
alignSelf: 'flex-start',
marginInlineStart: componentTheme.colorMixerButtonContainerLeftMargin
},
popoverContentContainer: {
Expand Down

0 comments on commit de420dd

Please sign in to comment.