Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tag badge to palette picker #8208

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const palettes = [
{
value: 'pallette_1',
title: 'EUI color blind (fixed)',
tag: 'Default',
palette: euiPaletteColorBlind(),
type: 'fixed',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/eui/src/components/badge/badge.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const euiBadgeStyles = (euiThemeContext: UseEuiTheme) => {
font-weight: ${euiTheme.font.weight.medium};
white-space: nowrap;
text-decoration: none;
cursor: default;
cursor: inherit;
Copy link
Contributor Author

@nickofthyme nickofthyme Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this so that when the badge is placed inside a clickable component, such that clicking the badge will bubble up and trigger a click handler, the cursor should adopt to the parent component style by default. If the badge itself is clickable, this cursor style is overridden.

border: ${euiTheme.border.width.thin} solid transparent;
border-radius: ${mathWithUnits(
euiTheme.border.radius.medium,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { css } from '@emotion/react';

import { UseEuiTheme } from '../../../services';
import { euiFontSize } from '../../../global_styling';

export const euiPalettePickerStyles = (euiThemeContext: UseEuiTheme) => {
const euiTheme = euiThemeContext.euiTheme;

return {
euiColorPalettePicker__itemTitleGroup: css`
display: flex;
flex-direction: row;
align-items: center;
gap: ${euiTheme.size.xs};
`,

euiColorPalettePicker__itemTag: css`
font-size: ${euiFontSize(euiThemeContext, 'xs').fontSize};
`,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import {
} from '../../form/super_select'; // Note: needs to be pointed at this specific subdir for Storybook to inherit types correctly??

import { EuiColorPaletteDisplay } from '../color_palette_display';
import { EuiBadge } from '../../badge';
import { useEuiMemoizedStyles } from '../../../services';
import { euiPalettePickerStyles } from './color_palette_picker.styles';

export interface PaletteColorStop {
stop: number;
Expand All @@ -32,6 +35,7 @@ export interface EuiColorPalettePickerPaletteTextProps extends CommonProps {
* The name of your palette
*/
title: string;
tag?: never;
/**
* `text`: a text only option (a title is required).
*/
Expand All @@ -51,6 +55,10 @@ export interface EuiColorPalettePickerPaletteFixedProps extends CommonProps {
* The name of your palette
*/
title?: string;
/**
* Tag used in badge for classification
*/
tag?: string;
/**
* `fixed`: individual color blocks
*/
Expand All @@ -70,6 +78,10 @@ export interface EuiColorPalettePickerPaletteGradientProps extends CommonProps {
* The name of your palette
*/
title?: string;
/**
* Tag used in badge for classification
*/
tag?: string;
/**
* `gradient`: each color fades into the next
*/
Expand Down Expand Up @@ -118,6 +130,7 @@ export const EuiColorPalettePicker: FunctionComponent<
selectionDisplay = 'palette',
...rest
}) => {
const styles = useEuiMemoizedStyles(euiPalettePickerStyles);
const getPalette = useCallback(
({
type,
Expand All @@ -136,7 +149,7 @@ export const EuiColorPalettePicker: FunctionComponent<
const paletteOptions = useMemo(
() =>
palettes.map((item: EuiColorPalettePickerPaletteProps) => {
const { type, value, title, palette, ...rest } = item;
const { type, value, title, tag, palette, ...rest } = item;
const paletteForDisplay =
item.type !== 'text' ? getPalette(item) : null;

Expand All @@ -153,13 +166,18 @@ export const EuiColorPalettePicker: FunctionComponent<
// color_palette_display_gradient. Adding the aria-hidden attribute
// here to ensure screen readers don't speak the listbox options twice.
<>
<EuiText
aria-hidden="true"
className="euiColorPalettePicker__itemTitle"
size="xs"
>
{title}
</EuiText>
<div css={styles.euiColorPalettePicker__itemTitleGroup}>
<EuiText
aria-hidden="true"
className="euiColorPalettePicker__itemTitle"
size="xs"
>
{title}
</EuiText>
{tag && <>
<EuiBadge css={styles.euiColorPalettePicker__itemTag} color="hollow">{tag}</EuiBadge>
</>}
</div>
<EuiSpacer size="xs" />
</>
)}
Expand Down
Loading