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 all commits
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
1 change: 1 addition & 0 deletions packages/eui/changelogs/upcoming/8208.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Updated `EuiColorPalettePicker` `title` prop to support `ReactNode`.
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
Expand Up @@ -6,14 +6,17 @@
* Side Public License, v 1.
*/

import React from 'react';
import { css } from '@emotion/react';
import type { Meta, StoryObj } from '@storybook/react';

import { euiPaletteColorBlind } from '../../../services';
import { euiPaletteColorBlind, euiPaletteForStatus } from '../../../services';

import {
EuiColorPalettePicker,
EuiColorPalettePickerProps,
} from './color_palette_picker';
import { EuiText } from '../../text';

const meta: Meta<EuiColorPalettePickerProps<string>> = {
title: 'Forms/EuiColorPalettePicker/EuiColorPalettePicker',
Expand Down Expand Up @@ -48,6 +51,63 @@ export const Playground: Story = {
palette: euiPaletteColorBlind(),
type: 'fixed',
},
{
value: 'palette2',
title: 'Palette 2',
palette: euiPaletteForStatus(10),
type: 'gradient',
},
],
valueOfSelected: 'palette1',
},
};

export const CustomTitles: Story = {
argTypes: {
palettes: {
control: false,
},
},
args: {
palettes: [
{
value: 'palette1',
title: (
<div
css={({ euiTheme }) => css`
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
gap: ${euiTheme.size.xs};
`}
>
<EuiText aria-hidden="true" size="xs">
Elastic
</EuiText>
<EuiText
css={css`
text-decoration: none;
// breaks flow to prevent parent text-decoration
float: left;
clear: both;
`}
color="subdued"
size="xs"
>
Default
</EuiText>
</div>
),
palette: euiPaletteColorBlind(),
type: 'fixed',
},
{
value: 'pallette2',
title: 'Status',
palette: euiPaletteForStatus(10),
type: 'gradient',
},
],
valueOfSelected: 'palette1',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
* Side Public License, v 1.
*/

import React, { FunctionComponent, useCallback, useMemo } from 'react';
import React, {
FunctionComponent,
ReactNode,
useCallback,
useMemo,
} from 'react';

import { CommonProps } from '../../common';
import { EuiSpacer } from '../../spacer';
Expand All @@ -31,7 +36,7 @@ export interface EuiColorPalettePickerPaletteTextProps extends CommonProps {
/**
* The name of your palette
*/
title: string;
title: NonNullable<ReactNode>;
/**
* `text`: a text only option (a title is required).
*/
Expand All @@ -50,7 +55,7 @@ export interface EuiColorPalettePickerPaletteFixedProps extends CommonProps {
/**
* The name of your palette
*/
title?: string;
title: ReactNode;
/**
* `fixed`: individual color blocks
*/
Expand All @@ -69,7 +74,7 @@ export interface EuiColorPalettePickerPaletteGradientProps extends CommonProps {
/**
* The name of your palette
*/
title?: string;
title: ReactNode;
/**
* `gradient`: each color fades into the next
*/
Expand Down Expand Up @@ -127,7 +132,11 @@ export const EuiColorPalettePicker: FunctionComponent<
| EuiColorPalettePickerPaletteFixedProps
| EuiColorPalettePickerPaletteGradientProps) => {
return (
<EuiColorPaletteDisplay type={type} palette={palette} title={title} />
<EuiColorPaletteDisplay
type={type}
palette={palette}
title={typeof title === 'string' ? title : undefined}
/>
);
},
[]
Expand All @@ -153,13 +162,17 @@ 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>
{typeof title !== 'string' ? (
title
) : (
<EuiText
aria-hidden="true"
className="euiColorPalettePicker__itemTitle"
size="xs"
>
{title}
</EuiText>
)}
Comment on lines +165 to +175
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm going to be an annoying jerk here - based on Marcialis's mocks, I'd rather add new prepend/append APIs over allowing title to be a ReactNode 🙈 It has the added benefit of less string/type shenanigans, and also matching existing APIs in EuiComboBox/EuiSelectable.

<EuiSpacer size="xs" />
</>
)}
Expand Down
Loading