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 append option to palette picker options #8208

Merged
merged 15 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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 = {
mgadewoll marked this conversation as resolved.
Show resolved Hide resolved
argTypes: {
palettes: {
control: false,
mgadewoll marked this conversation as resolved.
Show resolved Hide resolved
},
},
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>
)}
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
<EuiSpacer size="xs" />
</>
)}
Expand Down
Loading