-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add customization for column header (#141)
* ui customization for column header * update e2e test for dashboard scene variant * update layout and font size option * update to header: { fontSize, fontColor, backgroundColor } * update using fontSize * use separate editor for color picker * Update CHANGELOG.md * Remove unused code and apply size to header buttons * Formatting --------- Co-authored-by: Mikhail Volkov <[email protected]> Co-authored-by: asimonok <[email protected]>
- Loading branch information
1 parent
93df2bc
commit 5c5b743
Showing
19 changed files
with
500 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ponents/TableEditor/components/ColumnsEditor/components/ColorEditor/ColorEditor.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { css } from '@emotion/css'; | ||
import { GrafanaTheme2 } from '@grafana/data'; | ||
|
||
/** | ||
* Styles | ||
*/ | ||
export const getStyles = (theme: GrafanaTheme2) => { | ||
return { | ||
colorPickerContainer: css` | ||
align-items: center; | ||
`, | ||
colorPickerButtons: css` | ||
display: flex; | ||
justify-content: flex-start; | ||
align-items: center; | ||
gap: ${theme.spacing(1)}; | ||
padding: ${theme.spacing(0, 1)}; | ||
min-height: ${theme.spacing(4)}; | ||
`, | ||
}; | ||
}; |
51 changes: 51 additions & 0 deletions
51
...mponents/TableEditor/components/ColumnsEditor/components/ColorEditor/ColorEditor.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { getJestSelectors } from '@volkovlabs/jest-selectors'; | ||
import React from 'react'; | ||
|
||
import { ColorEditor, testIds } from './ColorEditor'; | ||
|
||
type Props = React.ComponentProps<typeof ColorEditor>; | ||
|
||
describe('ColorEditor', () => { | ||
/** | ||
* Selectors | ||
*/ | ||
const getSelectors = getJestSelectors(testIds); | ||
const selectors = getSelectors(screen); | ||
|
||
/** | ||
* Change | ||
*/ | ||
const onChange = jest.fn(); | ||
|
||
/** | ||
* Get component | ||
*/ | ||
const getComponent = (props: Partial<Props>) => { | ||
return <ColorEditor onChange={onChange} value={undefined} {...props} />; | ||
}; | ||
|
||
it('Should allow to change value', () => { | ||
render(getComponent({ value: '#ffffff', onChange })); | ||
|
||
expect(selectors.fieldValue()).toBeInTheDocument(); | ||
fireEvent.change(selectors.fieldValue(), { target: { value: '#000' } }); | ||
expect(onChange).toHaveBeenCalledWith('#000'); | ||
}); | ||
|
||
it('Should allow to reset value', () => { | ||
render(getComponent({ value: '#ffffff', onChange })); | ||
|
||
expect(selectors.fieldValue()).toBeInTheDocument(); | ||
expect(selectors.buttonClear()).toBeInTheDocument(); | ||
|
||
fireEvent.click(selectors.buttonClear()); | ||
expect(onChange).toHaveBeenCalledWith(undefined); | ||
}); | ||
|
||
it('Should not allow to reset value if empty', () => { | ||
render(getComponent({ value: undefined, onChange })); | ||
|
||
expect(selectors.buttonClear(true)).not.toBeInTheDocument(); | ||
}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
...or/components/TableEditor/components/ColumnsEditor/components/ColorEditor/ColorEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ColorPicker, IconButton, useStyles2 } from '@grafana/ui'; | ||
import React from 'react'; | ||
|
||
import { TEST_IDS } from '@/constants'; | ||
import { EditorProps } from '@/types'; | ||
|
||
import { getStyles } from './ColorEditor.styles'; | ||
|
||
/** | ||
* Properties | ||
*/ | ||
interface Props extends EditorProps<string | undefined> { | ||
/** | ||
* Test ID | ||
* | ||
* @type {string} | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
'data-testid'?: string; | ||
} | ||
|
||
/** | ||
* Test Ids | ||
*/ | ||
export const testIds = TEST_IDS.colorEditor; | ||
|
||
/** | ||
* Color Editor | ||
*/ | ||
export const ColorEditor: React.FC<Props> = ({ onChange, value, ...restProps }) => { | ||
/** | ||
* Styles | ||
*/ | ||
const styles = useStyles2(getStyles); | ||
|
||
return ( | ||
<div className={styles.colorPickerButtons}> | ||
<ColorPicker | ||
color={value || 'transparent'} | ||
onChange={(color) => { | ||
onChange(color); | ||
}} | ||
{...(restProps['data-testid'] ? { 'data-testid': restProps['data-testid'] } : testIds.fieldValue.apply())} | ||
/> | ||
{value && ( | ||
<IconButton | ||
name="times" | ||
size="md" | ||
variant="secondary" | ||
tooltip="Clear" | ||
onClick={() => onChange(undefined)} | ||
{...testIds.buttonClear.apply()} | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
...lesEditor/components/TableEditor/components/ColumnsEditor/components/ColorEditor/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ColorEditor'; |
Oops, something went wrong.